123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- using Aitex.Core.Util;
- using Aitex.Sorter.Common;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Xml.Linq;
- namespace Aitex.Sorter.UI.Config
- {
- public class SignalTowerManager : Singleton<SignalTowerManager>
- {
- public IEnumerable<SignalTowerEventItem> Load(string fileName)
- {
- if (File.Exists(fileName))
- {
- var doc = XDocument.Load(fileName);
- var result = doc.Root.Elements("Event").Select(x => new SignalTowerEventItem()
- {
- Name = x.Attribute("Name").Value,
- RedAction = (SignalTowerAction)Enum.Parse(typeof(SignalTowerAction), x.Attribute("Red").Value),
- BlueAction = (SignalTowerAction)Enum.Parse(typeof(SignalTowerAction), x.Attribute("Blue").Value),
- GreenAction = (SignalTowerAction)Enum.Parse(typeof(SignalTowerAction), x.Attribute("Green").Value),
- BuzzerAction = (SignalTowerAction)Enum.Parse(typeof(SignalTowerAction), x.Attribute("Red").Value),
- });
- return result;
- }
- return null;
- }
- public void Save(IEnumerable<SignalTowerEventItem> events, string fileName)
- {
- var result = events.Select(x =>
- new XElement("Event",
- new XAttribute("Name", x.Name),
- new XAttribute("Red", x.RedAction),
- new XAttribute("Blue", x.BlueAction),
- new XAttribute("Green", x.GreenAction),
- new XAttribute("Buzzer", x.BuzzerAction)
- ));
- var doc = new XDocument(new XElement("Events", result));
- doc.Save(fileName);
- }
- }
- public class SignalTowerEventItem : NotifyPropertyChangedBase
- {
- private string name;
- public string Name
- {
- get
- {
- return name;
- }
- set
- {
- name = value;
- OnPropertyChanged("Name");
- }
- }
- private SignalTowerAction redAction;
- public SignalTowerAction RedAction
- {
- get
- {
- return redAction;
- }
- set
- {
- redAction = value;
- OnPropertyChanged("RedAction");
- }
- }
- private SignalTowerAction blueAction;
- public SignalTowerAction BlueAction
- {
- get
- {
- return blueAction;
- }
- set
- {
- blueAction = value;
- OnPropertyChanged("BlueAction");
- }
- }
- private SignalTowerAction greenAction;
- public SignalTowerAction GreenAction
- {
- get
- {
- return greenAction;
- }
- set
- {
- greenAction = value;
- OnPropertyChanged("GreenAction");
- }
- }
- private SignalTowerAction buzzerAction;
- public SignalTowerAction BuzzerAction
- {
- get
- {
- return buzzerAction;
- }
- set
- {
- buzzerAction = value;
- OnPropertyChanged("BuzzerAction");
- }
- }
- }
- public enum SignalTowerAction
- {
- Off,
- On,
- Blink,
- }
- }
|