Пример #1
0
        public static void DeleteLegislation(CrmServiceClient existingService = null)
        {
            var doNotDispose = existingService != null ? true : false;

            CrmServiceClient service = null;

            try
            {
                service = existingService == null?CrmSdkHelper.Connect() : existingService;

                if (service.IsReady)
                {
                    Console.BackgroundColor = ConsoleColor.DarkRed;
                    Console.WriteLine("-----DELETING ANY EXISTING LEGISTLATION DATA-----");

                    CrmSdkHelper.DeleteLegislation(service);

                    Console.WriteLine("-----LEGISLATION DATA DELETED-----");
                }
                else
                {
                    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)
            {
                CrmSdkHelper.HandleException(ex);
            }
            finally
            {
                if (service != null && !doNotDispose)
                {
                    service.Dispose();
                }
            }
        }