Ejemplo n.º 1
0
 private void SaveCommand_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     if (LastSavePath == null || LastSavePath.Length == 0)
     {
         SaveAsCommand_Executed(sender, e);
         return;
     }
     //Exporter.ToXML(Dogs, LastSavePath);
     SaveTreeStructure(Tree_Hierarchy, LastSavePath);
     WindowTitle.RemoveStar(this);
 }
Ejemplo n.º 2
0
 //==========================================================================================
 //==========================================================================================
 // Save/load
 //==========================================================================================
 //==========================================================================================
 public void SaveTreeStructure(TreeView Tree, String Filename)
 {
     try
     {
         StreamWriter Writer = new StreamWriter(Filename, false, System.Text.Encoding.UTF8);
         foreach (TreeViewItem Item in Tree.Items)
         {
             SaveTreeItem(Writer, Item, 0);
         }
         Writer.Close();
         WindowTitle.RemoveStar(this);
     }
     catch (Exception) { MessageBox.Show("Сохранение не удалось", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); }
 }
Ejemplo n.º 3
0
 void ClearTreeView(TreeView Tree)
 {
     WindowTitle.RemoveStar(this);
     Tree.Items.Clear();
 }
Ejemplo n.º 4
0
        void LoadTreeStructure(String Filename)
        {
            ClearTreeView(Tree_Hierarchy);
            DataHandler.LocationList.Clear();
            WindowTitle.RemoveStar(this);

            bool                 ParsingData           = false;
            bool                 ParsingDecision       = false;
            bool                 ParsingSelector       = false;
            bool                 ParsingSelectorOption = false;
            TreeViewItem         Folder        = null;
            TreeViewItem         LocationItem  = null;
            LocationData         LocationEntry = null;
            LocationSelector     Selector      = null;
            Stack <TreeViewItem> Parent        = new Stack <TreeViewItem>();

            StreamReader Reader = new StreamReader(Filename, System.Text.Encoding.UTF8);

            while (!Reader.EndOfStream)
            {
                String Line = Reader.ReadLine();
                // Parsing location data
                if (Line.Contains("<LocationData>") == true)
                {
                    ParsingData   = true;
                    LocationItem  = DataHandler.AddLocation(this, Folder);
                    LocationEntry = new LocationData();
                    DataHandler.LocationList.Add(LocationEntry);
                }
                else if (Line.Contains("TreeViewId") == true && ParsingData)
                {
                    int StartIndex = Line.IndexOf("<TreeViewId>") + 12;
                    int EndIndex   = Line.IndexOf("</TreeViewId>");
                    LocationItem.Name             = Line.Substring(StartIndex, EndIndex - StartIndex);
                    LocationItem.ContextMenu.Name = LocationItem.Name;
                    LocationEntry.TreeViewId      = LocationItem.Name;
                }
                else if (Line.Contains("<Guid>") == true && ParsingData)
                {
                    int StartIndex = Line.IndexOf("<Guid>") + 6;
                    int EndIndex   = Line.IndexOf("</Guid>");
                    LocationEntry.Guid  = Line.Substring(StartIndex, EndIndex - StartIndex);
                    LocationItem.Header = LocationEntry.Guid;
                    if (LocationItem.Header.ToString().Length == 0)
                    {
                        LocationItem.Header = "Unnamed";
                    }
                }
                else if (Line.Contains("<Description>") == true && ParsingData)
                {
                    int StartIndex = Line.IndexOf("<Description>") + 13;
                    int EndIndex   = Line.IndexOf("</Description>");
                    LocationEntry.Description = Line.Substring(StartIndex, EndIndex - StartIndex);
                }
                else if (Line.Contains("<LocationDecision>") == true && ParsingData)
                {
                    ParsingDecision = true;
                    LocationEntry.Decisions.Add(new LocationDecision());
                }
                else if (Line.Contains("<Text>") == true && ParsingDecision)
                {
                    int StartIndex = Line.IndexOf("<Text>") + 6;
                    int EndIndex   = Line.IndexOf("</Text>");
                    LocationEntry.Decisions[LocationEntry.Decisions.Count - 1].Text = Line.Substring(StartIndex, EndIndex - StartIndex);
                }
                else if (Line.Contains("<LocationLink>") == true && ParsingDecision)
                {
                    int StartIndex = Line.IndexOf("<LocationLink>") + 14;
                    int EndIndex   = Line.IndexOf("</LocationLink>");
                    LocationEntry.Decisions[LocationEntry.Decisions.Count - 1].LocationLink = Line.Substring(StartIndex, EndIndex - StartIndex);
                }
                else if (Line.Contains("<Condition>") == true && ParsingDecision)
                {
                    int StartIndex = Line.IndexOf("<Condition>") + 11;
                    int EndIndex   = Line.IndexOf("</Condition>");
                    LocationEntry.Decisions[LocationEntry.Decisions.Count - 1].Condition = Line.Substring(StartIndex, EndIndex - StartIndex);
                }
                else if (Line.Contains("<Action>") == true && ParsingDecision)
                {
                    int StartIndex = Line.IndexOf("<Action>") + 8;
                    int EndIndex   = Line.IndexOf("</Action>");
                    LocationEntry.Decisions[LocationEntry.Decisions.Count - 1].Action = Line.Substring(StartIndex, EndIndex - StartIndex);
                }
                else if (Line.Contains("/LocationDecision>") == true)
                {
                    ParsingDecision = false;
                }
                else if (Line.Contains("</LocationData>") == true)
                {
                    LocationItem = null;
                    ParsingData  = false;
                }
                // Parsing location selector data
                else if (Line.Contains("<LocationSelector>") == true)
                {
                    ParsingSelector = true;
                    LocationItem    = DataHandler.AddSelector(this, Folder);
                    Selector        = new LocationSelector();
                    DataHandler.SelectorList.Add(Selector);
                }
                else if (Line.Contains("TreeViewId") == true && ParsingSelector)
                {
                    int StartIndex = Line.IndexOf("<TreeViewId>") + 12;
                    int EndIndex   = Line.IndexOf("</TreeViewId>");
                    LocationItem.Name             = Line.Substring(StartIndex, EndIndex - StartIndex);
                    LocationItem.ContextMenu.Name = LocationItem.Name;
                    Selector.TreeViewId           = LocationItem.Name;
                }
                else if (Line.Contains("<Guid>") == true && ParsingSelector)
                {
                    int StartIndex = Line.IndexOf("<Guid>") + 6;
                    int EndIndex   = Line.IndexOf("</Guid>");
                    Selector.Guid       = Line.Substring(StartIndex, EndIndex - StartIndex);
                    LocationItem.Header = Selector.Guid;
                    if (LocationItem.Header.ToString().Length == 0)
                    {
                        LocationItem.Header = "Unnamed";
                    }
                }
                else if (Line.Contains("<SelectorOption>") == true && ParsingSelector)
                {
                    ParsingSelectorOption = true;
                    Selector.Options.Add(new LocationSelectorEntry());
                }
                else if (Line.Contains("<Link>") == true && ParsingSelectorOption)
                {
                    int StartIndex = Line.IndexOf("<Link>") + 6;
                    int EndIndex   = Line.IndexOf("</Link>");
                    Selector.Options[Selector.Options.Count - 1].Link = Line.Substring(StartIndex, EndIndex - StartIndex);
                }
                else if (Line.Contains("<Chance>") == true && ParsingSelectorOption)
                {
                    int StartIndex = Line.IndexOf("<Chance>") + 8;
                    int EndIndex   = Line.IndexOf("</Chance>");
                    Selector.Options[Selector.Options.Count - 1].Chance = Int32.Parse(Line.Substring(StartIndex, EndIndex - StartIndex));
                }
                else if (Line.Contains("<Condition>") == true && ParsingSelectorOption)
                {
                    int StartIndex = Line.IndexOf("<Condition>") + 11;
                    int EndIndex   = Line.IndexOf("</Condition>");
                    Selector.Options[Selector.Options.Count - 1].Condition = Line.Substring(StartIndex, EndIndex - StartIndex);
                }
                else if (Line.Contains("<Action>") == true && ParsingSelectorOption)
                {
                    int StartIndex = Line.IndexOf("<Action>") + 8;
                    int EndIndex   = Line.IndexOf("</Action>");
                    Selector.Options[Selector.Options.Count - 1].Action = Line.Substring(StartIndex, EndIndex - StartIndex);
                }
                else if (Line.Contains("/SelectorOption>") == true)
                {
                    ParsingDecision = false;
                }
                else if (Line.Contains("</LocationSelector>") == true)
                {
                    LocationItem    = null;
                    ParsingSelector = false;
                }
                // Parsing folder data
                else if (Line.Contains("<Folder>") == true)
                {
                    if (Folder != null)
                    {
                        TreeViewItem LastParent = Folder;
                        Parent.Push(LastParent);
                        Folder = DataHandler.AddFolderFull(this, LastParent);
                    }
                    else
                    {
                        Folder = DataHandler.AddFolderFull(this, null);
                    }
                }
                else if (Line.Contains("<Name>"))
                {
                    int StartIndex = Line.IndexOf("<Name>") + 6;
                    int EndIndex   = Line.IndexOf("</Name>");
                    Folder.Name             = Line.Substring(StartIndex, EndIndex - StartIndex);
                    Folder.ContextMenu.Name = Folder.Name;
                }
                else if (Line.Contains("<Header>"))
                {
                    int StartIndex = Line.IndexOf("<Header>") + 8;
                    int EndIndex   = Line.IndexOf("</Header>");
                    Folder.Header = Line.Substring(StartIndex, EndIndex - StartIndex);
                }
                else if (Line.Contains("</Folder>"))
                {
                    if (Parent.Count == 0)
                    {
                        Folder = null;
                    }
                    else
                    {
                        Folder = Parent.Pop();
                    }
                }
            }
        }