Android calendar that pulls data from a server - is there any api's or plgins for - dynamic

Android calendar that pulls data from a server - is there any api's or SDK that would help with this.
Basically i have a site and want to add events to the calender in my app.. I haven't got the calender setup but will do..
I would like to dynamically pull data from my website or server..
Does anyone know of any resource or utorials on this that could help me in my quest for solving this..
any help appreciated..
I currently use libGDX framework for my apps if this help at all.
Best

You would need a way to access the database in your server, for example using PHP and MySql:
http://php.net/manual/en/book.mysqli.php
Then from libgdx a HttpRequest would work. Its the basics at least.
HttpRequest request = new HttpRequest(HttpMethods.GET);
request.setUrl("http://domainname.com/path/phpfile.php?argument=value");
Gdx.net.sendHttpRequest(request, new HttpResponseListener(){
#Override
public void handleHttpResponse(HttpResponse httpResponse){
Gdx.app.log("HttpRequestExample", "response: " + httpResponse.getResultAsString());
}
#Override
public void failed(Throwable t){
Gdx.app.error("HttpRequestExample", "something went wrong", t);
}
});

Related

How can I dynamically generate robots.txt correctly?

I have several sites, all of them have the same robots.txt.
When I modify one I have to modify others. That so troubles some.
I have an idea that generated robots.txt by back-end code. The back-end will get the data from a remote server by WEB API and generate it.
Here is the code from a tutorial in StackOverflow:
public class OthersController: Controller
{
[Route("/robots.txt")]
public ContentResult RotbotsTXT()
{
String Result=///some code get robots data from remote server.
return this.Content(Result, "text/plain", Encoding.UTF8);
}
}
In spite, it works well on the browser.
However, I met a strange situation.
Some spiders access the route correctly but can not detect it(for example Baidu spider).
And also, some spiders(for example Google bot) will strangely access route www.abc.com//robots.txt (the robots.txt never store in here) but not www.abc.com/robots.txt.
After return to the old way by creating a TXT file, all problems are clear.
What's wrong with my code? How can I solve it? Thank you.
Change [Route("/robots.txt")] to [Route("robots.txt")] like this:
public class OthersController: Controller
{
[Route("robots.txt")]
public ContentResult RobotsTXT()
{
String Result=///some code get robots data from remote server.
return this.Content(Result, "text/plain", Encoding.UTF8);
}
}

Send data to a REST API every time a new account is added to Salesforce

Sorry for the total newbie question here regarding triggers, but here is my scenerio:
What are some of the options available to send data to a 3rd party REST API every time a new account is added to Salesforce?
I have been initially looking at code examples for triggers on account after insert. In addition to this, is there a way using the SFDC streaming API? Any ideas on What API usage is best practice + code examples would be much appreciated.
Thanks in advance!
To be able to make callout from a trigger you need to make the callout asynchronous (using #future annotation) .
For example :
trigger AfterInsertAccount on Account (after insert){
futCls.asynchCallout(); //call a method with #future annotation
}
Class Code :
global futCls {
#future
Public static void asynchCallout(callout=true){
HttpRequest req = new HttpRequest();
req.setEndpoint('your 3rd party service URL goes here');
req.setMethod('GET');
Http http = new Http();
HTTPResponse res = http.send(req);
}
}
For more information refer to SFDC documentation.

SharpArch.Core.PreconditionException

I get this:
"A storage mechanism has already been configured for this application"
The thing is - I already have another s#arp archtecture web app successfuly running on the server - could this be the problem?
I have this:
private void InitializeNHibernateSession()
{
NHibernateSession.Init(
webSessionStorage,
new string[] { Server.MapPath("~/bin/Bla.Data.dll") },
new AutoPersistenceModelGenerator().Generate(),
Server.MapPath("~/NHibernate.config"));
}
which should be ok.
Thanks!
Christian
I had a similar issue. Try to run iisreset command
i move my app from work to home regularly. i get this error all the time when changing connection strings. in my case i just need to recompile. recompiling your app doesn't fix the problem?

Read Installed Device Driver Details (version, install date, path etc), on Win system

Can anyone help please in this regard ?
What API's can be used from win32 to get installed device drivers details like
version, installation date, path where installed ?
Regards,
Kedar
The best way is WMI, .NET supports it well with the System.Management namespace. You'll want to use the Win32_SystemDriver WMI class. I copied and pasted this code from WMICodeCreator, a great tool to experiment and auto-generate the code you need:
using System;
using System.Management; // Project + Add Reference required
public class MyWMIQuery {
public static void Main() {
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_SystemDriver");
foreach (ManagementObject queryObj in searcher.Get()) {
Console.WriteLine("Driver caption: {0}", queryObj["Caption"]);
}
Console.ReadLine();
}
}
Check out the links I left in this post, Win32_SystemDriver has many other properties beyond "Caption".
You need to consult the Setup API function for driver information.
I recently did something similar (Win32 via .NET). Here are some links that helped me:
http://www.codeproject.com/KB/system/SimpleSetup.aspx
http://www.pinvoke.net/default.aspx/setupapi/SetupDiGetDeviceRegistryProperty.html
http://www.codeguru.com/forum/showthread.php?t=360567

Disable (Politely) a website when the sql server is offline

I work at a college and have been developing an ASP.NET site with many, many reports about students, attendance stats... The basis for the data is an MSSQL server DB which is the back end to our student management system. This has a regular maintenance period on Thursday mornings for an unknown length of time (dependent on what has to be done).
Most of the staff are aware of this but the less regular users seem to be forever ringing me up. What is the easiest way to disable the site during maintenance obviously I can just try a DB query to test if it is up but am unsure of the best way to for instance redirect all users to a "The website is down for maintenance" message, bearing in mind they could have started a session prior to the website going down.
Hopefully, something can be implemented globally rather than per page.
Drop an html file called "app_offline.htm" into the root of your virtual directory. Simple as that.
Scott Guthrie on the subject and friendly errors.
I would suggest doing it in Application_PreRequestHandlerExecute instead of after an error occurs. Generally, it'd be best not to enter normal processing if you know your database isn't available. I typically use something like below
void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
{
string sPage = Request.ServerVariables["SCRIPT_NAME"];
if (!sPage.EndsWith("Maintenance.aspx", StringComparison.OrdinalIgnoreCase))
{
//test the database connection
//if it fails then redirect the user to Maintenance.aspx
string connStr = ConfigurationManager.ConnectionString["ConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(connStr);
try
{
conn.Open();
}
catch(Exception ex)
{
Session["DBException"] = ex;
Response.Redirect("Maintenance.aspx");
}
finally
{
conn.Close();
}
}
}
You could display a message to people who have logged in saying "the site will be down for maintenance in xxx minutes" then run a service to log everyone out after xxx minutes. Then set a flag somewhere that every page can access, and at the top of every page(or just the template page) you test if that flag is set, if it is, send a redirect header to a site is down for maintenance page.
What happens now when the site is down and someone tries to hit it? Does ADO.NET throw a specific exception you could catch and then redirect to the "website down" page?
You could add a "Global.asax" file to the project, and in its code-behind add an "Application_Error" event handler. It would fire whenever an exception is thrown and goes uncaught, from anywhere in your web app. For example, in C#:
protected void Application_Error(object sender, EventArgs e)
{
Exception e = Server.GetLastError().GetBaseException();
if(e is SqlException)
{
Server.ClearError();
Server.Transfer("~/offline.aspx");
}
}
You could also check the Number property on the exception, though I'm not sure which number(s) would indicate it was unable to connect to the database server. You could test this while it's down, find the SQL error number and look it up online to see if it's specifically what you really want to be checking for.
EDIT: I see what you're saying, petebob.
The "offline.html" page won't work if the user was already navigating within the site, or if he's accessing the site from a bookmark/external link to a specific page.
The solution I use is to create a second web site with the same address (IP or host header(s)), but have it disabled by default. When the website is down, a script deactivates the "real" web site and enables the "maintenance" website instead. When it comes back online, another script switches back to the "real" web site.
The "maintenance" web site is located in a different root directory, with a single page with the message (and any required images/css files)
To have the same message shown on any page, the "maintenance" web site is set up with a 404 error handler that will redirect any request to the same "website is down for maintenance" page.
A slightly more elegant version of the DB check on every page would be to do the check in the Global.asax file or to create a master page that all the other pages inherit from.
The suggestion of having an online site and an offline site is really good, but only really applicable if you have a limited number of sites to manage on the server.
EDIT: Damn, the other answers with these suggestions came up after I loaded the page. I need to remember to refresh before replying :)
James code forgets to close the connection, should probably be:
try
{
conn.Open();
}
catch(Exception ex)
{
Session["DBException"] = ex;
Response.Redirect("Maintenance.aspx");
}
finally
{
conn.Close();
}
Thanks for the replies so far I should point out I'm not the one that does the maintenance nor does I have access all the time to IIS. Also, I prefer options where I do nothing as like all programmers I am a bit lazy.
I know one way is to check a flag on every page but I'm hoping to avoid it. Could I not do something with the global.asax page, in fact, I think posting has engaged my brain:
Think I could put in Application_BeginRequest a bit of code to check the SQL state then redirect:
HttpContext context = HttpContext.Current;
if (!isOnline())
{
context.Response.ClearContent();
context.Response.Write("<script language='javascript'>" +
"top.location='" + Request.ApplicationPath + "/public/Offline.aspx';</scr" + "ipt>");
}
Or something like that may not be perfect not tested yet as I'm not at work. Comments appreciated.