Exemplo n.º 1
0
        private void Vcard2CSV()
        {
            try
            {
                string[] fileNames = new string[] { };
                if (ckBxFileMode.Checked)
                {
                    fileNames = Directory.GetFiles(inputFolder.SelectedPath, "*.vcf", SearchOption.AllDirectories);
                }

                if (fileNames.Length > 0)
                {
                    long fileCount = 0;
                    Data2Save = new StringBuilder();
                    Data2Save.AppendLine("\"FirstName\"," + "\"LastName\"," + "\"MiddleName\"," + "\"Phone1\"," + "\"Phone2\"," + "\"Phone3\"," + "\"Phone4\"," + "\"Phone5\"," + "\"Phone6\"," + "\"Email1\"," + "\"Email2\",");

                    foreach (string fileName in fileNames)
                    {
                        fileCount++;
                        LogFile.AppendLine(DateTime.Now.ToString() + " = Now Procesing: " + fileName);

                        threadSafeTextBoxUpdate(tbxPreview, fileName + "\n", true);
                        threadSafeLableUpdate(lblFileCounter, "Processing File: " + fileCount.ToString() + " of " + fileNames.Length.ToString());

                        Boolean ckBxVal = threadSafeCheckBoxRead(ckbxFilter);
                        String  tbxVal  = threadSafeTextBoxRead(tbxFilter);

                        VcardProcesssor VcardObj;

                        if (!ckBxVal)
                        {
                            VcardObj = new VcardProcesssor(fileName, ErrorFileNames);
                        }
                        else
                        {
                            if (tbxVal == "")
                            {
                                //  tbxFilter.BackColor = Color.Red;
                                throw new Exception("Please Provide Filter -ve Filter Text");
                            }
                            else
                            {
                                //  tbxFilter.BackColor = Color.White;
                                VcardObj = new VcardProcesssor(fileName, ErrorFileNames, tbxFilter.Text);
                            }
                        }


                        Data2Save = Data2Save.Append(VcardObj.GenerateCSVFile(false));
                    }
                }

                threadTriger = 1;
                threadStatus = threadExitStatus.Success;
                threadSafeEnableControl(btnGo, true);
            }
            catch (Exception ex)
            {
                threadStatus = threadExitStatus.Error;
                MessageBox.Show("File Parse Error: " + ex.Message.ToString(), "Vcard2Csv");

                threadTriger = 1;
                threadSafeEnableControl(btnGo, true);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// / File processing Methods Begin Herre.....
        /// </summary>
        private void iphone2NormalVcard()
        {
            try
            {
                string[] fileNames = new string[] { };
                if (ckBxFileMode.Checked)
                {
                    fileNames = Directory.GetFiles(inputFolder.SelectedPath, "*.vcf", SearchOption.AllDirectories);
                }

                if (fileNames.Length > 0)
                {
                    //outputFolder = new FolderBrowserDialog();
                    //outputFolder.SelectedPath=inputFolder.SelectedPath;
                    //outputFolder.ShowDialog();

                    long fileCount = 0;
                    Data2Save = new StringBuilder();

                    foreach (string fileName in fileNames)
                    {
                        fileCount++;

                        //tbxPreview.AppendText(fileName + "\n");
                        //lblFileCounter.Text = "Processing File: " + fileCount.ToString() + " of " + fileNames.Length.ToString();
                        //lblFileCounter.Update();

                        threadSafeTextBoxUpdate(tbxPreview, fileName + "\n", true);
                        threadSafeLableUpdate(lblFileCounter, "Processing File: " + fileCount.ToString() + " of " + fileNames.Length.ToString());

                        FileStream   inputFileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                        StreamReader sReader         = new StreamReader(inputFileStream);
                        string       readLIne        = sReader.ReadLine();

                        while (readLIne != null)
                        {
                            //lbLinesCounter.Text = "Now Processing Line: " + readLIne;
                            //lbLinesCounter.Update();

                            threadSafeLableUpdate(lbLinesCounter, "Now Processing Line: " + readLIne);
                            string LineWithoutSpaces = RemoveUnwantedCharacters(readLIne);

                            if (LineWithoutSpaces.Length > 1)
                            {
                                if (LineWithoutSpaces.Substring(0, 2) == "N:")
                                {
                                    Data2Save.AppendLine(LineWithoutSpaces);
                                }
                            }

                            if (LineWithoutSpaces.Length > 2)
                            {
                                if (LineWithoutSpaces.Substring(0, 3).ToUpper() == "FN:")
                                {
                                    Data2Save.AppendLine(LineWithoutSpaces);
                                }
                            }


                            if (LineWithoutSpaces.Length > 7)
                            {
                                if (LineWithoutSpaces.Substring(0, 8).ToUpper() == "VERSION:")
                                {
                                    Data2Save.AppendLine("VERSION:2.1");
                                }
                            }


                            if (LineWithoutSpaces.Length > 5)
                            {
                                if (LineWithoutSpaces.Substring(0, 6).ToUpper() == "BEGIN:")
                                {
                                    Data2Save.AppendLine(LineWithoutSpaces);
                                }
                            }

                            if (LineWithoutSpaces.Length > 3)
                            {
                                if (LineWithoutSpaces.Substring(0, 4).ToUpper() == "TEL;")
                                {
                                    string[] splitLine = LineWithoutSpaces.Split(new char[] { ':' });
                                    if (splitLine.Length != 2)
                                    {
                                        Data2Save.AppendLine("TEL;CELL:0000000000");
                                    }
                                    else
                                    {
                                        Data2Save.AppendLine("TEL;CELL:" + splitLine[1]);
                                    }
                                }
                            }

                            if (LineWithoutSpaces.Length > 5)
                            {
                                if (LineWithoutSpaces.Substring(0, 6).ToUpper() == "EMAIL;")
                                {
                                    string[] splitLine = LineWithoutSpaces.Split(new char[] { ':' });
                                    if (splitLine.Length != 2)
                                    {
                                        Data2Save.AppendLine("EMAIL;WORK: ");
                                    }
                                    else
                                    {
                                        Data2Save.AppendLine("EMAIL;WORK:" + splitLine[1]);
                                    }
                                }
                            }


                            if (LineWithoutSpaces.Length > 3)
                            {
                                if (LineWithoutSpaces.Substring(0, 4).ToUpper() == "ORG:")
                                {
                                    string[] splitLine = LineWithoutSpaces.Split(new char[] { ':' });
                                    if (splitLine.Length != 2)
                                    {
                                        Data2Save.AppendLine("ORG: ");
                                    }
                                    else
                                    {
                                        Data2Save.AppendLine("ORG:" + splitLine[1]);
                                    }
                                }
                            }

                            if (LineWithoutSpaces.Length > 5)
                            {
                                if (LineWithoutSpaces.Substring(0, 6).ToUpper() == "TITLE:")
                                {
                                    string[] splitLine = LineWithoutSpaces.Split(new char[] { ':' });
                                    if (splitLine.Length != 2)
                                    {
                                        Data2Save.AppendLine("TITLE: ");
                                    }
                                    else
                                    {
                                        Data2Save.AppendLine("TITLE:" + splitLine[1]);
                                    }
                                }
                            }

                            if (LineWithoutSpaces.Length > 3)
                            {
                                if (LineWithoutSpaces.Substring(0, 4).ToUpper() == "END:")
                                {
                                    Data2Save.AppendLine(LineWithoutSpaces);
                                }
                            }

                            readLIne = sReader.ReadLine();
                        }

                        inputFileStream.Close();
                    }
                }

                threadTriger = 1;
                threadStatus = threadExitStatus.Success;
                threadSafeEnableControl(btnGo, true);
            }
            catch (Exception ex)
            {
                threadStatus = threadExitStatus.Error;
                MessageBox.Show("File Parse Error: " + ex.Message);

                threadTriger = 1;
                threadSafeEnableControl(btnGo, true);
            }
        }