public void DeleteItemPackage(string id) { using (var cntx = ContextRegistry.NamedContextsFor(this.GetType())) { using (var session = DocumentStoreLocator.ContextualResolve()) { var libTarget = (from libs in session.Query <Lok.Unik.ModelCommon.Client.ContentLibrary>() where libs.Files.Any(file => file.Id == Guid.Parse(id)) select libs) .FirstOrDefault(); if (libTarget != null) { var tempItem = libTarget.Files.FirstOrDefault(file => file.Id == Guid.Parse(id)); if (tempItem != null) { var objPath = Path.Combine(libTarget.BasePath, string.Format("{0}.zip", tempItem.Id)); if (File.Exists(objPath)) { File.Delete(objPath); _log.InfoFormat("'{0}' LibraryItem has been removed from '{1}'", tempItem.Title, objPath); } libTarget.Files.Remove(tempItem); } } session.SaveChanges(); } } }
public IDevice SaveNewDevice(IDevice deviceDb) { using (var nctxs = ContextRegistry.NamedContextsFor(this.GetType())) { using (var session = DocumentStoreLocator.ContextualResolve()) { var objId = Guid.NewGuid(); deviceDb.Id = objId; deviceDb.Tags.Add(new Tag { Id = Guid.NewGuid(), Type = TagType.Device, Attribute = deviceDb.Name, Value = deviceDb.Name, CreateDate = DateTime.UtcNow, Category = new TagCategory { Name = objId.ToString(), Color = CategoryColor.Default } }); session.Store(deviceDb); session.SaveChanges(); return(deviceDb); } } }
public bool SendInvitationEmail(string sendTo, Uri currentUrl, ApplicationUser currentUser, string tenancy) { using (ContextRegistry.NamedContextsFor(GetType())) { using (var session = DocumentStoreLocator.ContextualResolve()) { var invitation = session.Query <Invitation>().FirstOrDefault( i => i.SentTo == sendTo && i.Status != InvitationStatus.Deleted); if (invitation == null) { return(false); } if (currentUrl != null) { var emailSender = this.CreateEmailSender( invitation.SentTo, invitation.Tenancy, invitation.AuthorizationCode.UrlEncodedCode, currentUrl); emailSender.Send(); } invitation.DateSent = DateTime.UtcNow; invitation.Status = invitation.ResentTimes > 0 ? InvitationStatus.ReSent : InvitationStatus.Sent; invitation.ResentTimes++; invitation.InvitingUserId = currentUser.PrincipalId; session.SaveChanges(); new UserManager().SetStatusUserByPrincipalId(invitation.AcceptingAppUserId); return(true); } } }
public IEnumerable <Tag> GetTagsFromContentPackage() { var tags = new List <Tag>(); using (var ntx = ContextRegistry.NamedContextsFor(this.GetType())) { using (var session = DocumentStoreLocator.ContextualResolve()) { var query = (from packages in session.Query <Lok.Unik.ModelCommon.Client.ContentPackage>() select packages). ToArray(); //foreach (var contentPackage in query) //{ // tags.AddRange(contentPackage.Tags.Select(tag => new Models.Tag // { // Id = tag.Id, // Name = tag.Attribute, // Type = tag.Type.ToString(), // Category = tag.Category.Name, // CreateDate = tag.CreateDate, // Color = tag.Category.Color.ToString() // })); //} return(tags); } } }
public void ChangeRoleUser(Guid userId, string newRoleToChange, string userEmail, ApplicationUser changingUser) { var aUser = GetCompleteUserQuery(userId); using (var session = DocumentStoreLocator.ResolveOrRoot(CommonConfiguration.CoreDatabaseRoute)) { var newRole = session.Load <ApplicationRole>(newRoleToChange); if (changingUser.Tenancy.Equals(DefaultRoles.SuperAdmin, StringComparison.OrdinalIgnoreCase)) { // //no send invitation.. var invitation = new InvitationManager().GetInvitationByEmail(userEmail); if (invitation != null) { var current = session.Load <Invitation>(invitation.Id); current.Role = newRole.Name; session.SaveChanges(); } } else { //tenant var invitation = new InvitationManager().GetInvitationByEmail(aUser.AppUser.ContactEmail); if (invitation != null) { using (var nctxs = ContextRegistry.NamedContextsFor(this.GetType())) { using (var sessionInv = DocumentStoreLocator.ContextualResolve()) { var current = sessionInv.Load <Invitation>(invitation.Id); current.Role = newRole.Name; sessionInv.SaveChanges(); } } } } if (aUser.AppUser == null) { return; } if (aUser.AppUser.AccountRoles == null) { return; } var currentUser = session.Load <ApplicationUser>(aUser.AppUser.Id); if (newRole != null && !currentUser.AccountRoles.Contains(newRole.Id)) { //Changing current role by the new one currentUser.AccountRoles.Clear(); currentUser.AccountRoles.Add(newRole.Id); } session.SaveChanges(); } }
public string GetRoleInvitationForUser(string relationshipAppUserId) { string roleInvitation; using (var session = DocumentStoreLocator.ResolveOrRoot(CommonConfiguration.CoreDatabaseRoute)) { roleInvitation = GetRoleInvitationFromUserId(relationshipAppUserId, session); } if (roleInvitation == null && !TenantManager.CurrentTenancy.Equals( DefaultRoles.SuperAdmin, StringComparison.OrdinalIgnoreCase)) { using (ContextRegistry.NamedContextsFor(GetType())) { using (var session = DocumentStoreLocator.ContextualResolve()) { roleInvitation = GetRoleInvitationFromUserId(relationshipAppUserId, session); } } } return(roleInvitation); }
public void DeletePackage(string id) { using (var cntx = ContextRegistry.NamedContextsFor(this.GetType())) { using (var session = DocumentStoreLocator.ContextualResolve()) { var query = (from packs in session.Query <Lok.Unik.ModelCommon.Client.ContentPackage>() select packs) .ToArray() .FirstOrDefault(x => x.Id.ToString() == id); session.Delete(query); session.SaveChanges(); if (query != null) { var objPath = Path.Combine(query.ConfigurationRelativePath, string.Format("{0}.zip", query.Id)); if (File.Exists(objPath)) { File.Delete(objPath); _log.InfoFormat("{0} has been deleted and removed from '{1}'", query.Name, objPath); } } } } }
public static void CreateIndexes() { using (var nctxs = ContextRegistry.NamedContextsFor(typeof(DeviceManager))) { using (var session = DocumentStoreLocator.ContextualResolve()) { var config = Catalog.Factory.Resolve <IConfig>(); var dbName = config[CommonConfiguration.DefaultDataDatabase]; var tenancyUris = ContextRegistry.ContextsOf("Tenancy"); if (tenancyUris.Any()) { var tenancyUri = tenancyUris.First(); var tenancy = tenancyUri.Segments.Count() > 1 ? tenancyUri.Segments[1] : string.Empty; if (!string.IsNullOrEmpty(tenancy) && !tenancy.Equals(Tenants.SystemOwner, StringComparison.InvariantCultureIgnoreCase)) { dbName = tenancy; } } var store = session.Advanced.DocumentStore; IndexesManager.CreateIndexes(store, dbName, typeof(AllDeviceIndex)); } } }
private static void DeviceHealthStatusInitialize(Kiosk dev) { using ( var ctx = ContextRegistry.NamedContextsFor(ContextRegistry.CreateNamed(ContextRegistry.Kind, UnikContextTypes. UnikWarehouseContextResourceKind))) { using (var dc = DocumentStoreLocator.ContextualResolve()) { var deviceHealthChangeEvt = new DeviceHealthStatusEvent { DeviceId = dev.Id, DeviceName = dev.Name, From = HealthStatus.Unknown, To = HealthStatus.Green, DeviceTags = dev.Tags, TimeChanged = DateTime.UtcNow }; dc.Store(deviceHealthChangeEvt); dc.SaveChanges(); } } }
public void DeleteLibrary(string id) { using (var cntx = ContextRegistry.NamedContextsFor(this.GetType())) { using (var session = DocumentStoreLocator.ContextualResolve()) { var libs = from q in session.Query <Lok.Unik.ModelCommon.Client.ContentLibrary>() select q; var lib = libs.ToArray().FirstOrDefault(x => x.Id.ToString() == id); if (lib != null) { foreach (var item in lib.Files) { var relativePath = Path.Combine(lib.BasePath, string.Format("{0}.zip", item.Id)); if (File.Exists(relativePath)) { File.Delete(relativePath); } _log.InfoFormat("Deleting {0} stored at {1}", lib.Title, lib.BasePath); } } session.Delete(lib); if (lib != null) { _log.InfoFormat("{0} Library has been deleted successfully", lib.Title); } session.SaveChanges(); } } }
public void DeleteUserRole(string id) { using (var cntx = ContextRegistry.NamedContextsFor(this.GetType())) { using (var session = DocumentStoreLocator.ContextualResolve()) { var query = (from libs in session.Query <Lok.Unik.ModelCommon.Client.ContentLibrary>() select libs) .ToArray(); var temp = query; for (var i = 0; i < temp.Length; i++) { for (var j = 0; j < temp[i].InvitedUsers.Count; j++) { var users = new UserManager().GetAll(); foreach (var user in users) { if (user.Id.ToString().Equals(id)) { query[i].InvitedUsers.RemoveAt(j); } } } } session.SaveChanges(); } } }
public bool UserHasInvitation(string contactEmail, string tenancy, out string code) { bool existInvitation; using (var session = DocumentStoreLocator.ResolveOrRoot(CommonConfiguration.CoreDatabaseRoute)) { existInvitation = ExistValidInvitation(contactEmail, tenancy, session, out code); } if (!existInvitation) { if (!DefaultRoles.SuperAdmin.Equals(tenancy, StringComparison.InvariantCultureIgnoreCase)) { using (ContextRegistry.NamedContextsFor(GetType())) { using (var session1 = DocumentStoreLocator.ContextualResolve()) { existInvitation = ExistValidInvitation(contactEmail, tenancy, session1, out code); } } } } return(existInvitation); }
public void IdDelete(string id) { using (var dc = DocumentStoreLocator.ContextualResolve()) { var target = dc.Load <TDataType>(id); dc.Delete(target); dc.SaveChanges(); } }
public IEnumerable <T> GetDevicesByType <T>() where T : Device { using (var nctxs = ContextRegistry.NamedContextsFor(this.GetType())) { using (var session = DocumentStoreLocator.ContextualResolve()) { return((from entity in session.Query <T>() select entity).ToArray()); } } }
private IDocumentSession ReturnContext(string tenancy) { using (var ctx = ContextRegistry.NamedContextsFor(GetType())) { return(string.IsNullOrEmpty(tenancy) || DefaultRoles.SuperAdmin.Equals(tenancy, StringComparison.InvariantCultureIgnoreCase) ? DocumentStoreLocator.ResolveOrRoot(CommonConfiguration.CoreDatabaseRoute) : DocumentStoreLocator.ContextualResolve()); } }
public void AssignTags <T>(Guid id, IList <Tag> tagsList, bool clear) where T : ITaggableEntity { using (ContextRegistry.NamedContextsFor(this.GetType())) { using (var session = DocumentStoreLocator.ContextualResolve()) { AssignTagsGeneric <T>(id, tagsList, clear, session); } } }
public IDocumentSession Sessiones() { using (var nctxs = ContextRegistry.NamedContextsFor(this.GetType())) { using (var session = DocumentStoreLocator.ContextualResolve()) { return(session); } } }
public void RemoveTags <T>(Guid id) where T : ITaggableEntity { using (ContextRegistry.NamedContextsFor(this.GetType())) { using (var session = DocumentStoreLocator.ContextualResolve()) { ResolveEntity <T>(id, session); session.SaveChanges(); } } }
public IEnumerable <GroupLink> GetAllGroupLink() { using (ContextRegistry.NamedContextsFor(GetType())) { using (var session = DocumentStoreLocator.ContextualResolve()) { var q2 = from groupLink in session.Query <GroupLink>() select groupLink; return(q2.ToArray()); } } }
public void Store <T>(T device) where T : Device { using (var nctxs = ContextRegistry.NamedContextsFor(this.GetType())) { using (var session = DocumentStoreLocator.ContextualResolve()) { session.Store(device); session.SaveChanges(); } } }
public IEnumerable <Device> GetDevices() { using (var nctxs = ContextRegistry.NamedContextsFor(this.GetType())) { using (var session = DocumentStoreLocator.ContextualResolve()) { var q = from entity in session.Query <Device, AllDeviceIndex>() select entity; return(q.ToArray()); } } }
public IEnumerable <Lok.Unik.ModelCommon.Client.SchedulePlan> GetAll() { using (var nctxs = ContextRegistry.NamedContextsFor(this.GetType())) { using (var session = DocumentStoreLocator.ContextualResolve()) { var q2 = from schedule in session.Query <Lok.Unik.ModelCommon.Client.SchedulePlan>() select schedule; return(q2.ToArray()); } } }
public IEnumerable <GroupLink> GetAllGroupLinkWithGroupTwoType(TagType tagType) { using (ContextRegistry.NamedContextsFor(GetType())) { using (var session = DocumentStoreLocator.ContextualResolve()) { var q2 = session.Query <GroupLink>().Where(x => x.GroupTwo.Type == tagType).ToList(); return(q2.ToArray()); } } }
public IEnumerable <Lok.Unik.ModelCommon.Client.ContentPackage> GetAll() { using (var cntx = ContextRegistry.NamedContextsFor(this.GetType())) { using (var session = DocumentStoreLocator.ContextualResolve()) { var query = from cp in session.Query <Lok.Unik.ModelCommon.Client.ContentPackage>() select cp; return(query.ToArray()); } } }
private void StoreDocuments(IEnumerable <TDataType> documents) { using (var dc = DocumentStoreLocator.ContextualResolve()) { foreach (var doc in documents) { dc.Store(doc); } dc.SaveChanges(); } }
public IEnumerable <Application> GetAllAplications() { using (var nctxs = ContextRegistry.NamedContextsFor(this.GetType())) { using (var session = DocumentStoreLocator.ContextualResolve()) { var list = session.Query <Application>().ToArray(); return(list); } } }
public void IdDeleteBatch(IList <string> ids) { using (var dc = DocumentStoreLocator.ContextualResolve()) { var docs = dc.Load <TDataType>(ids); foreach (var doc in docs) { dc.Delete(doc); } dc.SaveChanges(); } }
public IEnumerable <Tag> GetAllTags() { using (ContextRegistry.NamedContextsFor(this.GetType())) { using (var session = DocumentStoreLocator.ContextualResolve()) { var q = from tag in session.Query <Tag>() select tag; var list = q.ToList(); return(list); } } }
public void UpdateScheduleTag(SchedulePlan schedulePlan) { using (var nctxs = ContextRegistry.NamedContextsFor(this.GetType())) { using (var session = DocumentStoreLocator.ContextualResolve()) { var currentSchedule = session.Load <SchedulePlan>(schedulePlan.Id); currentSchedule.Tags = schedulePlan.Tags; session.SaveChanges(); } } }
public void Remove(Guid userId, ApplicationUser currentUser) { var aUser = GetCompleteUserQuery(userId); if (currentUser.Tenancy.Equals(DefaultRoles.SuperAdmin, StringComparison.OrdinalIgnoreCase)) { using (var session = DocumentStoreLocator.ResolveOrRoot(CommonConfiguration.CoreDatabaseRoute)) { if (!string.IsNullOrEmpty(aUser.InvitationId)) { var invitation = session.Load <Invitation>(aUser.InvitationId); invitation.Status = InvitationStatus.Deleted; session.SaveChanges(); } else { // //no send invitation.. var invitation = new InvitationManager().GetInvitationByEmail(aUser.AppUser.ContactEmail); if (invitation != null) { var current = session.Load <Invitation>(invitation.Id); current.Status = InvitationStatus.Deleted; session.SaveChanges(); } } } } else { using (ContextRegistry.NamedContextsFor(GetType())) { using (var sessionInv = DocumentStoreLocator.ContextualResolve()) { if (!string.IsNullOrEmpty(aUser.InvitationId)) { var invitation = sessionInv.Load <Invitation>(aUser.InvitationId); invitation.Status = InvitationStatus.Deleted; sessionInv.SaveChanges(); } } } } using (var sessionUser = DocumentStoreLocator.ResolveOrRoot(CommonConfiguration.CoreDatabaseRoute)) { aUser.AppUser.Status = UserStatus.Deleted; aUser.AppUser.AccountRoles = null; var current = sessionUser.Load <ApplicationUser>(aUser.AppUser.Id); current.Status = aUser.AppUser.Status; sessionUser.SaveChanges(); } }