/// <summary>
        /// Creates the profile.
        /// </summary>
        /// <param name="profile">The profile.</param>
        public void CreateProfile(MSCRMSolutionsTransportProfile profile)
        {
            if (!Directory.Exists(Folder + "\\" + profile.ProfileName))
                Directory.CreateDirectory(Folder + "\\" + profile.ProfileName);

            //Creating new Profile
            Profiles.Add(profile);
            WriteProfiles();
            LogManager.WriteLog("Solutions Transport Profile " + profile.ProfileName + " created");
        }
        /// <summary>
        /// Deletes the profile.
        /// </summary>
        /// <param name="profile">The profile.</param>
        /// <exception cref="System.Exception">Solutions Transport Profile deletion failed. The Solution Transport Profile  + profile.ProfileName +  was not found in the configuration file.</exception>
        public void DeleteProfile(MSCRMSolutionsTransportProfile profile)
        {
            int index = Profiles.FindIndex(d => d.ProfileName == profile.ProfileName);
            if (index > -1)
            {
                Profiles.RemoveAt(index);
            }
            else
            {
                LogManager.WriteLog("Solutions Transport Profile deletion failed. The Solution Transport Profile " + profile.ProfileName + " was not found in the configuration file.");
                throw new Exception("Solutions Transport Profile deletion failed. The Solution Transport Profile " + profile.ProfileName + " was not found in the configuration file.");
            }

            //Delete Profile folder
            try
            {
                if (Directory.Exists(profile.SolutionExportFolder))
                    Directory.Delete(profile.SolutionExportFolder, true);
            }
            catch (Exception)
            {
                throw;
            }

            //Save profiles
            WriteProfiles();
            LogManager.WriteLog("Solutions Transport Profile " + profile.ProfileName + " updated");
        }
        /// <summary>
        /// Exports the specified profile.
        /// </summary>
        /// <param name="profile">The profile.</param>
        private void Export(MSCRMSolutionsTransportProfile profile)
        {
            try
            {
                //Set Data export folder
                if (!Directory.Exists(profile.SolutionExportFolder))
                    Directory.CreateDirectory(profile.SolutionExportFolder);

                MSCRMConnection connection = profile.getSourceConneciton();
                _serviceProxy = cm.connect(connection);

                //Download fresh list of solutions for versions update
                List<MSCRMSolution> solutions = DownloadSolutions(connection);

                DateTime now = DateTime.Now;
                string folderName = String.Format("{0:yyyyMMddHHmmss}", now);

                if (!Directory.Exists(profile.SolutionExportFolder + "\\" + folderName))
                    Directory.CreateDirectory(profile.SolutionExportFolder + "\\" + folderName);

                foreach (string SolutionName in profile.SelectedSolutionsNames)
                {
                    //Check if customizations are to be published
                    if (profile.PublishAllCustomizationsSource)
                    {
                        LogManager.WriteLog("Publishing all Customizations on " + connection.ConnectionName + " ...");
                        PublishAllXmlRequest publishRequest = new PublishAllXmlRequest();
                        _serviceProxy.Execute(publishRequest);
                    }
                    LogManager.WriteLog("Exporting Solution " + SolutionName + " from " + connection.ConnectionName);

                    ExportSolutionRequest exportSolutionRequest = new ExportSolutionRequest();
                    exportSolutionRequest.Managed = profile.ExportAsManaged;
                    exportSolutionRequest.SolutionName = SolutionName;
                    exportSolutionRequest.ExportAutoNumberingSettings = profile.ExportAutoNumberingSettings;
                    exportSolutionRequest.ExportCalendarSettings = profile.ExportCalendarSettings;
                    exportSolutionRequest.ExportCustomizationSettings = profile.ExportCustomizationSettings;
                    exportSolutionRequest.ExportEmailTrackingSettings = profile.ExportEmailTrackingSettings;
                    exportSolutionRequest.ExportGeneralSettings = profile.ExportGeneralSettings;
                    exportSolutionRequest.ExportIsvConfig = profile.ExportIsvConfig;
                    exportSolutionRequest.ExportMarketingSettings = profile.ExportMarketingSettings;
                    exportSolutionRequest.ExportOutlookSynchronizationSettings = profile.ExportOutlookSynchronizationSettings;
                    exportSolutionRequest.ExportRelationshipRoles = profile.ExportRelationshipRoles;

                    string managed = "";
                    if (profile.ExportAsManaged)
                        managed = "managed";
                    MSCRMSolution selectedSolution = solutions.Find(s => s.UniqueName == SolutionName);
                    string selectedSolutionVersion = selectedSolution.Version.Replace(".","_");
                    ExportSolutionResponse exportSolutionResponse = (ExportSolutionResponse)_serviceProxy.Execute(exportSolutionRequest);
                    byte[] exportXml = exportSolutionResponse.ExportSolutionFile;
                    string filename = SolutionName + "_" + selectedSolutionVersion + "_" + managed + ".zip";
                    File.WriteAllBytes(profile.SolutionExportFolder + "\\" + folderName + "\\" + filename, exportXml);
                    LogManager.WriteLog("Export finished for Solution: " + SolutionName + ". Exported file: " + filename);
                }
                LogManager.WriteLog("Export finished for Profile: " + profile.ProfileName);
            }
            catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> ex)
            {
                LogManager.WriteLog("Error:" + ex.Detail.Message + "\n" + ex.Detail.TraceText);
                throw;
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                    LogManager.WriteLog("Error:" + ex.Message + "\n" + ex.InnerException.Message);
                else
                    LogManager.WriteLog("Error:" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// Imports the specified profile.
        /// </summary>
        /// <param name="profile">The profile.</param>
        private void Import(MSCRMSolutionsTransportProfile profile)
        {
            //Check if there is a solutions to import
            if (Directory.Exists(profile.SolutionExportFolder))
            {
                IOrderedEnumerable<string> subDirectories = Directory.GetDirectories(profile.SolutionExportFolder).OrderByDescending(x => x);
                if (subDirectories.Count<string>() == 0)
                {
                    LogManager.WriteLog("There are no solutions for import.");
                    return;
                }

                //Check which solutions to import: Newest, Oldest, specific exprot date solutions
                string solutionsToImportFolder = "";
                if (profile.SolutionsToImport == "Newest")
                    solutionsToImportFolder = subDirectories.ElementAt(0);
                else if (profile.SolutionsToImport == "Oldest")
                    solutionsToImportFolder = subDirectories.ElementAt(subDirectories.Count<string>() - 1);
                else
                    solutionsToImportFolder = subDirectories.First(s => s.EndsWith(profile.SolutionsToImport));

                if (solutionsToImportFolder == "")
                {
                    LogManager.WriteLog("The specified solutions to import were not found.");
                    return;
                }

                //get all solutions archives
                string[] solutionsArchivesNames = Directory.GetFiles(solutionsToImportFolder, "*.zip");
                if (solutionsArchivesNames.Count<string>() == 0)
                {
                    LogManager.WriteLog("There are no solutions for import.");
                    return;
                }

                string[] pathList = solutionsToImportFolder.Split(new Char [] {'\\'});
                string DirectoryName = pathList[pathList.Count<string>() -1];
                LogManager.WriteLog("Importing solutions from " + DirectoryName);

                MSCRMConnection connection = profile.getTargetConneciton();
                _serviceProxy = cm.connect(connection);
                LogManager.WriteLog("Start importing solutions in " + connection.ConnectionName);

                foreach (string solutionArchiveName in solutionsArchivesNames)
                {
                    bool selectedsolutionfound = false;
                    foreach (string solutionname in profile.SelectedSolutionsNames)
                    {
                        if (Path.GetFileName(solutionArchiveName).StartsWith(solutionname))
                            selectedsolutionfound = true;
                    }

                    if (!selectedsolutionfound)
                        continue;

                    //Import Solution
                    LogManager.WriteLog("Importing solution archive " + Path.GetFileName(solutionArchiveName) + " into " + connection.ConnectionName);

                    byte[] fileBytes = File.ReadAllBytes(solutionArchiveName);

                    Guid ImportJobId = Guid.NewGuid();

                    ImportSolutionRequest impSolReqWithMonitoring = new ImportSolutionRequest()
                    {
                        CustomizationFile = fileBytes,
                        OverwriteUnmanagedCustomizations = profile.OverwriteUnmanagedCustomizations,
                        PublishWorkflows = profile.PublishWorkflows,
                        ImportJobId = ImportJobId
                    };

                    _serviceProxy.Execute(impSolReqWithMonitoring);

                    Entity ImportJob = _serviceProxy.Retrieve("importjob", impSolReqWithMonitoring.ImportJobId, new ColumnSet(true));
                    //File.WriteAllText(solutionsToImportFolder + "\\importlog_ORIGINAL_" + Path.GetFileNameWithoutExtension(solutionArchiveName) + ".xml", (string)ImportJob["data"]);

                    RetrieveFormattedImportJobResultsRequest importLogRequest = new RetrieveFormattedImportJobResultsRequest()
                    {
                        ImportJobId = ImportJobId
                    };
                    RetrieveFormattedImportJobResultsResponse importLogResponse = (RetrieveFormattedImportJobResultsResponse)_serviceProxy.Execute(importLogRequest);

                    DateTime now = DateTime.Now;
                    string timeNow = String.Format("{0:yyyyMMddHHmmss}", now);

                    string exportedSolutionFileName = solutionsToImportFolder + "\\importlog_" + Path.GetFileNameWithoutExtension(solutionArchiveName) + "_" + timeNow + ".xml";

                    //Fix bad Status and Message export
                    System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                    doc.LoadXml((string)ImportJob["data"]);
                    String SolutionImportResult = doc.SelectSingleNode("//solutionManifest/result/@result").Value;

                    File.WriteAllText(exportedSolutionFileName, importLogResponse.FormattedResults);

                    LogManager.WriteLog("Solution " + Path.GetFileName(solutionArchiveName) + " was imported with success in " + connection.ConnectionName);
                }

                //Check if customizations are to be published
                if (profile.PublishAllCustomizationsTarget)
                {
                    LogManager.WriteLog("Publishing all Customizations on " + connection.ConnectionName + " ...");
                    PublishAllXmlRequest publishRequest = new PublishAllXmlRequest();
                    _serviceProxy.Execute(publishRequest);
                }

                LogManager.WriteLog("Solutions Import finished for Profile: " + profile.ProfileName);
            }
            else
            {
                LogManager.WriteLog("There are no solutions for import.");
                return;
            }
        }
        /// <summary>
        /// Runs the profile.
        /// </summary>
        /// <param name="profile">The profile.</param>
        public void RunProfile(MSCRMSolutionsTransportProfile profile)
        {
            LogManager.WriteLog("Running Solutions Transport Profile: " + profile.ProfileName);

            try
            {
                if (profile.Operation == 0)
                    Export(profile);
                else if (profile.Operation == 1)
                    Import(profile);
                else if (profile.Operation == 2)
                {
                    Export(profile);
                    Import(profile);
                }
            }
            catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> ex)
            {
                LogManager.WriteLog("Error:" + ex.Detail.Message + "\n" + ex.Detail.TraceText);
                return;
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    LogManager.WriteLog("Error:" + ex.Message + "\n" + ex.InnerException.Message);
                    return;
                }
                else
                {
                    LogManager.WriteLog("Error:" + ex.Message);
                    return;
                }
            }
        }
        /// <summary>
        /// Updates the profile.
        /// </summary>
        /// <param name="profile">The profile.</param>
        /// <exception cref="System.Exception">Solutions Transport Profile Update failed. The Solution Transport Profile  + profile.ProfileName +  was not found in the configuration file.</exception>
        public void UpdateProfile(MSCRMSolutionsTransportProfile profile)
        {
            if (!Directory.Exists(Folder + "\\" + profile.ProfileName))
                Directory.CreateDirectory(Folder + "\\" + profile.ProfileName);

            int index = Profiles.FindIndex(d => d.ProfileName == profile.ProfileName);
            if (index > -1)
            {
                Profiles[index] = profile;
            }
            else
            {
                LogManager.WriteLog("Solutions Transport Profile Update failed. The Solution Transport Profile " + profile.ProfileName + " was not found in the configuration file.");
                throw new Exception("Solutions Transport Profile Update failed. The Solution Transport Profile " + profile.ProfileName + " was not found in the configuration file.");
            }

            WriteProfiles();
            LogManager.WriteLog("Solutions Transport Profile " + profile.ProfileName + " updated.");
        }
Esempio n. 7
0
        /// <summary>
        /// Exports the specified profile.
        /// </summary>
        /// <param name="profile">The profile.</param>
        private void Export(MSCRMSolutionsTransportProfile profile)
        {
            try
            {
                //Set Data export folder
                if (!Directory.Exists(profile.SolutionExportFolder))
                {
                    Directory.CreateDirectory(profile.SolutionExportFolder);
                }

                MSCRMConnection connection = profile.getSourceConneciton();
                _serviceProxy = cm.connect(connection);

                //Download fresh list of solutions for versions update
                List <MSCRMSolution> solutions = DownloadSolutions(connection);

                DateTime now        = DateTime.Now;
                string   folderName = String.Format("{0:yyyyMMddHHmmss}", now);

                if (!Directory.Exists(profile.SolutionExportFolder + "\\" + folderName))
                {
                    Directory.CreateDirectory(profile.SolutionExportFolder + "\\" + folderName);
                }

                foreach (string SolutionName in profile.SelectedSolutionsNames)
                {
                    //Check if customizations are to be published
                    if (profile.PublishAllCustomizationsSource)
                    {
                        LogManager.WriteLog("Publishing all Customizations on " + connection.ConnectionName + " ...");
                        PublishAllXmlRequest publishRequest = new PublishAllXmlRequest();
                        _serviceProxy.Execute(publishRequest);
                    }
                    LogManager.WriteLog("Exporting Solution " + SolutionName + " from " + connection.ConnectionName);

                    ExportSolutionRequest exportSolutionRequest = new ExportSolutionRequest();
                    exportSolutionRequest.Managed      = profile.ExportAsManaged;
                    exportSolutionRequest.SolutionName = SolutionName;
                    exportSolutionRequest.ExportAutoNumberingSettings          = profile.ExportAutoNumberingSettings;
                    exportSolutionRequest.ExportCalendarSettings               = profile.ExportCalendarSettings;
                    exportSolutionRequest.ExportCustomizationSettings          = profile.ExportCustomizationSettings;
                    exportSolutionRequest.ExportEmailTrackingSettings          = profile.ExportEmailTrackingSettings;
                    exportSolutionRequest.ExportGeneralSettings                = profile.ExportGeneralSettings;
                    exportSolutionRequest.ExportIsvConfig                      = profile.ExportIsvConfig;
                    exportSolutionRequest.ExportMarketingSettings              = profile.ExportMarketingSettings;
                    exportSolutionRequest.ExportOutlookSynchronizationSettings = profile.ExportOutlookSynchronizationSettings;
                    exportSolutionRequest.ExportRelationshipRoles              = profile.ExportRelationshipRoles;

                    string managed = "";
                    if (profile.ExportAsManaged)
                    {
                        managed = "managed";
                    }
                    MSCRMSolution          selectedSolution        = solutions.Find(s => s.UniqueName == SolutionName);
                    string                 selectedSolutionVersion = selectedSolution.Version.Replace(".", "_");
                    ExportSolutionResponse exportSolutionResponse  = (ExportSolutionResponse)_serviceProxy.Execute(exportSolutionRequest);
                    byte[]                 exportXml = exportSolutionResponse.ExportSolutionFile;
                    string                 filename  = SolutionName + "_" + selectedSolutionVersion + "_" + managed + ".zip";
                    File.WriteAllBytes(profile.SolutionExportFolder + "\\" + folderName + "\\" + filename, exportXml);
                    LogManager.WriteLog("Export finished for Solution: " + SolutionName + ". Exported file: " + filename);
                }
                LogManager.WriteLog("Export finished for Profile: " + profile.ProfileName);
            }
            catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> ex)
            {
                LogManager.WriteLog("Error:" + ex.Detail.Message + "\n" + ex.Detail.TraceText);
                throw;
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    LogManager.WriteLog("Error:" + ex.Message + "\n" + ex.InnerException.Message);
                }
                else
                {
                    LogManager.WriteLog("Error:" + ex.Message);
                }
                throw;
            }
        }
Esempio n. 8
0
        private static void Main(string[] args)
        {
            //Set the application directory as the current directory
            string appPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);

            appPath = appPath.Replace("file:\\", "");
            Directory.SetCurrentDirectory(appPath);

            MSCRMSolutionsTransportManager man = new MSCRMSolutionsTransportManager();
            string selectedProfileName         = "";

            if (args.Length == 0)
            {
                if (man.Profiles.Count == 0)
                {
                    Console.WriteLine("\nNo profiles found.");
                    return;
                }

                //Display all profiles for selection
                Console.WriteLine("\nSpecify the Profile to run (1-{0}) [1] : ", man.Profiles.Count);
                int tpCpt = 1;
                foreach (MSCRMSolutionsTransportProfile profile in man.Profiles)
                {
                    Console.WriteLine(tpCpt + ". " + profile.ProfileName);
                    tpCpt++;
                }

                String input = Console.ReadLine();
                if (input == String.Empty)
                {
                    input = "1";
                }
                int depNumber;
                Int32.TryParse(input, out depNumber);
                if (depNumber > 0 && depNumber <= man.Profiles.Count)
                {
                    selectedProfileName = man.Profiles[depNumber - 1].ProfileName;
                }
                else
                {
                    Console.WriteLine("The specified Profile does not exist.");
                    return;
                }
            }
            else
            {
                //Check that the Profile name is provided
                if (string.IsNullOrEmpty(args[0]))
                {
                    return;
                }
                selectedProfileName = args[0];
            }

            MSCRMSolutionsTransportProfile p = man.GetProfile(selectedProfileName);

            if (p == null)
            {
                Console.WriteLine("The specified Profile does not exist.");
                return;
            }

            man.RunProfile(p);
        }
        private void deleteProfileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string currentProfileName = currentProfile.ProfileName;
            DialogResult dResTest;
            dResTest = MessageBox.Show("Deleting this Profile will delete also delete all the exported files in the Export Folder.\r\nAre you sure you want to delete this Solution Transport Profile ?", "Confirm Profile Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (dResTest == DialogResult.No)
            {
                return;
            }

            comboBoxProfiles.Items.Remove(currentProfile.ProfileName);
            comboBoxProfiles.SelectedItem = null;
            man.DeleteProfile(currentProfile);
            currentProfile = null;
            textBoxProfileName.Text = "";
            textBoxProfileName.Enabled = true;
            textBoxSelectedFolder.Text = "";
            comboBoxConnectionSource.SelectedItem = null;
            deleteProfileToolStripMenuItem.Enabled = false;
            newToolStripMenuItem.Enabled = false;
            saveToolStripMenuItem.Enabled = false;
            labelSolutionsRefreshedOn.Text = "";
            runProfileToolStripMenuItem.Enabled = false;
            checkBoxExportAsManaged.Checked = false;
            comboBoxOperation.SelectedIndex = -1;
            checkBoxPublishAllCustomizationsSource.Checked = false;
            checkedListBoxSettings.SetItemChecked(0, false);
            checkedListBoxSettings.SetItemChecked(1, false);
            checkedListBoxSettings.SetItemChecked(2, false);
            checkedListBoxSettings.SetItemChecked(3, false);
            checkedListBoxSettings.SetItemChecked(4, false);
            checkedListBoxSettings.SetItemChecked(5, false);
            checkedListBoxSettings.SetItemChecked(6, false);
            checkedListBoxSettings.SetItemChecked(7, false);
            checkedListBoxSettings.SetItemChecked(8, false);
            comboBoxConnectionTarget.SelectedIndex = -1;
            comboBoxSolutionsToImport.SelectedIndex = -1;
            checkBoxPublishAllCustomizationsTarget.Checked = false;
            checkBoxPublishWorkflows.Checked = false;
            checkBoxOverwriteUnmanagedCustomizations.Checked = false;

            this.importLogsToolStripMenuItem.DropDownItems.Clear();
            this.importLogsToolStripMenuItem.Visible = false;

            toolStripStatusLabel1.Text = "Profile " + currentProfileName + " deleted";
            LogManager.WriteLog("Profile " + currentProfileName + " deleted");
        }
        private void comboBoxSolutionExportProfiles_SelectedIndexChanged(object sender, EventArgs e)
        {
            comboBoxConnectionSource.SelectedItem = null;
            if (comboBoxProfiles.SelectedItem != null)
            {
                currentProfile = man.Profiles[comboBoxProfiles.SelectedIndex];
                textBoxProfileName.Text = currentProfile.ProfileName;
                comboBoxConnectionSource.SelectedItem = currentProfile.SourceConnectionName;
                deleteProfileToolStripMenuItem.Enabled = true;
                newToolStripMenuItem.Enabled = true;
                saveToolStripMenuItem.Enabled = true;
                textBoxProfileName.Enabled = false;
                runProfileToolStripMenuItem.Enabled = true;
                textBoxSelectedFolder.Text = currentProfile.SolutionExportFolder;

                checkBoxExportAsManaged.Checked = currentProfile.ExportAsManaged;
                comboBoxOperation.SelectedIndex = currentProfile.Operation;
                checkBoxPublishAllCustomizationsSource.Checked = currentProfile.PublishAllCustomizationsSource;

                checkedListBoxSettings.SetItemChecked(0, currentProfile.ExportAutoNumberingSettings);
                checkedListBoxSettings.SetItemChecked(1, currentProfile.ExportCalendarSettings);
                checkedListBoxSettings.SetItemChecked(2, currentProfile.ExportCustomizationSettings);
                checkedListBoxSettings.SetItemChecked(3, currentProfile.ExportEmailTrackingSettings);
                checkedListBoxSettings.SetItemChecked(4, currentProfile.ExportGeneralSettings);
                checkedListBoxSettings.SetItemChecked(5, currentProfile.ExportMarketingSettings);
                checkedListBoxSettings.SetItemChecked(6, currentProfile.ExportOutlookSynchronizationSettings);
                checkedListBoxSettings.SetItemChecked(7, currentProfile.ExportRelationshipRoles);
                checkedListBoxSettings.SetItemChecked(8, currentProfile.ExportIsvConfig);

                //Solution to import combobox update
                this.comboBoxSolutionsToImport.Items.Clear();
                this.comboBoxSolutionsToImport.Items.AddRange(new object[] { "Newest" });
                this.comboBoxSolutionsToImport.Items.AddRange(new object[] { "Oldest" });
                if (Directory.Exists(currentProfile.SolutionExportFolder))
                {
                    IOrderedEnumerable<string> subDirectories = Directory.GetDirectories(currentProfile.SolutionExportFolder).OrderByDescending(x => x);
                    foreach (string DirectoryPath in subDirectories)
                    {
                        string[] pathList = DirectoryPath.Split(new Char[] { '\\' });
                        string DirectoryName = pathList[pathList.Count<string>() - 1];
                        this.comboBoxSolutionsToImport.Items.AddRange(new object[] { DirectoryName });
                    }
                }

                comboBoxConnectionTarget.SelectedItem = currentProfile.TargetConnectionName;
                if (currentProfile.Operation == 2)
                    comboBoxSolutionsToImport.SelectedItem = "Newest";
                else
                    comboBoxSolutionsToImport.SelectedItem = currentProfile.SolutionsToImport;
                checkBoxPublishAllCustomizationsTarget.Checked = currentProfile.PublishAllCustomizationsTarget;
                checkBoxPublishWorkflows.Checked = currentProfile.PublishWorkflows;
                checkBoxOverwriteUnmanagedCustomizations.Checked = currentProfile.OverwriteUnmanagedCustomizations;

                toolStripStatusLabel1.Text = "Solution Transport Profile " + currentProfile.ProfileName + " loaded.";
                LogManager.WriteLog("Solution Transport Profile " + currentProfile.ProfileName + " loaded.");
            }
            else
            {
                currentProfile = null;
                textBoxProfileName.Text = "";
                deleteProfileToolStripMenuItem.Enabled = false;
                newToolStripMenuItem.Enabled = false;
                saveToolStripMenuItem.Enabled = false;
                textBoxProfileName.Enabled = true;
                labelSolutionsRefreshedOn.Text = "";
                runProfileToolStripMenuItem.Enabled = false;
                comboBoxConnectionSource.SelectedIndex = -1;
                checkBoxExportAsManaged.Checked = false;
                comboBoxOperation.SelectedIndex = -1;
                checkBoxPublishAllCustomizationsSource.Checked = false;
                checkedListBoxSettings.SetItemChecked(0, false);
                checkedListBoxSettings.SetItemChecked(1, false);
                checkedListBoxSettings.SetItemChecked(2, false);
                checkedListBoxSettings.SetItemChecked(3, false);
                checkedListBoxSettings.SetItemChecked(4, false);
                checkedListBoxSettings.SetItemChecked(5, false);
                checkedListBoxSettings.SetItemChecked(6, false);
                checkedListBoxSettings.SetItemChecked(7, false);
                checkedListBoxSettings.SetItemChecked(8, false);
                comboBoxConnectionTarget.SelectedIndex = -1;
                checkBoxPublishAllCustomizationsTarget.Checked = false;
                checkBoxPublishWorkflows.Checked = false;
                checkBoxOverwriteUnmanagedCustomizations.Checked = false;

                //Solution to import combobox update
                this.comboBoxSolutionsToImport.Items.Clear();
                this.comboBoxSolutionsToImport.Items.AddRange(new object[] { "Newest" });
                this.comboBoxSolutionsToImport.Items.AddRange(new object[] { "Oldest" });
            }

            this.importLogsToolStripMenuItem.DropDownItems.Clear();
            this.importLogsToolStripMenuItem.Visible = false;
        }
        private bool SaveProfile()
        {
            bool result = true;
            //Check that all fields are provided
            if (string.IsNullOrEmpty(textBoxProfileName.Text))
            {
                MessageBox.Show("Profile Name is mandatory!");
                return false;
            }

            if (comboBoxOperation.SelectedItem == null)
            {
                MessageBox.Show("The Operation is Mandatory!");
                return false;
            }

            //Check that the name of the connection is valid
            if (textBoxProfileName.Text.Contains(" ") ||
                    textBoxProfileName.Text.Contains("\\") ||
                    textBoxProfileName.Text.Contains("/") ||
                    textBoxProfileName.Text.Contains(">") ||
                    textBoxProfileName.Text.Contains("<") ||
                    textBoxProfileName.Text.Contains("?") ||
                    textBoxProfileName.Text.Contains("*") ||
                    textBoxProfileName.Text.Contains(":") ||
                    textBoxProfileName.Text.Contains("|") ||
                    textBoxProfileName.Text.Contains("\"") ||
                    textBoxProfileName.Text.Contains("'")
                    )
            {
                MessageBox.Show("You shouldn't use spaces nor the following characters (\\/<>?*:|\"') in the Profile Name as it will be used to create folders and files.");
                return false;
            }

            if (comboBoxConnectionSource.SelectedItem == null)
            {
                MessageBox.Show("You must select a Source for the Profile");
                return false;
            }

            if (this.textBoxSelectedFolder.Text == "")
            {
                MessageBox.Show("You must select an Export Folder for the Profile");
                return false;
            }

            if (comboBoxOperation.SelectedItem.ToString() != "Export Solutions")
            {
                if (comboBoxConnectionTarget.SelectedItem == null)
                {
                    MessageBox.Show("The Target Connection is Mandatory!");
                    return false;
                }
                if (comboBoxSolutionsToImport.SelectedItem == null)
                {
                    MessageBox.Show("The Solutions to Import are Mandatory!");
                    return false;
                }
            }

            dataGridView1.EndEdit();

            MSCRMSolutionsTransportProfile tempProfile = new MSCRMSolutionsTransportProfile();
            tempProfile.ProfileName = textBoxProfileName.Text;
            tempProfile.SourceConnectionName = comboBoxConnectionSource.SelectedItem.ToString();

            tempProfile.SelectedSolutionsNames = new List<string>();
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                DataGridViewCell cbc = row.Cells[0];

                if ((bool)cbc.Value)
                {
                    MSCRMSolution ms = (MSCRMSolution)row.DataBoundItem;
                    tempProfile.SelectedSolutionsNames.Add(ms.UniqueName);
                }
            }
            if (tempProfile.SelectedSolutionsNames.Count == 0)
            {
                MessageBox.Show("You must select at least 1 Solution for the Profile");
                return false;
            }

            tempProfile.SolutionExportFolder = textBoxSelectedFolder.Text;
            tempProfile.ExportAsManaged = checkBoxExportAsManaged.Checked;
            tempProfile.Operation = comboBoxOperation.SelectedIndex;
            tempProfile.ExportAutoNumberingSettings = checkedListBoxSettings.GetItemChecked(0);
            tempProfile.ExportCalendarSettings = checkedListBoxSettings.GetItemChecked(1);
            tempProfile.ExportCustomizationSettings = checkedListBoxSettings.GetItemChecked(2);
            tempProfile.ExportEmailTrackingSettings = checkedListBoxSettings.GetItemChecked(3);
            tempProfile.ExportGeneralSettings = checkedListBoxSettings.GetItemChecked(4);
            tempProfile.ExportMarketingSettings = checkedListBoxSettings.GetItemChecked(5);
            tempProfile.ExportOutlookSynchronizationSettings = checkedListBoxSettings.GetItemChecked(6);
            tempProfile.ExportRelationshipRoles = checkedListBoxSettings.GetItemChecked(7);
            tempProfile.ExportIsvConfig = checkedListBoxSettings.GetItemChecked(8);
            tempProfile.setSourceConneciton();
            tempProfile.PublishAllCustomizationsSource = checkBoxPublishAllCustomizationsSource.Checked;

            if (comboBoxConnectionTarget.SelectedItem != null)
            {
                tempProfile.TargetConnectionName = comboBoxConnectionTarget.SelectedItem.ToString();
                tempProfile.setTargetConneciton();
            }
            if (comboBoxSolutionsToImport.SelectedItem != null)
                tempProfile.SolutionsToImport = comboBoxSolutionsToImport.SelectedItem.ToString();
            tempProfile.PublishAllCustomizationsTarget = checkBoxPublishAllCustomizationsTarget.Checked;
            tempProfile.PublishWorkflows = checkBoxPublishWorkflows.Checked;
            tempProfile.OverwriteUnmanagedCustomizations = checkBoxOverwriteUnmanagedCustomizations.Checked;

            //Check if this is a creation
            if (currentProfile == null)
            {
                //Check if a Solution Transport Profile having the same name exist already
                MSCRMSolutionsTransportProfile profile = man.Profiles.Find(p => p.ProfileName.ToLower() == textBoxProfileName.Text.ToLower());
                if (profile != null)
                {
                    MessageBox.Show("Profile with the name " + textBoxProfileName.Text + " exist already. Please select another name");
                    return false;
                }

                man.CreateProfile(tempProfile);
                comboBoxProfiles.Items.AddRange(new object[] { tempProfile.ProfileName });
                comboBoxProfiles.SelectedItem = tempProfile.ProfileName;
                currentProfile = tempProfile;
            }
            else
            {
                currentProfile = tempProfile;
                man.UpdateProfile(currentProfile);
            }

            runProfileToolStripMenuItem.Enabled = true;
            toolStripStatusLabel1.Text = "Profile " + currentProfile.ProfileName + " saved.";
            return result;
        }