예제 #1
0
 protected override void ConnectionDetailsUpdated(NotifyCollectionChangedEventArgs ee)
 {
     ConnectButton.Visible   = false;
     ConnectionLabel.Visible = true;
     ConnectionLabel.Text    = $"Connected to {AdditionalConnectionDetails.First().ConnectionName}";
     CompareMenu.Enabled     = true;
     ShowMode.Enabled        = true;
 }
예제 #2
0
        private void TsbTransferDupeRulesClick(object sender, EventArgs e)
        {
            if (lvDedupeRules.SelectedItems.Count > 0 && AdditionalConnectionDetails.Count > 0)
            {
                var selectedRules = lvDedupeRules.SelectedItems.Cast <ListViewItem>().Select(item => (IGrouping <Guid, Entity>)item.Tag).ToList();

                lbLogs.Items.Clear();
                tsbLoadDupeRules.Enabled     = false;
                tsbTransferDupeRules.Enabled = false;
                btnSelectTarget.Enabled      = false;
                Cursor = Cursors.WaitCursor;

                var worker = new BackgroundWorker();
                worker.DoWork += (s, evt) =>
                {
                    var selections    = (List <IGrouping <Guid, Entity> >)evt.Argument;
                    var total         = selections.Count;
                    var current       = 0;
                    var targetService = AdditionalConnectionDetails.First().GetCrmServiceClient();

                    foreach (var ruleGroup in selections)
                    {
                        current++;

                        string name = ruleGroup.First().GetAttributeValue <string>("name");

                        SendMessageToStatusBar(this,
                                               new StatusBarMessageEventArgs(current * 100 / total, "Processing rule '" + name + "'..."));

                        try
                        {
                            var ruleToTransfer = new Entity(ruleGroup.First().LogicalName);
                            foreach (var attribute in ruleGroup.First().Attributes)
                            {
                                // skip related condition records
                                if (!attribute.Key.StartsWith("condition."))
                                {
                                    ruleToTransfer[attribute.Key] = attribute.Value;
                                }
                            }

                            // Delete existing conditions (or delete entire rule)
                            Guid existingId = _drManager.DedupeRuleExists(targetService, name);
                            if (existingId != Guid.Empty)
                            {
                                ruleToTransfer["duplicateruleid"] = existingId;

                                targetService.Delete(ruleToTransfer.LogicalName, existingId);
                            }

                            existingId = targetService.Create(ruleToTransfer);
                            ruleToTransfer["duplicateruleid"] = existingId;

                            // iterate conditions and apply those
                            foreach (var condition in ruleGroup)
                            {
                                var dedupeCondition = new Entity("duplicaterulecondition")
                                {
                                    ["regardingobjectid"] =
                                        new EntityReference(ruleToTransfer.LogicalName, existingId)
                                };
                                foreach (var attribute in condition.Attributes)
                                {
                                    // only use related condition records
                                    if (attribute.Key.StartsWith("condition.") && !attribute.Key.EndsWith(".duplicateruleconditionid"))
                                    {
                                        dedupeCondition[attribute.Key.Replace("condition.", String.Empty)] = ((AliasedValue)attribute.Value).Value;
                                    }
                                }

                                targetService.Create(dedupeCondition);
                            }

                            // publish if source as also pubished
                            if (ruleGroup.First().GetAttributeValue <OptionSetValue>("statecode").Value == 1) // active
                            {
                                PublishDuplicateRuleRequest publishReq = new PublishDuplicateRuleRequest
                                {
                                    DuplicateRuleId = existingId
                                };
                                targetService.Execute(publishReq);
                            }

                            Log(name, true);
                        }
                        catch (Exception error)
                        {
                            Log(name, false, error.Message);
                        }
                    }
                };
                worker.ProgressChanged += (s, evt) =>
                {
                    SendMessageToStatusBar?.Invoke(this, new StatusBarMessageEventArgs(0, evt.UserState.ToString()));
                };
                worker.RunWorkerCompleted += (s, evt) =>
                {
                    if (evt.Error != null)
                    {
                        MessageBox.Show(ParentForm, @"An error has occured while transferring dedupe rules: " + evt.Error.Message, @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    tsbLoadDupeRules.Enabled     = true;
                    tsbTransferDupeRules.Enabled = true;
                    btnSelectTarget.Enabled      = true;
                    Cursor = Cursors.Default;

                    SendMessageToStatusBar?.Invoke(this, new StatusBarMessageEventArgs(string.Empty));
                };
                worker.WorkerReportsProgress = true;
                worker.RunWorkerAsync(selectedRules);
            }
            else
            {
                MessageBox.Show(@"You have to select at least one source dedupe rule and a target organisation to continue.", @"Warning",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        private void TsbTransfertTemplatesClick(object sender, EventArgs e)
        {
            if (lvTemplates.SelectedItems.Count > 0 && AdditionalConnectionDetails.Count > 0)
            {
                var selectedTemplates = lvTemplates.SelectedItems.Cast <ListViewItem>().Select(item => (Entity)item.Tag).ToList();

                lbLogs.Items.Clear();
                tsbLoadTemplates.Enabled      = false;
                tsbTransfertTemplates.Enabled = false;
                btnSelectTarget.Enabled       = false;
                Cursor = Cursors.WaitCursor;

                var worker = new BackgroundWorker();
                worker.DoWork += (s, evt) =>
                {
                    List <Entity> templates     = (List <Entity>)evt.Argument;
                    var           total         = templates.Count;
                    var           current       = 0;
                    var           targetService = AdditionalConnectionDetails.First().GetCrmServiceClient();

                    foreach (var template in templates)
                    {
                        current++;

                        string etc  = template.GetAttributeValue <string>("associatedentitytypecode");
                        string name = template.GetAttributeValue <string>("name");

                        SendMessageToStatusBar(this, new StatusBarMessageEventArgs(current * 100 / total, "Processing template '" + name + "'..."));

                        try
                        {
                            int?oldEtc = tManager.GetEntityTypeCode(Service, etc);
                            int?newEtc = tManager.GetEntityTypeCode(targetService, etc);

                            tManager.ReRouteEtcViaOpenXML(template, name, etc, oldEtc, newEtc);

                            var templateToTransfer = new Entity(template.LogicalName);
                            foreach (var attribute in template.Attributes)
                            {
                                templateToTransfer[attribute.Key] = attribute.Value;
                            }
                            templateToTransfer["associatedentitytypecode"] = newEtc;

                            Guid existingId = tManager.TemplateExists(targetService, name);
                            if (existingId != null && existingId != Guid.Empty)
                            {
                                templateToTransfer["documenttemplateid"] = existingId;

                                targetService.Update(templateToTransfer);
                            }
                            else
                            {
                                targetService.Create(templateToTransfer);
                            }

                            Log(name, true);
                        }
                        catch (Exception error)
                        {
                            Log(name, false, error.Message);
                        }
                    }
                };
                worker.ProgressChanged += (s, evt) =>
                {
                    SendMessageToStatusBar?.Invoke(this, new StatusBarMessageEventArgs(0, evt.UserState.ToString()));
                };
                worker.RunWorkerCompleted += (s, evt) =>
                {
                    if (evt.Error != null)
                    {
                        MessageBox.Show(ParentForm, @"An error has occured while transferring templates: " + evt.Error.Message, @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    tsbLoadTemplates.Enabled      = true;
                    tsbTransfertTemplates.Enabled = true;
                    btnSelectTarget.Enabled       = true;
                    Cursor = Cursors.Default;

                    SendMessageToStatusBar?.Invoke(this, new StatusBarMessageEventArgs(string.Empty));
                };
                worker.WorkerReportsProgress = true;
                worker.RunWorkerAsync(selectedTemplates);
            }
            else
            {
                MessageBox.Show(@"You have to select at least one source template and a target organization to continue.", @"Warning",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
예제 #4
0
        private void ComparePluginsButton_Click(object sender, EventArgs ee)
        {
            SourceIdColumn.DisplayIndex      = 0;
            OtherIdColumn.DisplayIndex       = 1;
            SourceSizeColumn.DisplayIndex    = 2;
            OtherSizeColumn.DisplayIndex     = 3;
            NameColumn.DisplayIndex          = 4;
            SourceVersionColumn.DisplayIndex = 5;
            ResultColumn.DisplayIndex        = 6;
            OtherVersionColumn.DisplayIndex  = 7;

            SourceIdColumn.Width      = 0;
            OtherIdColumn.Width       = 0;
            SourceSizeColumn.Width    = 0;
            OtherSizeColumn.Width     = 3;
            NameColumn.Width          = 300;
            SourceVersionColumn.Width = 60;
            ResultColumn.Width        = 40;
            OtherVersionColumn.Width  = 60;

            ResultList.Items.Clear();

            var otherConnection = AdditionalConnectionDetails.First();
            var otherService    = otherConnection.GetCrmServiceClient();

            WorkAsync(new WorkAsyncInfo
            {
                Message = "Compare Plug-ins...",
                Work    = (w, e) =>
                {
                    var retrieveSourceAssembliesTask = Task.Run(() => RetrieveAssemblies(Service));
                    var retrieveOtherAssembliesTask  = Task.Run(() => RetrieveAssemblies(otherService));
                    Task.WaitAll(retrieveSourceAssembliesTask, retrieveOtherAssembliesTask);
                    var sourceAssemblies = retrieveSourceAssembliesTask.Result;
                    var otherAssemblies  = retrieveOtherAssembliesTask.Result;
                    var items            = new List <ListViewItem>();
                    foreach (var sourceAssembly in sourceAssemblies)
                    {
                        var name           = sourceAssembly.GetAttributeValue <string>("name");
                        var version        = sourceAssembly.GetAttributeValue <string>("version");
                        var versionParts   = version.Split('.');
                        var versionPattern = $"{versionParts[0]}.{versionParts[1]}.";
                        var otherAssembly  = otherAssemblies.FirstOrDefault(a => a.GetAttributeValue <string>("name") == name && a.GetAttributeValue <string>("version").StartsWith(versionPattern));
                        if (otherAssembly == null)
                        {
                            items.Add(new AssemblyComparerItem(name, sourceAssembly.Id, version, null, null)
                            {
                                Group = ResultList.Groups["PluginsGroup"]
                            });
                        }
                        else
                        {
                            items.Add(new AssemblyComparerItem(name, sourceAssembly.Id, version, otherAssembly.Id, otherAssembly.GetAttributeValue <string>("version"))
                            {
                                Group = ResultList.Groups["PluginsGroup"]
                            });
                            otherAssemblies.Remove(otherAssembly);
                        }
                    }
                    foreach (var otherAssembly in otherAssemblies)
                    {
                        items.Add(new AssemblyComparerItem(otherAssembly.GetAttributeValue <string>("name"), null, null, otherAssembly.Id, otherAssembly.GetAttributeValue <string>("version"))
                        {
                            Group = ResultList.Groups["PluginsGroup"]
                        });
                    }
                    e.Result = items.OrderBy(lvi => lvi.Name).ToArray();
                },
                PostWorkCallBack = e =>
                {
                    _items = (ListViewItem[])e.Result;
                    ShowMode_SelectedIndexChanged(null, null);
                },
                MessageWidth  = 340,
                MessageHeight = 150
            });
        }
예제 #5
0
        private void CompareWebResources(string resourveName, int[] resourceTypes)
        {
            SourceIdColumn.DisplayIndex      = 0;
            OtherIdColumn.DisplayIndex       = 1;
            SourceVersionColumn.DisplayIndex = 2;
            OtherVersionColumn.DisplayIndex  = 3;
            NameColumn.DisplayIndex          = 4;
            SourceSizeColumn.DisplayIndex    = 5;
            ResultColumn.DisplayIndex        = 6;
            OtherSizeColumn.DisplayIndex     = 7;

            SourceIdColumn.Width      = 0;
            OtherIdColumn.Width       = 0;
            SourceVersionColumn.Width = 0;
            OtherVersionColumn.Width  = 0;
            NameColumn.Width          = 300;
            SourceSizeColumn.Width    = 60;
            ResultColumn.Width        = 40;
            OtherSizeColumn.Width     = 60;

            ResultList.Items.Clear();

            var otherConnection = AdditionalConnectionDetails.First();
            var otherService    = otherConnection.GetCrmServiceClient();

            WorkAsync(new WorkAsyncInfo
            {
                Message = $"Compare {resourveName} Web Resources...",
                Work    = (w, e) =>
                {
                    var retrieveSourceResourcesTask = Task.Run(() => RetrieveWebResources(Service, resourceTypes));
                    var retrieveOtherResourcesTask  = Task.Run(() => RetrieveWebResources(otherService, resourceTypes));
                    Task.WaitAll(retrieveSourceResourcesTask, retrieveOtherResourcesTask);
                    var sourceResources = retrieveSourceResourcesTask.Result;
                    var otherResources  = retrieveOtherResourcesTask.Result;

                    var items = new List <ListViewItem>();
                    foreach (var sourceResource in sourceResources)
                    {
                        var name          = sourceResource.GetAttributeValue <string>("name");
                        var content       = sourceResource.GetAttributeValue <string>("content");
                        var otherResource = otherResources.FirstOrDefault(a => a.GetAttributeValue <string>("name") == name);
                        if (otherResource == null)
                        {
                            items.Add(new WebResourceComparerItem(name, sourceResource.Id, content, null, null));
                        }
                        else
                        {
                            items.Add(new WebResourceComparerItem(name, sourceResource.Id, content, otherResource.Id, otherResource.GetAttributeValue <string>("content")));
                            otherResources.Remove(otherResource);
                        }
                    }
                    foreach (var otherResource in otherResources)
                    {
                        items.Add(new WebResourceComparerItem(otherResource.GetAttributeValue <string>("name"), null, null, otherResource.Id, otherResource.GetAttributeValue <string>("content")));
                    }
                    e.Result = items.OrderBy(lvi => lvi.Name).ToArray();
                },
                PostWorkCallBack = e =>
                {
                    _items = (ListViewItem[])e.Result;
                    ShowMode_SelectedIndexChanged(null, null);
                },
                MessageWidth  = 400,
                MessageHeight = 150
            });
        }