예제 #1
0
        private IEnumerable <ManagedRole> UpdateRoles(IManagedTenant tenant, RoleList roles, ICollection <IEntity> entities)
        {
            using (Profiler.Measure("PlatformService.UpdateRoles:tenant"))
            {
                if (tenant == null)
                {
                    throw new ArgumentNullException("tenant");
                }

                var ids = roles == null?Enumerable.Empty <string>() : roles.Select(r => r.RemoteId.ToString());

                CastEntityHelper.Delete(tenant.Roles.Where(r => !ids.Contains(r.RemoteId)).Select(t => new EntityRef(t.Id)));

                if (roles == null)
                {
                    return(Enumerable.Empty <ManagedRole>());
                }

                var updatedEntities = roles.Where(r => r.RemoteId > 0).Select(r => UpdateRole(tenant, r, entities)).ToList();

                entities.AddRange(updatedEntities);

                return(updatedEntities);
            }
        }
예제 #2
0
        private IEnumerable <ManagedUser> UpdateUsers(IManagedTenant tenant, UserList users, ICollection <IEntity> entities)
        {
            using (Profiler.Measure("PlatformService.UpdateUsers"))
            {
                if (tenant == null)
                {
                    throw new ArgumentNullException("tenant");
                }

                var ids = users == null?Enumerable.Empty <string>() : users.Select(u => u.RemoteId.ToString());

                CastEntityHelper.Delete(tenant.Users.Where(u => !ids.Contains(u.RemoteId)).Select(t => new EntityRef(t.Id)));

                if (users == null)
                {
                    return(Enumerable.Empty <ManagedUser>());
                }

                var updatedEntities = users.Where(u => u.RemoteId > 0).Select(u => UpdateUser(tenant, u, entities)).ToList();

                entities.AddRange(updatedEntities);

                return(updatedEntities);
            }
        }
예제 #3
0
        private IEnumerable <ManagedAppVersion> UpdateInstalledApps(IManagedTenant tenant, ICollection <InstalledApplication> apps, ICollection <IEntity> entities, ICollection <ManagedApp> existingApps)
        {
            using (Profiler.Measure("PlatformService.UpdateInstalledApps"))
            {
                if (tenant == null)
                {
                    throw new ArgumentNullException("tenant");
                }

                var installedApps = apps ?? new List <InstalledApplication>();

                // remove any app versions no longer on the tenant
                var validVersionIds = installedApps.Where(a => a.ApplicationVersionId != Guid.Empty).Select(a => a.ApplicationVersionId).ToList();

                var removeApps = tenant.HasAppsInstalled
                                 .Where(installedAppVersion => (installedAppVersion.VersionId == null) ||
                                        (installedAppVersion.VersionId.Value == Guid.Empty) ||
                                        !validVersionIds.Contains(installedAppVersion.VersionId.Value)).ToList();

                tenant.HasAppsInstalled.RemoveRange(removeApps);

                var updatedEntities = installedApps.Where(a => a.ApplicationVersionId != Guid.Empty).Select(a =>
                {
                    var mav     = UpdateAppVersion(null, tenant, a, existingApps);
                    mav.Version = a.SolutionVersion;
                    return(mav);
                }).ToList();

                entities.AddRange(updatedEntities);

                return(updatedEntities);
            }
        }
예제 #4
0
        private static ManagedUser CreateTestUser(IManagedTenant tenant)
        {
            var user = Entity.Create <ManagedUser>();

            user.RemoteId = TestUserRemoteId.ToString();
            user.Name     = TestUserName;

            tenant.Users.Add(user);
            user.Tenant = tenant;

            return(user);
        }
예제 #5
0
        private ManagedUser UpdateUser(IManagedTenant tenant, RemoteUserInfo user, ICollection <IEntity> entities)
        {
            using (Profiler.Measure("PlatformService.UpdateUser"))
            {
                var mu = default(IManagedUser);

                if (user.RemoteId <= 0)
                {
                    return(null);
                }

                if (tenant != null)
                {
                    mu = tenant.Users.FirstOrDefault(u => u.RemoteId == user.RemoteId.ToString());
                }

                if (mu != null)
                {
                    mu = mu.AsWritable <ManagedUser>();
                }
                else
                {
                    mu          = CastEntityHelper.CreateUser();
                    mu.RemoteId = user.RemoteId.ToString();
                }

                mu.Name = user.Name;

                switch (user.Status)
                {
                case UserStatus.Active: mu.Status_Enum = ManagedUserStatusEnumeration.Active; break;

                case UserStatus.Disabled: mu.Status_Enum = ManagedUserStatusEnumeration.Disabled; break;

                case UserStatus.Expired: mu.Status_Enum = ManagedUserStatusEnumeration.Expired; break;

                case UserStatus.Locked: mu.Status_Enum = ManagedUserStatusEnumeration.Locked; break;

                default: mu.Status_Enum = ManagedUserStatusEnumeration.Unknown; break;
                }

                var r = UpdateRoles(mu, user.Roles, entities);
                mu.Roles.AddRange(r);

                if (tenant != null)
                {
                    mu.Tenant = tenant;
                }

                return((ManagedUser)mu);
            }
        }
예제 #6
0
        private ManagedTenant UpdateTenant(IManagedPlatform platform, RemoteTenantInfo tenant, ICollection <IEntity> entities, ICollection <ManagedApp> existingApps)
        {
            using (Profiler.Measure("PlatformService.UpdateTenant"))
            {
                IManagedTenant mt = null;

                if (platform != null)
                {
                    mt = platform.ContainsTenants.FirstOrDefault(t => t.RemoteId == tenant.RemoteId.ToString());
                }

                if (mt != null)
                {
                    mt = mt.AsWritable <ManagedTenant>();
                }
                else
                {
                    mt          = CastEntityHelper.CreateTenant();
                    mt.RemoteId = tenant.RemoteId.ToString();
                }

                mt.Name     = tenant.Name;
                mt.Disabled = tenant.Disabled;

                var userRoles = UpdateRoles(mt, tenant.Roles, entities);
                mt.Roles.AddRange(userRoles);

                var users = UpdateUsers(mt, tenant.Users, entities);
                mt.Users.AddRange(users);

                var apps = UpdateInstalledApps(mt, tenant.Apps, entities, existingApps);
                mt.HasAppsInstalled.AddRange(apps);

                if (platform != null)
                {
                    mt.Platform = platform;
                }

                return((ManagedTenant)mt);
            }
        }
예제 #7
0
        private ManagedRole UpdateRole(IManagedTenant tenant, RemoteRoleInfo role, ICollection <IEntity> entities)
        {
            using (Profiler.Measure("PlatformService.UpdateRole"))
            {
                var mr = default(IManagedRole);

                if (role.RemoteId <= 0)
                {
                    return(null);
                }

                if (tenant != null)
                {
                    mr = tenant.Roles.FirstOrDefault(r => r.RemoteId == role.RemoteId.ToString());
                }

                if (mr != null)
                {
                    mr = mr.AsWritable <ManagedRole>();
                }
                else
                {
                    mr          = CastEntityHelper.CreateRole();
                    mr.RemoteId = role.RemoteId.ToString();
                }

                mr.Name = role.Name;

                if (tenant != null)
                {
                    mr.Tenant = tenant;
                }

                return((ManagedRole)mr);
            }
        }
예제 #8
0
        private ManagedAppVersion UpdateAppVersion(IManagedPlatform platform, IManagedTenant tenant, AvailableApplication app, ICollection <ManagedApp> existingApps)
        {
            using (Profiler.Measure("PlatformService.UpdateAppVersion"))
            {
                IManagedApp        managedApp        = existingApps.FirstOrDefault(e => e.ApplicationId == app.ApplicationId);
                IManagedAppVersion managedAppVersion = null;

                // does it exit on the platform?
                if (platform != null)
                {
                    managedAppVersion = platform.AvailableAppVersions.FirstOrDefault(v => v.VersionId == app.ApplicationVersionId) ??
                                        GetAppVersion(app.ApplicationVersionId);
                }

                // or the tenant?
                if (tenant != null && managedAppVersion == null)
                {
                    managedAppVersion = tenant.HasAppsInstalled.FirstOrDefault(i => i.VersionId == app.ApplicationVersionId);
                }

                // or in amongst the list of apps just being created?
                if (managedAppVersion == null)
                {
                    managedAppVersion = existingApps.SelectMany(a => a.Versions).FirstOrDefault(v =>
                                                                                                (v.VersionId == app.ApplicationVersionId) &&
                                                                                                (v.Version == app.PackageVersion) &&
                                                                                                (v.Name == app.Name));
                }

                if (managedAppVersion != null)
                {
                    managedAppVersion = managedAppVersion.AsWritable <ManagedAppVersion>();

                    // it should have an app
                    if (managedAppVersion.Application != null)
                    {
                        managedApp = managedAppVersion.Application;
                    }
                }
                else
                {
                    managedAppVersion           = CastEntityHelper.CreateAppVersion();
                    managedAppVersion.VersionId = app.ApplicationVersionId;
                }

                managedAppVersion.Name        = app.Name;
                managedAppVersion.Version     = app.PackageVersion;
                managedAppVersion.PublishDate = app.ReleaseDate;

                // does the app exist then?
                if (managedApp == null)
                {
                    managedApp = UpdateApp(app);
                }

                if (managedApp != null)
                {
                    managedApp = managedApp.AsWritable <ManagedApp>();
                    managedApp.Versions.Add((ManagedAppVersion)managedAppVersion);

                    managedAppVersion.Application = managedApp;

                    existingApps.Add((ManagedApp)managedApp);
                }

                if (platform != null || tenant != null)
                {
                    if (platform != null)
                    {
                        platform.AvailableAppVersions.Add((ManagedAppVersion)managedAppVersion);
                    }

                    if (tenant != null)
                    {
                        tenant.HasAppsInstalled.Add((ManagedAppVersion)managedAppVersion);
                    }
                }

                return((ManagedAppVersion)managedAppVersion);
            }
        }