static void Main(string[] args) { try { GoogleContacts gc = new GoogleContacts("id", "pass"); // gc.GetContacts(); //List<ConciseContact> ccList = gc.GetContactsWithBirthdaysToday(); //ContactCleaner.CleanseContacts(ccList); Way2SmsAPI w2sAPI = new Way2SmsAPI("9999999999", "ffsf"); // For testing //w2sAPI.SendSms("9920999713", "Happy birthday !! " + "friend" + " " + "From: Sender"); bool Addr = w2sAPI.GetAddressBook(); //"9999999999" //foreach (ConciseContact cc in ccList) //{ // if(cc.IsValidPhone) // w2sAPI.SendSms(cc.PhoneNumber, "Happy birthday !! " + cc.AddressingName + " " + "From: Munish Goyal"); //} } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void Form1_Load(object sender, EventArgs e) { lvContacts.BeginUpdate(); populatelvContacts(); lvContacts.EndUpdate(); c = new GoogleContacts(); c.Connect(); if (c.Messages.Count > 0) { MessageBox.Show(c.Messages.ToString()); } }
public static void SendWishes(UserData ud, GreetingsData gd) { GoogleContacts gc = new GoogleContacts(ud._goog_id, ud._goog_pwd); // gc.GetContacts(); List <ConciseContact> ccList = gc.GetContactsWithBirthdaysToday(); ContactCleaner.CleanseContacts(ccList); Logger.LogIt("Fetched List of birthdays today. Count = " + ccList.Count); Way2SmsAPI w2sAPI = new Way2SmsAPI(ud._w2s_id, ud._w2s_pwd); // For testing //app.SendSms("9999999999", "Dear ....." + "Happy birthday !! " + " " + "~~ From: Munish Goyal ~~"); foreach (ConciseContact cc in ccList) { if (cc.IsValidPhone) { ContactData cd = null; if (!gd.WishTable.TryGetValue(cc.PhoneNumber, out cd)) { cd = new ContactData(cc); gd.WishTable.Add(cc.PhoneNumber, cd); gd.TotalCount++; } if (!cd.isWished) { if (w2sAPI.SendSms(cc.PhoneNumber, ud._msg + cc.AddressingName + " " + ud._signature)) { Logger.LogIt("Wished " + cc.AddressingName + " at " + cc.PhoneNumber); cd.isWished = true; gd.DoneCount++; } } } } }
public void FullSync(Config.Direction dir) { MutexManager.StartingFullSync(); try { try { if (dir == Config.Direction.dirToOutlook) { SetLastGoogleFetch(DateTime.Now); } if (StartSynching != null) { StartSynching(this); } List <ContactItem> OutlookContacts; List <Contact> GoogleContacts; logger.Info("Obtaining Outlook contacts..."); OutlookContacts = outlookAdapter.Contacts; logger.Info("Obtaining Google Contacts..."); GoogleContacts = googleAdapter.Contacts; EmailComparer comparer = new EmailComparer(); int i = 0; int total = OutlookContacts.Count() + GoogleContacts.Count(); foreach (ContactItem item in OutlookContacts) { try { try { if (Thread.CurrentThread.ThreadState == ThreadState.AbortRequested) { break; } i++; var qryFindGoogleContact = GoogleContacts.Where(c => c.Title == item.FullName || c.Emails.Contains(new EMail(item.Email1Address), comparer) || c.Emails.Contains(new EMail(item.Email2Address), comparer) || c.Emails.Contains(new EMail(item.Email3Address), comparer)); if (qryFindGoogleContact.Count() > 0) { if (dir == Config.Direction.dirToOutlook) { logger.Info(String.Format("{0}/{1} Updating Outlook contact: " + OutlookAdapter.ContactItemDisplay(item), i, total)); Contact gContact = qryFindGoogleContact.First(); logger.Info("Updating outlook contact"); SyncContact(gContact, item, dir); } else { logger.Info(String.Format("{0}/{1} Processing...", i, total)); } } else { logger.Info(String.Format("{0}/{1} Creating Google contact for " + OutlookAdapter.ContactItemDisplay(item), i, total)); // MutexManager.AddToBlockedContacts(item); CreateGoogleContact(item); } } finally { if (OutlookSynched != null) { OutlookSynched(this, item, i, OutlookContacts.Count()); } } } catch (System.Exception ex) { if (ex is ThreadAbortException) { break; } } } foreach (Contact item in GoogleContacts) { try { try { if (Thread.CurrentThread.ThreadState == ThreadState.AbortRequested) { break; } i++; var qryFindOutlookContact = OutlookContacts.Where(c => c.FullName == item.Title || item.Emails.Contains(new EMail(c.Email1Address), comparer) || item.Emails.Contains(new EMail(c.Email2Address), comparer) || item.Emails.Contains(new EMail(c.Email3Address), comparer)); if (qryFindOutlookContact.Count() > 0) { if (dir == Config.Direction.dirToGoogle) { logger.Info(String.Format("{0}/{1} Updating Google contact: " + GoogleAdapter.ContactDisplay(item), i, total)); ContactItem oContact = qryFindOutlookContact.First(); SyncContact(item, oContact, dir); } else { logger.Info(String.Format("{0}/{1} Processing...", i, total)); } } else { logger.Info(String.Format("{0}/{1} Creating Outlook contact for " + GoogleAdapter.ContactDisplay(item), i, total)); CreateOutlookContact(item); } } finally { if (GoogleSynched != null) { GoogleSynched(this, item, i, GoogleContacts.Count()); } } } catch (System.Exception ex) { if (ex is ThreadAbortException) { break; } } } if (EndSynching != null) { EndSynching(this); } } catch (System.Exception ex) { if ((EndSynching != null)) { EndSynching(this); } else if (!(ex is ThreadAbortException) & (Error != null)) { Error(this, ex); } } } finally { if (dir == Config.Direction.dirToGoogle) { SetLastGoogleFetch(DateTime.Now); } MutexManager.EndingFullSync(); } }
public static void SendWishes1(object o) { string todayDate = string.Empty; try { // First check if todays wishes are done. todayDate = DateTime.Now.Date.ToShortDateString().Replace('/', '-'); string todayFileName = Path.Combine(AppConfig.GreetingsDir, todayDate); Logger.LogIt("Started SendWishes for " + todayDate); GreetingsData gd; if (!File.Exists(todayFileName)) { gd = new GreetingsData(); } else { using (FileStream stream = File.Open(todayFileName, FileMode.Open)) { BinaryFormatter bformatter = new BinaryFormatter(); gd = (GreetingsData)bformatter.Deserialize(stream); } } // If some wishes are pending then only do it , else return for the day UserData ud; //Open the file written above and read values from it. // User data using (FileStream stream = File.Open(AppConfig.UdStoreFile, FileMode.Open)) { BinaryFormatter bformatter = new BinaryFormatter(); ud = (UserData)bformatter.Deserialize(stream); } GoogleContacts gc = new GoogleContacts(ud._goog_id, ud._goog_pwd); if (!gd.IsAllDone || gc.AreContactsModifiedToday()) { // Wishes SendWishes(ud, gd); // Check gd if (gd.TotalCount == gd.DoneCount) { gd.IsAllDone = true; } // Now write back the gd using (FileStream ws = File.Open(todayFileName, FileMode.Create)) { BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Serialize(ws, gd); } } } catch (Exception ex) { Logger.LogException(ex, ex.Message); } Logger.LogIt("Ended SendWishes for " + todayDate); }