Exemple #1
0
        public void ImportSolutionTest_AsyncRibbon_ComponetData()
        {
            Mock <IOrganizationService> orgSvc = null;
            Mock <MoqHttpMessagehander> fakHttpMethodHander = null;
            ServiceClient cli = null;

            testSupport.SetupMockAndSupport(out orgSvc, out fakHttpMethodHander, out cli, new Version("9.2.21013.117"));

            ImportSolutionResponse importResponse = new ImportSolutionResponse();

            orgSvc.Setup(f => f.Execute(It.Is <ImportSolutionRequest>(
                                            (p) =>
                                            p.CustomizationFile != null &&
                                            p.AsyncRibbonProcessing.Equals(true) &&
                                            p.ComponentParameters != null))).Returns(importResponse);

            string SampleSolutionPath = Path.Combine("TestMaterial", "EnvVarsSample_1_0_0_2.zip");

            EntityCollection entCollection = new EntityCollection();

            Dictionary <string, object> importParams = new Dictionary <string, object>();

            importParams.Add(ImportSolutionProperties.ASYNCRIBBONPROCESSING, true);
            importParams.Add(ImportSolutionProperties.COMPONENTPARAMETERSPARAM, entCollection);
            Guid importId = Guid.Empty;
            var  result   = cli.ImportSolution(SampleSolutionPath, out importId, activatePlugIns: true, extraParameters: importParams);

            Assert.NotEqual(result, Guid.Empty);
        }
Exemple #2
0
        public static bool ImportSolution(CrmServiceClient client, string path)
        {
            byte[] solutionBytes = CrmDeveloperExtensions2.Core.FileSystem.GetFileBytes(path);
            if (solutionBytes == null)
            {
                return(false);
            }

            try
            {
                ImportSolutionRequest request = new ImportSolutionRequest
                {
                    //TODO: make configurable
                    CustomizationFile = solutionBytes,
                    OverwriteUnmanagedCustomizations = true,
                    PublishWorkflows = true,
                    ImportJobId      = Guid.NewGuid()
                };

                ImportSolutionResponse response = (ImportSolutionResponse)client.Execute(request);

                return(true);
            }
            catch (FaultException <OrganizationServiceFault> crmEx)
            {
                OutputLogger.WriteToOutputWindow("Error Importing Solution To CRM: " + crmEx.Message + Environment.NewLine + crmEx.StackTrace, MessageType.Error);
                return(false);
            }
            catch (Exception ex)
            {
                OutputLogger.WriteToOutputWindow("Error Importing Solution To CRM: " + ex.Message + Environment.NewLine + ex.StackTrace, MessageType.Error);
                return(false);
            }
        }
Exemple #3
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]");
            }
        }
Exemple #4
0
        public virtual ImportSolutionResponse ImportSolution(Guid importJobId, byte[] content, bool holdingSolution, bool overwriteUnmanagedCustomizations, bool publishWorkflows, bool skipProductUpdateDependencies)
        {
            Logger.Trace(CultureInfo.InvariantCulture, TraceMessageHelper.EnteredMethod, SystemTypeName, MethodBase.GetCurrentMethod().Name);

            if (Guid.Empty.Equals(importJobId))
            {
                throw new ArgumentNullException(nameof(importJobId));
            }
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }

            ImportSolutionRequest req = new ImportSolutionRequest()
            {
                CustomizationFile = content,
                HoldingSolution   = holdingSolution,
                ImportJobId       = importJobId,
                OverwriteUnmanagedCustomizations = overwriteUnmanagedCustomizations,
                PublishWorkflows = publishWorkflows,
                SkipProductUpdateDependencies = skipProductUpdateDependencies
            };
            ImportSolutionResponse res = (ImportSolutionResponse)OrganizationService.Execute(req);

            Logger.Trace(CultureInfo.InvariantCulture, TraceMessageHelper.ExitingMethod, SystemTypeName, MethodBase.GetCurrentMethod().Name);

            return(res);
        }
        private void ImportUnmanagedSolution(string solutionPath)
        {
            byte[] solutionBytes = File.ReadAllBytes(solutionPath);

            var request = new ImportSolutionRequest
            {
                OverwriteUnmanagedCustomizations = true,
                PublishWorkflows  = true,
                CustomizationFile = solutionBytes,
                ImportJobId       = Guid.NewGuid()
            };

            ExConsole.WriteLine("Importing solution...");

            ImportSolutionResponse response = (ImportSolutionResponse)_targetOrganizationService.Execute(request);

            ExConsole.WriteLineToRight("[Done]");
        }
        public static void Main(String managedSolutionLocation, String crmUrl, String organization)
        {
            Guid _importJobId = Guid.NewGuid();

            try
            {
                using (_client = new CrmServiceClient("Url=" + crmUrl + organization + "; authtype=AD; RequireNewInstance=True;"))
                {
                    try
                    {
                        Console.WriteLine("----------------------------------------------------------------------");
                        if (_client.IsReady == false)
                        {
                            Console.WriteLine("No se pudo establecer la conexion verifique la fuente");
                            return;
                        }
                        byte[] fileBytes = File.ReadAllBytes(managedSolutionLocation);
                        ImportSolutionRequest impSolReq = new ImportSolutionRequest()
                        {
                            CustomizationFile = fileBytes,
                            ImportJobId       = _importJobId,
                            OverwriteUnmanagedCustomizations = true,
                            SkipProductUpdateDependencies    = true,
                            PublishWorkflows = true,
                        };
                        ImportSolutionResponse impSolResp = new ImportSolutionResponse();
                        _client.Execute(impSolReq);
                        // On success escribe el customization file .xml
                        CreateFile(impSolReq.ImportJobId, managedSolutionLocation, ".xml");
                    }
                    catch (FaultException <OrganizationServiceFault> ex)
                    {
                        string _voidMessageDumpError = ex.Message;
                        //No hago nada con el error ya que el metodo create file lo busca en tabla ImportJob y escribe si hay error en el customization file
                        CreateFile(_importJobId, managedSolutionLocation, ".xml");
                    }
                }
            }
            catch (FaultException <OrganizationServiceFault> ex)
            {
                string message = ex.Message;
                throw;
            }
        }
Exemple #7
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            base.WriteVerbose(string.Format("Importing Solution: {0}", SolutionFilePath));

            CrmConnection connection = CrmConnection.Parse(connectionString);

            if (importJobId == Guid.Empty)
            {
                ImportJobId = Guid.NewGuid();
            }

            base.WriteVerbose(string.Format("ImportJobId {0}", ImportJobId));

            using (OrganizationService service = new OrganizationService(connection))
            {
                byte[] solutionBytes = File.ReadAllBytes(solutionFilePath);

                ImportSolutionRequest importSolutionRequest = new ImportSolutionRequest()
                {
                    CustomizationFile = solutionBytes,
                    PublishWorkflows  = publishWorkflows,
                    ConvertToManaged  = convertToManaged,
                    OverwriteUnmanagedCustomizations = overwriteUnmanagedCustomizations,
                    SkipProductUpdateDependencies    = skipProductUpdateDependencies,
                    ImportJobId = ImportJobId,
                    RequestId   = ImportJobId
                };

                if (importAsync)
                {
                    Guid asyncJobId;

                    ExecuteAsyncRequest asyncRequest = new ExecuteAsyncRequest()
                    {
                        Request   = importSolutionRequest,
                        RequestId = ImportJobId
                    };
                    ExecuteAsyncResponse asyncResponse = service.Execute(asyncRequest) as ExecuteAsyncResponse;

                    asyncJobId = asyncResponse.AsyncJobId;

                    WriteObject(asyncJobId);

                    if (waitForCompletion)
                    {
                        DateTime end = DateTime.Now.AddSeconds(asyncWaitTimeout);

                        bool completed = false;
                        while (!completed)
                        {
                            if (end < DateTime.Now)
                            {
                                throw new Exception(string.Format("Import Timeout Exceeded: {0}", asyncWaitTimeout));
                            }

                            Thread.Sleep(SleepInterval * 1000);

                            AsyncOperation asyncOperation;

                            try
                            {
                                asyncOperation = service.Retrieve("asyncoperation", asyncJobId,
                                                                  new ColumnSet("asyncoperationid", "statuscode", "message")).ToEntity <AsyncOperation>();
                            }
                            catch (Exception ex)
                            {
                                base.WriteWarning(ex.Message);
                                continue;
                            }

                            switch (asyncOperation.StatusCode.Value)
                            {
                            //Succeeded
                            case 30:
                                completed = true;
                                break;

                            //Pausing //Canceling //Failed //Canceled
                            case 21:
                            case 22:
                            case 31:
                            case 32:
                                throw new Exception(string.Format("Solution Import Failed: {0} {1}",
                                                                  asyncOperation.StatusCode.Value, asyncOperation.Message));

                            default:
                                break;
                            }
                        }
                    }
                }
                else
                {
                    ImportSolutionResponse importSolutionResponse = service.Execute(importSolutionRequest) as ImportSolutionResponse;
                }

                base.WriteVerbose(string.Format("{0} Imported Completed {1}", SolutionFilePath, importJobId));
            }
        }
Exemple #8
0
        public void ImportSolution(string fileName)
        {
            byte[] importXml = System.IO.File.ReadAllBytes(fileName);

            Guid importId = Guid.NewGuid();
            ImportSolutionRequest importSolutionRequest = new ImportSolutionRequest();

            importSolutionRequest.ImportJobId       = importId;
            importSolutionRequest.CustomizationFile = importXml;
            importSolutionRequest.PublishWorkflows  = true;
            importSolutionRequest.OverwriteUnmanagedCustomizations = true;
            importSolutionRequest.PublishWorkflows = true;
            importSolutionRequest.SkipProductUpdateDependencies = false;
            try
            {
                ImportSolutionResponse resp = (ImportSolutionResponse)Service.Execute(importSolutionRequest);
                if (resp.Results.Count > 0)
                {
                    //Testing
                    resp = resp;
                }
            }
            catch (Exception ex)
            {
                //Could not find the import job. Let's output asyncJobError (hopefully there is something)
                throw new Exception("An error has occured while exporting the solution: " + ex.Message);
            }

            /*
             * var requestAsync = new ExecuteAsyncRequest
             * {
             *  Request = importSolutionRequest
             * };
             *
             * string asyncJobError = "";
             * var response = (ExecuteAsyncResponse)Service.Execute(requestAsync);
             *
             *  DateTime end = DateTime.Now.AddSeconds(600);
             * while (end >= DateTime.Now && String.IsNullOrEmpty(asyncJobError))
             * {
             *  Entity asyncOperation = Service.Retrieve("asyncoperation", response.AsyncJobId,
             *     new ColumnSet("asyncoperationid", "statuscode", "message"));
             *  switch (((OptionSetValue)asyncOperation["statuscode"]).Value)
             *  {
             *      //Succeeded
             *      case 30:
             *          break;
             *      //Pausing //Canceling //Failed //Canceled
             *      case 21:
             *      case 22:
             *      case 31:
             *      case 32:
             *          asyncJobError = (string)asyncOperation["message"];
             *          break;
             *      default:
             *          break;
             *  }
             * }
             *
             * try
             * {
             *  var job = Service.Retrieve("importjob", importId, new ColumnSet(true));
             *
             *  if (job.Contains("completedon"))
             *  {
             *      string data = (string)job["data"];
             *      if (data.IndexOf("result=\"failure\"") > 0 || !String.IsNullOrEmpty(asyncJobError))
             *      {
             *          throw new Exception("An error has occured while exporting the solution: " + asyncJobError + data);
             *      }
             *
             *  }
             * }
             * catch (System.ServiceModel.FaultException ex)
             * {
             *  //Could not find the import job. Let's output asyncJobError (hopefully there is something)
             *  throw new Exception("An error has occured while exporting the solution: " + asyncJobError);
             * }
             */
            PublishAll();
        }