Click here to Skip to main content
15,886,798 members
Home / Discussions / C#
   

C#

 
AnswerRe: Dual Screen Display Pin
OriginalGriff16-Nov-16 1:40
mveOriginalGriff16-Nov-16 1:40 
GeneralRe: Dual Screen Display Pin
Member 972228316-Nov-16 2:20
Member 972228316-Nov-16 2:20 
GeneralRe: Dual Screen Display Pin
Dave Kreskowiak16-Nov-16 3:47
mveDave Kreskowiak16-Nov-16 3:47 
GeneralRe: Dual Screen Display Pin
Member 97222835-Dec-16 20:20
Member 97222835-Dec-16 20:20 
AnswerRe: Dual Screen Display Pin
Richard MacCutchan16-Nov-16 1:41
mveRichard MacCutchan16-Nov-16 1:41 
Questionhow to keep original image aspect ratio ? Pin
Member 1285075615-Nov-16 15:49
Member 1285075615-Nov-16 15:49 
AnswerRe: how to keep original image aspect ratio ? Pin
Dave Kreskowiak16-Nov-16 2:37
mveDave Kreskowiak16-Nov-16 2:37 
QuestionParse 17,000 text files and insert into database Pin
davers15-Nov-16 6:29
davers15-Nov-16 6:29 
Hey Gang...I've got a folder with about 17,000 text files in it. I need to parse those text files and insert my parsed results into a Sql database. I've gotten it to where I'm doing about 4 - 5 files per second, but I need it to be faster that that. The text files aren't straight forward either. An example of the data in the text file is:

orld Clock Location Entries=INXX0102|Pune|India
Weather Location ID=48226|Detroit| MI (48226)
English/Metric Units=0
CLNAME001=
CLNUMBER001=xxx-xxx-xxxx
CLTYPE001=4
CLDATE001=11/09/16
CLTIME001=18:07
CLDURATION001=
CLBRIDGEDFLAG001=0
CLMISSEDCNTR001=1
CLBCALBL001=
CLNAME002=
CLNUMBER002=xxx-xxx-xxxx
CLTYPE002=4
CLDATE002=11/09/16
CLTIME002=17:59
CLDURATION002=
CLBRIDGEDFLAG002=0
CLMISSEDCNTR002=1
CLBCALBL002=
CLNAME003=
CLNUMBER003=xxxxxxxxxxxx
CLTYPE003=3
CLDATE003=11/09/16
CLTIME003=16:57
CLDURATION003= 1:54
CLBRIDGEDFLAG003=0
CLMISSEDCNTR003=0
CLBCALBL003=

etc......

This is a backup text file of an AVAYA 96xx phone. What you see above is 3 calls from the phones call history. There's more in that text file than just calls though, so to get just call info, I grab all the lines that start with "CL".

Here's a blurb of my code:

C#
while ((line = file.ReadLine()) != null)
{
    if (line.Substring(0, 2) == "CL")
    {
        try
        {
            string[] strArray = line.Split("=".ToCharArray());
            string key = strArray[0];
            string str = strArray[1];



One call is made up of 9 elements, so:

CLNAME, CLNUMBER, CLTYPE, CLDATE, CLTIME, CLDURATION, CLBRIDGEDFLAG, CLMISSEDCNTR, CLBCALBL all make up one call. My question to you is, how would you go about parsing this out and inserting into a database? Am I going about it the right way?

Below is my complete code:

C#
public static void letsdoit(SqlConnection con)
{
    string[] files;
    string line;
    int counter = 0;

    using (UNCAccessWithCredentials unc = new UNCAccessWithCredentials())
    {
        if (unc.NetUseWithCredentials(@"\\ql1telutil1\c$\inetpub\wwwroot", "xxxxxxxxxx", "xx", "xxxxxx"))
        {
            files = Directory.GetFiles(@"\\ql1telutil1\c$\inetpub\wwwroot\backup96XX");

            foreach (string f in files)
            {
                sqlString = null;
                int myCounter = 0;

                List<Int32> myCountList = new List<Int32>();
                List<Int32> UniqueCallNumber = new List<Int32>();

                System.IO.StreamReader file = new System.IO.StreamReader(f);

                string[] array2 = f.Split("\\".ToCharArray());

                string myStat = array2[7].ToString().Substring(0, 5);

                log.Info("Getting history for extension: " + myStat);

                while ((line = file.ReadLine()) != null)
                {
                    if (line.Substring(0, 2) == "CL")
                    {
                        try
                        {
                            string[] strArray = line.Split("=".ToCharArray());
                            string key = strArray[0];
                            string str = strArray[1];

                            sqlString = sqlString + MinifyB(str.Trim()) + "','";

                            myCounter = myCounter + 1;

                            if(myCounter == 9)
                            {
                                try
                                {
                                    addSQL =
                                        "INSERT INTO tblStationCallHistory(CLSTATION, CLNAME, CLNUMBER, CLTYPE, CLDATE, CLTIME, CLDURATION, CLBRIDGEDFLAG, CLMISSEDCNTR, CLBCALBL) " +
                                        "VALUES('" + myStat + "','" + sqlString.Substring(0,sqlString.Length - 2) + ")";

                                    SqlCommand updateCMD = new SqlCommand(addSQL, con);

                                    try
                                    {
                                        updateCMD.ExecuteNonQuery();
                                    }
                                    catch (Exception ex)
                                    {
                                        log.Error("There was a problem executing the command. " + ex.Message);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    log.Error("There was a problem inserting the coverage path into the table. " + ex.Message);
                                }

                                sqlString = null;
                                myCounter = 0;
                            }
                        }
                        catch (Exception ex)
                        {
                            string myError = ex.Message.ToString();
                        }
                    }
                    counter++;
                }

                file.Close();
            }
        }
    }
}


Any hints, guidance etc to help me speed this up would be greatly appreciated! Thanks for any help!!

Dave
AnswerRe: Parse 17,000 text files and insert into database Pin
peterkmx15-Nov-16 7:01
professionalpeterkmx15-Nov-16 7:01 
AnswerRe: Parse 17,000 text files and insert into database Pin
Gerry Schmitz15-Nov-16 7:13
mveGerry Schmitz15-Nov-16 7:13 
GeneralRe: Parse 17,000 text files and insert into database Pin
davers15-Nov-16 8:07
davers15-Nov-16 8:07 
GeneralRe: Parse 17,000 text files and insert into database Pin
OriginalGriff15-Nov-16 8:17
mveOriginalGriff15-Nov-16 8:17 
GeneralRe: Parse 17,000 text files and insert into database Pin
Gerry Schmitz15-Nov-16 8:19
mveGerry Schmitz15-Nov-16 8:19 
GeneralRe: Parse 17,000 text files and insert into database Pin
peterkmx15-Nov-16 8:50
professionalpeterkmx15-Nov-16 8:50 
AnswerRe: Parse 17,000 text files and insert into database Pin
Philippe Mori15-Nov-16 8:11
Philippe Mori15-Nov-16 8:11 
AnswerRe: Parse 17,000 text files and insert into database Pin
Nathan Minier15-Nov-16 8:33
professionalNathan Minier15-Nov-16 8:33 
AnswerRe: Parse 17,000 text files and insert into database Pin
Mycroft Holmes15-Nov-16 11:54
professionalMycroft Holmes15-Nov-16 11:54 
AnswerRe: Parse 17,000 text files and insert into database Pin
Bernhard Hiller15-Nov-16 21:33
Bernhard Hiller15-Nov-16 21:33 
AnswerRe: Parse 17,000 text files and insert into database Pin
Jimmanuel23-Nov-16 10:48
Jimmanuel23-Nov-16 10:48 
QuestionDevelop Web Service REST Pin
Member 1283622014-Nov-16 3:37
Member 1283622014-Nov-16 3:37 
QuestionTextbox updation Pin
Avinash.Banda14-Nov-16 0:24
Avinash.Banda14-Nov-16 0:24 
AnswerRe: Textbox updation Pin
OriginalGriff14-Nov-16 0:31
mveOriginalGriff14-Nov-16 0:31 
GeneralRe: Textbox updation Pin
Avinash.Banda14-Nov-16 0:36
Avinash.Banda14-Nov-16 0:36 
GeneralRe: Textbox updation Pin
OriginalGriff14-Nov-16 0:39
mveOriginalGriff14-Nov-16 0:39 
GeneralRe: Textbox updation Pin
Avinash.Banda14-Nov-16 0:43
Avinash.Banda14-Nov-16 0:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.