Esempio n. 1
0
        public StringBuilder GenerateCSVFile(Boolean appendHeader)
        {
            StringBuilder sb2Return = new StringBuilder();

            if (appendHeader)
            {
                sb2Return.AppendLine("\"FirstName\"," + "\"LastName\"," + "\"MiddleName\"," + "\"Phone1\"," + "\"Phone2\"," + "\"Phone3\"," + "\"Phone4\"," + "\"Phone5\"," + "\"Phone6\"," + "\"Email1\"," + "\"Email2\",");
            }


            foreach (string contactString in listOfRawContactStrings)
            {
                contactStrcture newContactItem = buildContacts(contactString);
                if (newContactItem.Names.Count == 0 | newContactItem.Phones.Count == 0)
                {
                }
                else
                {
                    string contactRowString = "";

                    for (int i = 0; i < 3; i++)
                    {
                        //errorString = newContactItem.Names.Count.ToString();
                        //errorString2 = i.ToString();
                        string string2append = "";
                        if (i < newContactItem.Names.Count)
                        {
                            string2append = newContactItem.Names[i].ToString();
                        }
                        contactRowString = contactRowString + "\"" + string2append + "\",";
                    }

                    for (int i = 0; i < 6; i++)
                    {
                        string string2append = "";
                        if (i < newContactItem.Phones.Count)
                        {
                            string2append = newContactItem.Phones[i].ToString();
                        }
                        contactRowString = contactRowString + "\"" + string2append + "\",";
                    }

                    for (int i = 0; i < 2; i++)
                    {
                        string string2append = "";
                        if (i < newContactItem.Emails.Count)
                        {
                            string2append = newContactItem.Emails[i].ToString();
                        }
                        contactRowString = contactRowString + "\"" + string2append + "\",";
                    }

                    sb2Return.AppendLine(contactRowString);
                }
            }

            return(sb2Return);
        }
Esempio n. 2
0
        private contactStrcture buildContacts(string TextWithConatcts)
        {
            contactStrcture contactItem = new contactStrcture();

            contactItem.Company  = "";
            contactItem.Emails   = new List <string> {
            };
            contactItem.Phones   = new List <string> {
            };
            contactItem.Names    = new List <string> {
            };
            contactItem.FullName = "";

            string[] arrayOfLines = TextWithConatcts.Split(new char[] { '\n' });

            if (arrayOfLines.Length > 2)
            {
                foreach (string line in arrayOfLines)
                {
                    //this.threadSafeLableUpdate(this.lbLinesCounter, "Now Processing Line: " + readLIne);

                    string LineWithoutSpaces = RemoveUnwantedCharacters(line);


                    if (LineWithoutSpaces.Length > 2)
                    {
                        if (LineWithoutSpaces.Substring(0, 3).ToUpper() == "FN:")
                        {
                            string[] splitName = line.Split(new char[] { ':' });
                            if (splitName.Length > 1)
                            {
                                contactItem.FullName = splitName[1];
                                contactItem.Names.Add(splitName[1]);
                            }
                        }
                    }



                    if (LineWithoutSpaces.Length > 3)
                    {
                        if (LineWithoutSpaces.Substring(0, 4).ToUpper() == "TEL;")
                        {
                            string[] splitLine = LineWithoutSpaces.Split(new char[] { ':' });
                            if (splitLine.Length == 2)
                            {
                                contactItem.Phones.Add(splitLine[1]);
                            }
                        }
                    }

                    if (LineWithoutSpaces.Length > 5)
                    {
                        if (LineWithoutSpaces.Substring(0, 6).ToUpper() == "EMAIL;")
                        {
                            string[] splitLine = LineWithoutSpaces.Split(new char[] { ':' });
                            if (splitLine.Length == 2)
                            {
                                contactItem.Emails.Add(splitLine[1]);
                            }
                        }
                    }


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


            return(contactItem);
        }