I set appointment in MS Exchange from ASP.NET MVC application.
When i run code from my computer in Ukraine - everyghing is ok,
but when I deploy my code on server in Russia - it shows:
The specified time zone isn't valid.
I tried a lot of things but can't fix that. Please help me with this issue.
I use:
Appointment appointment = new Appointment(service);
appointmet.Start;
If some people just come accross the same issue, it has been reported as an issue in EWS api (cf https://github.com/OfficeDev/ews-managed-api/issues/13) but seems most likely an issue in .NET's TimeZoneInfo parsing logic. An update of your .Net version might fix it.
This worked for me:
static TimeZoneInfo getCorrectTimeZone()
{
return TimeZoneInfo.CreateCustomTimeZone("Time zone to workaround a bug", TimeZoneInfo.Local.BaseUtcOffset, "Time zone to workaround a bug", "Time zone to workaround a bug");
}
static ExchangeService getExchangeService()
{
var service = new ExchangeService(ExchangeVersion.Exchange2010_SP2, getCorrectTimeZone());
return service;
}
Related
I'm using Azure Forecast Cost Management API to try to retrieve the forecast cost shown in the azure portal like below.
This is the API I'm using -> https://learn.microsoft.com/en-us/rest/api/cost-management/forecast/usage?tabs=HTTP
This is my request body looks like
{
"Dataset": {
"Aggregation": {
"TotalCost": {
"Function": "Sum",
"Name": "Cost"
}
},
"Granularity": "Monthly"
},
"TimePeriod": {
"From": "2023-02-01",
"To": "2023-02-28"
},
"Timeframe": "Custom",
"Type": "Usage"
}
Everything is working if i did the request not in the 1st day of month. But when i make a request to API in 1st day of month, the request is success and the API give me a response, but i can't find any information related to forecast cost amount.
I can see the forecast cost from the Azure portal, so i believe there must be a way to retrieve the data. Help me please?
Thanks.
I have try to modify the timeframe, granularity, and others in the request body. But still can't get the data.
Check the datetime you are using is the same as what is being used on Azure for the service/plan/account or whatever, these can differ on both sides.It could also be that Azure requires the datetime in GMT or a US format.
So it may be that your request is being read as last month, but azure is only providing data for this in the upcoming month.
To test this try switching to prior dates and see if any dates in the past give you the same data as what you are getting on the 1st. If so I would say that is what is happening.
The fact it only occurs on the first but the data is available in the portal would indicate to me it is definitely something to do with the timezone, but I could be wrong.
Personally I use Azure Cost Management connector in Power BI Desktop to retrieve the data. I scheduled a daily refresh and I never had problems.
I know for sure that there are problems with calculation in the early days of the month and I have a colleague that withdraw the last month after the first week.
I suggest you to open a ticket with the Azure Billing support.
Here comes the interesting issue. I want to know any settings makes this difference or any workaround to get it right.
We have different Dynamics 365 CRM online instances but all are identical as they are refreshed from Prod. Recently developed plugin code behaves differently across the environments.
var organizers = (EntityCollection)appointment["organizer"];
Entity record = organizers.Entities[0];
EntityReference organizer = (EntityReference)record["partyid"];
On appointment creation, the post-create async plugin code read the organizer - one of the activity party field but the result is very different. Though systemuserid is identical, the name is coming from that entity reference properly in Dev but coming as null in other environments.
That is a strange problem indeed. If you hadn't refreshed the other orgs from PROD, I would say maybe there's a different image registered in the plugin registration.
Since the code, environment, plugin registrations, and even record ID are the same, this one might be worth a Microsoft support ticket.
In the meantime, a workaround would be to check if Name is null, and if so, retrieve the Name. It's another call to the system, but will allow you to proceed while you see if Microsoft can offer any insight.
MS agreed this as a bug, but actually this context difference is identified between the classic web UI & the UCI. Only for appointment entity, because of some oData response known issue - UCI target entity is missing the formatted values.
I got the plugin profiler log from my QA team so I didn't realize they were testing in UCI but I tested in web, so the quick watch showed the difference while replay/debugging.
Anyway until MS prioritize & fix this bug, I have the below workaround to unblock this issue.
#region Workaround for fixing UCI app EntityReference coming as empty string
if (string.IsNullOrEmpty(organizer.Name))
{
ctLog.Log("organizer.Name is empty");
fetch = string.Format(#"<fetch>
<entity name='systemuser' >
<attribute name='fullname' />
<filter type='and' >
<condition attribute='systemuserid' operator='eq' value='{0}' />
</filter>
</entity>
</fetch>", organizer.Id);
ctLog.Log("fetch built");
results = userOrgService.RetrieveMultiple(new FetchExpression(fetch));
ctLog.Log("results count: " + results.Entities.Count);
if (results.Entities.Count > 0)
{
organizer.Name = results.Entities[0].GetAttributeValue<string>("fullname");
}
}
#endregion
I am using ASP MVC 4.5. I have view to input payment details. I use C# to get current time when user input payment. But after hosting it on server, i found a hot error. It gets another dateTime (may be my server's time) instead of my user's local time!
I want to get user's current time using C#. Should i use C# or javascript?
I think it is easy to get user's time using javascript. But i want to use C# for this. Can you help me?
My web API:
// POST api/PaymentApi
public HttpResponseMessage PostPayment(Payment payment)
{
if (ModelState.IsValid)
{
var mem= db.Members.Where(m => m.MemberID.Equals(payment.MemberID)).FirstOrDefault();
if (mem ==null)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
}
payment.Date = DateTime.Now;
db.Payments.Add(payment);
db.SaveChanges();
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, payment);
response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = payment.PaymentID }));
return response;
}
else
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
}
}
I used payment.Date = DateTime.Now.ToLocalTime(); also but not worked!
Many of here answered to use javascript date. That's why i used it. But javascript sends a datetime and my WebApi makes it slightly different.
Javascript: Date:Tue Dec 27 2016 11:04:12 GMT+0600 (Local Standard Time)
C#: Date:{27/12/2016 05:04:12}
It's impossible to get client DateTime at server-side if client is not sending it by itself.
You'll need to get the local date time in javascript and pass it to the server. I recommend you to use ISO8601 format.
DateTime works with local host's clock, e.g. the server. Most payments systems save the dates as relative to UTC, to avoid client/server time differences.
payment.Date = DateTime.UtcNow;
There isn't any way to know the user Local time from the server. What you need to do is send the local time from the client to the server inside the request in UTC format.
Javascript(requires Jquery):
var UTC = new Date().getTime();
For a project I have to sync hours from an external program to EPM. There is no requirement to use the Client Side Object Model of EPM 2013 or the PSI. But because Microsoft recommends the CSOM on their website for all new applications I tried to implement it with the CSOM. The first thing I wanted to test is to get all the hours, with the following code: (It isn't the most beautiful code because it is for testing purposes)
private static void GetTimesheets()
{
ProjectContext projContext = new ProjectContext("http://tfspsdemo/PWA/");
projContext.Load(projContext.TimeSheetPeriods);
projContext.ExecuteQuery();
foreach (var period in projContext.TimeSheetPeriods)
{
projContext.Load(period.TimeSheet);
projContext.ExecuteQuery();
Console.WriteLine(period.Name);
try
{
string tempName = period.TimeSheet.Name;
projContext.Load(period.TimeSheet.Lines);
projContext.ExecuteQuery();
Console.WriteLine(period.TimeSheet.Name);
foreach (var line in period.TimeSheet.Lines)
{
try
{
projContext.Load(line);
projContext.Load(line.Work);
projContext.ExecuteQuery();
foreach (var workLine in line.Work)
{
Console.WriteLine(workLine.ActualWork);
}
}
catch (Exception) { }
Console.WriteLine("Total: {0}", line.TotalWork);
}
}
catch (ServerObjectNullReferenceException) { }
}
}
But with above code I get only the code for the current user that is logged in, even if it is a person with rights to see other users hours. But what I want is to see all the hours of all the persons that have booked hours in EPM for a specific project plan. So I can later use this information to sync the hours from an external program to EPM. I thought I can solve this with impersonation but:
ProjectContext projContext = new ProjectContext("http://tfspsdemo/PWA/");
projContext.Credentials = new NetworkCredentials("username", "password");
But this isn't what I want because I have to do this for each user. And also I can't get the passwords of all users.
Does anyone now a solution to solve this problem and/or any suggestions? Solutions with the EPM PSI are also appreciated!
Thanks in advance!
Impersonation is not yet implemented in Project Sever 2016/Project Online. Please vote here: https://microsoftproject.uservoice.com/forums/218133-microsoft-project/suggestions/32981722-impersonation-support-for-csom-to-read-other-user
Thanks,
Werner
There are two modes in Proect server 2013. Proect server and SharePoint mode. I was able to get the above working in SharePoint mode, but alas I cannot read even Timesheet Periods as it says CSOMUnkownUser in Project server mode even after passing in the credentials. What mode are you running in currently on the server
This is probably a little late, but to access that kind of data in a provider/auto hosted app you need to access the sharepoint server through OData. CSOM is only intended to provide data from the current user context.
Using OAuth I do get access token from Google. The sample that comes with Google and even this one:
http://code.google.com/p/google-api-dotnet-client/source/browse/Tasks.SimpleOAuth2/Program.cs?repo=samples
show how to use Tasks API. However, I want to use Calendar API. I want to get access to user's calendar. Can anybody tell me how do I do that?
Take a look at the samples:
Getting Started with the .NET Client Library
On the right side of the page linked above there is a screen shot showing the sample projects contained in the Google Data API solution. They proofed to be very helpful (I used them to start my own Google Calendar application).
I recommend keeping both your own solution and the sample solution open. This way you can switch between the examples and your own implementation.
I also recommend to use the NuGet packages:
Google.GData.AccessControl
Google.GData.Calendar
Google.GData.Client
Google.GData.Extensions
and more ...
This way you easily stay up to date.
Sample to get the users calendars:
public void LoadCalendars()
{
// Prepare service
CalendarService service = new CalendarService("Your app name");
service.setUserCredentials("username", "password");
CalendarQuery query = new CalendarQuery();
query.Uri = new Uri("https://www.google.com/calendar/feeds/default/allcalendars/full");
CalendarFeed calendarFeed = (CalendarFeed)service.Query(query);
Console.WriteLine("Your calendars:\n");
foreach(CalendarEntry entry in calendarFeed.Entries)
{
Console.WriteLine(entry.Title.Text + "\n");
}
}