public void DeleteNode(TechNodeViewModel node)
        {
            WorkspaceViewModel.SelectedNode = null;
            TechTree.Remove(node);
            UnlinkParent(node);
            var parts = new PartViewModel[node.Parts.Count];

            node.Parts.CopyTo(parts, 0);
            foreach (var part in parts)
            {
                PartCollectionViewModel.RemovePartFromNode(part, node);
            }
            LinkNodes();
        }
        public void PopulateParts(
            PartCollectionViewModel pc,
            TreeType type = TreeType.TechMananger)
        {
            switch (type)
            {
            case TreeType.ATC:
                foreach (var part in pc.PartCollection)
                {
                    if (part.TechRequired == TechId)
                    {
                        _parts.Add(part);
                    }
                }
                break;

            case TreeType.TechMananger:
                var partTable = new Dictionary <string, PartViewModel>();

                foreach (var part in pc.PartCollection)
                {
                    partTable.Add(part.PartName, part);
                }

                foreach (var part in _techNode.Parts)
                {
                    if (partTable.ContainsKey(part))
                    {
                        _parts.Add(partTable[part]);
                        pc.PartCollection.Remove(partTable[part]);
                    }
                    else
                    {
                        var tmpPart = new Part(part)
                        {
                            Title        = part,
                            TechRequired = TechId,
                            Category     = "(Unknown)"
                        };
                        _parts.Add(new PartViewModel(tmpPart));
                    }
                }
                break;
            }
        }
        public void PopulateParts(
			PartCollectionViewModel pc,
			TreeType type = TreeType.TechMananger)
        {
            switch (type)
            {
                case TreeType.ATC:
                    foreach (var part in pc.PartCollection)
                    {
                        if (part.TechRequired == TechId)
                        {
                            _parts.Add(part);
                        }
                    }
                    break;

                case TreeType.TechMananger:
                    var partTable = new Dictionary<string, PartViewModel>();

                    foreach (var part in pc.PartCollection)
                    {
                        try
                        {
                            if (!partTable.ContainsKey(part.PartName))
                            {
                                partTable.Add(part.PartName, part);
                            }
                            else
                            {
                                var duplicate = partTable[part.PartName];
                                var existString = String.Format(" - Existing part: {0} ({1})", duplicate.PartName, duplicate.FileName);
                                Logger.Error(
                                             "PartLoader: Error while storing part \"{0}\" " +
                                             "({1}) into PartCollection - {2}{3}",
                                             part.PartName,
                                             part.FileName,
                                             "Part already exists",
                                             existString);
                            }
                        }
                        catch (Exception e)
                        {
                            Logger.Error(
                                         "PartLoader: Error while storing part \"{0}\" " +
                                         "({1}) into PartCollection - {2}",
                                         part.PartName,
                                         part.FileName,
                                         e.Message);
                        }
                    }

                    foreach (var part in _techNode.Parts)
                    {
                        if (partTable.ContainsKey(part))
                        {
                            _parts.Add(partTable[part]);
                            pc.PartCollection.Remove(partTable[part]);
                        }
                        else
                        {
                            var tmpPart = new Part(part)
                                          {
                                              Title = part,
                                              TechRequired = TechId,
                                              Category = "(Unknown)"
                                          };
                            _parts.Add(new PartViewModel(tmpPart));
                        }
                    }
                    break;
            }
        }
        public override void PopulateParts(PartCollectionViewModel pc, TechTreeViewModel ttvm)
        {
            // Create and init part table with name => partviewmodel
            var partTable = new Dictionary<string, PartViewModel>();
            foreach (PartViewModel part in pc.PartCollection)
            {
                try
                {
                    if (!partTable.ContainsKey(part.PartName))
                    {
                        partTable.Add(part.PartName, part);
                    }
                    else
                    {
                        var duplicate = partTable[part.PartName];
                        var existString = String.Format(" - Existing part: {0} ({1})", duplicate.PartName, duplicate.FileName);
                        Logger.Error("PartLoader: Error while storing part \"{0}\" " + "({1}) into PartCollection - {2}{3}", part.PartName, part.FileName, "Part already exists", existString);
                    }
                }
                catch (Exception e)
                {
                    Logger.Error("PartLoader: Error while storing part \"{0}\" " + "({1}) into PartCollection - {2}", part.PartName, part.FileName, e.Message);
                }
            }

            foreach( var node in ttvm.TechTree )
            {
                foreach (String part in node.TechNode.Parts)
                {
                    if (partTable.ContainsKey(part))
                    {
                        node.Parts.Add(partTable[part]);
                        pc.PartCollection.Remove(partTable[part]);
                    }
                    else
                    {
                        var tmpPart = new Part(part) { Title = part, TechRequired = node.Id, Category = "(Unknown)" };
                        node.Parts.Add(new PartViewModel(tmpPart));
                    }
                }
            }
        }
        public void PopulateParts(
            PartCollectionViewModel pc,
            TreeType type = TreeType.TechMananger)
        {
            switch (type)
            {
            case TreeType.ATC:
                foreach (var part in pc.PartCollection)
                {
                    if (part.TechRequired == TechId)
                    {
                        _parts.Add(part);
                    }
                }
                break;

            case TreeType.TechMananger:
                var partTable = new Dictionary <string, PartViewModel>();

                foreach (var part in pc.PartCollection)
                {
                    try
                    {
                        if (!partTable.ContainsKey(part.PartName))
                        {
                            partTable.Add(part.PartName, part);
                        }
                        else
                        {
                            var duplicate   = partTable[part.PartName];
                            var existString = String.Format(" - Existing part: {0} ({1})", duplicate.PartName, duplicate.FileName);
                            Logger.Error(
                                "PartLoader: Error while storing part \"{0}\" " +
                                "({1}) into PartCollection - {2}{3}",
                                part.PartName,
                                part.FileName,
                                "Part already exists",
                                existString);
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.Error(
                            "PartLoader: Error while storing part \"{0}\" " +
                            "({1}) into PartCollection - {2}",
                            part.PartName,
                            part.FileName,
                            e.Message);
                    }
                }

                foreach (var part in _techNode.Parts)
                {
                    if (partTable.ContainsKey(part))
                    {
                        _parts.Add(partTable[part]);
                        pc.PartCollection.Remove(partTable[part]);
                    }
                    else
                    {
                        var tmpPart = new Part(part)
                        {
                            Title        = part,
                            TechRequired = TechId,
                            Category     = "(Unknown)"
                        };
                        _parts.Add(new PartViewModel(tmpPart));
                    }
                }
                break;
            }
        }
Beispiel #6
0
 public abstract void PopulateParts(PartCollectionViewModel pc, TechTreeViewModel ttvm);