Ejemplo n.º 1
0
 /// <summary>
 /// Deprecated Method for adding a new object to the DeviceSetups EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToDeviceSetups(DeviceSetup deviceSetup)
 {
     base.AddObject("DeviceSetups", deviceSetup);
 }
Ejemplo n.º 2
0
        public bool InsertDevice(NodeLine device)
        {
            try
            {
                using (DB db = new DB())
                {
                    NodeLine node = (from o in db.DeviceSetups
                                      where o.Id == device.DeviceSetupId
                                      select new NodeLine
                                      {
                                          DeviceSetupId = o.Id,
                                          Client = o.LineSetup.DataCollectionNode.Client,
                                          AddressType = o.AddressType,
                                          DataType = o.DataType,
                                          DowntimeThreshold = o.LineSetup.DowntimeThreshold,
                                          UptimeThreshold = o.LineSetup.UptimeThreshold,
                                          IPAddress = o.IpAddress,
                                          Line = o.LineSetup.Line,
                                          TagType = o.TagType,
                                          TrackDowntime = o.TrackDowntime,
                                          TrackingType = o.TrackingType,
                                          TagName = o.TagName
                                      }).FirstOrDefault();

                    if (node != null)//Already exists
                    {
                        DeviceSetup setup = (from o in db.DeviceSetups
                                             where o.Id == node.DeviceSetupId
                                             select o).FirstOrDefault();

                        if (setup != null)
                        {
                            setup.IpAddress = device.IPAddress;
                            setup.TagName = device.TagName;
                            setup.TagType = device.TagType;
                            setup.TrackDowntime = device.TrackDowntime;
                            setup.TrackingType = device.TrackingType;

                            setup.AddressType = device.AddressType;
                            setup.DataType = device.DataType;
                            setup.LineSetup.Line = device.Line;
                            setup.LineSetup.DowntimeThreshold = device.DowntimeThreshold;
                            setup.LineSetup.UptimeThreshold = device.UptimeThreshold;
                            setup.LineSetup.DataCollectionNode.Client = device.Client;
                            setup.LineSetup.DataCollectionNode.ServerName = device.ServerName;

                            return db.SaveChanges() > 0;
                        }

                    }
                    else
                    {
                        DeviceSetup setup = new DeviceSetup();

                        setup.IpAddress = device.IPAddress;
                        setup.TagName = device.TagName;
                        setup.TagType = device.TagType;
                        setup.TrackDowntime = device.TrackDowntime;
                        setup.TrackingType = device.TrackingType;

                        setup.AddressType = device.AddressType;
                        setup.DataType = device.DataType;

                        DataCollectionNode dataNode = (from o in db.DataCollectionNodes
                                                       where o.Client == device.Client
                                                       select o).FirstOrDefault();

                        if (dataNode == null)
                        {
                            dataNode = new DataCollectionNode();
                            dataNode.Password = "******";

                            setup.LineSetup.DataCollectionNode = dataNode;
                        }

                        setup.LineSetup.DataCollectionNode.Client = device.Client;

                        LineSetup lineSetup = (from o in db.LineSetups
                                               where o.DataCollectionNode.Id == dataNode.Id
                                               select o).FirstOrDefault();

                        if (lineSetup == null)
                        {
                            lineSetup = new LineSetup();
                            setup.LineSetup = lineSetup;
                        }

                        setup.LineSetup.Line = device.Line;
                        setup.LineSetup.DowntimeThreshold = device.DowntimeThreshold;
                        setup.LineSetup.UptimeThreshold = device.UptimeThreshold;

                        db.AddToLineSetups(lineSetup);

                        return db.SaveChanges() > 0;
                    }
                }

                return false;
            }
            catch (Exception ex)
            {
                String fileName = this.Server.MapPath("~/App_Data/log.txt");
                File.AppendAllText(fileName, ex.ToString());
                throw ex;

            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Create a new DeviceSetup object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="ipAddress">Initial value of the IpAddress property.</param>
 /// <param name="trackingType">Initial value of the TrackingType property.</param>
 /// <param name="addressType">Initial value of the AddressType property.</param>
 /// <param name="tagName">Initial value of the TagName property.</param>
 /// <param name="tagType">Initial value of the TagType property.</param>
 /// <param name="dataType">Initial value of the DataType property.</param>
 /// <param name="trackDowntime">Initial value of the TrackDowntime property.</param>
 public static DeviceSetup CreateDeviceSetup(global::System.Int32 id, global::System.String ipAddress, global::System.Int32 trackingType, global::System.Int32 addressType, global::System.String tagName, global::System.Int32 tagType, global::System.Int32 dataType, global::System.Boolean trackDowntime)
 {
     DeviceSetup deviceSetup = new DeviceSetup();
     deviceSetup.Id = id;
     deviceSetup.IpAddress = ipAddress;
     deviceSetup.TrackingType = trackingType;
     deviceSetup.AddressType = addressType;
     deviceSetup.TagName = tagName;
     deviceSetup.TagType = tagType;
     deviceSetup.DataType = dataType;
     deviceSetup.TrackDowntime = trackDowntime;
     return deviceSetup;
 }