/// <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>
        /// 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;
            }
        }