Exemple #1
0
        public void writeData(string recKey, dataLine data, int logID)
        {
            string        connectionString;
            SqlConnection cnn;

            connectionString = ConfigurationManager.ConnectionStrings["LoggerDB"].ConnectionString;
            cnn = new SqlConnection(connectionString);
            try
            {
                cnn.Open();

                SqlCommand     command;
                SqlDataAdapter dataAdapter = new SqlDataAdapter();
                String         sql         = "";

                if ((data.group1.Length > 100) ||
                    (data.group2.Length > 100) ||
                    (data.group3.Length > 100) ||
                    (data.group4.Length > 100) ||
                    (data.group5.Length > 100) ||
                    (data.group7.Length > 100))
                {
                    Console.WriteLine("error");
                }


                sql = @"INSERT INTO loginfo(logkey, group1, group2, group3, group4, group5, group6, group7, group8,prjKey, logID) 
                        VALUES('" + recKey + "','" +
                      data.group1 + "','" +
                      data.group2 + "','" +
                      data.group3 + "','" +
                      data.group4 + "','" +
                      data.group5 + "','" +
                      data.group6 + "','" +
                      data.group7 + "','" +
                      WebUtility.HtmlEncode(data.group8 + data.group9) + "','" +
                      Key + "','" + logID + "')";

                command = new SqlCommand(sql, cnn);
                dataAdapter.InsertCommand = new SqlCommand(sql, cnn);
                dataAdapter.InsertCommand.ExecuteNonQuery();

                command.Dispose();
                cnn.Close();
            }
            catch (SqlException sqlEx)
            {
                Console.WriteLine(sqlEx.ToString());
            }
        }
Exemple #2
0
        public void uploadLog(string filename)
        {
            addLogToProject(this.pKey);
            int logID = attachLogToProject(this.pKey, filename);

            // create dictionary
            Dictionary <string, dataLine> dicData = new Dictionary <string, dataLine>();

            WriteLog("c:", "test.txt", "Testing Testing");
            string[] lstLines = File.ReadAllLines(filename);

            int    repLine       = 0;
            int    recProcessed  = 0;
            int    recSkipped    = 0;
            int    readRecs      = 0;
            int    recExtent     = 0;
            string prevTimeStamp = "";
            long   lineProcess   = 0;
            string strLine       = null;

            //foreach (string strLine in lstLines)
            while (lineProcess < lstLines.Length)
            {
                strLine = lstLines[lineProcess];
                dataLine record = new dataLine();
                if (strLine == "")
                {
                    recSkipped++;
                    lineProcess++;
                    continue;
                }
                if (strLine.Substring(0, 1) != "[")
                {
                    recSkipped++;
                    lineProcess++;
                    continue;
                }
                lineProcess++;

                while (lineProcess < lstLines.Length && lstLines[lineProcess] != "" &&
                       lstLines[lineProcess].Substring(0, 1) != "[")
                {
                    strLine += lstLines[lineProcess] + System.Environment.NewLine;
                    lineProcess++;
                }

                readRecs++;
                //
                Regex openGroup9 = new Regex(@"(\[.*\])(\[.*\])(\[.*\])(\[.*\])(\[.*\])(\[.*\])(\[.*\])(\[.*\])?(.*)");
                Regex openGroup8 = new Regex(@"(\[.*\])(\[.*\])(\[.*\])(\[.*\])(\[.*\])(\[.*\])(\[.*\])?(.*)");
                Regex closeGroup = new Regex("]");
                Regex dateGroup  = new Regex(@"\d\d\d\d-\d\d-\d\d.\d\d:\d\d:\d\d-\d\d\d");

                MatchCollection openGroupContent = openGroup9.Matches(strLine);
                if (openGroupContent.Count == 0)
                {
                    openGroupContent = openGroup8.Matches(strLine);
                }

                string strDate = "";

                foreach (Match item in openGroupContent[0].Groups)
                {
                    string strLineSub = "";

                    if (strLine.Length != item.Value.Length)
                    {
                        strLineSub = strLine.Substring(item.Value.Length, strLine.Length - item.Value.Length);
                        recExtent  = recExtent + strLineSub.Split('\n').Length;
                    }

                    foreach (Group group in item.Groups)
                    {
                        if (group.Value == strLine)
                        {
                            recProcessed++;
                            continue;
                        }
                        MatchCollection matches = dateGroup.Matches(group.Value);

                        group.Value.Replace(@"'", @"''");
                        switch (group.Name)
                        {
                        case "0":
                            strDate = matches[0].Value;
                            break;

                        case "1":
                            record.group1 = group.Value.Replace(@"'", @"''");
                            break;

                        case "2":
                            record.group2 = group.Value.Replace(@"'", @"''");
                            break;

                        case "3":
                            record.group3 = group.Value.Replace(@"'", @"''");
                            break;

                        case "4":
                            record.group4 = group.Value.Replace(@"'", @"''");
                            break;

                        case "5":
                            record.group5 = group.Value.Replace(@"'", @"''");
                            break;

                        case "6":
                            record.group6 = group.Value.Replace(@"'", @"''");
                            break;

                        case "7":
                            record.group7 = group.Value.Replace(@"'", @"''");
                            break;

                        case "8":
                            record.group8 = group.Value.Replace(@"'", @"''") + strLineSub;
                            break;

                        default:
                            record.group9 = group.Value.Replace(@"'", @"''");
                            break;
                        }

                        if (group.Name == "1")
                        {
                            strDate = matches[0].Value;

                            record.group0 = matches[0].Value;

                            if (strDate == prevTimeStamp)
                            {
                                repLine++;
                            }
                            else
                            {
                                repLine = 0;
                            }
                        }

                        if (group.Name == (item.Groups.Count - 1).ToString())
                        {
                            //repLine = 0;
                            bool flagAdd = false;
                            while (!flagAdd)
                            {
                                try
                                {
                                    // add the data to the dictionary
                                    //groupsData = groupsData + group.Value + strLineSub;

                                    //dataLine rec = new dataLine();
                                    string recKey = strDate + "-" + repLine.ToString();
                                    dicData.Add(recKey, record);

                                    int recCount = dicData.Count;
                                    // insert data into db
                                    writeData(recKey, record, logID);


                                    prevTimeStamp = strDate;
                                    flagAdd       = true;
                                    //repLine++;
                                }
                                catch (System.ArgumentException e)
                                {
                                    repLine++;
                                }
                            }
                        }
                    }

                    break;
                }
            }

            /*          Console.WriteLine("Records Processed {0}", recProcessed);
             *          Console.WriteLine("Records Skipped {0}", recSkipped);
             *          Console.WriteLine("Records read {0}", readRecs);
             *          Console.WriteLine("Records Extended {0}", recExtent);
             *          Console.ReadKey();*/
        }