예제 #1
0
 private void LoadLayoutFromString(string xmlFile)
 {
     try
     {
         this.m_layout   = new TISLayout();
         this.m_layout.g = this.CanvasRoot;
         this.m_layout.OnTrainChangeNumber += new Layout.TrainChangeNumberHandler(this.Layout_OnTrainChangeNumber);
         this.m_layout.OnTrainRoute        += new Layout.TrainRouteHandler(this.Layout_OnTrainRoute);
         this.m_layout.OnTrainProperties   += new Layout.TrainPropertiesHandler(this.Layout_OnTrainProperties);
         if (this.m_layout.LoadFromString(xmlFile))
         {
             this.m_layout.DrawElements();
             this.TrainsStateLoadFromCache(this.CacheVersion);
             this.OnTimerGetState();
             this.m_timer.Start();
             this.Content_Resized(null, null);
         }
         else
         {
             MessageBox.Show("Failed to load layout..." + this.m_layout.LastError);
         }
     }
     catch (Exception exception)
     {
         MessageBox.Show(exception.Message);
     }
 }
예제 #2
0
 private void LoadLayoutFromString(string xmlFile)
 {
     try
     {
         this.m_layout = new TISLayout();
         this.m_layout.g = this.CanvasRoot;
         this.m_layout.OnTrainChangeNumber += new Layout.TrainChangeNumberHandler(this.Layout_OnTrainChangeNumber);
         this.m_layout.OnTrainRoute += new Layout.TrainRouteHandler(this.Layout_OnTrainRoute);
         this.m_layout.OnTrainProperties += new Layout.TrainPropertiesHandler(this.Layout_OnTrainProperties);
         if (this.m_layout.LoadFromString(xmlFile))
         {
             this.m_layout.DrawElements();
             this.TrainsStateLoadFromCache(this.CacheVersion);
             this.OnTimerGetState();
             this.m_timer.Start();
             this.Content_Resized(null, null);
         }
         else
         {
             MessageBox.Show("Failed to load layout..." + this.m_layout.LastError);
         }
     }
     catch (Exception exception)
     {
         MessageBox.Show(exception.Message);
     }
 }
예제 #3
0
        public bool LoadFromString(string data)
        {
            XmlSerializer serializer = null;
            StringReader  textReader = null;
            bool          flag       = true;

            this.ClearContent();
            try
            {
                PathElementPassive passive;
                serializer = this.GetSerializer();
                textReader = new StringReader(data);
                TISLayout layout = (TISLayout)serializer.Deserialize(textReader);
                this.ClearContent();
                base.m_alConnections   = layout.Connections;
                base.m_alElements      = layout.Elements;
                base.m_htID2Element    = new Hashtable();
                base.m_htAPIID2Element = new Hashtable();
                foreach (Element element in base.m_alElements)
                {
                    if (base.m_htID2Element.ContainsKey(element.ID))
                    {
                        base.LastError = "Element ID should be uniqie within XML definition";
                        return(false);
                    }
                    base.m_htID2Element[element.ID] = element;
                    element.UpdateBounds();
                }
                foreach (Connection connection in base.m_alConnections)
                {
                    int index = base.m_alElements.IndexOf(connection.Element1);
                    int num2  = base.m_alElements.IndexOf(connection.Element2);
                    if (index < 0)
                    {
                        throw new Exception(string.Format("Element '{0}' not found in schema", connection.Element1.ID));
                    }
                    if (num2 < 0)
                    {
                        throw new Exception(string.Format("Element '{0}' not found in schema", connection.Element2.ID));
                    }
                    Element element2 = (Element)base.m_alElements[index];
                    Element element3 = (Element)base.m_alElements[num2];
                    connection.Element1 = element2;
                    connection.Element2 = element3;
                    element2.Connect(connection);
                    element3.Connect(connection);
                }
                foreach (Element element in base.m_alElements)
                {
                    ArrayList list;
                    element.m_Layout = this;
                    if (element is StateElement)
                    {
                        if (base.m_htAddress2StateElement.ContainsKey((element as StateElement).Address))
                        {
                            list = (ArrayList)base.m_htAddress2StateElement[(element as StateElement).Address];
                        }
                        else
                        {
                            list = new ArrayList();
                            base.m_htAddress2StateElement[(element as StateElement).Address] = list;
                        }
                        list.Add(element);
                    }
                    if (element is PathElementPassive)
                    {
                        passive = (PathElementPassive)element;
                        if (base.m_htSegment2PathElementPassive.ContainsKey(passive.Segment))
                        {
                            list = (ArrayList)base.m_htSegment2PathElementPassive[passive.Segment];
                        }
                        else
                        {
                            list = new ArrayList();
                            base.m_htSegment2PathElementPassive[passive.Segment] = list;
                        }
                        list.Add(passive);
                        if (element is PathElement)
                        {
                            base.m_alPathElements.Add(element);
                        }
                    }
                    else if (element is Perron)
                    {
                        Debug.Assert(!base.m_htPerrons.ContainsKey(element.ID));
                        base.m_htPerrons[element.ID] = element;
                    }
                    else if (element is Station)
                    {
                        base.m_alStations.Add(element);
                    }
                }
                base.m_alStations.Clear();
                foreach (Element element in base.m_alElements)
                {
                    if (element is Station)
                    {
                        Station s = element as Station;
                        base.m_alStations.AddRude(this, s);
                    }
                }
                foreach (Element element in base.m_alElements)
                {
                    if (element is IconElement)
                    {
                        IconElement element4 = (IconElement)element;
                        if (base.m_htAPIID2Element.ContainsKey(element4.APIID))
                        {
                            base.LastError = string.Format("Element APIID ({0}) should be uniqie within XML definition", element4.APIID);
                            return(false);
                        }
                        base.m_htAPIID2Element[element4.APIID] = element4;
                    }
                    else if (element is PathElementPassive)
                    {
                        passive = (PathElementPassive)element;
                        if (passive.StationArea.Length != 0)
                        {
                            Station stationByID = base.m_alStations.GetStationByID(passive.StationArea);
                            if (stationByID == null)
                            {
                                base.LastError = string.Format("Element StationArea ({0}) is unknown", passive.StationArea);
                                return(false);
                            }
                            passive.m_StationArea = stationByID;
                        }
                    }
                    element.InitAfterLoad(this);
                }
            }
            catch (Exception exception)
            {
                base.LastError = exception.Message;
                flag           = false;
                Debug.WriteLine(string.Format("{0}: {1}", this.ToString(), exception.Message));
            }
            if (textReader != null)
            {
                textReader.Close();
            }
            return(flag);
        }