Ejemplo n.º 1
0
        private static MapRow[] GetMemoryRowsFromDataTable(DataTable memoryTable)
        {
            ArrayList mapList = new ArrayList();

            for (int i = 0; i < memoryTable.Rows.Count; i++)
            {
                DataRow dataRow = memoryTable.Rows[i];
                int     address;
                if (int.TryParse(dataRow["FieldAddress"].ToString(), out address))
                {
                    MapRow map = new MapRow();
                    map.Address = address;
                    map.Code    = dataRow["FieldCode"].ToString();
                    map.Name    = dataRow["FieldName"].ToString();
                    int dataLength;
                    if (int.TryParse(dataRow["DataLength"].ToString(), out dataLength) == false)
                    {
                        dataLength = 1;
                    }
                    int decPoint;
                    if (int.TryParse(dataRow["DecimalPoint"].ToString(), out decPoint) == false)
                    {
                        decPoint = 0;
                    }

                    map.DataLength   = dataLength;
                    map.DecimalPoint = decPoint;
                    map.IsUsed       = dataRow["UseOrNot"].ToString().ToUpper().Equals("Y") ? true : false;
                    map.IsSaved      = dataRow["SaveOrNot"].ToString().ToUpper().Equals("Y") ? true : false;
                    map.Reference    = dataRow["Reference"].ToString();

                    mapList.Add(map);
                }
            }
            MapRow[] memorymap = (MapRow[])mapList.ToArray(typeof(MapRow));
            return(memorymap);
        }
Ejemplo n.º 2
0
        private static void HandleSaveMachineError(MachineInformation machineInfo,
                                                   Dictionary <string, string> newMachineData)
        {
            System.Diagnostics.Stopwatch SW = new System.Diagnostics.Stopwatch();
            SW.Start();
            string machineCode = machineInfo.MachineCode;

            EntireMachineData[machineCode] = newMachineData;
            try
            {
                DateTime now = DateTime.Now;
                if (EntireMachineData.ContainsKey(machineCode))
                {
                    System.Diagnostics.Stopwatch SW2 = new System.Diagnostics.Stopwatch();
                    SW2.Start();
                    //이전 machineData 에 error와 현재 machineData error 비교 후 sql 실행
                    //Dictionary<string, string> preMachineData = EntireMachineData[machineCode];
                    Dictionary <string, string> preErrorStates = DbHelper.getPreviousErrorStates(machineCode);
                    string[] fieldCodes = newMachineData.Keys.ToArray();
                    MapRow[] memorymap  = MemoryMaps[machineCode];

                    for (int i = 0; i < newMachineData.Count; i++)
                    {
                        string fieldCode = fieldCodes[i];
                        string errorText = string.Empty;

                        if (fieldCode.Substring(0, 1).ToUpper().Equals("M"))
                        {
                            MapRow row = new MapRow();
                            for (int rowIndex = 0; rowIndex < memorymap.Length; rowIndex++)
                            {
                                if (memorymap[rowIndex].Code == fieldCode)
                                {
                                    row = memorymap[rowIndex];
                                }
                            }

                            string newErrorState = newMachineData[fieldCode];
                            string preErrorState = preErrorStates.GetValueOrDefault(fieldCode);

                            if (newErrorState != preErrorState)
                            {
                                DbHelper.UpdateErrorList(machineInfo, fieldCode, newErrorState, now);

                                if (newErrorState.Trim() == "1")
                                {
                                    //Send Android Push Alarm
                                    string title = machineInfo.MachineName;
                                    string body  = row.Name;
                                    AndroidFcmSender.SendNotificationToTopic(CompanyCode, title, body);
                                }
                            }
                        }
                    }
                    SW2.Stop();

                    Console.WriteLine(machineCode + " :" + "오류 총 저장 소요시간 " + SW2.ElapsedMilliseconds);
                }
                SW.Stop();
            }
            catch (Exception ex)
            {
                LogWriter.WriteLog_Error(ex);
            }
        }