예제 #1
0
 public static IOs GetInstance()
 {
     if (_Instance == null)
     {
         _Instance = new Windows.Win32();
     }
     return _Instance;
 }
예제 #2
0
        public void Disconnect()
        {
            ServerGetCMD.RemoveClient(this);
            ClientTCP.Close();

            Console.WriteLine(ClientIP + " lecsatlakozott ekkor " + DateTime.Now + " innen " + ClientIP);
            IOs.MakeLog(ClientIP + " lecsatlakozott innen " + ClientIP, 0);
        }
예제 #3
0
 public bool WriteIo(IOs io, bool enable)
 {
     lock (this)
     {
         m_buffer[1] = (byte)OPCODE.WRITE_SINGLE;
         m_buffer[2] = (byte)io;
         m_buffer[3] = (byte)(enable == true ? 1 : 0);
         m_client.Write(m_buffer, 0, 4);
         return(true);
     }
 }
예제 #4
0
 public bool ClearIO(IOs io)
 {
     lock (this)
     {
         m_buffer[1] = (byte)OPCODE.WRITE_SINGLE;
         m_buffer[2] = (byte)io;
         m_buffer[3] = 0;
         m_client.Write(m_buffer, 0, 4);
         return(true);
     }
 }
예제 #5
0
 public Computer(IBios bios, IOs os)
 {
     this.bios = bios;
     this.os   = os;
 }
예제 #6
0
 public void LoadControl(K64LanToIo client, IOs io, string text)
 {
     m_client    = client;
     m_io        = io;
     label1.Text = text;
 }
예제 #7
0
 public void LoadControl(IOs io, string text)
 {
     m_io        = io;
     label1.Text = text;
 }
예제 #8
0
        public void GetCMD()
        {
            while (ReceiveCMD)
            {
                try
                {
                    byte[] buffer = new byte[ClientTCP.ReceiveBufferSize];

                    ClientStream.Read(buffer, 0, buffer.Length);

                    string msg = Encoding.UTF8.GetString(buffer).TrimEnd('\0').Replace("/checkLife", "");

                    string answ = "";

                    if (msg == "")
                    {
                        answ = "/alive";

                        buffer = Encoding.UTF8.GetBytes(answ);

                        ClientStream.Write(buffer, 0, buffer.Length);

                        Thread.Sleep(ClientTCP.ReceiveTimeout - 4500);

                        continue;
                    }


                    string cmd = ManageCMDs.GetCMD(msg);
                    msg = msg.Replace("/" + cmd + " ", "");

                    answ = ManageCMDs.WhichCMD(cmd, msg);

                    if (answ == null)
                    {
                        answ = "nem található parancs";
                    }

                    if (answ.StartsWith("###"))
                    {
                        answ = answ.Remove(0, 3);
                    }

                    buffer = Encoding.UTF8.GetBytes(answ);
                    ClientStream.Write(buffer, 0, buffer.Length);

                    Thread.Sleep(500);

                    continue;
                }
                catch (IOException ex)
                {
                    Console.WriteLine("A " + ClientIP + " bezárta a kapcsolatot");
                    IOs.MakeLog("A " + ClientIP + " bezárta a kapcsolatot::" + ex.Message, 0);
                }
                catch (SocketException ex)
                {
                    if (ex.SocketErrorCode == SocketError.TimedOut)
                    {
                        if (errcounter < 10)
                        {
                            errcounter++;
                            ClientTCP.ReceiveTimeout += errcounter * 1000;
                            ClientTCP.SendTimeout    += errcounter * 1000;
                            GetCMD();
                        }
                        else
                        {
                            Console.WriteLine("A szerver nem válaszolt a megadott időn belűl!");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Hiba lépett fel a szerverrel való kommunikáció közben");
                        IOs.MakeLog("Hiba lépett fel a szerverrel való kommunikáció közben::" + ex.Message + ":::" + ex.SocketErrorCode.ToString(), 0);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Hiba lépett fel a csomagfogádasa közben");
                    IOs.MakeLog("A " + ClientIP + " ismeretlen hiba lépett fel::" + ex.Message, 0);
                }
                ReceiveCMD = false;
            }
            Disconnect();
        }
        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);
        }
예제 #10
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);
        }
예제 #11
0
 public static void Register(IOs osIntance)
 {
     os = osIntance;
 }