Exemplo n.º 1
0
        private void BtnImportClick(object sender, EventArgs e)
        {
            var iSettings = new ImportSettings
            {
                ImportId = Guid.NewGuid(),
                DownloadLog = chkDownload.Checked,
                IsFolder = true,
                Path = txtFolderPath.Text,
                Publish = chkPublish.Checked,
                Activate = chkActivate.Checked,
                ConvertToManaged = chkConvertToManaged.Checked,
                OverwriteUnmanagedCustomizations = chkOverwriteUnmanagedCustomizations.Checked,
            };

            ExecuteMethod(ImportArchive, iSettings);
        }
Exemplo n.º 2
0
        //Downloads the import log file
        public string DownloadLogFile(string path, ImportSettings settings)
        {
            try
            {
                var importLogRequest = new RetrieveFormattedImportJobResultsRequest
                                           {
                                               ImportJobId = settings.ImportId
                                           };
                var importLogResponse =
                    (RetrieveFormattedImportJobResultsResponse)innerService.Execute(importLogRequest);
                DateTime time = DateTime.Now;
                string format = "yyyy_MM_dd__HH_mm";
                string filePath = path.Replace(".zip", "-") + time.ToString(format) + ".xml";
                File.WriteAllText(filePath, importLogResponse.FormattedResults);

                return filePath;
            }
            catch (Exception)
            {
                // Do nothing
                return string.Empty;
            }
        }
Exemplo n.º 3
0
        public void ImportSolutionArchive(string archivePath, ImportSettings settings)
        {
            try
            {
                importPath = archivePath; //sets the global variable for the import path



                var request = new ImportSolutionRequest
                {
                    ConvertToManaged  = settings.ConvertToManaged,
                    CustomizationFile = File.ReadAllBytes(archivePath),
                    OverwriteUnmanagedCustomizations = settings.OverwriteUnmanagedCustomizations,
                    PublishWorkflows = settings.Activate,
                    ImportJobId      = settings.ImportId
                };

                if (settings.MajorVersion >= 6)
                {
                    var requestAsync = new ExecuteAsyncRequest
                    {
                        Request = request
                    };

                    innerService.Execute(requestAsync);

                    bool isfinished = false;
                    do
                    {
                        try
                        {
                            var job = innerService.Retrieve("importjob", settings.ImportId, new ColumnSet(true));

                            if (job.Contains("completedon"))
                            {
                                isfinished = true;
                            }
                        }
                        catch
                        {
                        }

                        Thread.Sleep(2000);
                    } while (isfinished == false);
                }
                else
                {
                    innerService.Execute(request);
                }
            }
            catch (FaultException <OrganizationServiceFault> error)
            {
                throw new Exception("An error while importing archive: " + error.Message);
            }
            finally
            {
                if (settings.DownloadLog)
                {
                    string filePath = DownloadLogFile(importPath, settings);

                    if (MessageBox.Show("Do you want to open the log file now?\r\n\r\nThe file will also be available on disk: " + filePath, "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        Process.Start("Excel.exe", "\"" + filePath + "\"");
                    }
                }
            }
        }
Exemplo n.º 4
0
 private void GbImportSolutionDragDrop(object sender, DragEventArgs e)
 {
     var iSettings = new ImportSettings
     {
         ImportId = Guid.NewGuid(),
         DownloadLog = chkDownload.Checked,
         IsFolder = false,
         Path = ((string[])e.Data.GetData(DataFormats.FileDrop))[0],
         Publish = chkPublish.Checked,
         Activate = chkActivate.Checked,
         ConvertToManaged = chkConvertToManaged.Checked,
         OverwriteUnmanagedCustomizations = chkOverwriteUnmanagedCustomizations.Checked,
     };
     ExecuteMethod(ImportArchive, iSettings);
 }
Exemplo n.º 5
0
        private void ImportArchive(ImportSettings iSettings)
        {
            if (ConnectionDetail.OrganizationMajorVersion == 8)
            {
                if (DialogResult.No == MessageBox.Show(ParentForm,
                        "This plugin has not been tested with CRM 2016 yet, especially regarding new solution framework\r\n\r\nAre you sure you want to continue?",
                        "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning))
                {
                    return;
                }
            }

            sManager = new SolutionManager(Service);
            iSettings.MajorVersion = ConnectionDetail.OrganizationMajorVersion;

            currentOperationId = iSettings.ImportId;

            EnableControls(false);

            WorkAsync(new WorkAsyncInfo
            {
                Message = "Importing solution...",
                AsyncArgument = iSettings,
                Work = (bw, e) =>
                {
                    var settings = (ImportSettings)e.Argument;

                    // Launch a new thread to monitor import status
                    if (settings.IsFolder)
                    {
                        sManager.ImportSolutionFolder(settings);
                    }
                    else
                    {
                        sManager.ImportSolutionArchive(settings.Path, settings);
                    }

                    if (((ImportSettings)e.Argument).Publish)
                    {
                        bw.ReportProgress(101, "Publishing solution...");
                        sManager.PublishAll();
                    }
                },
                PostWorkCallBack = e =>
                {
                    if (e.Error != null)
                    {
                        var eForm = new ErrorForm(e.Error.Message);
                        eForm.ShowDialog();
                    }

                    EnableControls(true);
                },
                ProgressChanged = e => { SetWorkingMessage(e.ProgressPercentage <= 100 ? "Importing solution..." : "Publishing solution..."); }
            });
        }
Exemplo n.º 6
0
        private void ImportArchive(ImportSettings iSettings)
        {
            sManager = new SolutionManager(Service);
            iSettings.MajorVersion = ConnectionDetail.OrganizationMajorVersion;

            currentOperationId = iSettings.ImportId;

            EnableControls(false);

            WorkAsync("Importing solution...",
                (bw, e) =>
                {
                    var settings = (ImportSettings)e.Argument;

                    // Launch a new thread to monitor import status
                    if (settings.IsFolder)
                    {
                        sManager.ImportSolutionFolder(settings);
                    }
                    else
                    {
                        sManager.ImportSolutionArchive(settings.Path, settings);
                    }

                    if (((ImportSettings)e.Argument).Publish)
                    {
                        bw.ReportProgress(101, "Publishing solution...");
                        sManager.PublishAll();
                    }
                },
                e =>
                {
                    if (e.Error != null)
                    {
                        var eForm = new ErrorForm(e.Error.Message);
                        eForm.ShowDialog();
                    }

                    EnableControls(true);
                },
                e => SetWorkingMessage(e.ProgressPercentage <= 100 ? "Importing solution..." : "Publishing solution..."),
                iSettings);
        }
Exemplo n.º 7
0
        public void ImportSolutionArchive(string archivePath, ImportSettings settings)
        {
            try
            {
                importPath = archivePath; //sets the global variable for the import path

                var request = new ImportSolutionRequest
                                  {
                                      ConvertToManaged = settings.ConvertToManaged,
                                      CustomizationFile = File.ReadAllBytes(archivePath),
                                      OverwriteUnmanagedCustomizations = settings.OverwriteUnmanagedCustomizations,
                                      PublishWorkflows = settings.Activate,
                                      ImportJobId = settings.ImportId
                                  };

                if (settings.MajorVersion >= 6)
                {
                    var requestAsync = new ExecuteAsyncRequest
                    {
                        Request = request
                    };

                    innerService.Execute(requestAsync);

                    bool isfinished = false;
                    do
                    {
                        try
                        {
                            var job = innerService.Retrieve("importjob", settings.ImportId, new ColumnSet(true));

                            if (job.Contains("completedon"))
                            {
                                isfinished = true;
                            }
                        }
                        catch
                        {
                        }

                        Thread.Sleep(2000);
                    } while (isfinished == false);
                }
                else
                {
                    innerService.Execute(request);
                }
            }
            catch (FaultException<OrganizationServiceFault> error)
            {
                throw new Exception("An error while importing archive: " + error.Message);
            }
            finally
            {
                if (settings.DownloadLog)
                {
                    string filePath = DownloadLogFile(importPath, settings);

                    if (MessageBox.Show("Do you want to open the log file now?\r\n\r\nThe file will also be available on disk: " + filePath, "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        Process.Start("Excel.exe", "\"" + filePath + "\"");
                    }
                }
            }
        }
Exemplo n.º 8
0
        public void ImportSolutionFolder(ImportSettings settings)
        {
            try
            {
                var di = new DirectoryInfo(settings.Path);
                string folderToZip = di.FullName;
                zipFile = di.Name + ".zip";

                // Zip folder content
                ZipManager.ZipFiles(settings.Path, zipFile);

                ImportSolutionArchive(zipFile, settings);

                File.Delete(zipFile);
            }
            catch (FaultException<OrganizationServiceFault> error)
            {
                throw new Exception("An error while importing archive: " + error.Message);
            }
            catch (Exception error)
            {
                throw new Exception("An error while importing archive: " + error.Message);
            }
            finally
            {
                if (settings.DownloadLog)
                {
                    string filePath = DownloadLogFile(importPath, settings);

                    if (MessageBox.Show("Do you want to open the log file now?\r\n\r\nThe file will also be available on disk: " + filePath, "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        Process.Start("Excel.exe", "\"" + filePath + "\"");
                    }
                }
            }
        }