Exemplo n.º 1
0
        private static void Run()
        {
            IOrganizationService sourceOrg = CrmConnectorUtil.Connect(Properties.Settings.Default.SourceCrmConnectionString);
            IOrganizationService targetOrg = CrmConnectorUtil.Connect(Properties.Settings.Default.TargetCrmConnectionString);

            string uniqueName = Prompt("Solution Unique Name", "Cannot be empty");

            Console.Write("Exporting...");
            ExportSolutionResponse exportRespone = ExportSolution(uniqueName, sourceOrg);

            byte[] solutionBytes = exportRespone.ExportSolutionFile;
            ExConsole.WriteLineToRight("[Done]");

            Console.Write("Importing...");
            ImportSolutionResponse importResponse = ImportSolution(solutionBytes, targetOrg);

            ExConsole.WriteLineToRight("[Done]");

            if (importResponse != null)
            {
                Console.Write("Publishing...");
                Publish(targetOrg);
                ExConsole.WriteLineToRight("[Done]");
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            // Connect to CRM
            _organizationService = CrmConnectorUtil.Connect(Properties.Settings.Default.CrmConnectionString);

            // Prompt for existing option set attribute name
            string entityLogicalName    = PromptEntityLogicalName();
            string attributeLogicalName = PromptAttributeLogicalName();

            // Retrieve option set
            IList <OptionMetadata> optionMetadatas = RetrieveOptionSetAttributeMetadata(entityLogicalName, attributeLogicalName);

            if (!Validator.IsNullOrEmpty(optionMetadatas))
            {
                // Prompt for new global option set name
                string globalOptionSetLogicalName = PromptGlobalOptionSetLogicalName();
                string globalOptionSetDisplayName = PromptGlobalOptionSetDisplayName();

                // Create global option set
                if (!DoesGlobalOptionSetExist(globalOptionSetLogicalName))
                {
                    CreateGlobalOptionSet(globalOptionSetLogicalName, globalOptionSetDisplayName, optionMetadatas);
                }
            }

            Console.WriteLine("Complete");
            Console.ReadLine();
        }
Exemplo n.º 3
0
        static IOrganizationService GetOrganizationService(string connectionString = null)
        {
            IAppSettingsManager   appSettingsManager   = new AppSettingsManager(Properties.Settings.Default);
            ICrmCredentialManager crmCredentialManager = new CrmCredentialManager(appSettingsManager);
            IOrganizationService  organizationService  = CrmConnectorUtil.Connect(crmCredentialManager);

            return(organizationService);
        }
Exemplo n.º 4
0
        private static IOrganizationService ConnectToTarget(string connectionString)
        {
            string crmConnectionString = Properties.Settings.Default.TargetCrmConnectionString;

            if (string.IsNullOrEmpty(crmConnectionString) && string.IsNullOrEmpty(connectionString))
            {
                return(null);
            }
            return(CrmConnectorUtil.Connect(connectionString ?? crmConnectionString));
        }
Exemplo n.º 5
0
        private static void Main(string[] args)
        {
            // Connect to CRM
            string crmConnectionString = Properties.Settings.Default.CrmConnectionString;
            IOrganizationService organizationService = CrmConnectorUtil.Connect(crmConnectionString);

            // Get solution
            Entity solution = SolutionUtil.GetSolution(organizationService);

            if (solution == null)
            {
                return;
            }

            // Execute action
            Action <IOrganizationService, Entity> action = PromptForAction();

            action.Invoke(organizationService, solution);

            Console.WriteLine("Complete");
            Console.ReadLine();
        }
Exemplo n.º 6
0
        private static void Main()
        {
            Config config = ConfigParser <Config> .Read("Config.json");

            OrganizationServiceProxy organizationService = CrmConnectorUtil.Connect(config.ConnectionString) as OrganizationServiceProxy;

            if (organizationService != null)
            {
                IList <string> solutionUniqueNames = config.Solutions;

                if (config.TimeoutMinutes > 0)
                {
                    organizationService.Timeout = new TimeSpan(0, config.TimeoutMinutes, 0);
                }

                if (Validator.IsNullOrEmpty(solutionUniqueNames))
                {
                    ExConsole.WriteLine("No solutions found in Config.json, backing up all");
                    solutionUniqueNames = GetAllUnmanagedSolutions(organizationService);
                    if (config.ExcludeDefault)
                    {
                        solutionUniqueNames = solutionUniqueNames.Where(n => n.ToLower() != "default").ToList();
                    }
                }

                ExConsole.WriteLine($"Discovered {solutionUniqueNames.Count} solutions");

                new SolutionExport(organizationService).ExportMultiple(solutionUniqueNames, config.OutputPath, config.OutputFolderDateFormat);
            }

            ExConsole.WriteColor("Complete", ConsoleColor.Green);
            if (config.PromptBeforeClose)
            {
                Console.ReadLine();
            }
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            try
            {
                string connectionString = Properties.Settings.Default.CrmConnectionString;
                using (OrganizationServiceProxy orgSvc = CrmConnectorUtil.Connect(connectionString) as OrganizationServiceProxy)
                {
                    // This statement is required to enable early-bound type support.
                    orgSvc.EnableProxyTypes();

                    FunctionType functionType = Prompter.ChooseFunction();
                    switch (functionType)
                    {
                    case FunctionType.ShowSolutionDependencies:
                    {
                        new SolutionComponentDependencyReport(orgSvc).Create();
                        break;
                    }

                    case FunctionType.MarkAttributesAsDepricated:
                    {
                        var reporter = new AttributeNoDependencyReport(orgSvc);
                        IList <ComponentInfo> componentInfos = reporter.Find();

                        bool prompt     = Prompter.YesNo("Prompt before marking depricated", true);
                        var  depricator = new AttributeDeprecator(orgSvc, prompt);
                        depricator.Process(componentInfos);

                        break;
                    }

                    case FunctionType.ShowAttributesWithNoDependencies:
                    {
                        var reporter = new AttributeNoDependencyReport(orgSvc);
                        IList <ComponentInfo> componentInfos = reporter.Find();
                        break;
                    }

                    case FunctionType.ShowGlobalOptionSetDependecies:
                    {
                        new GlobalOptionSetDependecyReport(orgSvc).Create();
                        break;
                    }

                    default:
                    {
                        throw new NotImplementedException($"Function type {functionType} is not implemented");
                    }
                    }
                }
            }
            catch (FaultException <OrganizationServiceFault> ex)
            {
                Console.WriteLine("The application terminated with an error.");
                Console.WriteLine("Timestamp: {0}", ex.Detail.Timestamp);
                Console.WriteLine("Code: {0}", ex.Detail.ErrorCode);
                Console.WriteLine("Message: {0}", ex.Detail.Message);
                Console.WriteLine("Plugin Trace: {0}", ex.Detail.TraceText);
                Console.WriteLine("Inner Fault: {0}",
                                  null == ex.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault");
            }
            catch (TimeoutException ex)
            {
                Console.WriteLine("The application terminated with an error.");
                Console.WriteLine("Message: {0}", ex.Message);
                Console.WriteLine("Stack Trace: {0}", ex.StackTrace);
                Console.WriteLine("Inner Fault: {0}", ex.InnerException.Message ?? "No Inner Fault");
            }
            catch (Exception ex)
            {
                Console.WriteLine("The application terminated with an error.");
                Console.WriteLine(ex.Message);

                // Display the details of the inner exception.
                if (ex.InnerException != null)
                {
                    Console.WriteLine(ex.InnerException.Message);

                    FaultException <OrganizationServiceFault> fe = ex.InnerException
                                                                   as FaultException <OrganizationServiceFault>;
                    if (fe != null)
                    {
                        Console.WriteLine("Timestamp: {0}", fe.Detail.Timestamp);
                        Console.WriteLine("Code: {0}", fe.Detail.ErrorCode);
                        Console.WriteLine("Message: {0}", fe.Detail.Message);
                        Console.WriteLine("Plugin Trace: {0}", fe.Detail.TraceText);
                        Console.WriteLine("Inner Fault: {0}",
                                          null == fe.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault");
                    }
                }
            }
            // Additional exceptions to catch: SecurityTokenValidationException, ExpiredSecurityTokenException,
            // SecurityAccessDeniedException, MessageSecurityException, and SecurityNegotiationException.
            finally
            {
                Console.WriteLine("Press <Enter> to exit.");
                Console.ReadLine();
            }
        }
Exemplo n.º 8
0
        private static IOrganizationService ConnectToSource(string connectionString)
        {
            string crmConnectionString = Properties.Settings.Default.SourceCrmConnectionString;

            return(CrmConnectorUtil.Connect(connectionString ?? crmConnectionString));
        }