Example #1
0
 public bool ProcessCommands()
 {
     Contact cContact = null;
        DateTime start = DateTime.Now;
        this.abManager = Manager.Connect( );
        if (this.cmd == Commands.listbooks)
        {
     if (verbose == true)
     {
      Console.WriteLine("Command::listbooks");
     }
     foreach(AddressBook tmpBook in abManager)
     {
      Console.WriteLine(tmpBook.Name);
      Console.WriteLine("");
     }
        }
        else
        if (this.cmd == Commands.createbook)
        {
     if (verbose == true)
     {
      Console.WriteLine("Command::createbook");
     }
     bool atLeastOne = false;
     foreach(string bookName in this.bookList)
     {
      if (verbose == true)
      {
       Console.WriteLine("Creating Address Book: " + bookName);
      }
      AddressBook cBook = abManager.CreateAddressBook(bookName);
      atLeastOne = true;
     }
     if (atLeastOne == false)
     {
      Console.WriteLine("invalid parameters");
     }
        }
        else
        if (this.cmd == Commands.deletebook)
        {
     if (displayCommandHelp == true)
     {
     }
     else
     {
      bool atLeastOne = false;
      foreach(string bookName in this.bookList)
      {
       if (verbose == true)
       {
        Console.WriteLine("Deleting Address Book: " + bookName);
       }
       try
       {
        AddressBook cBook = abManager.GetAddressBookByName(bookName);
        cBook.Delete();
        cBook.Commit();
        atLeastOne = true;
       }
       catch{}
      }
      if (atLeastOne == false)
      {
       Console.WriteLine("invalid parameters");
      }
     }
        }
        else
        if (this.cmd == Commands.importvcard)
        {
     if (OpenAddressBook())
     {
      if (this.fileList != null && this.fileList.Count > 0)
      {
       foreach(String filename in this.fileList)
       {
        if (verbose == true)
        {
     Console.WriteLine("Importing vCards(s) from file: " + filename);
        }
        cAddressBook.ImportVCard(filename);
       }
      }
      else
      {
       Console.WriteLine("invalid parameters");
      }
     }
        }
        else
        if (this.cmd == Commands.listcontacts)
        {
     if (verbose == true)
     {
      Console.WriteLine("Command::listcontacts");
     }
     if (OpenAddressBook())
     {
      foreach(Contact lContact in cAddressBook)
      {
       Console.WriteLine(lContact.UserName);
      }
     }
        }
        else
        if (this.cmd == Commands.createcontact)
        {
     if (OpenAddressBook())
     {
      foreach(string contactName in this.contactList)
      {
       if (verbose == true)
       {
        Console.WriteLine("Adding contact: " + contactName);
       }
       Contact tmpContact = new Contact();
       tmpContact.UserName = contactName;
       cAddressBook.AddContact(tmpContact);
       tmpContact.Commit();
      }
     }
        }
        else
        if (this.cmd == Commands.deletecontact)
        {
     if (OpenAddressBook())
     {
      foreach(string contactName in this.contactList)
      {
       if (verbose == true)
       {
        Console.WriteLine("Deleting contact: " + contactName);
       }
       IABList cList = cAddressBook.SearchUsername(contactName, Simias.Storage.SearchOp.Equal);
       foreach(Contact tmpContact in cList)
       {
        tmpContact.Delete();
       }
      }
     }
        }
        else
        if (this.cmd == Commands.listproperties)
        {
     if (OpenAddressBook())
     {
      if (this.contactList != null)
      {
       IABList cList =
        cAddressBook.SearchUsername(
     (string) this.contactList[0],
     Simias.Storage.SearchOp.Equal);
       foreach(Contact tmpContact in cList)
       {
        this.ListProperties(tmpContact);
        break;
       }
      }
     }
        }
        else
        if (this.cmd == Commands.deleteproperty)
        {
     if (verbose == true)
     {
      Console.WriteLine("Command::deleteproperty");
     }
     if (OpenAddressBook())
     {
      if (this.contactList != null)
      {
       IABList cList =
        cAddressBook.SearchUsername(
     (string) this.contactList[0],
     Simias.Storage.SearchOp.Equal);
       foreach(Contact tmpContact in cList)
       {
        if (verbose == true)
        {
     Console.WriteLine("Contact: " + tmpContact.UserName);
        }
        foreach(string propertyString in this.propertyList)
        {
     Regex o = new Regex(@"=");
     IEnumerator enumTokens = o.Split(propertyString).GetEnumerator();
     while(enumTokens.MoveNext())
     {
      string token = (string) enumTokens.Current;
      token.ToLower();
      if (verbose == true)
      {
       Console.WriteLine("Deleting property: " + token);
      }
      if (token == "organization")
      {
       tmpContact.Organization = null;
      }
      else
      if (token == "blog")
      {
       tmpContact.Blog = null;
      }
      else
      if (token == "url")
      {
       tmpContact.Url = null;
      }
      else
      if (token == "title")
      {
       tmpContact.Title = null;
      }
      else
      if (token == "role")
      {
       tmpContact.Role = null;
      }
      else
      if (token == "workforceid")
      {
       tmpContact.WorkForceID = null;
      }
      else
      if (token == "birthday")
      {
       tmpContact.Birthday = null;
      }
      else
      if (token == "email")
      {
       if (enumTokens.MoveNext())
       {
        IABList eAddresses = cContact.GetEmailAddresses();
        foreach (Email tmpMail in eAddresses)
        {
     if (tmpMail.Address == (string) enumTokens.Current)
     {
      if (verbose == true)
      {
       Console.WriteLine("   Deleting e-mail address: " + tmpMail.Address);
      }
      tmpMail.Delete();
      break;
     }
        }
       }
      }
      else
      if (token == "managerid")
      {
       tmpContact.ManagerID = null;
      }
      else
      if (token == "note")
      {
       tmpContact.Note = null;
      }
      else
      if (token == "nickname")
      {
       tmpContact.Nickname = null;
      }
     }
        }
        tmpContact.Commit();
        break;
       }
      }
     }
        }
        else
        if (this.cmd == Commands.addproperty)
        {
     if (verbose == true)
     {
      Console.WriteLine("Command::addproperty");
     }
     if (this.displayCommandHelp == true)
     {
      this.DisplayAddPropertyUsage();
     }
     else
     if (OpenAddressBook())
     {
      if (this.contactList != null)
      {
       IABList cList =
        cAddressBook.SearchUsername(
     (string) this.contactList[0],
     Simias.Storage.SearchOp.Equal);
       foreach(Contact tmpContact in cList)
       {
        if (verbose == true)
        {
     Console.WriteLine("Contact: " + tmpContact.UserName);
        }
        this.AddProperties(tmpContact);
        break;
       }
      }
     }
        }
        else
        if (this.cmd == Commands.addnameproperty)
        {
     if (verbose == true)
     {
      Console.WriteLine("Command::addnameproperty");
     }
     if (this.displayCommandHelp == true)
     {
      this.DisplayAddNamePropertyUsage();
     }
     else
     if (OpenAddressBook())
     {
      if (this.contactList != null)
      {
       IABList cList =
        cAddressBook.SearchUsername(
     (string) this.contactList[0],
     Simias.Storage.SearchOp.Equal);
       foreach(Contact tmpContact in cList)
       {
        if (verbose == true)
        {
     Console.WriteLine("Contact: " + tmpContact.UserName);
        }
        this.AddNameProperty(tmpContact);
        break;
       }
      }
     }
        }
        else
        if (this.cmd == Commands.addaddressproperty)
        {
     if (verbose == true)
     {
      Console.WriteLine("Command::addaddressproperty");
     }
     if (this.displayCommandHelp == true)
     {
      this.DisplayAddAddressPropertyUsage();
     }
     else
     if (OpenAddressBook())
     {
      if (this.contactList != null)
      {
       IABList cList =
        cAddressBook.SearchUsername(
     (string) this.contactList[0],
     Simias.Storage.SearchOp.Equal);
       foreach(Contact tmpContact in cList)
       {
        if (verbose == true)
        {
     Console.WriteLine("Contact: " + tmpContact.UserName);
        }
        this.AddAddressProperty(tmpContact);
        break;
       }
      }
     }
        }
        else
        if (this.cmd == Commands.exportvcard)
        {
     if (verbose == true)
     {
      Console.WriteLine("Command::exportvcard");
     }
     if (OpenAddressBook())
     {
      if (this.contactList != null)
      {
       string path = "";
       if (this.fileList != null)
       {
        path = (string) this.fileList[0];
        if (path[path.Length - 1] != Path.DirectorySeparatorChar)
        {
     path += Path.DirectorySeparatorChar;
        }
        if (verbose == true)
        {
     Console.WriteLine("Creating vCards at: " + path);
        }
       }
       foreach(string contactName in this.contactList)
       {
        IABList cList =
     cAddressBook.SearchUsername(
      contactName,
      Simias.Storage.SearchOp.Equal);
        foreach(Contact tmpContact in cList)
        {
     string vCardFileName = path;
     if (tmpContact.FN != "")
     {
      vCardFileName += tmpContact.FN;
      vCardFileName += ".vcf";
     }
     else
     {
      vCardFileName = tmpContact.ID + ".vcf";
     }
     if (verbose == true)
     {
      Console.WriteLine("Exporting vCard: " + vCardFileName);
     }
     tmpContact.ExportVCard(vCardFileName);
     break;
        }
       }
      }
     }
        }
        if (timeIt == true)
        {
     DateTime stop = DateTime.Now;
     TimeSpan ts = stop - start;
     Console.WriteLine("");
     Console.WriteLine("Command(s) completed in: ");
     Console.WriteLine("   {0} seconds", ts.TotalSeconds);
     Console.WriteLine("   {0} milliseconds", ts.TotalMilliseconds);
        }
        return(true);
 }