Пример #1
0
        /// <summary>
        /// This method creates any entity records that this sample requires.
        /// Create a new recurring appointment.
        /// </summary>
        public static void CreateRequiredRecords(CrmServiceClient service)
        {
            // Define an anonymous type to define the possible recurrence pattern values.
            var RecurrencePatternTypes = new
            {
                Daily = 0,
                Weekly = 1,
                Monthly = 2,
                Yearly = 3
            };

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

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

            // Create a new recurring appointment
            RecurringAppointmentMaster newRecurringAppointment =
                new RecurringAppointmentMaster
                {
                    Subject = "Sample Recurring Appointment",
                    StartTime = DateTime.Now.AddHours(1),
                    EndTime = DateTime.Now.AddHours(2),
                    RecurrencePatternType = new OptionSetValue(
                        RecurrencePatternTypes.Weekly),
                    Interval = 1,
                    DaysOfWeekMask = DayOfWeek.Thursday,
                    PatternStartDate = DateTime.Today,
                    Occurrences = 5,
                    PatternEndType = new OptionSetValue(
                        RecurrenceRulePatternEndType.Occurrences)

                };

            _recurringAppointmentMasterId = service.Create(newRecurringAppointment);
            Console.WriteLine("Created {0}", newRecurringAppointment.Subject);

            return;
        }
Пример #2
0
        /// <summary>
        /// Create and configure the organization service proxy.
        /// Initiate the method to create any data that this sample requires.
        /// End 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 = 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();

                    //<snippetEndRecurringAppointmentSeries1>

                    // Retrieve a recurring appointment series
                    RecurringAppointmentMaster retrievedRecurringAppointmentSeries = (RecurringAppointmentMaster)_serviceProxy.Retrieve(RecurringAppointmentMaster.EntityLogicalName, _recurringAppointmentMasterId, new ColumnSet(true));

                    // Use the DeleteOpenInstances message to end the series to the
                    // last occurring past instance date w.r.t. the series end date
                    // (i.e., 20 days from today). Effectively, that means that the
                    // series will end after the third instance (day 14) as this
                    // instance is the last occuring past instance w.r.t the specified
                    // series end date (20 days from today).
                    // Also specify that the state of past instances (w.r.t. the series
                    // end date) be set to 'completed'.
                    DeleteOpenInstancesRequest endAppointmentSeries = new DeleteOpenInstancesRequest
                    {
                        Target               = retrievedRecurringAppointmentSeries,
                        SeriesEndDate        = DateTime.Today.AddDays(20),
                        StateOfPastInstances = (int)AppointmentState.Completed
                    };
                    _serviceProxy.Execute(endAppointmentSeries);

                    Console.WriteLine("The recurring appointment series has been ended after the third occurrence.");

                    //</snippetEndRecurringAppointmentSeries1>

                    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;
            }
        }
Пример #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;
            }
        }
        /// <summary>
        /// This method creates any entity records that this sample requires.
        /// Create a new recurring appointment.
        /// </summary>
        public void CreateRequiredRecords()
        {
            // Define an anonymous type to define the possible recurrence pattern values.
            var RecurrencePatternTypes = new
            {
                Daily = 0,
                Weekly = 1,
                Monthly = 2,
                Yearly = 3
            };

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

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

            // Create a new recurring appointment
            RecurringAppointmentMaster newRecurringAppointment =
                new RecurringAppointmentMaster
                {
                    Subject = "Sample Recurring Appointment",
                    StartTime = DateTime.Now.AddHours(1),
                    EndTime = DateTime.Now.AddHours(2),
                    RecurrencePatternType = new OptionSetValue(
                        RecurrencePatternTypes.Weekly),
                    Interval = 1,
                    DaysOfWeekMask = DayOfWeek.Thursday,
                    PatternStartDate = DateTime.Today,
                    Occurrences = 5,
                    PatternEndType = new OptionSetValue(
                        RecurrenceRulePatternEndType.Occurrences)

                };

            _recurringAppointmentMasterId = _serviceProxy.Create(newRecurringAppointment);
            Console.WriteLine("Created {0} with {1} occurrences.", newRecurringAppointment.Subject, newRecurringAppointment.Occurrences);

            return;
        }
Пример #5
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

                    // Retrieve a recurring appointment series
                    RecurringAppointmentMaster retrievedRecurringAppointmentSeries = (RecurringAppointmentMaster)service.Retrieve(RecurringAppointmentMaster.EntityLogicalName, _recurringAppointmentMasterId, new ColumnSet(true));

                    // Use the DeleteOpenInstances message to end the series to the
                    // last occurring past instance date w.r.t. the series end date
                    // (i.e., 20 days from today). Effectively, that means that the
                    // series will end after the third instance (day 14) as this
                    // instance is the last occuring past instance w.r.t the specified
                    // series end date (20 days from today).
                    // Also specify that the state of past instances (w.r.t. the series
                    // end date) be set to 'completed'.
                    DeleteOpenInstancesRequest endAppointmentSeries = new DeleteOpenInstancesRequest
                    {
                        Target               = retrievedRecurringAppointmentSeries,
                        SeriesEndDate        = DateTime.Today.AddDays(20),
                        StateOfPastInstances = (int)AppointmentState.Completed
                    };
                    service.Execute(endAppointmentSeries);

                    Console.WriteLine("The recurring appointment series has been ended after the third occurrence.");


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

                else
                {
                    const string UNABLE_TO_LOGIN_ERROR = "Unable to Login to Common Data Service";
                    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();
            }
        }
Пример #6
0
        /// <summary>
        /// Create and configure the organization service proxy.
        /// Create a recurring appointment.
        /// Retrieve the recurring appointment.
        /// Update the retrieved 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();


                    //<snippetCRUDRecurringAppointment1>
                    // Define an anonymous type to define the possible recurrence pattern values.
                    var RecurrencePatternTypes = new
                    {
                        Daily = 0,
                        Weekly = 1,
                        Monthly = 2,
                        Yearly = 3
                    };

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

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

                    // Create a recurring appointment
                    RecurringAppointmentMaster newRecurringAppointment = new RecurringAppointmentMaster
                        {
                            Subject = "Sample Recurring Appointment",
                            StartTime = DateTime.Now.AddHours(1),
                            EndTime = DateTime.Now.AddHours(2),
                            RecurrencePatternType = new OptionSetValue(RecurrencePatternTypes.Weekly),
                            Interval = 1,
                            DaysOfWeekMask = DayOfWeek.Thursday,
                            PatternStartDate = DateTime.Today,
                            Occurrences = 10,
                            PatternEndType = new OptionSetValue(RecurrenceRulePatternEndType.Occurrences)
                        };

                    _recurringAppointmentMasterId = _serviceProxy.Create(newRecurringAppointment);
                    Console.WriteLine("Created {0}.", newRecurringAppointment.Subject);

                    // Retrieve the newly created recurring appointment
                    QueryExpression recurringAppointmentQuery = new QueryExpression
                    {
                        EntityName = RecurringAppointmentMaster.EntityLogicalName,
                        ColumnSet = new ColumnSet("subject"),
                        Criteria = new FilterExpression
                        {
                            Conditions =
                        {
                            new ConditionExpression
                            {
                                AttributeName = "subject",
                                Operator = ConditionOperator.Equal,
                                Values = { "Sample Recurring Appointment" }
                            },
                            new ConditionExpression
                            {
                                AttributeName = "interval",
                                Operator = ConditionOperator.Equal,
                                Values = { 1 }
                            }
                        }
                        },
                        PageInfo = new PagingInfo
                        {
                            Count = 1,
                            PageNumber = 1
                        }
                    };

                    RecurringAppointmentMaster retrievedRecurringAppointment =
                        _serviceProxy.RetrieveMultiple(recurringAppointmentQuery).
                        Entities.Select(x => (RecurringAppointmentMaster)x).FirstOrDefault();

                    Console.WriteLine("Retrieved the recurring appointment.");

                    // Update the recurring appointment.
                    // Update the following for the retrieved recurring appointment series:
                    // 1. Update the subject.
                    // 2. Update the number of occurences to 5.
                    // 3. Update the appointment interval to 2.

                    retrievedRecurringAppointment.Subject = "Updated Recurring Appointment";
                    retrievedRecurringAppointment.Occurrences = 5;
                    retrievedRecurringAppointment.Interval = 2;
                    _serviceProxy.Update(retrievedRecurringAppointment);

                    Console.WriteLine("Updated the subject, occurrences, and interval of the recurring appointment.");
                    //</snippetCRUDRecurringAppointment1>

                    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.
        /// Create a recurring appointment.
        /// Retrieve the recurring appointment.
        /// Update the retrieved 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();


                    // Define an anonymous type to define the possible recurrence pattern values.
                    var RecurrencePatternTypes = new
                    {
                        Daily   = 0,
                        Weekly  = 1,
                        Monthly = 2,
                        Yearly  = 3
                    };

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

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

                    // Create a recurring appointment
                    RecurringAppointmentMaster newRecurringAppointment = new RecurringAppointmentMaster
                    {
                        Subject               = "Sample Recurring Appointment",
                        StartTime             = DateTime.Now.AddHours(1),
                        EndTime               = DateTime.Now.AddHours(2),
                        RecurrencePatternType = new OptionSetValue(RecurrencePatternTypes.Weekly),
                        Interval              = 1,
                        DaysOfWeekMask        = DayOfWeek.Thursday,
                        PatternStartDate      = DateTime.Today,
                        Occurrences           = 10,
                        PatternEndType        = new OptionSetValue(RecurrenceRulePatternEndType.Occurrences)
                    };

                    _recurringAppointmentMasterId = _serviceProxy.Create(newRecurringAppointment);
                    Console.WriteLine("Created {0}.", newRecurringAppointment.Subject);

                    // Retrieve the newly created recurring appointment
                    QueryExpression recurringAppointmentQuery = new QueryExpression
                    {
                        EntityName = RecurringAppointmentMaster.EntityLogicalName,
                        ColumnSet  = new ColumnSet("subject"),
                        Criteria   = new FilterExpression
                        {
                            Conditions =
                            {
                                new ConditionExpression
                                {
                                    AttributeName = "subject",
                                    Operator      = ConditionOperator.Equal,
                                    Values        = { "Sample Recurring Appointment" }
                                },
                                new ConditionExpression
                                {
                                    AttributeName = "interval",
                                    Operator      = ConditionOperator.Equal,
                                    Values        = {                              1 }
                                }
                            }
                        },
                        PageInfo = new PagingInfo
                        {
                            Count      = 1,
                            PageNumber = 1
                        }
                    };

                    RecurringAppointmentMaster retrievedRecurringAppointment =
                        _serviceProxy.RetrieveMultiple(recurringAppointmentQuery).
                        Entities.Select(x => (RecurringAppointmentMaster)x).FirstOrDefault();

                    Console.WriteLine("Retrieved the recurring appointment.");

                    // Update the recurring appointment.
                    // Update the following for the retrieved recurring appointment series:
                    // 1. Update the subject.
                    // 2. Update the number of occurences to 5.
                    // 3. Update the appointment interval to 2.

                    retrievedRecurringAppointment.Subject     = "Updated Recurring Appointment";
                    retrievedRecurringAppointment.Occurrences = 5;
                    retrievedRecurringAppointment.Interval    = 2;
                    _serviceProxy.Update(retrievedRecurringAppointment);

                    Console.WriteLine("Updated the subject, occurrences, and interval of the 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;
            }
        }
Пример #8
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

                    // Define an anonymous type to define the possible recurrence pattern values.
                    var RecurrencePatternTypes = new
                    {
                        Daily   = 0,
                        Weekly  = 1,
                        Monthly = 2,
                        Yearly  = 3
                    };

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

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

                    // Create a recurring appointment
                    //RecurringAppointmentMaster newRecurringAppointment = new RecurringAppointmentMaster
                    var newRecurringAppointment = new RecurringAppointmentMaster
                    {
                        Subject               = "Sample Recurring Appointment",
                        StartTime             = DateTime.Now.AddHours(1),
                        EndTime               = DateTime.Now.AddHours(2),
                        RecurrencePatternType = new OptionSetValue(RecurrencePatternTypes.Weekly),
                        Interval              = 1,
                        DaysOfWeekMask        = DayOfWeek.Thursday,
                        PatternStartDate      = DateTime.Today,
                        Occurrences           = 10,
                        PatternEndType        = new OptionSetValue(RecurrenceRulePatternEndType.Occurrences)
                    };

                    recurringAppointmentMasterId = service.Create(newRecurringAppointment);
                    Console.WriteLine("Created {0}.", newRecurringAppointment.Subject);

                    // Retrieve the newly created recurring appointment
                    var recurringAppointmentQuery = new QueryExpression
                    {
                        EntityName = RecurringAppointmentMaster.EntityLogicalName,
                        ColumnSet  = new ColumnSet("subject"),
                        Criteria   = new FilterExpression
                        {
                            Conditions =
                            {
                                new ConditionExpression
                                {
                                    AttributeName = "subject",
                                    Operator      = ConditionOperator.Equal,
                                    Values        = { "Sample Recurring Appointment" }
                                },
                                new ConditionExpression
                                {
                                    AttributeName = "interval",
                                    Operator      = ConditionOperator.Equal,
                                    Values        = {                              1 }
                                }
                            }
                        },
                        PageInfo = new PagingInfo
                        {
                            Count      = 1,
                            PageNumber = 1
                        }
                    };

                    var retrievedRecurringAppointment =
                        service.RetrieveMultiple(recurringAppointmentQuery).
                        Entities.Select(x => (RecurringAppointmentMaster)x).FirstOrDefault();

                    Console.WriteLine("Retrieved the recurring appointment.");

                    // Update the recurring appointment.
                    // Update the following for the retrieved recurring appointment series:
                    // 1. Update the subject.
                    // 2. Update the number of occurences to 5.
                    // 3. Update the appointment interval to 2.

                    retrievedRecurringAppointment.Subject     = "Updated Recurring Appointment";
                    retrievedRecurringAppointment.Occurrences = 5;
                    retrievedRecurringAppointment.Interval    = 2;
                    service.Update(retrievedRecurringAppointment);

                    Console.WriteLine("Updated the subject, occurrences, and interval of the 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 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();
            }
        }
Пример #9
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;
            }
        }