Exemplo n.º 1
0
        public TemplateNode(Node parent, Atts atts)
            : base(parent, atts)
        {
            if(!Atts.ContainsKey("File"))
                throw new ApplicationException("Template must have File");

            XmlNode template = TemplateCache.Get(File);

            if(template == null)
                throw new ApplicationException("Could not load file: " + File);

            foreach(XmlNode child in template.ChildNodes)
                if(child.NodeType == XmlNodeType.Element)
                    AddChild(XMLNodeParser.Parse(this, child));
        }
Exemplo n.º 2
0
        /// <summary>已重载。</summary>
        /// <returns></returns>
        public override String ToString()
        {
            var tname = Type.ToString().TrimStart("Binding");

            if (Atts.Count == 0)
            {
                return(tname);
            }

            if (Atts.Count == 1)
            {
                return("{0} {1}".F(tname, Atts.FirstOrDefault().Value));
            }

            return("{0}[{1}] {2}".F(tname, Atts.Count, Atts.FirstOrDefault().Value));
        }
Exemplo n.º 3
0
 public NullNode(Node parent, Atts atts)
     : base(parent, atts)
 {
 }
Exemplo n.º 4
0
 public TerminalNode(Node parent, Atts atts)
     : base(parent, atts)
 {
 }
Exemplo n.º 5
0
 public ConstNode(Node parent, Atts atts)
     : base(parent, atts)
 {
 }
Exemplo n.º 6
0
 public FileValueNode(Node parent, Atts atts)
     : base(parent, atts)
 {
 }
Exemplo n.º 7
0
Arquivo: RefNode.cs Projeto: wrmsr/xdc
 public RefNode(Node parent, Atts atts)
     : base(parent, atts)
 {
     if(!Atts.ContainsKey("Value"))
         throw new ApplicationException("RefNode must have value");
 }
Exemplo n.º 8
0
 public ValueFileNode(Node parent, Atts atts)
     : base(parent, atts)
 {
     if(!atts.ContainsKey("Name"))
         throw new ApplicationException("Name required");
 }
Exemplo n.º 9
0
 public ProxyNode(Node parent, Atts atts)
     : base(parent, atts)
 {
 }
Exemplo n.º 10
0
 public DateNode(Node parent, Atts atts)
     : base(parent, atts)
 {
 }
Exemplo n.º 11
0
 public ChanceNode(Node parent, Atts atts)
     : base(parent, atts)
 {
 }
        public async Task <HttpResponseMessage> Post([FromBody] GalaxyObjects request)
        {
            Console.WriteLine("#01 - Initializing Program");
            GalaxyObjects          GObjcts   = request;
            List <InstanceContent> vContents = GObjcts.List;

            string DIObjectName = vContents.Select(c => c.IOTag.PLC.Name).FirstOrDefault();

            Console.WriteLine("DIOBJECTNAME = " + DIObjectName);
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.BadRequest);

            response.ReasonPhrase = "Request did not initialize";

            //Contents.PushToDbset(vContents); Maybe To be Used Later!!!!

            //Extract Contained Classes, and push them to the database
            Console.WriteLine("#02 - Extract Contained Classes, and push them to the database");
            List <Model.Attribute> Attributes_ToPush = vContents.Select(c => c.Attribute).ToList();
            List <Model.Instance>  Instances_ToPush  = vContents.Select(c => c.Instance).ToList();
            List <Model.IOTag>     IOTags_ToPush     = vContents.Select(c => c.IOTag).ToList();

            Contents.Attributes.PushToDbset(Attributes_ToPush);
            Contents.Instances.PushToDbset(Instances_ToPush);
            Contents.IOTags.PushToDbset(IOTags_ToPush);
            Contents.context.SaveChanges();

            //Update the contained classes in the entities, so that they are not null or incomplete
            //List<InstanceContent> EntsToPush = Contents.GetListSyncFromDB(vContents);
            //Contents.context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;

            Console.WriteLine("#03 - Sync with DB: Update the contained classes in the entities, so that they are not null or incomplete");

            //List<InstanceContent> EntsToPush = new List<InstanceContent>();

            //db Values
            List <Model.Instance>  dbInstances  = Contents.Instances.EntityCollection;
            List <Model.Attribute> dbAttributes = Contents.Attributes.EntityCollection;
            List <Model.IOTag>     dbIOTags     = Contents.IOTags.EntityCollection;
            List <Model.PLCTag>    dbPLCTags    = Contents.PLCTags.EntityCollection;
            List <InstanceContent> dbContents   = Contents.EntityCollection;


            //Contents.context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
            Console.WriteLine("#03 - Sync with DB: JOIN TABLES");
            List <InstanceContent> EntsToPush = (from Cont in vContents
                                                 join db_Contents in dbContents
                                                 on
                                                 new { InstName = Cont.Instance.Name, AttName = Cont.Attribute.Name }
                                                 equals
                                                 new { InstName = db_Contents.Instance.Name, AttName = db_Contents.Attribute.Name }
                                                 into dbCs
                                                 from cs in dbCs.DefaultIfEmpty(Cont)
                                                 join db_Instances in dbInstances on Cont.Instance.Name equals db_Instances.Name
                                                 into Ins
                                                 from i in Ins.DefaultIfEmpty(Cont.Instance)
                                                 join db_Attributes in dbAttributes on Cont.Attribute.Name equals db_Attributes.Name
                                                 into Atts
                                                 from a in Atts.DefaultIfEmpty(Cont.Attribute)
                                                 join db_IOTags in dbIOTags on
                                                 new { IOTagName = Cont.IOTag.Name, PLCName = Cont.IOTag.PLC.Name }
                                                 equals
                                                 new { IOTagName = db_IOTags.Name, PLCName = db_IOTags.PLC.Name }
                                                 into IOs
                                                 from io in IOs.DefaultIfEmpty(Cont.IOTag)
                                                 //into IC InstanceContentID = cs != null ? cs.InstanceContentID : -1,
                                                 select new InstanceContent()
            {
                InstanceContentID = cs != null ? cs.InstanceContentID : -1,
                Instance = i != null ? i : new Model.Instance(),
                InstanceID = i != null ? i.ID : 0,
                Attribute = a != null ? a : new Model.Attribute(),
                AttributeID = a != null ? a.ID: 0,
                PLCTag = cs != null ? cs.PLCTag: new Model.PLCTag(),
                PLCTagID = cs != null ? cs.PLCTagID : 0,
                IOTag = io != null ? io: new Model.IOTag(),
                IOTagID = io != null ? io.ID: 0,
                AssetName = cs != null ? cs.AssetName : ""
            }).ToList();

            //foreach (InstanceContent Cont in vContents)
            //{

            //    Console.WriteLine("SYNC ENTITY : " + Cont.Instance.Name + "." + Cont.Attribute.Name);
            //    EntsToPush.Add(
            //        new InstanceContent()
            //        {
            //            InstanceContentID = Contents.GetID(Cont.Instance.Name, Cont.Attribute.Name),
            //            Instance = Contents.Instances.GetSyncFromDB(Cont.Instance),
            //            InstanceID = Contents.Instances.GetID(Cont.Instance.Name),
            //            Attribute = Contents.Attributes.GetSyncFromDB(Cont.Attribute),
            //            AttributeID = Contents.Attributes.GetID(Cont.Attribute.Name),
            //            PLCTag = Contents.EntityCollection
            //                          .Where(EC => EC.InstanceContentID == Contents.GetID(Cont.Instance.Name, Cont.Attribute.Name))
            //                          .Select(EC => EC.PLCTag).FirstOrDefault(),
            //            PLCTagID = Contents.EntityCollection
            //                                    .Where(EC => EC.InstanceContentID == Contents.GetID(Cont.Instance.Name, Cont.Attribute.Name))
            //                                    .Select(EC => EC.PLCTagID).FirstOrDefault(),
            //            IOTag = Contents.IOTags.GetSyncFromDB(Cont.IOTag),
            //            IOTagID = Contents.IOTags.GetID(Cont.IOTag.Name),
            //            AssetName = Contents.GetAssetName(Cont.Instance.Name, Cont.Attribute.Name)
            //        });
            //}

            int ii = 0;

            foreach (InstanceContent InsCont in EntsToPush)
            {
                ++ii;
                Console.WriteLine("SYNCED COLLECTION " + ii + " : ID: " + InsCont.InstanceContentID + " - " + InsCont.Instance.Name + "." + InsCont.Attribute.Name + "  PLC = " + InsCont.IOTag.PLC.Name + "  IOTAG = " + InsCont.IOTag.Name + ",ID=" + InsCont.IOTag.ID);
            }


            //Find contents that as NOT in the database, and insert them
            Console.WriteLine("#04 - Find contents that as NOT in the database, and insert them");
            //List<InstanceContent> Entities_NOTinDb = Contents.NOTInDatabase(EntsToPush);

            List <InstanceContent> Entities_NOTinDb = EntsToPush.Where(c => c.InstanceContentID <= 0).ToList();

            if (Entities_NOTinDb.Count > 0)
            {
                Contents.InsertList(Entities_NOTinDb);
            }

            ii = 0;
            foreach (InstanceContent InsCont in Entities_NOTinDb)
            {
                ++ii;
                Console.WriteLine("ENTITIES NOT IN DB " + ii + " : ID: " + InsCont.InstanceContentID + " - " + InsCont.Instance.Name + "." + InsCont.Attribute.Name + "  PLC = " + InsCont.IOTag.PLC.Name);
            }

            //Find contents that are in the database, and update them
            Console.WriteLine("#05 - Find contents that are in the database, and update them");
            //List<InstanceContent> Entities_inDb = Contents.InDatabase(EntsToPush);

            List <InstanceContent> Entities_inDb = EntsToPush.Where(c => c.InstanceContentID > 0).ToList();

            if (Entities_inDb.Count > 0)
            {
                Contents.UpdateList(Entities_inDb);
            }

            ii = 0;
            foreach (InstanceContent InsCont in Entities_inDb)
            {
                ++ii;
                Console.WriteLine("ENTITIES IN DB " + ii + " : ID: " + InsCont.InstanceContentID + " - " + InsCont.Instance.Name + "." + InsCont.Attribute.Name + "  PLC = " + InsCont.IOTag.PLC.Name);
            }

            //----------------------------------------------------------------------------
            Console.WriteLine("#06 - Save Changes in DbContext Object");
            Contents.context.SaveChanges();
            //HttpResponseMessage Response = await Contents.PushToDbset(vContents);

            //EXTRA - For future use
            Console.WriteLine("#07 - Resolve Surplus (Recent)");
            //List<InstanceContent> Surplus = Contents.SurplusInDatabase(EntsToPush).Where(c => c.IOTag.PLC.Name == DIObjectName).ToList();

            List <InstanceContent> Surplus = (from dbconts in Contents.EntityCollection.Where(c => c.IOTag.PLC.Name == DIObjectName)
                                              where !EntsToPush.Any
                                                  (ents =>
                                                  dbconts.Attribute.ID == ents.Attribute.ID &&
                                                  dbconts.Instance.ID == ents.Instance.ID &&
                                                  dbconts.IOTag.ID == ents.IOTag.ID
                                                  )
                                              select dbconts).ToList();

            ii = 0;
            foreach (InstanceContent InsCont in Surplus)
            {
                ++ii;
                Console.WriteLine("SURPLUS ENTITIES " + ii + " : ID: " + InsCont.InstanceContentID + " - " + InsCont.Instance.Name + "." + InsCont.Attribute.Name + "  PLC = " + InsCont.IOTag.PLC.Name + "  IOTAgID = " + InsCont.IOTag.ID + "  IOTAgNAme = " + InsCont.IOTag.Name);
            }

            if (Surplus.Count > 0)
            {
                Contents.DeleteList(Surplus);
                context.SaveChanges();
            }

            Console.WriteLine("#08 - Return Message");
            response = new HttpResponseMessage(HttpStatusCode.OK);
            return(response);
        }
Exemplo n.º 13
0
        public async Task <HttpResponseMessage> Post([FromBody]  List <InstanceContent> request)
        {
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.BadRequest);

            response.ReasonPhrase = "Request did not initialize";

            Console.WriteLine("#01 - Initializing Program");
            List <InstanceContent> vContents = request;

            //Extract Contained Classes, and push them to the database
            Console.WriteLine("#02 - Extract Contained Classes, and push them to the database");
            List <Model.PLCTag> PLCTags_ToPush = vContents.Select(c => c.PLCTag).ToList();

            Contents.PLCTags.PushToDbset(PLCTags_ToPush);
            Contents.context.SaveChanges();


            List <Model.Instance>  dbInstances  = Contents.Instances.EntityCollection;
            List <Model.Attribute> dbAttributes = Contents.Attributes.EntityCollection;
            List <Model.IOTag>     dbIOTags     = Contents.IOTags.EntityCollection;
            List <Model.PLCTag>    dbPLCTags    = Contents.PLCTags.EntityCollection;
            List <InstanceContent> dbContents   = Contents.EntityCollection;


            //Update the contained classes in the entities, so that they are not null or incomplete
            //List<InstanceContent> EntsToPush = Contents.GetListSyncFromDB(request);

            //Contents.context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
            Console.WriteLine("#03 - Sync with DB: JOIN TABLES");
            List <InstanceContent> EntsToPush = (from Cont in vContents
                                                 join db_Contents in dbContents
                                                 on
                                                 new { InstName = Cont.Instance.Name, AttName = Cont.Attribute.Name }
                                                 equals
                                                 new { InstName = db_Contents.Instance.Name, AttName = db_Contents.Attribute.Name }
                                                 into dbCs
                                                 from cs in dbCs.DefaultIfEmpty(Cont)
                                                 join db_Instances in dbInstances on Cont.Instance.Name equals db_Instances.Name
                                                 into Ins
                                                 from i in Ins.DefaultIfEmpty(Cont.Instance)
                                                 join db_Attributes in dbAttributes on Cont.Attribute.Name equals db_Attributes.Name
                                                 into Atts
                                                 from a in Atts.DefaultIfEmpty(Cont.Attribute)
                                                 join db_IOTags in dbIOTags on
                                                 new { IOTagName = Cont.IOTag.Name, PLCName = Cont.IOTag.PLC.Name }
                                                 equals
                                                 new { IOTagName = db_IOTags.Name, PLCName = db_IOTags.PLC.Name }
                                                 into IOs
                                                 from io in IOs.DefaultIfEmpty(Cont.IOTag)
                                                 join db_PLCTags in dbPLCTags on
                                                 new { PLCTagName = Cont.PLCTag.Name, PLCName = Cont.PLCTag.PLC.Name }
                                                 equals
                                                 new { PLCTagName = db_PLCTags.Name, PLCName = db_PLCTags.PLC.Name }
                                                 into PLCs
                                                 from P in PLCs.DefaultIfEmpty(Cont.PLCTag)
                                                 //into IC InstanceContentID = cs != null ? cs.InstanceContentID : -1,
                                                 select new InstanceContent()
            {
                InstanceContentID = cs != null ? cs.InstanceContentID : -1,
                Instance = i != null ? i : new Model.Instance(),
                InstanceID = i != null ? i.ID : 0,
                Attribute = a != null ? a : new Model.Attribute(),
                AttributeID = a != null ? a.ID : 0,
                PLCTag = P != null ? P : new Model.PLCTag(),
                PLCTagID = P != null ? P.ID : 0,
                IOTag = io != null ? io : new Model.IOTag(),
                IOTagID = io != null ? io.ID : 0,
                AssetName = Cont.AssetName
            }).ToList();

            //Find contents that are in the database, and update them
            //List<InstanceContent> Entities_inDb = Contents.InDatabase(EntsToPush);


            List <InstanceContent> Entities_inDb = EntsToPush.Where(c => c.InstanceContentID > 0).ToList();

            if (Entities_inDb.Count > 0)
            {
                Contents.UpdateList(Entities_inDb);
            }

            foreach (InstanceContent IC in Entities_inDb)
            {
                Console.WriteLine("In DB:  ID" + IC.InstanceContentID + ":" + IC.Instance.Name + "." + IC.Attribute.Name + "  PLCTagID:" + IC.PLCTag.ID + ":" + IC.PLCTag.Name);
            }
            Contents.context.SaveChanges();

            response = new HttpResponseMessage(HttpStatusCode.OK);
            return(response);
        }
Exemplo n.º 14
0
Arquivo: TryNode.cs Projeto: wrmsr/xdc
 public TryNode(Node parent, Atts atts)
     : base(parent, atts)
 {
 }
Exemplo n.º 15
0
 public MetaNode(Node parent, Atts atts)
     : base(parent, atts)
 {
 }