예제 #1
0
        public void Calculate(IList <IExplorerTreeItem> items)
        {
            _items = items;
            if (items != null)
            {
                Connectors = items.Count(a =>
                                         !string.IsNullOrEmpty(a.ResourceType) &&
                                         a.ResourceType.Contains(@"Service") &&
                                         a.ResourceType != @"WorkflowService" &&
                                         a.ResourceType != @"ReservedService");

                Services = items.Count(a => !string.IsNullOrEmpty(a.ResourceType) &&
                                       a.ResourceType == @"WorkflowService" &&
                                       a.IsResourceChecked == true);

                Sources = items.Count(a => !string.IsNullOrEmpty(a.ResourceType) &&
                                      IsSource(a.ResourceType) &&
                                      a.IsResourceChecked == true);

                Unknown = items.Count(a => a.ResourceType == @"Unknown" || string.IsNullOrEmpty(a.ResourceType));

                if (_destination.SelectedEnvironment != null)
                {
                    var explorerItemViewModels = _destination.SelectedEnvironment.UnfilteredChildren.Flatten(model => model.UnfilteredChildren ?? new ObservableCollection <IExplorerItemViewModel>());
                    var explorerTreeItems      = explorerItemViewModels as IExplorerItemViewModel[] ?? explorerItemViewModels.ToArray();
                    var idConflicts            = from b in explorerTreeItems
                                                 join explorerTreeItem in items on b.ResourceId equals explorerTreeItem.ResourceId
                                                 where b.ResourceType != @"Folder" && explorerTreeItem.ResourceType != @"Folder" && explorerTreeItem.IsResourceChecked.HasValue && explorerTreeItem.IsResourceChecked.Value
                                                 select new Conflict {
                        SourceName = explorerTreeItem.ResourcePath, DestinationName = b.ResourcePath, DestinationId = b.ResourceId, SourceId = explorerTreeItem.ResourceId
                    };

                    var pathConflicts = from b in explorerTreeItems
                                        join explorerTreeItem in items on b.ResourcePath equals explorerTreeItem.ResourcePath
                                        where b.ResourceType != @"Folder" && explorerTreeItem.ResourceType != @"Folder" && explorerTreeItem.IsResourceChecked.HasValue && explorerTreeItem.IsResourceChecked.Value
                                        select new Conflict {
                        SourceName = explorerTreeItem.ResourcePath, DestinationName = b.ResourcePath, DestinationId = b.ResourceId, SourceId = explorerTreeItem.ResourceId
                    };
                    var allConflicts = new List <Conflict>();
                    allConflicts.AddRange(idConflicts);
                    allConflicts.AddRange(pathConflicts);
                    _conflicts = allConflicts.Distinct(new ConflictEqualityComparer()).ToList();
                    _new       = items.Where(p => p.IsResourceChecked == true && Conflicts.All(c => p.ResourceId != c.SourceId)).Except(explorerTreeItems);
                    var ren = from b in explorerTreeItems
                              join explorerTreeItem in items on new { b.ResourcePath } equals new { explorerTreeItem.ResourcePath }
                    where b.ResourceType != @"Folder" && explorerTreeItem.ResourceType != @"Folder" && explorerTreeItem.IsResourceChecked.HasValue && explorerTreeItem.IsResourceChecked.Value
                    select new { SourceName = explorerTreeItem.ResourcePath, DestinationName = b.ResourcePath, SourceId = explorerTreeItem.ResourceId, DestinationId = b.ResourceId };
                    var errors = ren.Where(ax => ax.SourceId != ax.DestinationId).ToArray();
                    if (errors.Any())
                    {
                        RenameErrors = Resources.Languages.Core.DeployResourcesSamePathAndName;
                        foreach (var error in errors)
                        {
                            RenameErrors += $"\n{error.SourceName}-->{error.DestinationName}";
                        }
                        RenameErrors += Environment.NewLine + Resources.Languages.Core.DeployRenameBeforeContinue;
                    }
                    else
                    {
                        RenameErrors = @"";
                    }
                }
                else
                {
                    _conflicts = new List <Conflict>();
                    _new       = new List <IExplorerTreeItem>();
                }

                Overrides    = Conflicts.Count;
                NewResources = New.Count;
            }
            else
            {
                Connectors = 0;
                Services   = 0;
                Sources    = 0;
                Unknown    = 0;
                _conflicts = new List <Conflict>();
                _new       = new List <IExplorerTreeItem>();
            }

            OnPropertyChanged(() => Conflicts);
            OnPropertyChanged(() => New);
            CalculateAction?.Invoke();
            CheckDestinationPersmisions();
        }