private async Task CreateDescription(StepFullInfo node)
        {
            if (node.PluginType == null)
            {
                return;
            }

            this._iWriteToOutput.WriteToOutputStartOperation(null, Properties.OperationNames.CreatingFileWithDescription);

            ToggleControls(null, false, Properties.OutputStrings.CreatingDescription);

            StringBuilder result = new StringBuilder();

            string fileName = string.Empty;

            if (node.PluginType != null)
            {
                const string _formatFileTxt = "{0} {1} - Description.txt";

                fileName = string.Format(
                    _formatFileTxt
                    , Path.GetFileNameWithoutExtension(node.PluginDescription.FilePath)
                    , node.PluginType.TypeName);

                if (result.Length > 0)
                {
                    result.AppendLine().AppendLine().AppendLine();
                }

                {
                    PluginTypeConfigurationDescriptionHandler handler = new PluginTypeConfigurationDescriptionHandler();

                    var desc = await handler.CreateDescriptionAsync(node.PluginType);

                    if (!string.IsNullOrEmpty(desc))
                    {
                        if (result.Length > 0)
                        {
                            result.AppendLine().AppendLine().AppendLine();
                        }

                        result.AppendLine(desc);
                    }
                }
            }

            if (!string.IsNullOrEmpty(fileName))
            {
                string filePath = Path.Combine(_commonConfig.FolderForExport, FileOperations.RemoveWrongSymbols(fileName));

                File.WriteAllText(filePath, result.ToString(), new UTF8Encoding(false));

                this._iWriteToOutput.PerformAction(null, filePath);
            }

            ToggleControls(null, true, Properties.OutputStrings.CreatingDescriptionCompleted);

            this._iWriteToOutput.WriteToOutputEndOperation(null, Properties.OperationNames.CreatingFileWithDescription);
        }
        private async Task RegisterSteps(StepFullInfo step)
        {
            if (step.PluginType == null)
            {
                return;
            }

            ConnectionData connectionData = null;

            cmBCurrentConnection.Dispatcher.Invoke(() =>
            {
                connectionData = cmBCurrentConnection.SelectedItem as ConnectionData;
            });

            if (connectionData.IsReadOnly)
            {
                this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectionIsReadOnlyFormat1, connectionData.Name);
                return;
            }

            ToggleControls(connectionData, false, Properties.WindowStatusStrings.RegisteringPluginStepsFormat1, connectionData.Name);

            if (connectionData != null && connectionData.IsReadOnly == false)
            {
                var service = await GetService();

                var helper = new RegistrerPluginHelper(service);

                try
                {
                    string filePath = string.Empty;

                    if (step.PluginStep != null)
                    {
                        filePath = await helper.RegisterPluginsForPluginStepAsync(this._commonConfig.FolderForExport, step.PluginAssembly.Name, step.PluginType.TypeName, step.PluginStep);
                    }
                    else if (step.PluginType != null)
                    {
                        filePath = await helper.RegisterPluginsForPluginTypeAsync(this._commonConfig.FolderForExport, step.PluginAssembly.Name, step.PluginType);
                    }
                    else if (step.PluginAssembly != null)
                    {
                        filePath = await helper.RegisterPluginsForAssemblyAsync(this._commonConfig.FolderForExport, step.PluginAssembly);
                    }

                    if (File.Exists(filePath))
                    {
                        this._iWriteToOutput.PerformAction(null, filePath);
                    }
                }
                catch (Exception ex)
                {
                    this._iWriteToOutput.WriteErrorToOutput(null, ex);
                }
            }

            ToggleControls(connectionData, true, Properties.WindowStatusStrings.RegisteringPluginStepsCompletedFormat1, connectionData.Name);
        }
        private void RecursiveExpandedAll(StepFullInfo item, bool isExpanded)
        {
            item.IsExpanded = isExpanded;

            foreach (var child in item.Items)
            {
                RecursiveExpandedAll(child, isExpanded);
            }
        }
        private StepFullInfo CreateNodeMessage(string message)
        {
            var nodeMessage = new StepFullInfo()
            {
                Name  = message,
                Image = _imageMessage,
            };

            return(nodeMessage);
        }
        private StepFullInfo CreateNodeEntity(string entityName)
        {
            var nodeMessage = new StepFullInfo()
            {
                Name  = entityName,
                Image = _imageEntity,
            };

            return(nodeMessage);
        }
        private StepFullInfo CreateNodeStage(int stage, int mode)
        {
            string temp = Nav.Common.VSPackages.CrmDeveloperHelper.Repository.SdkMessageProcessingStepRepository.GetStageName(stage, mode);

            var nodeStage = new StepFullInfo()
            {
                Name  = temp,
                Image = _imageStage,
            };

            return(nodeStage);
        }
        private StepFullInfo CreateNodeStep(StepFullInfo step)
        {
            string nameStep    = GetStepName(step);
            string tooltipStep = GetStepTooltip(step);

            step.Name    = nameStep;
            step.Tooltip = tooltipStep;

            step.Image = step.PluginStep.StateCode == 0 ? _imageStep : _imageStepDisabled;

            return(step);
        }
        private StepFullInfo GetSelectedEntity()
        {
            StepFullInfo result = null;

            if (this.trVPluginTree.SelectedItem != null &&
                this.trVPluginTree.SelectedItem is StepFullInfo
                )
            {
                result = this.trVPluginTree.SelectedItem as StepFullInfo;
            }

            return(result);
        }
        private StepFullInfo CreateNodeAssembly(StepFullInfo assemblyStep)
        {
            var nodeMessage = new StepFullInfo()
            {
                Name  = assemblyStep.PluginAssembly.Name,
                Image = _imagePluginAssembly,

                PluginDescription = assemblyStep.PluginDescription,
                PluginAssembly    = assemblyStep.PluginAssembly,
            };

            return(nodeMessage);
        }
        private StepFullInfo CreateNodeImage(PluginImage image)
        {
            string nameImage    = GetImageName(image);
            string tooltipImage = GetImageTooltip(image);

            var nodeImage = new StepFullInfo()
            {
                Name  = nameImage,
                Image = _imageImage,

                Tooltip = tooltipImage,
            };

            return(nodeImage);
        }
        private StepFullInfo CreateNodePluginType(StepFullInfo pluginTypeStep)
        {
            var nodeType = new StepFullInfo()
            {
                Name = pluginTypeStep.PluginType.TypeName,

                Image = _imagePluginType,

                PluginDescription = pluginTypeStep.PluginDescription,
                PluginAssembly    = pluginTypeStep.PluginAssembly,
                PluginType        = pluginTypeStep.PluginType,
            };

            return(nodeType);
        }
        private string GetStepName(StepFullInfo step)
        {
            StringBuilder nameStep = new StringBuilder();

            if (step.PluginStep.ExecutionOrder.HasValue)
            {
                nameStep.AppendFormat("{0}. ", step.PluginStep.ExecutionOrder.ToString());
            }

            nameStep.Append(step.PluginType.TypeName);

            if (step.PluginStep.FilteringAttributes.Count > 0)
            {
                nameStep.AppendFormat("    Filtering: {0}", string.Join(",", step.PluginStep.FilteringAttributes.OrderBy(s => s)));
            }

            return(nameStep.ToString());
        }
        private string GetStepTooltip(StepFullInfo step)
        {
            if (!step.PluginStep.FilteringAttributes.Any())
            {
                return(null);
            }

            StringBuilder tooltipStep = new StringBuilder();

            tooltipStep.AppendLine("Filtering:");

            foreach (string item in step.PluginStep.FilteringAttributes.OrderBy(s => s))
            {
                tooltipStep.AppendLine().AppendFormat("  " + item);
            }

            return(tooltipStep.ToString());
        }
        private bool IsFromStage(StepFullInfo s, PluginStage stage)
        {
            switch (stage)
            {
            case PluginStage.PreValidation:
                return(s.PluginStep.Stage == 10);

            case PluginStage.Pre:
                return(s.PluginStep.Stage == 20);

            case PluginStage.PostSynch:
                return(s.PluginStep.Stage == 40 && s.PluginStep.ExecutionMode == 0);

            case PluginStage.PostAsych:
                return(s.PluginStep.Stage == 40 && s.PluginStep.ExecutionMode == 1);

            default:
                break;
            }

            return(false);
        }
 private void ExpandNode(StepFullInfo node)
 {
     node.IsExpanded = true;
 }
        private ObservableCollection <StepFullInfo> FillTreeByAssembly(List <StepFullInfo> result)
        {
            ObservableCollection <StepFullInfo> list = new ObservableCollection <StepFullInfo>();

            var groupsByAssembly = result.GroupBy(ent => ent.PluginAssembly.Name).OrderBy(gr => gr.Key);

            foreach (var grAssembly in groupsByAssembly)
            {
                var assemblyStep = grAssembly.FirstOrDefault();

                var nodeAssembly = CreateNodeAssembly(assemblyStep);

                list.Add(nodeAssembly);

                var groupsByPluginType = grAssembly.GroupBy(ent => ent.PluginType.TypeName).OrderBy(gr => gr.Key);

                foreach (var grPluginType in groupsByPluginType)
                {
                    var pluginTypeStep = grPluginType.FirstOrDefault();

                    var nodePluginType = CreateNodePluginType(pluginTypeStep);

                    AddStepFullInfo(nodeAssembly, nodePluginType);

                    var groupsByEnity = grPluginType.GroupBy(ent => ent.PluginStep.PrimaryEntity).OrderBy(gr => gr.Key);

                    foreach (var grEntity in groupsByEnity)
                    {
                        var nodeEntity = CreateNodeEntity(grEntity.Key);

                        AddStepFullInfo(nodePluginType, nodeEntity);

                        var groupsByMessages = grEntity.GroupBy(ent => ent.PluginStep.Message).OrderBy(mess => mess.Key, MessageComparer.Comparer);

                        foreach (var mess in groupsByMessages)
                        {
                            StepFullInfo nodeMessage = CreateNodeMessage(mess.Key);

                            AddStepFullInfo(nodeEntity, nodeMessage);

                            var groupsStage = mess.GroupBy(ent => ent.PluginStep.Stage.Value).OrderBy(item => item.Key);

                            foreach (var stage in groupsStage)
                            {
                                StepFullInfo nodeStage      = null;
                                StepFullInfo nodePostAsynch = null;

                                foreach (var step in stage.OrderBy(s => s.PluginStep.ExecutionMode).ThenBy(s => s.PluginStep.ExecutionOrder).ThenBy(s => s.PluginStep.Name))
                                {
                                    StepFullInfo nodeTarget = null;

                                    if (step.PluginStep.ExecutionMode.Value == 1)
                                    {
                                        if (nodePostAsynch == null)
                                        {
                                            nodePostAsynch = CreateNodeStage(stage.Key, step.PluginStep.ExecutionMode.Value);

                                            AddStepFullInfo(nodeMessage, nodePostAsynch);
                                        }

                                        nodeTarget = nodePostAsynch;
                                    }
                                    else
                                    {
                                        if (nodeStage == null)
                                        {
                                            nodeStage = CreateNodeStage(stage.Key, step.PluginStep.ExecutionMode.Value);

                                            AddStepFullInfo(nodeMessage, nodeStage);
                                        }

                                        nodeTarget = nodeStage;
                                    }

                                    StepFullInfo nodeStep = CreateNodeStep(step);

                                    AddStepFullInfo(nodeTarget, nodeStep);

                                    var queryImage = from image in step.PluginStep.PluginImages
                                                     orderby image.ImageType.Value
                                                     select image;

                                    foreach (var image in queryImage)
                                    {
                                        StepFullInfo nodeImage = CreateNodeImage(image);

                                        AddStepFullInfo(nodeStep, nodeImage);
                                    }

                                    ExpandNode(nodeStep);
                                }

                                if (nodeStage != null)
                                {
                                    ExpandNode(nodeStage);
                                }

                                if (nodePostAsynch != null)
                                {
                                    ExpandNode(nodePostAsynch);
                                }
                            }

                            ExpandNode(nodeMessage);
                        }

                        ExpandNode(nodeEntity);
                    }
                }
            }

            return(list);
        }
 private void AddStepFullInfo(StepFullInfo node, StepFullInfo childNode)
 {
     node.Items.Add(childNode);
 }