// line raw filename// cep // cep file name.
        public void ProcessToAssignModuleMessageBody(SQLClass p_sqlclass, Environment p_currentEnvironment)
        {
            bool isthisNewDay = false;

            for (int i = 0; i < m_numberOfLines; i++)// Access Each line folder.
            {
                isthisNewDay = m_Linestatus[i].ProcessSingleDateFolderInfo(p_currentEnvironment);
                if (isthisNewDay == true)
                {
                    p_sqlclass.TruncateTable("[LS_IoTEDGE].[dbo].[T_NG]");
                }

                m_Linestatus[i].m_ModuleMessageBody.TrimExcess();
                foreach (var messageStructure in m_Linestatus[i].m_ModuleMessageBody)
                {
                    m_totalMessageBodiesOfAllLines.Enqueue(messageStructure);
                }
            }// end of for
        }
Пример #2
0
        static void CreateDBAndNGTable(SQLClass p_sqlclass, Environment p_environment)
        {
            string dbname    = "LS_IoTEDGE";
            string tablename = "T_NG"; // NG_TABLE

            string dbfilepath = string.Empty;

            if (p_environment == Environment.productionOnlinux)
            {
                dbfilepath = "'/var/opt/mssql/lsiotedge.mdf'";
            }
            else if (p_environment == Environment.testOnWindow)
            {
                dbfilepath = @"'C:\LSIoTEdgeSolution\config\lsiotedge.mdf'";
            }
            p_sqlclass.CreateDBInSQL(dbname, dbfilepath);
            p_sqlclass.CreateTableInSQL(dbname, tablename, "(LINE varchar(50), 시험일자 varchar(50), Model varchar(50), BarCode varchar(50), 재판정결과 varchar(50), CREATEDT datetime, RAWLocation varchar(250), CEPLocation varchar(250), APSLocation varchar(250))");
            p_sqlclass.SetSqlNameAndTable(dbname, tablename);
        }
Пример #3
0
        static void Main(string[] args)
        {
            stopwatch = new Stopwatch();
            stopwatch.Start();

            ModuleManager moduleManager     = null;
            ModuleClient  moduleclient      = null;
            SQLClass      sqlclass          = null;
            Environment   currentEnvironmet = Environment.productionOnlinux;


            int    count      = 0;
            string logmessage = string.Empty;

            currentEnvironmet = Environment.productionOnlinux;
            moduleManager     = new ModuleManager("");
            string configfile = "";
            bool   repeat     = true;

            if (currentEnvironmet == Environment.productionOnlinux)
            {
                configfile    = "/app/documents/config.txt";
                moduleclient  = ConnectionManager.Init().Result;
                moduleManager = new ModuleManager("/app/documents/config.txt");
            }
            else if (currentEnvironmet == Environment.testOnWindow)
            {
                configfile    = "C:\\Users\\sena.kim\\Documents\\Projects\\LS산전\\Azure_LS_EdgeSolution\\LSIoTEdgeSolution\\config\\config.txt";
                moduleManager = new ModuleManager("C:\\Users\\sena.kim\\Documents\\Projects\\LS산전\\Azure_LS_EdgeSolution\\LSIoTEdgeSolution\\config\\config.txt");
            }
            moduleManager.Init();
            LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, configfile);

            sqlclass = new SQLClass(moduleManager.GetsqlConnectionString());
            sqlclass.CheckSqlConnection();
            CreateDBAndNGTable(sqlclass, currentEnvironmet);
            ////////////////////////////////////////// Initialization Complete ////////////////////////////
            logmessage = "Initialization complete : Time elapsed: {" + stopwatch.Elapsed.ToString("hh\\:mm\\:ss\\:ff") + "}"; //local test : {00:00:00:38}
            LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, logmessage);

            while (repeat == true)//count < 1)//true
            {
                count++;
                Process(moduleManager, currentEnvironmet, sqlclass, moduleclient);

                ////////////////////////////////////////// Process Complete ////////////////////////////
                moduleManager.Clear();
                sqlclass.CloseSQL();                                                                                                                  // only print messages that contains raw cep aps
                stopwatch.Stop();                                                                                                                     // Stop
                if (count == 1)
                {                                                                                                                                     // Write hours, minutes , seconds , milliseconds/.
                    logmessage = "All Process Complete For the First Time : Time elapsed: {" + stopwatch.Elapsed.ToString("hh\\:mm\\:ss\\:ff") + "}"; // Write hours, minutes , seconds , milliseconds/.
                }
                else if (count < 10)
                {
                    logmessage = " " + count + " Process Complete : Time elapsed: {" + stopwatch.Elapsed.ToString("hh\\:mm\\:ss\\:ff") + "}";  // Write hours, minutes , seconds , milliseconds/.
                }
                LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, logmessage);
                stopwatch.Reset();
            }
            // Wait until the app unloads or is cancelled
            var cts = new CancellationTokenSource();

            AssemblyLoadContext.Default.Unloading += (ctx) => cts.Cancel();
            Console.CancelKeyPress += (sender, cpe) => cts.Cancel();
            ConnectionManager.WhenCancelled(cts.Token).Wait();
        }
Пример #4
0
        static void Process(ModuleManager p_moduleManager, Environment p_currentEnvironment, SQLClass p_sqlclass, ModuleClient p_moduleclient)
        {
            string tempmessage = "Start Processing Line reports.";

            LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, tempmessage);

            p_moduleManager.ProcessToAssignModuleMessageBody(p_sqlclass, p_currentEnvironment);
            p_moduleManager.m_totalMessageBodiesOfAllLines.TrimExcess();
            int tempMax = p_moduleManager.m_totalMessageBodiesOfAllLines.Count;
            int count   = 0;

            foreach (var temp in p_moduleManager.m_totalMessageBodiesOfAllLines)
            {
                count++;
                var messageBody   = LogBuilder.AssignTempMessageBody(temp.LineName, temp.Raw, temp.Cep);
                var messageString = JsonConvert.SerializeObject(messageBody);
                tempmessage = $"This ID : {count} Line Name {temp.LineName}, Barcode {temp.BadProductInfo.BarCode}";

                LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, tempmessage);


                if (p_sqlclass.ReadSQL($"SELECT COUNT([BarCode]) AS ISEIXSTS FROM [LS_IoTEDGE].[dbo].[T_NG]	WHERE [BarCode] = '{ temp.BadProductInfo.BarCode}'	;") == "0")
                {
                    Random _r = new Random();
                    int    a  = _r.Next(2);
                    if (a == 0)
                    {
                        temp.BadProductInfo.Result = "NG";
                    }
                    else if (a == 1)
                    {
                        temp.BadProductInfo.Result = "OK";
                    }
                    //Chek if the data already exist
                    p_sqlclass.InsertTableInSQL(temp.LineName, temp.BadProductInfo.Date, temp.BadProductInfo.Model, temp.BadProductInfo.BarCode, temp.BadProductInfo.Result, temp.Raw, temp.Cep, temp.Aps);

                    if (p_currentEnvironment == Environment.productionOnlinux)
                    {
                        ConnectionManager.SendData(p_moduleclient, messageString).Wait();
                    }
                    else if (p_currentEnvironment == Environment.testOnWindow)
                    {
                        LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, messageString);
                    }
                }
            }
        }// end of Process void