/// <summary>
        /// Add <c>recurrence</c> information to an existing <c>appointment</c> with <see cref="XrmRecurringAppointment"/> object.
        /// Please note that when you convert an existing appointment to a recurring appointment, the data from the existing appointment is copied to a new recurring appointment master instance and the existing appointment record is deleted.
        /// <para>
        /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.addrecurrencerequest(v=crm.7).aspx
        /// </para>
        /// </summary>
        /// <param name="appointmentId"><c>Appointment</c> Id</param>
        /// <param name="recurringAppointment">
        /// <see cref="XrmRecurringAppointment"/>
        /// </param>
        /// <returns>
        /// Newly created <c>Recurring Appointment</c> Id (<see cref="Guid"/>)
        /// </returns>
        public Guid AddRecurrence(Guid appointmentId, XrmRecurringAppointment recurringAppointment)
        {
            ExceptionThrow.IfGuidEmpty(appointmentId, "appointmentId");

            AddRecurrenceRequest request = new AddRecurrenceRequest()
            {
                AppointmentId = appointmentId,
                Target        = recurringAppointment.ToEntity()
            };

            return(((AddRecurrenceResponse)this.OrganizationService.Execute(request)).id);
        }
        /// <summary>
        /// Add <c>recurrence</c> information to an existing <c>appointment</c>.
        /// Please note that when you convert an existing appointment to a recurring appointment, the data from the existing appointment is copied to a new recurring appointment master instance and the existing appointment record is deleted.
        /// <para>
        /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.addrecurrencerequest(v=crm.7).aspx
        /// </para>
        /// </summary>
        /// <param name="appointmentId"><c>Appointment</c> Id</param>
        /// <param name="recurringAppointment">
        /// Recurring Appointment entity (<see cref="Entity"/>)
        /// </param>
        /// <returns>
        /// Newly created <c>Recurring Appointment</c> Id (<see cref="Guid"/>)
        /// </returns>
        public Guid AddRecurrence(Guid appointmentId, Entity recurringAppointment)
        {
            ExceptionThrow.IfGuidEmpty(appointmentId, "appointmentId");
            ExceptionThrow.IfNull(recurringAppointment, "recurringAppointment");
            ExceptionThrow.IfNullOrEmpty(recurringAppointment.LogicalName, "Entity.LogicalName");
            ExceptionThrow.IfNotExpectedValue(recurringAppointment.LogicalName, "Entity.LogicalName", "recurringappointmentmaster");

            AddRecurrenceRequest request = new AddRecurrenceRequest()
            {
                AppointmentId = appointmentId,
                Target        = recurringAppointment
            };

            return(((AddRecurrenceResponse)this.OrganizationService.Execute(request)).id);
        }
示例#3
0
        /// <summary>
        /// Create and configure the organization service proxy.
        /// Initiate the method to create any data that this sample requires.
        /// Convert an appointment to a recurring appointment.
        /// 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();

                    //<snippetConvertAnAppointmenttoRecurringAppointment1>

                    // Specify the recurrence information that needs to be added to the
                    // existing appointment.
                    // 1.  Define an anonymous type to define the possible recurrence pattern values.
                    var RecurrencePatternTypes = new
                    {
                        Daily   = 0,
                        Weekly  = 1,
                        Monthly = 2,
                        Yearly  = 3
                    };

                    // 2.  Define an anonymous type to define the possible values for days
                    // of the week
                    var DayOfWeek = new
                    {
                        Sunday    = 0x01,
                        Monday    = 0x02,
                        Tuesday   = 0x04,
                        Wednesday = 0x08,
                        Thursday  = 0x10,
                        Friday    = 0x20,
                        Saturday  = 0x40
                    };

                    // 3.  Define an anonymous type to define the possible values
                    // for the recurrence rule pattern end type.
                    var RecurrenceRulePatternEndType = new
                    {
                        NoEndDate      = 1,
                        Occurrences    = 2,
                        PatternEndDate = 3
                    };

                    // 4.  Finally, use a recurring appointment master object to specify
                    //     the recurrence information. Other appointment details such as
                    //     'subject' and 'location' are copied from the existing appointment
                    //     to the recurring appointment master object.

                    RecurringAppointmentMaster newRecurringAppointmentInfo = new RecurringAppointmentMaster
                    {
                        StartTime             = DateTime.Now.AddHours(2),
                        EndTime               = DateTime.Now.AddHours(3),
                        RecurrencePatternType = new OptionSetValue(RecurrencePatternTypes.Weekly),
                        Interval              = 1,
                        DaysOfWeekMask        = DayOfWeek.Thursday,
                        PatternStartDate      = DateTime.Today,
                        PatternEndType        = new OptionSetValue(RecurrenceRulePatternEndType.Occurrences),
                        Occurrences           = 5
                    };


                    // Use the AddRecurrence message to convert the existing appointment
                    // object to a recurring appointment master object. The existing
                    // appointment object is deleted thereafter.

                    AddRecurrenceRequest recurringInfoRequest = new AddRecurrenceRequest
                    {
                        Target        = newRecurringAppointmentInfo,
                        AppointmentId = _appointmentId
                    };

                    AddRecurrenceResponse recurringInfoResponse = (AddRecurrenceResponse)_serviceProxy.Execute(recurringInfoRequest);
                    __recurringAppointmentMasterId = recurringInfoResponse.id;

                    // Verify that the newly created recurring appointment master has same 'subject'
                    // as the existing appointment.

                    RecurringAppointmentMaster retrievedMasterAppointment = (RecurringAppointmentMaster)_serviceProxy.Retrieve(RecurringAppointmentMaster.EntityLogicalName, __recurringAppointmentMasterId, new ColumnSet(true));
                    if (retrievedMasterAppointment.Subject == "Sample Appointment")
                    {
                        Console.WriteLine("Sample Appointment is converted to a recurring appointment.");
                    }

                    //</snippetConvertAnAppointmenttoRecurringAppointment1>

                    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;
            }
        }
示例#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

                    // Specify the recurrence information that needs to be added to the
                    // existing appointment.
                    // 1.  Define an anonymous type to define the possible recurrence pattern values.
                    var RecurrencePatternTypes = new
                    {
                        Daily   = 0,
                        Weekly  = 1,
                        Monthly = 2,
                        Yearly  = 3
                    };

                    // 2.  Define an anonymous type to define the possible values for days
                    // of the week
                    var DayOfWeek = new
                    {
                        Sunday    = 0x01,
                        Monday    = 0x02,
                        Tuesday   = 0x04,
                        Wednesday = 0x08,
                        Thursday  = 0x10,
                        Friday    = 0x20,
                        Saturday  = 0x40
                    };

                    // 3.  Define an anonymous type to define the possible values
                    // for the recurrence rule pattern end type.
                    var RecurrenceRulePatternEndType = new
                    {
                        NoEndDate      = 1,
                        Occurrences    = 2,
                        PatternEndDate = 3
                    };

                    // 4.  Finally, use a recurring appointment master object to specify
                    //     the recurrence information. Other appointment details such as
                    //     'subject' and 'location' are copied from the existing appointment
                    //     to the recurring appointment master object.

                    RecurringAppointmentMaster newRecurringAppointmentInfo = new RecurringAppointmentMaster
                    {
                        StartTime             = DateTime.Now.AddHours(2),
                        EndTime               = DateTime.Now.AddHours(3),
                        RecurrencePatternType = new OptionSetValue(RecurrencePatternTypes.Weekly),
                        Interval              = 1,
                        DaysOfWeekMask        = DayOfWeek.Thursday,
                        PatternStartDate      = DateTime.Today,
                        PatternEndType        = new OptionSetValue(RecurrenceRulePatternEndType.Occurrences),
                        Occurrences           = 5
                    };


                    // Use the AddRecurrence message to convert the existing appointment
                    // object to a recurring appointment master object. The existing
                    // appointment object is deleted thereafter.

                    AddRecurrenceRequest recurringInfoRequest = new AddRecurrenceRequest
                    {
                        Target        = newRecurringAppointmentInfo,
                        AppointmentId = _appointmentId
                    };

                    AddRecurrenceResponse recurringInfoResponse = (AddRecurrenceResponse)service.Execute(recurringInfoRequest);
                    __recurringAppointmentMasterId = recurringInfoResponse.id;

                    // Verify that the newly created recurring appointment master has same 'subject'
                    // as the existing appointment.

                    RecurringAppointmentMaster retrievedMasterAppointment = (RecurringAppointmentMaster)service.Retrieve(RecurringAppointmentMaster.EntityLogicalName, __recurringAppointmentMasterId, new ColumnSet(true));
                    if (retrievedMasterAppointment.Subject == "Sample Appointment")
                    {
                        Console.WriteLine("Sample Appointment is converted to a recurring appointment.");
                    }

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

                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;
                    }
                }
            }
            #endregion Sample code

            catch (Exception ex)
            {
                SampleHelpers.HandleException(ex);
            }

            finally
            {
                if (service != null)
                {
                    service.Dispose();
                }

                Console.WriteLine("Press <Enter> to exit.");
                Console.ReadLine();
            }
        }
        /// <summary>
        /// Create and configure the organization service proxy.
        /// Initiate the method to create any data that this sample requires.
        /// Convert an appointment to a recurring appointment.
        /// 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();

                    //<snippetConvertAnAppointmenttoRecurringAppointment1>                

                    // Specify the recurrence information that needs to be added to the
                    // existing appointment.
                    // 1.  Define an anonymous type to define the possible recurrence pattern values.
                    var RecurrencePatternTypes = new
                    {
                        Daily = 0,
                        Weekly = 1,
                        Monthly = 2,
                        Yearly = 3
                    };

                    // 2.  Define an anonymous type to define the possible values for days 
                    // of the week
                    var DayOfWeek = new
                    {
                        Sunday = 0x01,
                        Monday = 0x02,
                        Tuesday = 0x04,
                        Wednesday = 0x08,
                        Thursday = 0x10,
                        Friday = 0x20,
                        Saturday = 0x40
                    };

                    // 3.  Define an anonymous type to define the possible values  
                    // for the recurrence rule pattern end type.
                    var RecurrenceRulePatternEndType = new
                    {
                        NoEndDate = 1,
                        Occurrences = 2,
                        PatternEndDate = 3
                    };

                    // 4.  Finally, use a recurring appointment master object to specify
                    //     the recurrence information. Other appointment details such as
                    //     'subject' and 'location' are copied from the existing appointment
                    //     to the recurring appointment master object.

                    RecurringAppointmentMaster newRecurringAppointmentInfo = new RecurringAppointmentMaster
                        {
                            StartTime = DateTime.Now.AddHours(2),
                            EndTime = DateTime.Now.AddHours(3),
                            RecurrencePatternType = new OptionSetValue(RecurrencePatternTypes.Weekly),
                            Interval = 1,
                            DaysOfWeekMask = DayOfWeek.Thursday,
                            PatternStartDate = DateTime.Today,
                            PatternEndType = new OptionSetValue(RecurrenceRulePatternEndType.Occurrences),
                            Occurrences = 5
                        };


                    // Use the AddRecurrence message to convert the existing appointment
                    // object to a recurring appointment master object. The existing
                    // appointment object is deleted thereafter.

                    AddRecurrenceRequest recurringInfoRequest = new AddRecurrenceRequest
                    {
                        Target = newRecurringAppointmentInfo,
                        AppointmentId = _appointmentId
                    };

                    AddRecurrenceResponse recurringInfoResponse = (AddRecurrenceResponse)_serviceProxy.Execute(recurringInfoRequest);
                    __recurringAppointmentMasterId = recurringInfoResponse.id;

                    // Verify that the newly created recurring appointment master has same 'subject' 
                    // as the existing appointment.

                    RecurringAppointmentMaster retrievedMasterAppointment = (RecurringAppointmentMaster)_serviceProxy.Retrieve(RecurringAppointmentMaster.EntityLogicalName, __recurringAppointmentMasterId, new ColumnSet(true));
                    if (retrievedMasterAppointment.Subject == "Sample Appointment")
                    {
                        Console.WriteLine("Sample Appointment is converted to a recurring appointment.");
                    }

                    //</snippetConvertAnAppointmenttoRecurringAppointment1>

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