public void MakeAppointment(IContactFacet contact, IDateTimeFacet at, IDurationFacet duration, ITextFacet subject) { if (contact == null || at == null) { return; } var store = ExtensionHooks.GetKeyValueStore(); var username = store.GetString("username"); var password = store.GetProtectedString("password"); if (username == null || password == null) { throw new RequiresConfigurationException(typeof(Configurators.CredentialsConfigurator), typeof(CalendarFacet)); } var cal = new CalendarService("Commando"); cal.setUserCredentials(username, password); var finalDuration = duration != null ? duration.Duration : TimeSpan.FromHours(1); var e = new EventEntry(subject == null ? "Appointment" : subject.Text); e.Times.Add(new When(at.Value, at.Value.Add(finalDuration))); var who = new Who(); who.Email = contact.Email; who.Rel = Who.RelType.EVENT_ATTENDEE; e.Participants.Add(who); try { cal.Insert(new Uri("https://www.google.com/calendar/feeds/default/private/full"), e); } catch (CaptchaRequiredException) { throw new InvalidOperationException( "Google has locked the account. Please visit http://www.google.com/accounts/DisplayUnlockCaptcha to unlock it."); } catch (InvalidCredentialsException) { throw new RequiresConfigurationException(typeof(Configurators.CredentialsConfigurator), typeof(CalendarFacet), "The username and/or password are incorrect."); } catch (ClientFeedException ex) { throw new InvalidOperationException(string.Format("Could not add the appointment: {0}", ex.Message)); } catch (Exception ex) { throw new InvalidOperationException("Could not add the appointment.", ex); } }
public virtual bool IsConfigured() { var store = ExtensionHooks.GetKeyValueStore(); foreach (var property in _metadata.Value.Properties) { if (store[property.StoreKey] == null) { return(false); } } return(true); }
protected LoaderExtension(string path) { if (path == null) { throw new ArgumentNullException("path"); } Path = path; _fileDateTime = new FileInfo(path).LastWriteTime; _fileMD5 = GetFileMD5(Path); _hooks = new ExtensionHooks(this); _items = new List <LoaderExtensionItem>(); _missingDependencies = new List <AssemblyName>(); _missingDependenciesColl = new ReadOnlyCollection <AssemblyName>(_missingDependencies); }
protected virtual void OnSaveToStore() { var store = ExtensionHooks.GetKeyValueStore(); foreach (var property in _metadata.Value.Properties) { if (property.IsPassword) { store.SetProtectedString(property.StoreKey, (string)GetValue(property.PropertyName)); } else { store[property.StoreKey] = GetValue(property.PropertyName); } } }
protected virtual void OnLoadFromStore() { var store = ExtensionHooks.GetKeyValueStore(); foreach (var property in _metadata.Value.Properties) { if (property.IsPassword) { SetValue(property.PropertyName, store.GetProtectedString(property.StoreKey)); } else { SetValue(property.PropertyName, store[property.StoreKey]); } } }
protected override IEnumerable <FacetMoniker> EnumerateIndexImpl() { var store = ExtensionHooks.GetKeyValueStore(); var username = store.GetString("username"); var password = store.GetProtectedString("password"); if (username == null || password == null) { throw new RequiresConfigurationException(typeof(Configurators.CredentialsConfigurator), typeof(GoogleContactFactory)); } var cs = new ContactsService("Commando"); cs.setUserCredentials(username, password); ContactsFeed feed; try { feed = cs.Query(new ContactsQuery(ContactsQuery.CreateContactsUri("default"))); } catch (CaptchaRequiredException) { throw new InvalidOperationException( "Google has locked the account. Please visit http://www.google.com/accounts/DisplayUnlockCaptcha to unlock it."); } catch (InvalidCredentialsException) { throw new RequiresConfigurationException(typeof(CredentialsConfigurator), typeof(CalendarFacet), "The username and/or password are incorrect."); } catch (Exception) { yield break; } foreach (var entry in feed.Entries.Cast <ContactEntry>().ToArray()) { if (entry.Name == null && entry.PrimaryEmail == null) { continue; } var ci = new ContactInfo(); if (entry.Name != null) { ci.FirstName = entry.Name.GivenName; ci.LastName = entry.Name.FamilyName; ci.DisplayName = entry.Name.FullName; } ci.Email = entry.PrimaryEmail == null ? null : entry.PrimaryEmail.Address; if (ci.FirstName == null && ci.LastName == null && ci.DisplayName != null) { var split = ci.DisplayName.Split(' '); if (split.Length > 0) { ci.FirstName = split[0]; } if (split.Length > 1) { ci.LastName = split[1]; } } if (ci.DisplayName == null) { if (ci.FirstName != null) { if (ci.LastName != null) { ci.DisplayName = ci.FirstName + " " + ci.LastName; } else { ci.DisplayName = ci.FirstName; } } else if (ci.LastName != null) { ci.DisplayName = ci.LastName; } else { ci.DisplayName = ci.Email; } } if (ci.Email != null && ci.DisplayName != ci.Email) { ci.DisplayName = ci.DisplayName + " (" + ci.Email + ")"; } yield return(new FacetMoniker(GetType(), typeof(ContactFacet), ci.ToXml(), ci.DisplayName, sourceName: "Google Contacts")); } }