How to get Exchange server current datetime using ExchanceService api? - c#

I stumbled with a legacy application in C# that creates an item, saves it, fetches the creation date and deletes it right after, using ExchangeService api. All this to simply get the current server time.
There's gotta be a better way of doing this, but I went through all the online docs and did a few searches about it and couldn't find anything.
So, simple question: how to fetch Exchange server current datetime using C#?
Thanks in advance.

Where is the application running ? eg if its running on the server or any domain connected machine then querying the time from the Exchange server should be redundant. Eg Windows servers within a Domain should sync there time via Windows time service https://learn.microsoft.com/en-us/windows-server/networking/windows-time-service/how-the-windows-time-service-works. And usually you would setup a DC to sync the time from NTP so every machine should have same time (in theory).
The Exchange API's don't have an time methods but any request to an Exchange server should return the Date Header in the Response headers as it a mandatory property in Http https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.18

Related

mobile application using xamarin forms and Azure SQL Database

I have built a mobile application using Xamarin forms and my application works fine for 3 days i.e it pulls the data from Azure database exactly how I wanted but on 4th day it only pulls 1 item even though there are many. Any idea what is causing problem. I am confused where exactly the problem is, whether with Xamarin part or database part.
I have built a mobile application using Xamarin forms and my application works fine for 3 days i.e it pulls the data from Azure database exactly how I wanted but on 4th day it only pulls 1 item even though there are many.
AFAIK, when using offline sync, you could invoke the PullAsync without pass the query ID, then all records would be retrieved from your remote table. While if you specific the query ID, the mobile SDK would perform the incremental sync. For more details, you could refer to here.
I would recommend you use fiddler to capture the network traces when you pull the data in your mobile client. Moreover, you could call the Http table API via postman or the browser for retrieving the data from your remote table as follows to narrow this issue:
Get https://{your-appname}.azurewebsites.net/tables/{table-name}?ZUMO-API-VERSION=2.0.0
Note: If you enable the authentication, you need to specific the x-zumo-auth header with the value via MobileServiceClient.CurrentUser.MobileServiceAuthenticationToken after you invoked the MobileServiceClient.LoginAsync for logging. Moreover, there has the max page size up to 50 for a single GET operation.
Additionally, you need to make sure your remote table records have not been marked as deleted. If you still could not locate this issue, you could update your question with the code snippet to pull the data and the detailed network traces when calling the pull operation.
Here are some useful tutorials, you could refer to them:
30 DAYS OF ZUMO.V2 (AZURE MOBILE APPS): DAY 13 – THE HTTP TABLE INTERFACE
Chapter 3 - Data Access and Offline Sync
The recommended way to connect to the database is using an API that will manage the interaction with the database. The mobile application should consume that API. Try using a .NET API. That should solve the issue.
If you want your application to operate offline also, you can retrieve data using the API and then store it locally using SQLLite, Realm, or Azure Easy Table. Azure Easy Table is the easiest way to do it. Realm is gaining a lot of adoption.
Hope this helps.

How to get an ApplicationServiceHost instance with TFS 2013's Server Object Model?

I spent a lot of time looking how to get an instance of a ApplicationServiceHost with TeamFoundation 12.0 (TFS 2013) using the TFS Server Object Model... This class used to be in Microsoft.TeamFoundation.Framework.Server.dll within TeamFoundation 10.0. But I don't find how to get it with TeamFoundation 12.0.
I need to use the Server Object Model as I want to access the Queued Jobs of TFS (using the method QueryJobQueue of the Server Job Service), a method not available Client side.
Using the Server Object Model of TFS 2010, one could do something like:
var applicationHost = new ApplicationServiceHost(
Guid.Empty,
applicationDatabaseConnectionString,
"unused",
Path.Combine(toolPath, "Plugins"),
"/tfs",
true);
But I cannot figure out how to do it concretely with the Server Object Model 12.0. According to MSDN, I should get first a TeamFoundationServiceHost (Application or Collection) and use its property ApplicationServiceHost. But how can I get such a TeamFoundationServiceHost programmaticaly ?
Once I can get such an instance, I will use the C# Server OM code sample from here to access the job service from a console application. The purpose is to check if any Backup job is running before rebooting the TFS server and give Windows' patches a chance to be applied...
If you're just wanting to know if a backup is running, then you'd probably want to use the client API, not the server API. The server API is intended for plugins such as server side event subscriptions (ISubscriber interface) and custom jobs for the job agent to run.
Unfortunately, as you've probably found, the client API can list all the job definitions and you can look at job history, but you can't see the job queue itself or wether a job is running.
So, what to do?
If you just want to know if there are no backups running before you can reboot and you're OK checking things manually you can look at the job agent status via the operations interface by browsing to http://yourserver:8080/tfs/_oi/
If you want to detect things via code then it might be worth a look at what calls the Job Queue page is making under the hood using your browser developer tools (i.e. the F12 tools). You'll see calls to the http://yourserver:8080/tfs/_oi/_monitoring/GetJobQueue API. If you call that API via code you should be able to see if there are any InProgress jobs.
Note: the API is undocumented so you might need to experiment a little to determine the right parameters for the call.

Only update data in local database from web service if the data is new

I have coded a C# Web API 2 web service, and am wanting to retrieve this data in an android application that I have coded.
I wish to have a local SQL database on my android device that stores the data from the web service.
Whenever data is to be used in my android application, I wish to check to see if the local database data is the most up to date, and if it isn't, then I wish to retrieve the latest data from the web service.
I am thinking of the following:
Each time data is saved into the local database, save an integer value as an update number.
Whenever data is required, retrieve the latest update number from the local database, send a request to the web service with this update number, and only return data if the web service data has a newer update number.
Would this work well? Is there a better approach to this problem than my above idea? Are there any disadvantages or errors that could occur?
Thanks in advance.
I did exactly same thing with my synchronization algorithm. It's like this.
My web service methods gets datetime parameters, web service sends objects only created or modified after that time.
On the mobile side, I keep synchronization start time, and for the each synchronization, i send previous sync start time. (By the way, I ask date to server just before sync starts)
I dont keep sync end time, because some of the data may be modified after sync started.
I have done similar thing in my sync adapter where user click on sync and it get data from web feeds and store only updated data into sqlite.
refer to SyncAdapter.java file of sync adapter sample provided on http://developer.android.com/training/sync-adapters/creating-sync-adapter.html

Time-based notifications on Windows Azure

I have been building a Windows Phone 8 app and Windows Azure cloud service that will allow people to store schedules in the cloud. I have implemented a single sign on system and a cloud service used to store the schedule items.
I have also started building a cloud service to send push notifications however the plan is to send notifications based on scheduled times that have been stored in the cloud, the notification system works however only if I send a notification with a tester application.
Does anyone know how to send notifications based on a time record in an SQL database on Azure?
Thanks
As far as i understand you want a user to make a todoitem with a timestamp.?
If this is true, you could do it in some different ways. The easiest and most expensive is to only use azure. Then you need to use azure scheduler, to compare a time stamp with the current time and when the current time exceeds the time stamp, you send a push notification.
A cheaper way is to have an old pc, where you install server capabilities and go to the server and check the database with the time stamp. And then invoke a server api when you have a match.
But be aware of timezones :)
A link about timestamp in Azure tables
How to use Windows Azure Table Storage Timestamp or Etag field
Are you referring to the Azure Scheduler in Mobile Services?
Check out this link.
Otherwise I believe you'd need to have a service running that will run a task on scheduled times and occasionally poll the database for new times to run (pretty simple to do. Sounds like you probably have most of that already).

sending email notifications for future dates in asp.net 3.5

I want to develop an Online Reminder service in ASP.NET 2.0 (C#) and SQL2005. But I am not getting the concept of reminder service. What I know is using an online reminder service I can schedule a reminder for future dates, which is sent to me (who schedule reminder) via email or SMS on that date. But in asp.net how to do this, caz anyone can schedule a reminder for any date, how we'll know that when to send that mail to the person. We have to put some loop or what.
So please guide me, what is the concept of an online reminder service and how I can easily develop this application using ASP.NET and SQL
Edited
I am on Shared hosting server, so that solution must be able to work on shared hosting.
Or
Please tell me if anyone knows about any FREE and open-source reminder service CMS which I can download and study it.
Microsoft SQL Server 2005 have scheduling (sql jobs) and email features. You may even donot need to use ASP.NET.
Ideally, you would have a windows service that would periodically (every few minutes) check if any new reminders need to be sent out. Since you are on shared hosting, you probably can't install a service though.
I'm not very familiar with windows shared hosting, but if you have the option of creating scheduled/cron job type tasks you could probably do it that way.
If you can't create a scheduled task on your server, another option would be to create a scheduled task on your home PC with a program/script that runs every few minutes and simply hits a special web page on your site. That page could then have the code that checks for reminders and sends them out. It's a bit of a hack, but it should work.
Have a look at Quartz.Net (http://quartznet.sourceforge.net/). You can create an instance of the quartz scheduler in your Application_Start event and as long as the ASP.Net application is running, it will poll the database and trigger any functions you have registered with it. Since you are on a shared host environment, this is probably your best bet unless your hosting provider has a scheduler that can trigger a WebForm (or ASP.Net MVC Controller) periodically.
First you will obviously need to create a user interface and database to store the reminders. That part you got. The next step is to create a service which periodically queries the database for reminders that are due for notification.
The best way to do this is to write a lightweight Windows Service which, as you suggest, uses a loop and a reasonable sleep time (so as not to monopolize the CPU) to continually check the database for reminders and dispatches notifications. It then processes each reminder based on your requirements.
But since you are on shared hosting, you can't deploy a Windows Service, so the next best thing is to run a background thread on Application_Start of your global.asax. There are many examples of how to do this, e.g.:
http://www.west-wind.com/WebLog/posts/67557.aspx
What are some best practices for managing background threads in IIS?
Shared hosting will not work well with what you are trying to do. You could create a background polling thread on Application start, but it will get shut down at some point and may actually be prohibited by your hosting company. An infinite loop will most likely be detected by your hoster and result in your account being automatically shut down, especially if it is using a fair bit of CPU. As John suggests, there may be a scheduled tasks or hosted cron option with your ISP, but generally, those are just for doing things like nightly backups, not really having the level of granularity you need.
Simple answer is, you most likely need something other than a hosted account. You may need to look into a VPS shared hosting service or you may wish to consider looking into MS Azure or Amazon EC2. To do this right, you need to create an application, or better, a service that runs constantly, something a shared hosting account will not provide.
There also a few services out there who can call a specific web page on your service periodically. You could use that to make the page check if there are any reminders that need to be sent.
However since you're then relying on an external site you can't control this might not be the ideal solution if it is very important that the reminders are always being sent.
1) Create a database for storing messages, with a datestamp
2) Create an SQL job, that selects all messages in a time period
3) From the SQL job, you can initialize an .net based SQL Function, that would send out the emails with the System.Net.Mail namespace.
You might consider a 'hack' using the Cache expiration in for triggering events. Create new cache keys that expire at specific Date-Times to run the reminder or make it recur at defined intervals, checking a queue to see if anything new should be sent.
See:
Easy Background Tasks in ASPNET

Categories

Resources