/// <summary> /// Create and configure the organization service proxy. /// Retrieve the working hours of multiple users. /// Optionally delete any entity records that were created for this sample. /// </summary> /// <param name="serverConfig">Contains server connection information.</param> /// <param name="promptforDelete">When True, the user will be prompted to delete all /// created entities.</param> public void Run(ServerConnection.Configuration serverConfig, bool promptForDelete) { try { // Connect to the Organization service. // The using statement assures that the service proxy will be properly disposed. using (_serviceProxy = ServerConnection.GetOrganizationProxy(serverConfig)) { // This statement is required to enable early-bound type support. _serviceProxy.EnableProxyTypes(); // Call the method to create any data that this sample requires. CreateRequiredRecords(); //<snippetQueryWorkingHoursOfMultipleUsers1> // Retrieve the working hours of the current and the other user. QueryMultipleSchedulesRequest scheduleRequest = new QueryMultipleSchedulesRequest(); scheduleRequest.ResourceIds = new Guid[2]; scheduleRequest.ResourceIds[0] = _currentUserId; scheduleRequest.ResourceIds[1] = _otherUserId; scheduleRequest.Start = DateTime.Now; scheduleRequest.End = DateTime.Today.AddDays(7); scheduleRequest.TimeCodes = new TimeCode[] { TimeCode.Available }; QueryMultipleSchedulesResponse scheduleResponse = (QueryMultipleSchedulesResponse)_serviceProxy.Execute(scheduleRequest); // Verify if some data is returned for the availability of the users if (scheduleResponse.TimeInfos.Length > 0) { Console.WriteLine("Successfully queried the working hours of multiple users."); } //</snippetQueryWorkingHoursOfMultipleUsers1> } } // Catch any service fault exceptions that Microsoft Dynamics CRM throws. catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> ) { // You can handle an exception here or pass it back to the calling method. throw; } }
[STAThread] // Added to support UX static void Main(string[] args) { CrmServiceClient service = null; try { service = SampleHelpers.Connect("Connect"); if (service.IsReady) { #region Sample Code ////////////////////////////////////////////// #region Set up SetUpSample(service); #endregion Set up // Retrieve the working hours of the current and the other user. QueryMultipleSchedulesRequest scheduleRequest = new QueryMultipleSchedulesRequest(); scheduleRequest.ResourceIds = new Guid[2]; scheduleRequest.ResourceIds[0] = _currentUserId; scheduleRequest.ResourceIds[1] = _otherUserId; scheduleRequest.Start = DateTime.Now; scheduleRequest.End = DateTime.Today.AddDays(7); scheduleRequest.TimeCodes = new TimeCode[] { TimeCode.Available }; QueryMultipleSchedulesResponse scheduleResponse = (QueryMultipleSchedulesResponse)service.Execute(scheduleRequest); // Verify if some data is returned for the availability of the users if (scheduleResponse.TimeInfos.Length > 0) { Console.WriteLine("Successfully queried the working hours of multiple users."); } } #endregion Demonstrate else { const string UNABLE_TO_LOGIN_ERROR = "Unable to Login to Dynamics CRM"; if (service.LastCrmError.Equals(UNABLE_TO_LOGIN_ERROR)) { Console.WriteLine("Check the connection string values in cds/App.config."); throw new Exception(service.LastCrmError); } else { throw service.LastCrmException; } } } catch (Exception ex) { SampleHelpers.HandleException(ex); } finally { if (service != null) { service.Dispose(); } Console.WriteLine("Press <Enter> to exit."); Console.ReadLine(); } }