// Factory method to create a new item processor based on the item type public static ItemProcessor Create(User user, UserStorageContext storage, Guid itemTypeID) { if (itemTypeID == SystemItemTypes.Contact) return new ContactProcessor(user, storage); if (itemTypeID == SystemItemTypes.Step) return new StepProcessor(user, storage); return null; }
public static bool GetUserInfo(User user, UserStorageContext storage) { // set up the FB API context FBGraphAPI fbApi = new FBGraphAPI(); UserCredential cred = user.GetCredential(UserCredential.FacebookConsent); if (cred != null && cred.AccessToken != null) { fbApi.AccessToken = cred.AccessToken; } else { TraceLog.TraceError(TRACE_NO_FB_TOKEN); return false; } // store user information from Facebook in UserProfile UserProfile userProfile = storage.ClientFolder.GetUserProfile(user); if (userProfile == null) { TraceLog.TraceError("Could not access UserProfile to import Facebook information into."); return false; } try { // import information about the current user // using foreach because the Query API returns an IEnumerable, but there is only one result foreach (var userInfo in fbApi.Query("me", FBQueries.BasicInformation)) { // import FacebookID userProfile.FacebookID = (string)userInfo[FBQueryResult.ID]; // import name if not already set if (userProfile.FirstName == null) userProfile.FirstName = (string)userInfo["first_name"]; if (userProfile.LastName == null) userProfile.LastName = (string)userInfo["last_name"]; // import picture if not already set if (userProfile.Picture == null) userProfile.Picture = String.Format("https://graph.facebook.com/{0}/picture", userProfile.FacebookID); // import birthday if not already set if (userProfile.Birthday == null) userProfile.Birthday = (string)userInfo[FBQueryResult.Birthday]; // import gender if not already set if (userProfile.Gender == null) userProfile.Gender = (string)userInfo[FBQueryResult.Gender]; // import geolocation if not already set if (userProfile.GeoLocation == null) userProfile.GeoLocation = (string)((FBQueryResult)userInfo[FBQueryResult.Location])[FBQueryResult.Name]; TraceLog.TraceInfo("Imported Facebook information into UserProfile"); } } catch (Exception ex) { TraceLog.TraceException("Facebook query for basic User information failed", ex); return false; } return true; }
public GoogleClient(User user, UserStorageContext storage) { // for using existing access token with renewal this.user = user; this.storage = storage; if (user.UserCredentials == null || user.UserCredentials.Count == 0) { // ensure UserCredentials are present this.user = storage.GetUser(user.ID, true); } UserCredential googleConsent = this.user.GetCredential(UserCredential.GoogleConsent); if (googleConsent != null) { this.googleAuthenticator = CreateGoogleAuthenticator(GetAccessToken); } }
public static Item InstallActivity(UserStorageContext userContext, SuggestionsStorageContext suggestionsContext, User user, Folder category, Guid? subCategory, GalleryActivity galleryActivity) { // get activity from context var activity = suggestionsContext.GalleryActivities.FirstOrDefault(ga => ga.ID == galleryActivity.ID); if (activity == null) return null; if (category == null) { var galleryCategory = suggestionsContext.GalleryCategories.FirstOrDefault(gc => gc.ID == activity.CategoryID); if (galleryCategory == null) return null; category = CreateCategory(userContext, user, galleryCategory.Name); } return InstallActivity(userContext, suggestionsContext, category, subCategory, activity); }
public static bool DeleteItemReferences(User currentUser, UserStorageContext storageContext, Item item) { string itemID = item.ID.ToString(); var itemRefs = storageContext.Items.Include("FieldValues"). Where(i => i.UserID == currentUser.ID && i.ItemTypeID == SystemItemTypes.Reference && i.FieldValues.Any(fv => fv.FieldName == FieldNames.EntityRef && fv.Value == itemID)).ToList(); bool commit = false; foreach (var itemRef in itemRefs) { storageContext.Items.Remove(itemRef); commit = true; } // commit deletion of References if (commit) { storageContext.SaveChanges(); } return commit; }
public static List<User> DefaultUsers() { List<User> users = new List<User>(); User user; // create the Task users.Add(user = new User() { ID = SystemUsers.System, Name = "System", Email = "*****@*****.**" }); #if !CLIENT user.CreateDate = new DateTime(2012, 1, 1); #endif users.Add(user = new User() { ID = SystemUsers.User, Name = "User", Email = "*****@*****.**" }); #if !CLIENT user.CreateDate = new DateTime(2012, 1, 1); #endif return users; }
// get or create a list for an ItemType in the UserFolder for given user public Item GetListForItemType(User user, Guid itemTypeID) { Folder userFolder = Get(user); if (userFolder != null) { return storage.GetOrCreateListByValue(user, userFolder, itemTypeID.ToString(), SystemItemTypes.Names[itemTypeID]); } return null; }
// get or create the EntityRefs list in the UserFolder for given user public Item GetEntityRefsList(User user) { Folder userFolder = Get(user); if (userFolder != null) { return storage.GetOrCreateList(user, userFolder, SystemEntities.EntityRefs); } return null; }
// get or create an reference to the given entity in the UserFolder EntityRefs list public Item GetEntityRef(User user, ServerEntity entity) { Item entityRefsList = GetEntityRefsList(user); if (entityRefsList == null) return null; var entityID = entity.ID.ToString(); try { // get existing reference to given entity if (storage.Items.Include("FieldValues").Any(i => i.UserID == user.ID && i.FolderID == entityRefsList.FolderID && i.ParentID == entityRefsList.ID && i.FieldValues.Any(fv => fv.FieldName == FieldNames.EntityRef && fv.Value == entityID))) { return storage.Items.Include("FieldValues").Single(i => i.UserID == user.ID && i.FolderID == entityRefsList.FolderID && i.ParentID == entityRefsList.ID && i.FieldValues.Any(fv => fv.FieldName == FieldNames.EntityRef && fv.Value == entityID)); } else { // create new reference to given entity DateTime now = DateTime.UtcNow; var entityRefItemID = Guid.NewGuid(); var entityRefItem = new Item() { ID = entityRefItemID, Name = entity.Name, FolderID = entityRefsList.FolderID, UserID = user.ID, ItemTypeID = SystemItemTypes.Reference, ParentID = entityRefsList.ID, Created = now, LastModified = now, FieldValues = new List<FieldValue>() { new FieldValue() { ItemID = entityRefItemID, FieldName = FieldNames.EntityRef, Value = entityID }, new FieldValue() { ItemID = entityRefItemID, FieldName = FieldNames.EntityType, Value = entity.GetType().Name }, } }; storage.Items.Add(entityRefItem); storage.SaveChanges(); TraceLog.TraceInfo(String.Format("Created entity ref item {0} for user {1}", entity.Name, user.Name)); return entityRefItem; } } catch (Exception ex) { TraceLog.TraceException(String.Format("Created entity ref item {0} for user {1}", entity.Name, user.Name), ex); return null; } }
public static List<Folder> DefaultFolders(User currentUser) { List<Folder> folders = new List<Folder>(); Dictionary<Guid, object> defaultLists = new Dictionary<Guid, object>(); DateTime now = DateTime.Now; Item item; Folder folder; Guid folderID = Guid.NewGuid(); #if !CLIENT FolderUser folderUser; folderUser = new FolderUser() { ID = Guid.NewGuid(), FolderID = folderID, UserID = currentUser.ID, PermissionID = Permissions.Full }; #endif // create Inbox folder folder = new Folder() { ID = folderID, SortOrder = 1000, Name = UserEntities.Inbox, ItemTypeID = SystemItemTypes.Category, #if CLIENT Items = new ObservableCollection<Item>(), #else Items = new List<Item>(), UserID = currentUser.ID, FolderUsers = new List<FolderUser>() { folderUser } #endif }; folders.Add(folder); // make this defaultList for Activities defaultLists.Add(SystemItemTypes.Activity, folder); folderID = Guid.NewGuid(); #if !CLIENT folderUser = new FolderUser() { ID = Guid.NewGuid(), FolderID = folderID, UserID = currentUser.ID, PermissionID = Permissions.Full }; #endif // create Personal folder folder = new Folder() { ID = folderID, SortOrder = 2000, Name = UserEntities.Personal, ItemTypeID = SystemItemTypes.Category, #if CLIENT Items = new ObservableCollection<Item>(), #else Items = new List<Item>(), UserID = currentUser.ID, FolderUsers = new List<FolderUser>() { folderUser } #endif }; folders.Add(folder); folderID = Guid.NewGuid(); #if !CLIENT folderUser = new FolderUser() { ID = Guid.NewGuid(), FolderID = folderID, UserID = currentUser.ID, PermissionID = Permissions.Full }; #endif // create Auto folder folder = new Folder() { ID = folderID, SortOrder = 3000, Name = UserEntities.Auto, ItemTypeID = SystemItemTypes.Category, #if CLIENT Items = new ObservableCollection<Item>(), #else Items = new List<Item>(), UserID = currentUser.ID, FolderUsers = new List<FolderUser>() { folderUser } #endif }; folders.Add(folder); folderID = Guid.NewGuid(); #if !CLIENT folderUser = new FolderUser() { ID = Guid.NewGuid(), FolderID = folderID, UserID = currentUser.ID, PermissionID = Permissions.Full }; #endif // create Home folder folder = new Folder() { ID = folderID, SortOrder = 4000, Name = UserEntities.Home, ItemTypeID = SystemItemTypes.Category, #if CLIENT Items = new ObservableCollection<Item>(), #else Items = new List<Item>(), UserID = currentUser.ID, FolderUsers = new List<FolderUser>() { folderUser } #endif }; folders.Add(folder); folderID = Guid.NewGuid(); #if !CLIENT folderUser = new FolderUser() { ID = Guid.NewGuid(), FolderID = folderID, UserID = currentUser.ID, PermissionID = Permissions.Full }; #endif // create Finance folder folder = new Folder() { ID = folderID, SortOrder = 5000, Name = UserEntities.Finance, ItemTypeID = SystemItemTypes.Category, #if CLIENT Items = new ObservableCollection<Item>(), #else Items = new List<Item>(), UserID = currentUser.ID, FolderUsers = new List<FolderUser>() { folderUser } #endif }; folders.Add(folder); folderID = Guid.NewGuid(); #if !CLIENT folderUser = new FolderUser() { ID = Guid.NewGuid(), FolderID = folderID, UserID = currentUser.ID, PermissionID = Permissions.Full }; #endif // create People folder folder = new Folder() { ID = folderID, SortOrder = 50000, Name = UserEntities.People, ItemTypeID = SystemItemTypes.Contact, #if CLIENT Items = new ObservableCollection<Item>(), #else Items = new List<Item>(), UserID = currentUser.ID, FolderUsers = new List<FolderUser>() { folderUser } #endif }; folders.Add(folder); // make this defaultList for Contacts defaultLists.Add(SystemItemTypes.Contact, folder); folderID = Guid.NewGuid(); #if !CLIENT folderUser = new FolderUser() { ID = Guid.NewGuid(), FolderID = folderID, UserID = currentUser.ID, PermissionID = Permissions.Full }; #endif // create Places folder folder = new Folder() { ID = folderID, SortOrder = 50001, Name = UserEntities.Places, ItemTypeID = SystemItemTypes.Location, #if CLIENT Items = new ObservableCollection<Item>(), #else Items = new List<Item>(), UserID = currentUser.ID, FolderUsers = new List<FolderUser>() { folderUser } #endif }; folders.Add(folder); // make this defaultList for Locations defaultLists.Add(SystemItemTypes.Location, folder); #if !CLIENT folderID = Guid.NewGuid(); folderUser = new FolderUser() { ID = Guid.NewGuid(), FolderID = folderID, UserID = currentUser.ID, PermissionID = Permissions.Full }; // create $WebClient folder folder = new Folder() { ID = folderID, SortOrder = 0, Name = SystemEntities.WebClient, ItemTypeID = SystemItemTypes.NameValue, Items = new List<Item>(), UserID = currentUser.ID, FolderUsers = new List<FolderUser>() { folderUser } }; folders.Add(folder); #endif folderID = Guid.NewGuid(); #if !CLIENT folderUser = new FolderUser() { ID = Guid.NewGuid(), FolderID = folderID, UserID = currentUser.ID, PermissionID = Permissions.Full }; #endif // create $PhoneClient folder folder = new Folder() { ID = folderID, SortOrder = 0, Name = SystemEntities.PhoneClient, ItemTypeID = SystemItemTypes.NameValue, #if CLIENT Items = new ObservableCollection<Item>(), #else Items = new List<Item>(), UserID = currentUser.ID, FolderUsers = new List<FolderUser>() { folderUser } #endif }; folders.Add(folder); folderID = Guid.NewGuid(); #if !CLIENT folderUser = new FolderUser() { ID = Guid.NewGuid(), FolderID = folderID, UserID = currentUser.ID, PermissionID = Permissions.Full }; #endif // create $Client folder folder = new Folder() { ID = folderID, SortOrder = 0, Name = SystemEntities.Client, ItemTypeID = SystemItemTypes.NameValue, #if CLIENT Items = new ObservableCollection<Item>(), #else Items = new List<Item>(), UserID = currentUser.ID, FolderUsers = new List<FolderUser>() { folderUser } #endif }; folders.Add(folder); // create DefaultLists list var defaultListItemID = Guid.NewGuid(); item = new Item() { ID = defaultListItemID, SortOrder = 0, Name = SystemEntities.DefaultLists, FolderID = folder.ID, IsList = true, ItemTypeID = SystemItemTypes.Reference, ParentID = null, Created = now, LastModified = now, #if !CLIENT UserID = currentUser.ID, #endif }; folder.Items.Add(item); // add defaultList References for each ItemType int sortOrder = 1; foreach (var keyValue in defaultLists) { item = new Item() { ID = Guid.NewGuid(), SortOrder = sortOrder++, Name = SystemItemTypes.Names[keyValue.Key], FolderID = folder.ID, IsList = false, ItemTypeID = SystemItemTypes.Reference, ParentID = defaultListItemID, Created = now, LastModified = now, #if CLIENT FieldValues = new ObservableCollection<FieldValue>(), #else FieldValues = new List<FieldValue>(), UserID = currentUser.ID, #endif }; if (keyValue.Value is Folder) { Folder folderToRef = (Folder)keyValue.Value; #if CLIENT item.GetFieldValue(FieldNames.EntityRef, true).Value = folderToRef.ID.ToString(); item.GetFieldValue(FieldNames.EntityType, true).Value = EntityTypes.Folder; item.GetFieldValue(FieldNames.Value, true).Value = keyValue.Key.ToString(); #else item.FieldValues.Add(Item.CreateFieldValue(item.ID, FieldNames.EntityRef, folderToRef.ID.ToString())); item.FieldValues.Add(Item.CreateFieldValue(item.ID, FieldNames.EntityType, EntityTypes.Folder)); item.FieldValues.Add(Item.CreateFieldValue(item.ID, FieldNames.Value, keyValue.Key.ToString())); #endif } if (keyValue.Value is Item) { Item itemToRef = (Item)keyValue.Value; #if CLIENT item.GetFieldValue(FieldNames.EntityRef, true).Value = itemToRef.ID.ToString(); item.GetFieldValue(FieldNames.EntityType, true).Value = EntityTypes.Item; item.GetFieldValue(FieldNames.Value, true).Value = keyValue.Key.ToString(); #else item.FieldValues.Add(Item.CreateFieldValue(item.ID, FieldNames.EntityRef, itemToRef.ID.ToString())); item.FieldValues.Add(Item.CreateFieldValue(item.ID, FieldNames.EntityType, EntityTypes.Item)); item.FieldValues.Add(Item.CreateFieldValue(item.ID, FieldNames.Value, keyValue.Key.ToString())); #endif } folder.Items.Add(item); } return folders; }
// add an operation to the Operations table public Operation CreateOperation(User user, string opType, int? code, object body, object oldBody, string session = null) { Operation operation = null; try { // add the operation to the Operations table string name; Type bodyType = body.GetType(); Guid id = (Guid)bodyType.GetProperty("ID").GetValue(body, null); if (body is Suggestion) { // Suggestion does not have a Name property, use GroupDisplayName property name = (string)bodyType.GetProperty("GroupDisplayName").GetValue(body, null); } else { name = (string)bodyType.GetProperty("Name").GetValue(body, null); } operation = new Operation() { ID = Guid.NewGuid(), UserID = user.ID, Username = user.Name, EntityID = id, EntityName = name, EntityType = bodyType.Name, OperationType = opType, StatusCode = (int?)code, Body = JsonSerializer.Serialize(body), OldBody = JsonSerializer.Serialize(oldBody), Session = session, Timestamp = DateTime.Now }; Operations.Add(operation); if (SaveChanges() < 1) { // log failure to record operation TraceLog.TraceError("Failed to record operation: " + opType); } } catch (Exception ex) { // log failure to record operation TraceLog.TraceException("Failed to record operation", ex); } return operation; }
// get a list of children for an ItemID public List<Item> GetChildren(User user, Guid itemID) { return Items.Include("FieldValues").Where(i => i.ParentID == itemID && i.UserID == user.ID).ToList(); }
public AppointmentProcessor(User user, UserStorageContext storage) { this.user = user; this.storage = storage; }
private static Folder CreateCategory(UserStorageContext userContext, User user, string name) { var category = userContext.Folders.FirstOrDefault(f => f.UserID == user.ID && f.Name == name); if (category == null) { category = new Folder() { ID = Guid.NewGuid(), Name = name, UserID = user.ID, ItemTypeID = SystemItemTypes.Category, }; // make this the last category in the list float sortOrder = (userContext.Folders.Any(i => i.UserID == user.ID && i.ItemTypeID == SystemItemTypes.Category) ? userContext.Folders.Where(i => i.UserID == user.ID && i.ItemTypeID == SystemItemTypes.Category). Select(i => i.SortOrder). Max() : 0f) + 1000f; category.SortOrder = sortOrder; userContext.Folders.Add(category); userContext.SaveChanges(); } return category; }
// get or create a List by name in given folder for given user public Item GetOrCreateList(User user, Folder folder, string name, Guid? itemTypeID = null) { return GetOrCreateItem(user, folder, name, itemTypeID, true); }
// get or create an Item by name in given folder for given user (include FieldValues if NOT a List) public Item GetOrCreateItem(User user, Folder folder, string name, Guid? itemTypeID = null, bool isList = false) { if (itemTypeID == null) { itemTypeID = SystemItemTypes.NameValue; } try { // get the list with given name in given folder if (Items.Any(i => i.UserID == user.ID && i.FolderID == folder.ID && i.Name == name)) { if (isList) return Items.Single(i => i.UserID == user.ID && i.FolderID == folder.ID && i.Name == name); else return Items.Include("FieldValues").Single(i => i.UserID == user.ID && i.FolderID == folder.ID && i.Name == name); } else { // create new item with given name in given folder DateTime now = DateTime.UtcNow; var item = new Item() { ID = Guid.NewGuid(), Name = name, FolderID = folder.ID, UserID = user.ID, IsList = isList, ItemTypeID = itemTypeID.Value, ParentID = null, Created = now, LastModified = now }; Items.Add(item); SaveChanges(); TraceLog.TraceInfo(string.Format("Created item named '{0}' in folder '{1}' for user '{2}'", name, folder.Name, user.Name)); return item; } } catch (Exception ex) { TraceLog.TraceException(string.Format("Could not find or create item named '{0}' in folder '{1}' for user '{2}'", name, folder.Name, user.Name), ex); return null; } }
// get or create a Folder by name for given user public Folder GetOrCreateFolder(User user, string name, Guid itemTypeID) { try { // get the folder by name for user if (Folders.Any(f => f.UserID == user.ID && f.Name == name)) { return Folders.Single(f => f.UserID == user.ID && f.Name == name); } else { // create the folder with given name and itemTypeID for user var folderUser = new FolderUser() { ID = Guid.NewGuid(), FolderID = Guid.NewGuid(), UserID = user.ID, PermissionID = BuiltSteady.Product.Shared.Entities.Permissions.Full }; var folder = new Folder() { ID = folderUser.FolderID, SortOrder = 0, Name = name, UserID = user.ID, ItemTypeID = itemTypeID, Items = new List<Item>(), FolderUsers = new List<FolderUser>() { folderUser } }; Folders.Add(folder); SaveChanges(); TraceLog.TraceInfo(string.Format("Created folder named '{0}' for user '{1}'", name, user.Name)); return folder; } } catch (Exception ex) { TraceLog.TraceException(string.Format("Could not find or create folder named '{0}' for user '{1}'", name, user.Name), ex); return null; } }
// get Item by ID (including FieldValues) public Item GetItem(User user, Guid itemID) { if (Items.Any(i => i.UserID == user.ID && i.ID == itemID)) { return Items.Include("FieldValues").Single<Item>(i => i.UserID == user.ID && i.ID == itemID); } return null; }
public List<Item> GetChildrenForFieldValue(User user, Item item, string fieldValueName) { var fv = item.GetFieldValue(fieldValueName); if (fv == null || fv.Value == null) return null; return GetChildren(user, new Guid(fv.Value)); }
public StepProcessor(User user, UserStorageContext storage) { this.user = user; this.storage = storage; }
// get or create a List by value in given folder for given user public Item GetOrCreateListByValue(User user, Folder folder, string value, string name, Guid? itemTypeID = null) { if (itemTypeID == null) { itemTypeID = SystemItemTypes.NameValue; } try { // get the list with given value in given folder if (Items.Any(i => i.UserID == user.ID && i.FolderID == folder.ID && i.FieldValues.Any(fv => fv.FieldName == FieldNames.Value && fv.Value == value))) { return Items.Single(i => i.UserID == user.ID && i.FolderID == folder.ID && i.FieldValues.Any(fv => fv.FieldName == FieldNames.Value && fv.Value == value)); } else { // create new list with given value and name in given folder DateTime now = DateTime.UtcNow; var list = new Item() { ID = Guid.NewGuid(), Name = name, FolderID = folder.ID, UserID = user.ID, IsList = true, ItemTypeID = itemTypeID.Value, ParentID = null, Created = now, LastModified = now, FieldValues = new List<FieldValue>() }; list.GetFieldValue(FieldNames.Value, true).Value = value; Items.Add(list); SaveChanges(); TraceLog.TraceInfo(string.Format("Created list by value '{0}' in folder '{1}' for user '{2}'", value, folder.Name, user.Name)); return list; } } catch (Exception ex) { TraceLog.TraceException(string.Format("Could not find or create list by value '{0}' in folder '{1}' for user '{2}'", value, folder.Name, user.Name), ex); return null; } }
// get a list of children for an Item public List<Item> GetChildren(User user, Item item) { return GetChildren(user, item.ID); }
// may return either Folder or Item (caller should verify) public static object InstallCategory(UserStorageContext userContext, SuggestionsStorageContext suggestionsContext, User user, Folder category, Guid? parentID, GalleryCategory newCategory) { object result = null; try { // find the gallery category in the database (by ID if present, otherwise by name) GalleryCategory galleryCategory = newCategory.ID > 0 ? suggestionsContext.GalleryCategories.FirstOrDefault(gc => gc.ID == newCategory.ID) : suggestionsContext.GalleryCategories.FirstOrDefault(gc => gc.Name == newCategory.Name); if (galleryCategory == null) { TraceLog.TraceError("InstallCategory could not find Category ID " + newCategory.ID); return result; } // if the caller didn't pass in a Category, merge with an existing folder (by name), or create a new folder if (category == null) { category = CreateCategory(userContext, user, newCategory.Name); parentID = null; result = category; } else { // otherwise, create this (sub)category as a subitem DateTime now = DateTime.Now; var subCategory = new Item() { ID = Guid.NewGuid(), Name = galleryCategory.Name, FolderID = category.ID, ParentID = parentID, UserID = category.UserID, ItemTypeID = SystemItemTypes.Category, IsList = true, Created = now, LastModified = now, }; result = subCategory; // make this the last subcategory in the category float sortOrder = (userContext.Items.Any(i => i.UserID == category.UserID && i.FolderID == category.ID && i.ItemTypeID == SystemItemTypes.Category && (parentID.HasValue ? i.ParentID == parentID : i.ParentID == null)) ? userContext.Items.Where(i => i.UserID == category.UserID && i.FolderID == category.ID && i.ItemTypeID == SystemItemTypes.Category && (parentID.HasValue ? i.ParentID == parentID : i.ParentID == null)). Select(i => i.SortOrder). Max() : 0f) + 1000f; subCategory.SortOrder = sortOrder; userContext.Items.Add(subCategory); userContext.SaveChanges(); parentID = subCategory.ID; } // process all of the subcategories under this (sub)category in the database var subCategories = suggestionsContext.GalleryCategories.Where(gc => gc.ParentID == galleryCategory.ID); foreach (var sc in subCategories) InstallCategory(userContext, suggestionsContext, user, category, parentID, sc); // process all the Activities under this (sub)category var activities = suggestionsContext.GalleryActivities.Where(ga => ga.CategoryID == galleryCategory.ID); foreach (var activity in activities) InstallActivity(userContext, suggestionsContext, category, parentID, activity); } catch (Exception ex) { TraceLog.TraceException("InstallCategory failed", ex); return result; } return result; }
// get or create the CalendarSettings item in the $Client folder for given user public CalendarSettings GetCalendarSettings(User user) { Folder clientFolder = Get(user); if (clientFolder != null) { Item item = storage.GetOrCreateItem(user, clientFolder, SystemEntities.CalendarSettings); Item metaItem = storage.UserFolder.GetEntityRef(user, item); if (item != null && metaItem != null) { return new CalendarSettings(item, metaItem); } } return null; }
private void SetAuthCookie(string username, bool persistent, bool isMobile = false) { if (Membership.Provider is UserMembershipProvider) { User user = new User { Name = username }; HttpCookie authCookie = UserMembershipProvider.CreateAuthCookie(user, out this.renewFBToken, isMobile); this.Response.Cookies.Add(authCookie); } else { FormsAuthentication.SetAuthCookie(username, persistent); } }
// get or create the UserProfile item in the $Client folder for given user public UserProfile GetUserProfile(User user) { Folder clientFolder = Get(user); if (clientFolder != null) { Item item = storage.GetOrCreateItem(user, clientFolder, SystemEntities.UserProfile); Item metaItem = storage.UserFolder.GetEntityRef(user, item); if (item != null && metaItem != null) { return new UserProfile(item, metaItem); } } return null; }
public bool GetUserInfo(User user, UserStorageContext storage) { // store user information from Facebook in UserProfile UserProfile userProfile = storage.ClientFolder.GetUserProfile(user); if (userProfile == null) { TraceLog.TraceError("Could not access UserProfile to import Google information into."); return false; } try { // import information about the current user var settings = this.CalendarSettings; if (userProfile.Timezone == null) { var olsonTZ = settings.Items.FirstOrDefault(i => i.Id == "timezone").Value; var tzinfo = OlsonTimeZoneToTimeZoneInfo(olsonTZ); userProfile.Timezone = tzinfo.Id; userProfile.TimezoneHoursOffset = tzinfo.BaseUtcOffset.Hours.ToString(); } storage.SaveChanges(); TraceLog.TraceInfo("Imported Google information into UserProfile"); } catch (Exception ex) { TraceLog.TraceException("Google query for basic User information failed", ex); return false; } return true; }
// get or create the $WebClient folder for given user public Folder GetWeb(User user) { return storage.GetOrCreateFolder(user, SystemEntities.WebClient, SystemItemTypes.NameValue); }
private static string NextStepsList(User user, UserStorageContext userContext) { // get steps with duedates var steps = userContext.Items.Include("FieldValues").Where(i => i.UserID == user.ID && i.ItemTypeID == SystemItemTypes.Step && i.Status == StatusTypes.Active && i.FieldValues.Any(fv => fv.FieldName == FieldNames.DueDate)). ToList(); // create an ordered list of steps that have a duedate on or before today var stepList = new List<StepInfo>(); DateTime date; foreach (var s in steps) if (DateTime.TryParse(s.GetFieldValue(FieldNames.DueDate).Value, out date) && date.Date <= DateTime.Today) stepList.Add(new StepInfo() { Name = s.Name, Date = date }); var orderedSteps = stepList.OrderBy(s => s.Date); // build a string that contains a step in "date: name" format for each step var sb = new StringBuilder(); foreach (var s in orderedSteps) sb.AppendFormat("{0}: {1}\n", s.Date.ToString("MMM dd"), s.Name); var stepString = sb.ToString(); return stepString; }
// get or create the UserFolder for given user public Folder Get(User user) { return storage.GetOrCreateFolder(user, SystemEntities.User, SystemItemTypes.System); }