Ejemplo n.º 1
0
        private void tsddbFile_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            if (e.ClickedItem == tsmiSave)
            {
                Resource.Save();
                tsmiSave.Enabled = false;
            }
            else if (e.ClickedItem == tsmiUpdatePublish)
            {
                var us = new UpdateResourcesSettings
                {
                    Webresources = new List <Webresource> {
                        Resource
                    },
                    Publish = true
                };

                mainControl.PerformUpdate(us);
            }
            else if (e.ClickedItem == tsmiRefreshFromDisk)
            {
                Resource.RefreshFromDisk();
            }
            else if (e.ClickedItem == tsmiReplace)
            {
                ReplaceWithNewFile();
            }
        }
        private void btnApply_Click(object sender, EventArgs e)
        {
            var us = new UpdateResourcesSettings
            {
                Webresources  = clbWebresources.CheckedItems.Cast <Webresource>(),
                Publish       = rdbUpdatePublish.Checked || rdbUpdatePublishAdd.Checked,
                AddToSolution = rdbUpdatePublishAdd.Checked
            };

            mainControl.PerformUpdate(us);
        }
        private void UpdateResources(bool publish = false, bool addToSolution = false)
        {
            var us = new UpdateResourcesSettings
            {
                Webresources = new List <Webresource> {
                    contextStripResource
                },
                Publish       = publish,
                AddToSolution = addToSolution
            };

            ExecuteMethod(UpdateWebResources, us);
        }
        private void tsddCrmMenu_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            if (e.ClickedItem == TsmiLoadWebResources)
            {
                ExecuteMethod(LoadWebresourcesGeneral, false);
            }
            else if (e.ClickedItem == TsmiLoadWebResourcesFromASpecificSolution)
            {
                ExecuteMethod(LoadWebresourcesGeneral, true);
            }
            else if (e.ClickedItem == tsmiReloadFromCurrentSolution)
            {
                LoadWebresources(lastSettings);
            }
            else if (e.ClickedItem == tsmiUpdateWebresources)
            {
                var us = new UpdateResourcesSettings
                {
                    Webresources = WebresourcesCache.Where(r => r.Node.Checked)
                };

                ExecuteMethod(UpdateWebResources, us);
            }
            else if (e.ClickedItem == tsmiUpdatePublishWebresources)
            {
                var us = new UpdateResourcesSettings
                {
                    Webresources = WebresourcesCache.Where(r => r.Node != null && r.Node.Checked),
                    Publish      = true
                };

                ExecuteMethod(UpdateWebResources, us);
            }
            else if (e.ClickedItem == tsmiUpdatePublishAddWebresources)
            {
                var us = new UpdateResourcesSettings
                {
                    Webresources  = WebresourcesCache.Where(r => r.Node.Checked),
                    Publish       = true,
                    AddToSolution = true
                };

                ExecuteMethod(UpdateWebResources, us);
            }
        }
        public void UpdateWebResources(UpdateResourcesSettings us)
        {
            if (us.AddToSolution)
            {
                var sPicker = new SolutionPicker(Service, true)
                {
                    StartPosition = FormStartPosition.CenterParent
                };

                if (sPicker.ShowDialog(this) == DialogResult.OK)
                {
                    us.SolutionUniqueName = sPicker.SelectedSolution["uniquename"].ToString();
                }
                else
                {
                    return;
                }
            }

            // TODO Disable controls during update

            tv.Service = Service;

            WorkAsync(new WorkAsyncInfo
            {
                Message       = "Updating web resources...",
                AsyncArgument = us,
                Work          = (bw, e) =>
                {
                    var settings         = (UpdateResourcesSettings)e.Argument;
                    var resourcesUpdated = new List <Webresource>();
                    var resources        = new List <Webresource>();

                    // Add Regular Resources, and Associated Web Resources
                    foreach (var resource in settings.Webresources)
                    {
                        resources.Add(resource);
                        if (resource.AssociatedResources != null)
                        {
                            resources.AddRange(resource.AssociatedResources);
                        }
                    }

                    foreach (var resource in resources)
                    {
                        try
                        {
                            bw.ReportProgress(1, $"Updating {resource}...");
                            resource.Update(Service, us.Overwrite);

                            resourcesUpdated.Add(resource);
                            resource.LastException = null;
                        }
                        catch (Exception error)
                        {
                            resource.LastException = error;
                        }
                    }

                    // Process post Update command
                    if (!string.IsNullOrEmpty(Settings.Instance.AfterUpdateCommand))
                    {
                        foreach (var webResource in resourcesUpdated)
                        {
                            EventManager.ActAfterUpdate(webResource, Settings.Instance);
                        }
                    }

                    // if publish
                    if (settings.Publish && resourcesUpdated.Count > 0)
                    {
                        bw.ReportProgress(2, "Publishing web resources...");

                        Webresource.Publish(resourcesUpdated, Service);
                    }

                    // Process post Publish command
                    if (!string.IsNullOrEmpty(Settings.Instance.AfterPublishCommand))
                    {
                        foreach (var webResource in resourcesUpdated)
                        {
                            EventManager.ActAfterPublish(webResource, Settings.Instance);
                        }
                    }

                    if (settings.AddToSolution && !string.IsNullOrEmpty(settings.SolutionUniqueName) && resourcesUpdated.Count > 0)
                    {
                        bw.ReportProgress(3, "Adding web resources to solution...");
                        Webresource.AddToSolution(resourcesUpdated, settings.SolutionUniqueName, Service);
                    }

                    e.Result = new UpdateResourcesResult
                    {
                        FaultedResources   = resources.Except(resourcesUpdated),
                        Publish            = settings.Publish,
                        AddToSolution      = settings.AddToSolution,
                        SolutionUniqueName = settings.SolutionUniqueName
                    };
                },
                ProgressChanged  = e => { SetWorkingMessage(e.UserState.ToString()); },
                PostWorkCallBack = e =>
                {
                    if (e.Error != null)
                    {
                        MessageBox.Show(this, e.Error.Message, @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    var result = (UpdateResourcesResult)e.Result;

                    // Identifies resources with concurrency behavior error
                    //var unsyncResources = result.FaultedResources.Where(r =>
                    //    r.LastException is FaultException<OrganizationServiceFault>
                    //    && ((FaultException<OrganizationServiceFault>)r.LastException).Detail.ErrorCode ==
                    //    -2147088254).ToList();
                    var unsyncResources =
                        result.FaultedResources.Where(r => r.LastException is MoreRecentRecordExistsException).ToList();
                    var otherResources = result.FaultedResources.Except(unsyncResources).ToList();

                    if (unsyncResources.Any() || otherResources.Any())
                    {
                        var dialog = new ConcurrencySummaryDialog(unsyncResources, otherResources);
                        if (dialog.ShowDialog(this) == DialogResult.Retry)
                        {
                            var retryUs = new UpdateResourcesSettings
                            {
                                Webresources       = unsyncResources,
                                Publish            = result.Publish,
                                AddToSolution      = result.AddToSolution,
                                SolutionUniqueName = result.SolutionUniqueName,
                                Overwrite          = true
                            };

                            UpdateWebResources(retryUs);
                        }
                    }
                }
            });
        }
 public void PerformUpdate(UpdateResourcesSettings us)
 {
     ExecuteMethod(UpdateWebResources, us);
 }
        private void cmsWebresourceTreeview_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            if (e.ClickedItem != tsmiAddNewResource)
            {
                cmsWebresourceTreeview.Hide();
            }

            if (e.ClickedItem == tsmiProperties)
            {
                if (rpd.IsDisposed)
                {
                    rpd = new ResourcePropertiesDialog();
                }

                rpd.Resource = contextStripResource;
                rpd.ShowDocked();
            }
            else if (e.ClickedItem == tsmiSetDependencies)
            {
                var dialog = new DependencyDialog(contextStripResource, this);
                if (dialog.ShowDialog(this) == DialogResult.OK)
                {
                    contextStripResource.DependencyXml = dialog.UpdatedDependencyXml;
                }
            }
            else if (e.ClickedItem == tsmiCopyNameToClipboard)
            {
                Clipboard.SetData(DataFormats.StringFormat, contextStripResource.Name);
            }
            else if (e.ClickedItem == tsmiOpenInCrm)
            {
                if (contextStripResource.Id == Guid.Empty)
                {
                    MessageBox.Show(this, @"This web resource does not exist on the CRM organization or is not synced", @"Warning",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                Process.Start($"{ConnectionDetail.WebApplicationUrl}/main.aspx?id={contextStripResource.Id}&etc=9333&pagetype=webresourceedit");
            }
            else if (e.ClickedItem == tsmiDelete)
            {
                ExecuteMethod(DeleteWebresource, contextStripResource);
            }
            else if (e.ClickedItem == tsmiUpdate)
            {
                var us = new UpdateResourcesSettings
                {
                    Webresources = new List <Webresource> {
                        contextStripResource
                    },
                };

                ExecuteMethod(UpdateWebResources, us);
            }
            else if (e.ClickedItem == tsmiUpdatePublish)
            {
                var us = new UpdateResourcesSettings
                {
                    Webresources = new List <Webresource> {
                        contextStripResource
                    },
                    Publish = true
                };

                ExecuteMethod(UpdateWebResources, us);
            }
            else if (e.ClickedItem == tsmiUpdatePublishAdd)
            {
                var us = new UpdateResourcesSettings
                {
                    Webresources = new List <Webresource> {
                        contextStripResource
                    },
                    Publish       = true,
                    AddToSolution = true
                };

                ExecuteMethod(UpdateWebResources, us);
            }
            else if (e.ClickedItem == tsmiGetLatest)
            {
                try
                {
                    contextStripResource.GetLatestVersion();
                }
                catch (Exception error)
                {
                    MessageBox.Show(this, error.Message, @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else if (e.ClickedItem == tsmiRefreshFileFromDisk)
            {
                if (string.IsNullOrEmpty(contextStripResource.FilePath))
                {
                    MessageBox.Show(this, @"This webresource is not synced with a local file", @"Warning",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                contextStripResource.RefreshFromDisk();
            }
            else if (e.ClickedItem == tsmiUpdateFolderFromDisk)
            {
                if (string.IsNullOrEmpty(contextFolderNode.FolderPath))
                {
                    MessageBox.Show(this,
                                    @"This folder node is not synced with a local folder. Cannot refresh from disk", @"Warning",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                var invalidFileNames = new List <string>();
                tv.RefreshFolderNodeContent(contextFolderNode, invalidFileNames, null);

                if (invalidFileNames.Any())
                {
                    if (ifnd == null || ifnd.IsDisposed)
                    {
                        ifnd = new InvalidFilenamesDialog();
                    }

                    ifnd.InvalidFiles = invalidFileNames;
                    ifnd.ShowDocked(DockState.DockBottom);
                }
            }
            else if (e.ClickedItem == tsmiRenameWebresource)
            {
                var renameDialog = new RenameWebResourceDialog(contextStripResource.Name, ConnectionDetail?.OrganizationMajorVersion ?? -1);

                if (renameDialog.ShowDialog(this) == DialogResult.OK)
                {
                    if (contextStripResource.Name != renameDialog.WebResourceName)
                    {
                        ExecuteMethod(RenameWebresource, renameDialog.WebResourceName);
                    }
                }
            }
            else if (e.ClickedItem == tsmiAddNewFolder)
            {
                var newFolderDialog = new NewFolderDialog(ConnectionDetail?.OrganizationMajorVersion ?? -1);
                if (newFolderDialog.ShowDialog(this) == DialogResult.OK)
                {
                    tv.AddSingleFolder(contextFolderNode, newFolderDialog.FolderName);
                }
            }
            else if (e.ClickedItem == tsmiAddExistingFile)
            {
                var ofd = new OpenFileDialog {
                    Multiselect = true, Title = @"Select file(s) to add as webresource(s)"
                };

                if (ofd.ShowDialog(ParentForm) == DialogResult.OK)
                {
                    var invalidFileNames = new List <string>();
                    tv.AddFilesAsNodes(contextFolderNode, ofd.FileNames.ToList(), invalidFileNames);

                    if (invalidFileNames.Any())
                    {
                        if (ifnd == null || ifnd.IsDisposed)
                        {
                            ifnd = new InvalidFilenamesDialog();
                        }

                        ifnd.InvalidFiles = invalidFileNames;
                        ifnd.ShowDocked(DockState.DockBottom);
                    }
                }
            }
            else if (e.ClickedItem == tsmiNewCss)
            {
                tv.AddNewWebresource(contextFolderNode, WebresourceType.Css);
            }
            else if (e.ClickedItem == tsmiNewData)
            {
                tv.AddNewWebresource(contextFolderNode, WebresourceType.Data);
            }
            else if (e.ClickedItem == tsmiNewHtml)
            {
                tv.AddNewWebresource(contextFolderNode, WebresourceType.WebPage);
            }
            else if (e.ClickedItem == tsmiNewResx)
            {
                tv.AddNewWebresource(contextFolderNode, WebresourceType.Resx);
            }
            else if (e.ClickedItem == tsmiNewScript)
            {
                tv.AddNewWebresource(contextFolderNode, WebresourceType.Script);
            }
            else if (e.ClickedItem == tsmiNewXsl)
            {
                tv.AddNewWebresource(contextFolderNode, WebresourceType.Xsl);
            }
            else if (e.ClickedItem == tsmiExpand)
            {
                contextFolderNode.ExpandAll();
            }
            else if (e.ClickedItem == tsmiCollapse)
            {
                contextFolderNode.Collapse(false);
            }
        }
        public void ReceiveKeyDownShortcut(KeyEventArgs e)
        {
            var activeContent = dpMain.ActiveContent;

            if (e.Control && e.KeyCode == Keys.S)
            {
                if (activeContent is BaseContentForm bcf)
                {
                    bcf.Resource.Save();
                }

                isCtrlM = false;
                isCtrlK = false;
            }
            else if (e.Control && e.KeyCode == Keys.U)
            {
                if (!isCtrlK)
                {
                    if (activeContent is BaseContentForm bcf)
                    {
                        var us = new UpdateResourcesSettings
                        {
                            Webresources = new List <Webresource> {
                                bcf.Resource
                            },
                            Publish = true
                        };

                        ExecuteMethod(UpdateWebResources, us);
                    }
                }
                else if (activeContent is CodeEditorForm cef)
                {
                    cef.UncommentSelectedLines();
                }

                isCtrlM = false;
                isCtrlK = false;
            }
            else if (e.Control && e.KeyCode == Keys.G)
            {
                if (activeContent is CodeEditorForm cef)
                {
                    cef.GoToLine();
                }

                isCtrlM = false;
                isCtrlK = false;
            }
            else if (e.Control && e.KeyCode == Keys.F)
            {
                if (activeContent is CodeEditorForm cef)
                {
                    cef.Find(false);
                }
                isCtrlM = false;
                isCtrlK = false;
            }
            else if (e.Control && e.KeyCode == Keys.H)
            {
                if (activeContent is CodeEditorForm cef)
                {
                    cef.Find(true);
                }
                isCtrlM = false;
                isCtrlK = false;
            }
            else if (e.Control && e.KeyCode == Keys.M)
            {
                isCtrlM = true;
                isCtrlK = false;
            }
            else if (e.Control && e.KeyCode == Keys.K)
            {
                isCtrlM = false;
                isCtrlK = true;
            }
            else if (e.Control && e.KeyCode == Keys.O)
            {
                if (isCtrlM && activeContent is CodeEditorForm cef)
                {
                    cef.ContractFolds();
                }

                isCtrlM = false;
                isCtrlK = false;
            }
            else if (e.Control && e.KeyCode == Keys.C)
            {
                if (activeContent is CodeEditorForm cef)
                {
                    if (isCtrlK)
                    {
                        cef.CommentSelectedLines();
                    }
                    else
                    {
                        cef.Copy();
                    }
                }

                isCtrlM = false;
                isCtrlK = false;
            }
            else
            {
                isCtrlM = false;
                isCtrlK = false;
            }
        }