public RescheduleResponse Any(RescheduleRequest request)
        {
            Scheduler.GetJobDetail(new JobKey(request.JobKey));
            Scheduler.RescheduleJob(new TriggerKey(request.TriggerKey), CreateTrigger(request.Task));

            Console.WriteLine("Job Rescheduled " + request.JobKey + " To " + request.Task.Expression + " At " + DateTime.Now);
            return(new RescheduleResponse());
        }
        public void Reschedule <T>(RescheduleRequest <T> request) where T : IJob
        {
            var job = _jobs.FindJob <T>();

            if (job != null)
            {
                Schedule(job, request.NextTime);
            }
        }
        /// <summary>
        /// <c>Reschedule</c> an appointment.
        /// <para>
        /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.reschedulerequest(v=crm.7).aspx
        /// </para>
        /// </summary>
        /// <param name="appointmentId"></param>
        /// <param name="start">Start time</param>
        /// <param name="end">End time</param>
        /// <returns>
        /// <see cref="RescheduleResponse"/>
        /// </returns>
        public RescheduleResponse Reschedule(Guid appointmentId, DateTime start, DateTime end)
        {
            ExceptionThrow.IfGuidEmpty(appointmentId, "appointmentId");
            ExceptionThrow.IfEquals(start, "start", DateTime.MinValue);
            ExceptionThrow.IfEquals(start, "start", DateTime.MaxValue);
            ExceptionThrow.IfEquals(end, "end", DateTime.MinValue);
            ExceptionThrow.IfEquals(end, "end", DateTime.MaxValue);

            Entity target = new Entity("appointment");

            target["activityid"]     = appointmentId;
            target["scheduledstart"] = start;
            target["scheduledend"]   = end;

            RescheduleRequest request = new RescheduleRequest()
            {
                Target = target
            };

            return((RescheduleResponse)this.OrganizationService.Execute(request));
        }
示例#4
0
        [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
                    #region Demonstrate

                    // Retrieve the individual appointment instance that falls on or after
                    // 10 days from today. Basically this will be the second instance in the
                    // recurring appointment series.

                    QueryExpression instanceQuery = new QueryExpression
                    {
                        EntityName = Appointment.EntityLogicalName,
                        ColumnSet  = new ColumnSet
                        {
                            Columns = { "activityid", "scheduledstart", "scheduledend" }
                        },
                        Criteria = new FilterExpression
                        {
                            Conditions =
                            {
                                new ConditionExpression
                                {
                                    AttributeName = "seriesid",
                                    Operator      = ConditionOperator.Equal,
                                    Values        = { _recurringAppointmentMasterId }
                                },
                                new ConditionExpression
                                {
                                    AttributeName = "scheduledstart",
                                    Operator      = ConditionOperator.OnOrAfter,
                                    Values        = { DateTime.Today.AddDays(10)    }
                                }
                            }
                        }
                    };

                    EntityCollection individualAppointments = service.RetrieveMultiple(instanceQuery);
                    // Retrieve a recurring appointment series



                    #region Reschedule an instance of recurring appointment

                    // Update the scheduled start and end dates of the appointment
                    // to reschedule it.
                    Appointment updateAppointment = new Appointment
                    {
                        ActivityId     = individualAppointments.Entities.Select(x => (Appointment)x).First().ActivityId,
                        ScheduledStart = individualAppointments.Entities.Select(x => (Appointment)x).First().ScheduledStart.Value.AddHours(1),
                        ScheduledEnd   = individualAppointments.Entities.Select(x => (Appointment)x).First().ScheduledEnd.Value.AddHours(2)
                    };

                    RescheduleRequest reschedule = new RescheduleRequest
                    {
                        Target = updateAppointment
                    };

                    RescheduleResponse rescheduled = (RescheduleResponse)service.Execute(reschedule);
                    Console.WriteLine("Rescheduled the second instance of the recurring appointment.");

                    #endregion Reschedule an instance of recurring appointment

                    #region Cancel an instance of recurring appointment

                    // Cancel the last instance of the appointment. The status of this appointment
                    // instance is set to 'Canceled'. You can view this appoinyment instance under
                    // the 'All Activities' view.
                    SetStateRequest appointmentRequest = new SetStateRequest
                    {
                        State         = new OptionSetValue((int)AppointmentState.Canceled),
                        Status        = new OptionSetValue(4),
                        EntityMoniker = new EntityReference(Appointment.EntityLogicalName,
                                                            new Guid(individualAppointments.Entities.Select(x => (Appointment)x).Last().ActivityId.ToString()))
                    };

                    service.Execute(appointmentRequest);
                    Console.WriteLine("Canceled the last instance of the recurring appointment.");

                    #endregion Cancel an instance of recurring appointment

                    #region Clean up
                    CleanUpSample(service);
                    #endregion Clean up
                }
                #endregion Demonstrate
                #endregion Sample Code

                else
                {
                    const string UNABLE_TO_LOGIN_ERROR = "Unable to Login to Microsoft Dataverse";
                    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();
            }
        }
示例#5
0
 public void Reschedule(RescheduleRequest <T> request)
 {
     _controller.Reschedule(request);
 }
示例#6
0
        /// <summary>
        /// Create and configure the organization service proxy.
        /// Initiate the method to create any data that this sample requires.
        /// Reschedule an instance of the recurring appointment series.
        /// Cancel another instance of the recurring appointment series.
        /// 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 = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri, serverConfig.Credentials, serverConfig.DeviceCredentials))
                {
                    // This statement is required to enable early-bound type support.
                    _serviceProxy.EnableProxyTypes();

                    // Call the method to create any data that this sample requires.
                    CreateRequiredRecords();

                    // Retrieve the individual appointment instance that falls on or after
                    // 10 days from today. Basically this will be the second instance in the
                    // recurring appointment series.

                    QueryExpression instanceQuery = new QueryExpression
                    {
                        EntityName = Appointment.EntityLogicalName,
                        ColumnSet  = new ColumnSet
                        {
                            Columns = { "activityid", "scheduledstart", "scheduledend" }
                        },
                        Criteria = new FilterExpression
                        {
                            Conditions =
                            {
                                new ConditionExpression
                                {
                                    AttributeName = "seriesid",
                                    Operator      = ConditionOperator.Equal,
                                    Values        = { _recurringAppointmentMasterId }
                                },
                                new ConditionExpression
                                {
                                    AttributeName = "scheduledstart",
                                    Operator      = ConditionOperator.OnOrAfter,
                                    Values        = { DateTime.Today.AddDays(10)    }
                                }
                            }
                        }
                    };

                    EntityCollection individualAppointments = _serviceProxy.RetrieveMultiple(instanceQuery);


                    #region Reschedule an instance of recurring appointment

                    // Update the scheduled start and end dates of the appointment
                    // to reschedule it.
                    Appointment updateAppointment = new Appointment
                    {
                        ActivityId     = individualAppointments.Entities.Select(x => (Appointment)x).First().ActivityId,
                        ScheduledStart = individualAppointments.Entities.Select(x => (Appointment)x).First().ScheduledStart.Value.AddHours(1),
                        ScheduledEnd   = individualAppointments.Entities.Select(x => (Appointment)x).First().ScheduledEnd.Value.AddHours(2)
                    };

                    RescheduleRequest reschedule = new RescheduleRequest
                    {
                        Target = updateAppointment
                    };

                    RescheduleResponse rescheduled = (RescheduleResponse)_serviceProxy.Execute(reschedule);
                    Console.WriteLine("Rescheduled the second instance of the recurring appointment.");

                    #endregion Reschedule an instance of recurring appointment

                    #region Cancel an instance of recurring appointment

                    // Cancel the last instance of the appointment. The status of this appointment
                    // instance is set to 'Canceled'. You can view this appoinyment instance under
                    // the 'All Activities' view.
                    SetStateRequest appointmentRequest = new SetStateRequest
                    {
                        State         = new OptionSetValue((int)AppointmentState.Canceled),
                        Status        = new OptionSetValue(4),
                        EntityMoniker = new EntityReference(Appointment.EntityLogicalName,
                                                            new Guid(individualAppointments.Entities.Select(x => (Appointment)x).Last().ActivityId.ToString()))
                    };

                    _serviceProxy.Execute(appointmentRequest);
                    Console.WriteLine("Canceled the last instance of the recurring appointment.");

                    #endregion Cancel an instance of recurring appointment

                    DeleteRequiredRecords(promptForDelete);
                }
            }
            // 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;
            }
        }
        /// <summary>
        /// Create and configure the organization service proxy.
        /// Initiate the method to create any data that this sample requires.
        /// Reschedule an instance of the recurring appointment series.
        /// Cancel another instance of the recurring appointment series.
        /// 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 = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri,serverConfig.Credentials, serverConfig.DeviceCredentials))
                {
                    // This statement is required to enable early-bound type support.
                    _serviceProxy.EnableProxyTypes();

                    // Call the method to create any data that this sample requires.
                    CreateRequiredRecords();

                    //<snippetRescheduleandCancelRecurringAppointmentInstance1>                
                    // Retrieve the individual appointment instance that falls on or after
                    // 10 days from today. Basically this will be the second instance in the
                    // recurring appointment series.                                          

                    QueryExpression instanceQuery = new QueryExpression
                    {
                        EntityName = Appointment.EntityLogicalName,
                        ColumnSet = new ColumnSet
                        {
                            Columns = { "activityid", "scheduledstart", "scheduledend" }
                        },
                        Criteria = new FilterExpression
                        {
                            Conditions = 
                        {
                            new ConditionExpression 
                            {
                                AttributeName = "seriesid",
                                Operator = ConditionOperator.Equal,
                                Values = { _recurringAppointmentMasterId }
                            },
                            new ConditionExpression 
                            {
                                 AttributeName = "scheduledstart",
                                 Operator = ConditionOperator.OnOrAfter,
                                 Values = { DateTime.Today.AddDays(10) }
                            }
                        }
                        }
                    };

                    EntityCollection individualAppointments = _serviceProxy.RetrieveMultiple(instanceQuery);

                    //<snippetRescheduleandCancelRecurringAppointmentInstance2>                

                    #region Reschedule an instance of recurring appointment

                    // Update the scheduled start and end dates of the appointment
                    // to reschedule it.
                    Appointment updateAppointment = new Appointment
                    {
                        ActivityId = individualAppointments.Entities.Select(x => (Appointment)x).First().ActivityId,
                        ScheduledStart = individualAppointments.Entities.Select(x => (Appointment)x).First().ScheduledStart.Value.AddHours(1),
                        ScheduledEnd = individualAppointments.Entities.Select(x => (Appointment)x).First().ScheduledEnd.Value.AddHours(2)
                    };

                    RescheduleRequest reschedule = new RescheduleRequest
                    {
                        Target = updateAppointment
                    };

                    RescheduleResponse rescheduled = (RescheduleResponse)_serviceProxy.Execute(reschedule);
                    Console.WriteLine("Rescheduled the second instance of the recurring appointment.");

                    #endregion Reschedule an instance of recurring appointment
                    //</snippetRescheduleandCancelRecurringAppointmentInstance2>                
                    //<snippetRescheduleandCancelRecurringAppointmentInstance3>                

                    #region Cancel an instance of recurring appointment

                    // Cancel the last instance of the appointment. The status of this appointment
                    // instance is set to 'Canceled'. You can view this appoinyment instance under
                    // the 'All Activities' view. 
                    SetStateRequest appointmentRequest = new SetStateRequest
                    {
                        State = new OptionSetValue((int)AppointmentState.Canceled),
                        Status = new OptionSetValue(4),
                        EntityMoniker = new EntityReference(Appointment.EntityLogicalName,
                            new Guid(individualAppointments.Entities.Select(x => (Appointment)x).Last().ActivityId.ToString()))
                    };

                    _serviceProxy.Execute(appointmentRequest);
                    Console.WriteLine("Canceled the last instance of the recurring appointment.");

                    #endregion Cancel an instance of recurring appointment
                    //</snippetRescheduleandCancelRecurringAppointmentInstance3>                
                    //</snippetRescheduleandCancelRecurringAppointmentInstance1>

                    DeleteRequiredRecords(promptForDelete);

                }
            }
            // 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;
            }
        }