示例#1
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public LocSetEditorForm(IRailway railway, IEntitySet3 <ILoc> locs)
 {
     this.locs = locs;
     InitializeComponent();
     if (railway != null)
     {
         foreach (var loc in railway.GetLocs().Where(x => !locs.Contains(x)).OrderBy(x => x.Description))
         {
             lbAll.Items.Add(loc);
         }
         foreach (var loc in locs.OrderBy(x => x.Description))
         {
             lbSet.Items.Add(loc);
         }
         if (lbAll.Items.Count > 0)
         {
             lbAll.SelectedIndex = 0;
         }
         if (lbSet.Items.Count > 0)
         {
             lbSet.SelectedIndex = 0;
         }
     }
     UpdateComponents();
 }
 /// <summary>
 /// Initialize the controls for the given set.
 /// </summary>
 private void Initialize(IRouteEventSet events)
 {
     this.events = events;
     lbAll.Items.Clear();
     lbSet.Nodes.Clear();
     behaviorGrid.SelectedObject = null;
     if (module != null)
     {
         foreach (var sensor in module.Sensors.Where(x => events.All(e => e.Sensor != x)).OrderBy(x => x.Description, NameWithNumbersComparer.Instance))
         {
             lbAll.Items.Add(sensor);
         }
         foreach (var @event in events.OrderBy(x => x.Description, NameWithNumbersComparer.Instance))
         {
             lbSet.Nodes.Add(new EventNode(railway, @event));
         }
         if (lbAll.Items.Count > 0)
         {
             lbAll.SelectedIndex = 0;
         }
         if (lbSet.Nodes.Count > 0)
         {
             lbSet.SelectedNode = lbSet.Nodes[0];
         }
         lbSetSensors.Text = "Events";
     }
     if (railway != null)
     {
         cbViewLocs.Items.Clear();
         cbViewLocs.Items.Add(Strings.ViewAllLocs);
         foreach (var loc in railway.GetLocs().OrderBy(x => x.Description, NameWithNumbersComparer.Instance))
         {
             cbViewLocs.Items.Add(loc);
         }
         cbViewLocs.SelectedIndex = 0;
     }
     UpdateComponents();
 }
示例#3
0
 /// <summary>
 /// Gets all address entities contained in the given railway.
 /// </summary>
 public static IEnumerable <IAddressEntity> GetAddressEntities(this IRailway railway)
 {
     return(railway.GetModules().SelectMany(x => x.GetAddressEntities()).Concat(railway.GetLocs()));
 }
        /// <summary>
        /// Generate a report now in a file with the given path.
        /// </summary>
        public void Generate(string targetPath)
        {
            var container = new MHtmlContainer();

            var doc  = new XElement("html");
            var head = doc.AddElement("head");
            var meta = head.AddElement("meta");

            meta.SetAttributeValue("content", "text/html; charset=unicode");
            meta.SetAttributeValue("http-equiv", "Content-Type");
            head.Add(new XElement("style", CSS));
            var body    = doc.AddElement("body");
            var heading = body.AddElement("h1", string.Format("Locs in {0}", railway.Description));
            var table   = body.AddElement("table");

            table.SetAttributeValue("cellspacing", "0");
            table.SetAttributeValue("cellpadding", "5");

            var hrow = table.AddElement("tr");

            hrow.SetAttributeValue("class", "hdr");
            hrow.Add(new XElement("td", "Image"));
            hrow.Add(new XElement("td", "Name"));
            hrow.Add(new XElement("td", "Address"));
            hrow.Add(new XElement("td", "Change direction"));
            hrow.Add(new XElement("td", "Min. speed"));
            hrow.Add(new XElement("td", "Med. speed"));
            hrow.Add(new XElement("td", "Max. speed"));
            hrow.Add(new XElement("td", "Groups"));

            var odd = false;

            foreach (var loc in railway.GetLocs().OrderBy(x => x.Description))
            {
                var row = table.AddElement("tr");
                row.SetAttributeValue("class", odd ? "odd" : "");

                var image = loc.Image;
                if (image != null)
                {
                    var src = "loc-" + loc.Id + ".png";
                    container.AddPart("image/png", src, image.ToArray());
                    var img = row.AddElement("td").AddElement("img");
                    img.SetAttributeValue("src", "cid:" + src);
                }
                else
                {
                    // No image
                    row.AddElement("td", "No image");
                }

                row.Add(new XElement("td", loc.Description));
                row.Add(new XElement("td", loc.Address));
                row.Add(new XElement("td", (loc.ChangeDirection == ChangeDirection.Allow) ? "Allow" : "Avoid"));
                row.Add(new XElement("td", string.Format("{0}%", loc.SlowSpeed)));
                row.Add(new XElement("td", string.Format("{0}%", loc.MediumSpeed)));
                row.Add(new XElement("td", string.Format("{0}%", loc.MaximumSpeed)));
                row.Add(new XElement("td", GetGroups(loc)));
                odd = !odd;
            }

            container.WriteTo(targetPath, doc);
        }