private void PublishInCrm(bool isFromSolutionExplorer)
        {
            _outputWindow = new OutputWindow();
            _outputWindow.Show();

            //getting selected files
            List <string> selectedFiles = GetSelectedFilesPath(isFromSolutionExplorer);

            //checking selected files extensions
            var inValidFiles = CheckFilesExtension(selectedFiles);

            if (inValidFiles.Count > 0)
            {
                AddErrorToOutputWindow(string.Format("Invalid file extensions : {0}", string.Join(", ", inValidFiles)));
                AddErrorLineToOutputWindow(string.Format("Error : Invalid file extensions : \n\t- {0}", string.Join("\n\t- ", inValidFiles)));
                return;
            }

            //getting connection string
            var solutionPath     = GetSolutionPath();
            var connectionString = GetConnectionString(solutionPath);

            if (connectionString == string.Empty)
            {
                SetConnectionLabelText("Connection string is not found.", _error);
                AddErrorLineToOutputWindow("Error : Connection string is not found.");

                var userCredential = new UserCredential(solutionPath);
                userCredential.ShowDialog();

                if (string.IsNullOrEmpty(userCredential.ConnectionString))
                {
                    SetConnectionLabelText("Connection failed.", _error);
                    AddErrorLineToOutputWindow("Error : Connection failed.");
                    return;
                }
                connectionString = userCredential.ConnectionString;
            }

            //updating/creating files one by one
            var thread = new Thread(o => UpdateWebResources(connectionString, selectedFiles));

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
        }
        private void PublishInCrm(bool isFromSolutionExplorer)
        {
            _outputWindow = new OutputWindow();
            _outputWindow.Show();

            //getting selected files
            List<string> selectedFiles = GetSelectedFilesPath(isFromSolutionExplorer);

            //checking selected files extensions
            var inValidFiles = CheckFilesExtension(selectedFiles);
            if (inValidFiles.Count > 0)
            {
                AddErrorToOutputWindow(string.Format("Invalid file extensions : {0}", string.Join(", ", inValidFiles)));
                AddErrorLineToOutputWindow(string.Format("Error : Invalid file extensions : \n\t- {0}", string.Join("\n\t- ", inValidFiles)));
                return;
            }

            //getting connection string
            var solutionPath = GetSolutionPath();
            var connectionString = GetConnectionString(solutionPath);
            if (connectionString == string.Empty)
            {
                SetConnectionLabelText("Connection string is not found.", _error);
                AddErrorLineToOutputWindow("Error : Connection string is not found.");

                var userCredential = new UserCredential(solutionPath);
                userCredential.ShowDialog();

                if (string.IsNullOrEmpty(userCredential.ConnectionString))
                {
                    SetConnectionLabelText("Connection failed.", _error);
                    AddErrorLineToOutputWindow("Error : Connection failed.");
                    return;
                }
                connectionString = userCredential.ConnectionString;
            }

            //updating/creating files one by one
            var thread = new Thread(o => UpdateWebResources(connectionString, selectedFiles));
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
        }
Ejemplo n.º 3
0
 private void UpdateWebresources(Dictionary<string, WebResource> toBeUpdatedList, OrganizationService orgService,
     List<WebResource> toBePublishedWebResources, OutputWindow outputWindow)
 {
     if (toBeUpdatedList.Count > 0)
     {
         outputWindow.StartUpdating();
         foreach (var toBeUpdated in toBeUpdatedList)
         {
             outputWindow.AddLineToTextBox(string.Format("Updating to webresource({0}) ..", Path.GetFileName(toBeUpdated.Key)));
             UpdateWebResource(orgService, toBeUpdated.Value, toBeUpdated.Key);
             outputWindow.AddLineToTextBox(string.Format("{0} is updated.", toBeUpdated.Value.Name));
             toBePublishedWebResources.Add(toBeUpdatedList[toBeUpdated.Key]);
         }
         outputWindow.FinishUpdating(_success);
     }
 }
Ejemplo n.º 4
0
        private void PublishInCrmCallback(object sender, EventArgs e)
        {
            _myStopwatch = new Stopwatch();
            _myStopwatch.Start();

            _outputWindow = new OutputWindow();
            _outputWindow.Show();

            var selectedFilePath = GetSelectedFilePath();
            if (!CheckFileExtension(selectedFilePath))
            {
                AddErrorLineToOutputWindow("Error : Selected file extension is not valid.");
                return;
            }

            var solutionPath = GetSolutionPath();
            var connectionString = GetConnectionString(solutionPath);
            if (connectionString == string.Empty)
            {
                AddErrorLineToOutputWindow("Error : Connection string is not found.");

                var userCredential = new UserCredential();
                userCredential.ShowDialog();

                if (string.IsNullOrEmpty(userCredential.ConnectionString))
                {
                    AddErrorLineToOutputWindow("Error : Connection failed.");
                    return;
                }

                connectionString = userCredential.ConnectionString;

                WriteConnectionStringToFile(Path.GetFileNameWithoutExtension(solutionPath), connectionString, Path.GetDirectoryName(solutionPath));

            }

            AddLineToOutputWindow(string.Format("Publishig the {0} in Crm..", Path.GetFileName(selectedFilePath)));

            //Start the thread for updating and publishing the webresource.
            var thread =
                new Thread(o => UpdateTheWebresource(selectedFilePath, connectionString));
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
        }
Ejemplo n.º 5
0
        private void UpdateWebResources(string connectionString, List<string> selectedFiles, OutputWindow outputWindow)
        {
            try
            {
                var toBePublishedWebResources = new List<WebResource>();
                OrganizationService orgService;
                var crmConnection = CrmConnection.Parse(connectionString);
                // To escape "another assembly" exception
                crmConnection.ProxyTypesAssembly = Assembly.GetExecutingAssembly();
                var stopwatch = new Stopwatch();
                stopwatch.Start();
                using (orgService = new OrganizationService(crmConnection))
                {

                    outputWindow.SetConnectionLabelText(string.Format("Connected to : {0}", crmConnection.ServiceUri), _success);
                    outputWindow.AddLineToTextBox(string.Format("Connected to : {0}", crmConnection.ServiceUri));

                    Dictionary<string, WebResource> toBeCreatedList;
                    Dictionary<string, WebResource> toBeUpdatedList;

                    GetWebresources(orgService, selectedFiles, out toBeCreatedList, out toBeUpdatedList, outputWindow);

                    CreateWebresources(toBeCreatedList, orgService, toBePublishedWebResources, outputWindow);

                    UpdateWebresources(toBeUpdatedList, orgService, toBePublishedWebResources, outputWindow);

                    PublishWebResources(orgService, toBePublishedWebResources, outputWindow);
                }
                stopwatch.Stop();
                outputWindow.AddLineToTextBox(string.Format("Time : {0}", stopwatch.Elapsed));
            }
            catch (Exception ex)
            {
                outputWindow.AddErrorText(ex.Message);
                outputWindow.AddErrorLineToTextBox("Error : " + ex.Message);
            }
        }
Ejemplo n.º 6
0
        private void PublishWebResources(OrganizationService orgService, List<WebResource> toBePublishedWebResources, OutputWindow outputWindow)
        {
            if (toBePublishedWebResources.Count < 1)
            {
                outputWindow.FinishPublishing(_error, "There is no webresource to publish.");
                outputWindow.AddLineToTextBox("There is no webresource to publish.");
                return;
            }

            outputWindow.StartPublishing();
            var webResourcesString = "";
            foreach (var webResource in toBePublishedWebResources)
                webResourcesString = webResourcesString + string.Format("<webresource>{0}</webresource>", webResource.Id);

            var prequest = new PublishXmlRequest
            {
                ParameterXml = string.Format("<importexportxml><webresources>{0}</webresources></importexportxml>", webResourcesString)
            };
            orgService.Execute(prequest);
            outputWindow.FinishPublishing(_success, null);

            var webResourcesNames = new string[toBePublishedWebResources.Count];
            for (var i = 0; i < toBePublishedWebResources.Count; i++)
            {
                webResourcesNames[i] = toBePublishedWebResources[i].Name;
            }
            outputWindow.AddLineToTextBox(string.Format("Published webresources : \n\t- {0}", string.Join("\n\t- ", webResourcesNames)));
        }
Ejemplo n.º 7
0
        private Thread PublishInCrm(bool isFromSolutionExplorer, string connectionString)
        {
            var outputWindow = new OutputWindow();
            outputWindow.Show();

            //getting selected files
            List<string> selectedFiles = GetSelectedFilesPath(isFromSolutionExplorer);

            //checking selected files extensions
            var inValidFiles = CheckFilesExtension(selectedFiles);
            if (inValidFiles.Count > 0)
            {

                outputWindow.AddErrorText(string.Format("Invalid file extensions : {0}", string.Join(", ", inValidFiles)));
                outputWindow.AddErrorLineToTextBox(string.Format("Error : Invalid file extensions : \n\t- {0}", string.Join("\n\t- ", inValidFiles)));
                return null;
            }

            // Check connection string
            if (connectionString == string.Empty)
            {
                outputWindow.SetConnectionLabelText("Connection string was not provided.", _error);
                outputWindow.AddErrorLineToTextBox("Error : Connection string was not provided.");

                var userCredential = new ManageConnectionProfilesWindow(GetSolutionPath());
                userCredential.ShowDialog();

                if (string.IsNullOrEmpty(userCredential.ConnectionString))
                {
                    outputWindow.SetConnectionLabelText("Connection failed.", _error);
                    outputWindow.AddErrorLineToTextBox("Error : Connection failed.");
                    return null;
                }
                connectionString = userCredential.ConnectionString;
            }

            //updating/creating files one by one
            var thread = new Thread(o => UpdateWebResources(connectionString, selectedFiles, outputWindow));
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();

            return thread;
        }
Ejemplo n.º 8
0
 private void GetWebresources(OrganizationService orgService, List<string> selectedFiles, out Dictionary<string, WebResource> toBeCreatedList, out Dictionary<string, WebResource> toBeUpdatedList, OutputWindow outputWindow)
 {
     outputWindow.StartGettingWebresources();
     toBeCreatedList = new Dictionary<string, WebResource>();
     toBeUpdatedList = new Dictionary<string, WebResource>();
     for (int i = 0; i < selectedFiles.Count; i++)
     {
         var fileName = Path.GetFileName(selectedFiles[i]);
         var chosenWebResource = GetWebresource(orgService, fileName);
         if (chosenWebResource == null)
         {
             outputWindow.AddErrorLineToTextBox(string.Format("Error : {0} is not exist in CRM.", fileName));
             toBeCreatedList.Add(selectedFiles[i], null);
         }
         else
         {
             toBeUpdatedList.Add(selectedFiles[i], chosenWebResource);
         }
     }
     outputWindow.FinishGettingWebresources(_success);
 }
Ejemplo n.º 9
0
 private void CreateWebresources(Dictionary<string, WebResource> toBeCreatedList, OrganizationService orgService,
     List<WebResource> toBePublishedWebResources, OutputWindow outputWindow)
 {
     if (toBeCreatedList.Count > 0)
     {
         outputWindow.StartCreating();
         List<string> keys = new List<string>(toBeCreatedList.Keys);
         foreach (var key in keys)
         {
             outputWindow.AddLineToTextBox(string.Format("Creating new webresource({0})..", Path.GetFileName(key)));
             toBeCreatedList[key] = CreateWebResource(Path.GetFileName(key), orgService, key);
             if (toBeCreatedList[key] == null)
             {
                 outputWindow.AddLineToTextBox(string.Format("Creating new webresource({0}) is cancelled.", Path.GetFileName(key)));
                 continue;
             }
             outputWindow.AddLineToTextBox(string.Format("{0} is created.", Path.GetFileName(key)));
             toBePublishedWebResources.Add(toBeCreatedList[key]);
         }
         outputWindow.FinishCreating(_success);
     }
 }