Ejemplo n.º 1
0
        public void ImportSolution(OrganizationServiceProxy _serviceProxy)
        {
            string hostName = _serviceProxy.ServiceManagement.CurrentServiceEndpoint.ListenUri.Host;

            _serviceProxy.Timeout = TimeSpan.MaxValue;
            foreach (string solution in this.Settings.SolutionsToBeImport)
            {
                Console.WriteLine($"importing {solution} into {hostName} at {DateTime.Now.ToLongTimeString()}");
                byte[] fileBytes = ReadSolutionFile(solution);
                ImportSolutionRequest impSolReq = new ImportSolutionRequest()
                {
                    CustomizationFile = fileBytes,
                    PublishWorkflows  = true
                };
                _serviceProxy.Execute(impSolReq);
                Console.WriteLine($"{solution} has been imported into {hostName}  at  {DateTime.Now.ToLongTimeString()}");
            }

            if (this.Settings.PublishAllCustomizationAfterImported)
            {
                Console.WriteLine("Publishing all customizations " + DateTime.Now.ToLongTimeString());
                PublishAllXmlRequest pubReq = new PublishAllXmlRequest();
                _serviceProxy.Execute(pubReq);
                _serviceProxy.Dispose();
                Console.WriteLine("All customizations have been published!");
            }
        }
Ejemplo n.º 2
0
        private static int Run <T>(BaseTask <T> task, T opts) where T : BaseOptions
        {
            Console.WriteLine(task.TaskName);
            task.Options = opts;
            OrganizationServiceProxy serviceProxy = null;

            try
            {
                // Obtain the target organization's web address and client logon credentials
                // from the user by using a helper class.
                ServerConnection serverConnect        = new ServerConnection();
                ServerConnection.Configuration config = serverConnect.GetServerConfiguration();

                // Establish an authenticated connection to the Organization web service.
                serviceProxy = new OrganizationServiceProxy(config.OrganizationUri, config.HomeRealmUri,
                                                            config.Credentials, null);
                task.Service = serviceProxy;
                task.Run();
            }
            catch (Exception e)
            {
                HandleException(e);
                return(1);
            }
            finally
            {
                // Always dispose the service object to close the service connection and free resources.
                if (serviceProxy != null)
                {
                    serviceProxy.Dispose();
                }
            }
            return(0);
        }
 private void Dispose(bool disposing)
 {
     ReleaseUnmanagedResources();
     if (disposing)
     {
         _organizationServiceProxy?.Dispose();
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Invalidates the organisation service proxy.
 /// </summary>
 private void InvalidateProxy()
 {
     if (proxy != default(OrganizationServiceProxy))
     {
         proxy.Dispose();
         proxy = default(OrganizationServiceProxy);
     }
 }
Ejemplo n.º 5
0
        static public void Main(string[] args)
        {
            // The connection to the Organization web service.
            OrganizationServiceProxy serviceProxy = null;

            try
            {
                // Obtain the target organization's web address and client logon credentials
                // from the user by using a helper class.
                ServerConnection serverConnect        = new ServerConnection();
                ServerConnection.Configuration config = serverConnect.GetServerConfiguration();

                // Establish an authenticated connection to the Organization web service.
                serviceProxy = new OrganizationServiceProxy(config.OrganizationUri, config.HomeRealmUri,
                                                            config.Credentials, config.DeviceCredentials);

                CRUDOperations app = new CRUDOperations();

                // Create any records that must exist in the database. These record references are
                // stored in a collection so the records can be deleted later.
                EntityReferenceCollection records =
                    app.CreateRequiredEntityRecords(serviceProxy);

                // Perform the primary operation of this sample.
                app.Run(serviceProxy, records);

                // Delete all remaining records that were created by this sample.
                app.DeleteEntityRecords(serviceProxy, records, true);
            }

            // Some exceptions to consider catching.
            //<snippetCRUDOperations3>
            catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> e) { HandleException(e); }
            catch (TimeoutException e) { HandleException(e); }
            catch (SecurityTokenValidationException e) { HandleException(e); }
            catch (ExpiredSecurityTokenException e) { HandleException(e); }
            catch (MessageSecurityException e) { HandleException(e); }
            catch (SecurityNegotiationException e) { HandleException(e); }
            catch (SecurityAccessDeniedException e) { HandleException(e); }
            catch (Exception e) { HandleException(e); }
            //</snippetCRUDOperations3>

            finally
            {
                // Always dispose the service object to close the service connection and free resources.
                if (serviceProxy != null)
                {
                    serviceProxy.Dispose();
                }

                Console.WriteLine("Press <Enter> to exit.");
                Console.ReadLine();
            }
        }
Ejemplo n.º 6
0
        static public void Main(string[] args)
        {
            // The connection to the Organization web service.
            OrganizationServiceProxy serviceProxy = null;

            try
            {
                // Obtain the target organization's web address and client logon credentials
                // from the user by using a helper class.
                ServerConnection serverConnect = new ServerConnection();
                ServerConnection.Configuration config = serverConnect.GetServerConfiguration();

                // Establish an authenticated connection to the Organization web service. 
                serviceProxy = new OrganizationServiceProxy(config.OrganizationUri, config.HomeRealmUri,
                                                            config.Credentials, config.DeviceCredentials);

                CRUDOperations app = new CRUDOperations();

                // Create any records that must exist in the database. These record references are
                // stored in a collection so the records can be deleted later.
                EntityReferenceCollection records =
                    app.CreateRequiredEntityRecords(serviceProxy);

                // Perform the primary operation of this sample.
                app.Run(serviceProxy, records);

                // Delete all remaining records that were created by this sample.
                app.DeleteEntityRecords(serviceProxy, records, true);
            }

            // Some exceptions to consider catching.
            //<snippetCRUDOperations3>
            catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> e) { HandleException(e); }
            catch (TimeoutException e) { HandleException(e); }
            catch (SecurityTokenValidationException e) { HandleException(e); }
            catch (ExpiredSecurityTokenException e) { HandleException(e); }
            catch (MessageSecurityException e) { HandleException(e); }
            catch (SecurityNegotiationException e) { HandleException(e); }
            catch (SecurityAccessDeniedException e) { HandleException(e); }
            catch (Exception e) { HandleException(e); }
            //</snippetCRUDOperations3>

            finally
            {
                // Always dispose the service object to close the service connection and free resources.
                if (serviceProxy != null) serviceProxy.Dispose();

                Console.WriteLine("Press <Enter> to exit.");
                Console.ReadLine();
            }
        }
Ejemplo n.º 7
0
        public static void Main(string[] args)
        {
            try
            {
                if (args.Length == 0 || string.IsNullOrEmpty(args[0]))
                {
                    throw new ArgumentNullException(@"Should run with CSV Input File, e.g. C:\foo\foo.csv");
                }
                csvInputFile   = args[0];
                csvOutputFile  = csvInputFile.Replace(".csv", "");
                runLogFileName = csvOutputFile + "_RunLog.txt";

                RecordInGroup = string.IsNullOrEmpty(ConfigurationManager.AppSettings["RecordInGroup"]) ? 200 : int.Parse(ConfigurationManager.AppSettings["RecordInGroup"]);

                WriteRunLog($"Job start at: {DateTime.Now}. Connecting to CRM ...");

                _serviceProxy = CreateDurablesServiceClient();

                WriteRunLog($"CRM is connected at: {DateTime.Now}.");

                ProcessRecords();
            }
            catch (FaultException <OrganizationServiceFault> ex)
            {
                WriteRunLog($"The application terminated with a FaultException while processing serial number: {runLogSerialNumber}." +
                            $"Fault Exception: {ex.StackTrace}");
            }
            catch (TimeoutException ex)
            {
                WriteRunLog($"The application terminated with a TimeoutException while processing serial number: {runLogSerialNumber}." +
                            $"Timeout Exception: {ex.Message}");
            }
            catch (Exception ex)
            {
                WriteRunLog($"The application terminated with an error while processing serial number: {runLogSerialNumber}." +
                            $"message: {ex.Message}, Stack Trace: {ex.StackTrace}");
            }
            finally
            {
                if (_serviceProxy != null)
                {
                    _serviceProxy.Dispose();
                }
                WriteRunLog($"Job end at: {DateTime.Now}.");
                //Console.ReadLine();
            }
        }
Ejemplo n.º 8
0
    protected virtual void Dispose(bool disposing)
    {
        if (!disposing)
        {
            return;
        }

        try
        {
            if (_service == null)
            {
                return;
            }
            _service.Dispose();
            _service = null;
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
            throw;
        }
    }
Ejemplo n.º 9
0
 /// <summary>
 /// Dispose.
 /// </summary>
 /// <param name="disposing"></param>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (OrganizationServiceProxy != null)
         {
             OrganizationServiceProxy.Dispose();
         }
         if (OrganizationServiceContext != null)
         {
             OrganizationServiceContext.Dispose();
         }
         if (organizationServiceProxy != null)
         {
             organizationServiceProxy.Dispose();
             organizationServiceProxy = null;
         }
         if (organizationServiceContext != null)
         {
             organizationServiceContext.Dispose();
             organizationServiceContext = null;
         }
     }
 }
Ejemplo n.º 10
0
 public void Disconnect()
 {
     _serviceProxy?.Dispose();
 }
Ejemplo n.º 11
0
        static public void Main(string[] args)
        {
            try
            {
                ClientCredentials credentials = new ClientCredentials();

                //Change below 3 lines as per your env.
                Uri discoveryServerUri = new Uri("http://onefarm7508.onefarm7508dom.extest.microsoft.com/CITTest/XRMServices/2011/Organization.svc");
                credentials.UserName.UserName = "******";
                credentials.UserName.Password = "******";

                serviceProxy = new OrganizationServiceProxy(discoveryServerUri, null, credentials, null);
                serviceProxy.EnableProxyTypes();
                service = (IOrganizationService)serviceProxy;

                //Create an Account with multiple Contacts, so that it shows in associated grid.
                //CreateOneAccountWithMultipleContacts(1, 70);

                //********** FOR ACCOUNT **********
                //To create Account. One can implement method similar to CreateAccounts for other entities like CreateContacts.
                CreateAccounts(1, 5, 10);

                //If needed to delete above created records (Can also delete some of them), uncomment below line.
                //DeleteAccountRecords(1, 5);


                //********** FOR OPPORTUNITY **********
                //To create opportunity
                // CreateOpportunities(1, 70);

                //If needed to delete, then uncomment below lines.
                // DeleteOpportunityRecords(1, 5);


                //********** FOR CUSTOM ENTITY **********
                //If you need to create Custom Entity uncomment below lines. Next time comment creation of customEntity.
                // CreateCustomEntity();

                //Create customEntity records
                //CreateCustomEntityRecords(1, 70);

                //To delete customEntity records created using this tool, uncomment below line
                // DeleteCustomEntityRecords(1, 5);

                //If you want to delete the CustomEntity itself, which you created earlier using this tool, then uncomment below line
                // DeleteCustomEntity();

                //********** FOR CUSTOM ACTIVITY **********
                //If you need to create Custom Activity records uncomment below lines. Next time comment creation of customActivity.
                // CreateCustomActivity();

                //Create customActivity records
                //CreateCustomActivityRecords(1, 70);

                //To delete customActivity records created using this tool, uncomment below line
                //DeleteCustomActivityRecords(1, 70);

                //If you want to delete the CustomActivity itself, which you created earlier using this tool
                //DeleteCustomActivity();
            }
            catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> e) { HandleException(e); }
            catch (TimeoutException e) { HandleException(e); }
            catch (SecurityTokenValidationException e) { HandleException(e); }
            catch (ExpiredSecurityTokenException e) { HandleException(e); }
            catch (MessageSecurityException e) { HandleException(e); }
            catch (SecurityNegotiationException e) { HandleException(e); }
            catch (SecurityAccessDeniedException e) { HandleException(e); }
            catch (Exception e) { HandleException(e); }
            finally
            {
                // Always dispose the service object to close the service connection and free resources.
                if (serviceProxy != null)
                {
                    serviceProxy.Dispose();
                }

                Console.WriteLine("Press <Enter> to exit.");
                Console.ReadLine();
            }
        }
Ejemplo n.º 12
0
 public void logout()
 {
     organizationServiceProxy.Dispose();
 }