Exemplo n.º 1
0
        /// <summary>
        /// Extract Transaction ID from the log files.
        /// </summary>
        /// <param name="file">FileInfo of the log file which contains the transaction id</param>
        /// <returns>transaction ID</returns>
        public static string GetTransactionId_StreamReader(FileInfo file)
        {
            try
            {
                //check if file exists
                if (File.Exists(file.FullName))
                {
                    // create streamReader
                    StreamReader streamReader = new StreamReader(file.FullName);

                    int    counter = 1;
                    string line;
                    string transactionId = null;

                    //transaction Id is at line 2
                    while ((line = streamReader.ReadLine()) != null)
                    {
                        if (counter == 2)
                        {
                            string txtFile = line;
                            //get the last string from line 2
                            string[] txtArray = txtFile.Split(' ');
                            //get last array
                            transactionId = txtArray[txtArray.Length - 1];
                            transactionId = ExtractDigits(transactionId);
                            if (transactionId.Contains("\r"))
                            {
                                transactionId = transactionId.Replace("\r", "");
                            }
                            if (transactionId.Contains("\n"))
                            {
                                transactionId = transactionId.Replace("\n", "");
                            }
                            break;
                        }
                        else
                        {
                            counter++;
                        }
                    }

                    return(transactionId);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                PrintHelper.Trace(string.Format(Messages.ReadTransactionIdFail, file.FullName));
                PrintHelper.Error(ex.ToString());
                throw;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Extract Transaction ID from the log files.
        /// </summary>
        /// <param name="file">FileInfo of the log file which contains the transaction id</param>
        /// <returns></returns>
        public static string GetTransactionId_XXX(FileInfo file)
        {
            try
            {
                //check if file exists
                if (File.Exists(file.FullName))
                {
                    //read logfiles as text
                    string txtFile = File.ReadAllText(file.FullName);

                    //look for the word "Transaction" and get the transactionId
                    string[] txtArray      = txtFile.Split(' ');
                    string   transactionId = null;
                    for (int i = 0; i < txtArray.Length; i++)
                    {
                        string outString = txtArray[i];
                        if (outString.ToLower().Contains("transaction"))
                        {
                            // Transaction ID : XXXXXXXXXXXXXXXX
                            // Transaction ID : 221119020153251
                            // Transaction ID : 910919040027358
                            transactionId = txtArray[i + 3];
                            // after getting the transaction id, exit loop
                            break;
                        }
                    }
                    if (!string.IsNullOrEmpty(transactionId))
                    {
                        //remove any possible Line Feed (\n) or Carriage Return (\r) inside transaction ID
                        transactionId = transactionId.Replace("\r\nINFO", "");
                        transactionId = transactionId.Replace("\r\nWARN", "");
                        transactionId = transactionId.Replace("\nINFO", "");
                        transactionId = transactionId.Replace("\nWARN", "");
                        transactionId = transactionId.Replace("\r", "");
                        transactionId = transactionId.Replace("\n", "");
                        transactionId = transactionId.Replace("\r\n", "");
                    }

                    return(transactionId);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                PrintHelper.Trace(string.Format(Messages.ReadTransactionIdFail, file.FullName));
                PrintHelper.Error(ex.ToString());
                return(string.Empty);
            }
        }
Exemplo n.º 3
0
        //public enum ServiceName
        //{
        //    BCRM_Update,
        //    Create_CPP,
        //    Create_SNC,
        //    Update_CPP,
        //    Update_SNC,
        //    ERMS_Update
        //}

        public DataTable QueryTable(string query, OracleParameter[] parameters = null)
        {
            DataSet   ds = new DataSet();
            DataTable dt = new DataTable();

            using (OracleConnection oraconn = new OracleConnection(ConnectionString))
            {
                try
                {
                    if (oraconn.State == ConnectionState.Open)
                    {
                        oraconn.Close();
                    }
                    oraconn.Open();
                    OracleCommand cmd = new OracleCommand(query, oraconn);
                    cmd.CommandType = CommandType.Text;
                    cmd.BindByName  = true;
                    if (parameters != null)
                    {
                        cmd.Parameters.AddRange(parameters);
                    }
                    OracleDataAdapter da = new OracleDataAdapter(cmd);
                    da.Fill(dt);
                }
                catch (Exception ex)
                {
                    PrintHelper.Trace(ex.Message);
                    PrintHelper.ErrorLog(string.Format(Messages.GetOracleQuery, query));
                    if (parameters != null)
                    {
                        PrintHelper.ErrorLog("Parameter List: ");
                        for (int i = 0; i < parameters.Length; i++)
                        {
                            PrintHelper.ErrorLog
                                (string.Format("{0} = {1}",
                                               parameters[i].ParameterName,
                                               parameters[i].Value));
                        }
                    }
                    PrintHelper.Error(ex.ToString());
                    throw;
                }
                finally
                {
                    oraconn.Close();
                }
            }
            //return ds.Tables.Count > 0 ? ds.Tables[0] : new DataTable();
            return(dt);
        }
Exemplo n.º 4
0
 //not used.
 private static void GenerateExcel(List <string> swTransactionList, List <string> soaTransactionList)
 {
     //Generate Excel
     Console.WriteLine("Generating Excel");
     try
     {
         string fileName = ExcelHelper.ExportExcel(swTransactionList, soaTransactionList);
         logger.Log(LogLevel.Trace, Messages.ExcelSuccess + fileName);
     }
     catch (Exception ex)
     {
         PrintHelper.Error(Messages.ExcelError);
         PrintHelper.Error(ex.ToString());
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Main will call this function. Start Here
        /// </summary>
        /// <param name="myService"></param>
        private static void StartProgram(ServiceCode myService)
        {
            PrintHelper.Trace(string.Format(Messages.GetServiceName, myService.ToString()));
            try
            {
                ServiceHelper sh = new ServiceHelper(myService);

                //SWTNBHelper sWTNB = new SWTNBHelper();
                //List<string> retString = sWTNB.GetTransId(inputDate, sh);

                //get logfiles from folder based on date and insert data to SOA Transaction
                List <FileInfo> logFiles = ReadHelper.Read_SW_Logs(inputDate, sh);
                PrintHelper.Trace(Messages.InsertSOA_TRANSACTION);
                Insert_SOA_Transaction(logFiles, sh);

                //Compare with QS Report and save difference in KSF_SYSTEM_SOA_FAIL_TRANS
                List <string> soaTransactionList = ReadHelper.Read_QS_TransactionId(inputDate, sh);
                List <string> swTransactionList  = ReadHelper.Read_SW_Transaction_ID(logFiles);

                PrintHelper.Trace(Messages.RemoveDuplicates);
                soaTransactionList = soaTransactionList.Distinct().ToList();
                swTransactionList  = swTransactionList.Distinct().ToList();

                PrintHelper.Trace(string.Format(Messages.TotalTransId_QS, soaTransactionList.Count));
                PrintHelper.Trace(string.Format(Messages.TotalTransId_SW, swTransactionList.Count));

                //this will insert the difference into KSF_SYSTEM_SOA_FAIL_TRANS table
                PrintHelper.Trace(Messages.InsertKSF_SYSTEM_SOA_FAIL_TRANS);
                var difference = soaTransactionList.Except(swTransactionList);
                //var difference = swTransactionList.Except(soaTransactionList);
                if (difference.Count() == 0)
                {
                    PrintHelper.Trace(string.Format(Messages.TotalDifferenceZero, difference.Count().ToString()));
                }
                else
                {
                    PrintHelper.Trace(string.Format(Messages.TotalDifference, difference.Count().ToString()));
                    Insert_SOA_Fail_Trans(difference, sh, inputDate);
                }
            }
            catch (Exception ex)
            {
                PrintHelper.Error(ex.Message);
                PrintHelper.Error(ex.ToString());
            }
        }
Exemplo n.º 6
0
        private void HandleConnectionAsync(TcpClient client)
        {
            PrintHelper.PrintLine();
            PrintHelper.PrintRow(client.Client.ProtocolType.ToString(), client.Client.RemoteEndPoint.ToString(), client.Client.Available.ToString(), "ESTABLISHED");

            try
            {
                byte[] bytes = new Byte[1024]; // 1 KB buffer
                //string data = null;
                int           i;
                NetworkStream stream = client.GetStream();

                while (true)
                {
                    //client established correctly
                    while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
                    {
                        var data = BitConverter.ToString(bytes, 0, i).Replace("-", string.Empty);

                        PrintHelper.PrintRow(client.Client.ProtocolType.ToString(), client.Client.RemoteEndPoint.ToString(), i.ToString(), "RECEIVING DATA");
                        TrafficUtility.AddReceivedTraffic(i);

                        if (Program.debug)
                        {
                            PrintHelper.PrintDump(data);
                        }

                        fm112x.Parse(client, data);
                    }

                    if (i == 0)
                    {
                        break;
                    }
                }

                PrintHelper.PrintRow(client.Client.ProtocolType.ToString(), client.Client.RemoteEndPoint.ToString(), client.Client.Available.ToString(), "CLOSED");
                _clients--;
                clients.Remove(client);
            }
            catch (Exception ex)
            {
                PrintHelper.Error(ex.Message);
                LogUtility.WriteErrorLog(string.Format("Message:\n{0}\nStackTrace:\n{1}", ex.Message, ex.StackTrace));
            }
        }
Exemplo n.º 7
0
 public void ExecNonQuery(string query, OracleParameter[] parameters = null)
 {
     using (OracleConnection oraconn = new OracleConnection(ConnectionString))
     {
         try
         {
             if (oraconn.State == ConnectionState.Open)
             {
                 oraconn.Close();
             }
             oraconn.Open();
             OracleCommand cmd = new OracleCommand(query, oraconn);
             cmd.CommandType = CommandType.Text;
             cmd.BindByName  = true;
             if (parameters != null)
             {
                 cmd.Parameters.AddRange(parameters);
             }
             int retVal = cmd.ExecuteNonQuery();
         }
         catch (Exception ex)
         {
             PrintHelper.Trace(ex.Message);
             PrintHelper.ErrorLog(string.Format(Messages.GetOracleQuery, query));
             if (parameters != null)
             {
                 PrintHelper.ErrorLog("Parameter List below: ");
                 for (int i = 0; i < parameters.Length; i++)
                 {
                     PrintHelper.ErrorLog
                         (string.Format("{0} = {1}",
                                        parameters[i].ParameterName,
                                        parameters[i].Value));
                 }
             }
             PrintHelper.Error(ex.ToString());
             throw;
         }
         finally
         {
             oraconn.Close();
         }
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// This will insert the transaction ID from Logs into SOA_TRANSACTION table
        /// </summary>
        /// <param name="logFiles">List of Log files from SW folder</param>
        /// <param name="sh">Instance of Service Helper</param>
        private static void Insert_SOA_Transaction(List <FileInfo> logFiles, ServiceHelper sh)
        {
            SWTNBHelper sw = new SWTNBHelper();

            if (logFiles.Count > 0)
            {
                try
                {
                    //sw.DeleteTransLog(inputDate, sh);
                    int totalRows = sw.Insert_Soa_Trans(logFiles.ToList(), sh);
                    PrintHelper.Trace(string.Format(Messages.TotalRowsInserted, totalRows));
                }
                catch (Exception ex)
                {
                    PrintHelper.Error(Messages.InsertDataFail);
                    PrintHelper.Error(ex.ToString());
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// this will insert the difference into KSF_SYSTEM_SOA_FAIL_TRANS table
        /// </summary>
        /// <param name="difference">List string of Transaction Id </param>
        /// <param name="sh">Instance of Service Helper</param>
        /// <param name="inputDate">selected Date</param>
        private static void Insert_SOA_Fail_Trans(IEnumerable <string> difference, ServiceHelper sh, DateTime inputDate)
        {
            SWTNBHelper sw = new SWTNBHelper();

            if (difference.Count() > 0)
            {
                try
                {
                    //sw.DeleteFailTrans(DateTime.Now, sh, inputDate);
                    int totalRows = sw.Insert_SOAFailTrans(difference, inputDate, sh);
                    PrintHelper.Trace(string.Format(Messages.TotalRowsInserted,
                                                    totalRows.ToString()));
                }
                catch (Exception ex)
                {
                    PrintHelper.Error(Messages.InsertDataFail);
                    PrintHelper.Error(ex.ToString());
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// sub function of ReadSW_FileLogs. this will read based on Server Name (server1, server2, server3)
        /// </summary>
        /// <param name="selDate">input Date. i.e the date used to filter logs</param>
        /// <param name="sh">instance of service code helper</param>
        /// <param name="serverNumber">choose from server 1 to 3</param>
        /// <returns></returns>
        private static List <FileInfo> ReadSW_FileLogs_ByServerName(DateTime selDate, ServiceHelper sh, int serverNumber)
        {
            List <FileInfo> filter1 = new List <FileInfo>();
            DateTime        newDate = new DateTime(selDate.Year, selDate.Month, selDate.Day);
            //get path from servers
            string path = GetTransactionLogFolderPath(sh, serverNumber);

            try
            {
                PrintHelper.Trace(string.Format(Messages.GetFolderLocation, path));
                PrintHelper.Trace(Messages.PleaseWait);
                //get list of fileNames from the path provided
                List <string> files = Directory.GetFiles(path).ToList();

                //use foreach loop to convert files to fileInfo
                List <FileInfo> allFiles = new List <FileInfo>();
                foreach (string filePath in files)
                {
                    FileInfo file = new FileInfo(filePath);
                    allFiles.Add(file);
                }

                if (allFiles.Count > 0)
                {
                    //filter which files to take based on Modified date and service name
                    filter1 = allFiles
                              .Where(s => s.Name.Contains(sh.FileNameContains) &&
                                     s.LastWriteTime.Date == newDate.Date &&
                                     s.LastWriteTime.Month == newDate.Month &&
                                     s.LastWriteTime.Year == newDate.Year).ToList();
                }
                //PrintHelper.Trace(string.Format(Messages.ModifiedDateTime, newDate.ToShortDateString()));
                PrintHelper.Trace(string.Format(Messages.ReadTotal_Log, filter1.Count.ToString()));
            }
            catch (Exception ex)
            {
                PrintHelper.Error(string.Format(Messages.ReadFileError, path));
                PrintHelper.Error(ex.ToString());
            }
            return(filter1);
        }
Exemplo n.º 11
0
        public async Task <bool> CheckServerStatus()
        {
            return(await Task.Run(() =>
            {
                var httpWebRequest = (HttpWebRequest)WebRequest.Create(_clientURI + "/api/");
                httpWebRequest.ContentType = "application/json";
                httpWebRequest.Method = "GET";

                try
                {
                    var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                    var result = httpResponse.GetResponseHeader("Content-Type");
                    return true;
                }
                catch (Exception ex)
                {
                    PrintHelper.Error(ex.Message);
                    LogUtility.WriteExceptionLog(ex);
                    return false;
                }
            }));
        }
Exemplo n.º 12
0
        private void WebRequestPOST(List <EntityFM112X> data)
        {
            try
            {
                var httpWebRequest = (HttpWebRequest)WebRequest.Create(_clientURI + "/api/records/" + data[0].IMEI + "/");
                httpWebRequest.ContentType = "application/json";
                httpWebRequest.Method      = "POST";

                foreach (EntityFM112X value in data)
                {
                    using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                    {
                        string json = JsonConvert.SerializeObject(value);

                        streamWriter.Write(json);
                        streamWriter.Flush();
                        streamWriter.Close();
                    }

                    var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

                    using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                    {
                        var result = streamReader.ReadToEnd();
                    }
                }
            }
            catch (Exception ex)
            {
                PrintHelper.Error(ex.Message);
                LogUtility.WriteExceptionLog(ex);
                return;
            }

            PrintHelper.PrintInformation("The data was sent correctly!");
        }
Exemplo n.º 13
0
 private void Fm112x_Error(object sender, string e)
 {
     PrintHelper.Error(e);
     LogUtility.WriteErrorLog(e);
 }