Ejemplo n.º 1
0
        private static void ReadScenarioSetttings(string scenario, ref InstalledApplication installedApp, ref AvailableApplication availableApp, ref AppSecurityModel security)
        {
            Guid appId = Guid.NewGuid( );

            string [] parts = scenario.Split(',');
            foreach (string part in parts)
            {
                string [] pair  = part.Trim( ).Split('=');
                string    key   = pair [0];
                string    value = pair [1];

                switch (key)
                {
                case "AppLib":
                    // Pass a version string, or 'none' to indicate that no version is available.
                    if (value != "none")
                    {
                        availableApp = new AvailableApplication
                        {
                            ApplicationId  = appId,
                            Name           = "TestApp",
                            PackageVersion = value
                        };
                    }
                    break;

                case "Tenant":
                    // Pass a version string, or 'none' to indicate that no version is available.
                    if (value != "none")
                    {
                        installedApp = new InstalledApplication
                        {
                            ApplicationId   = appId,
                            Name            = "TestApp",
                            PackageVersion  = value,
                            SolutionVersion = value,
                        };
                    }
                    break;

                case "Security":
                    security = ( AppSecurityModel )Enum.Parse(typeof(AppSecurityModel), value);
                    break;

                case "InstallPerm":
                    if (availableApp != null)
                    {
                        availableApp.HasInstallPermission = value == "True";
                    }
                    break;

                case "PublishPerm":
                    if (availableApp != null)
                    {
                        availableApp.HasPublishPermission = value == "True";
                    }
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        private ManagedApp UpdateApp(AvailableApplication app)
        {
            using (Profiler.Measure("PlatformService.UpdateApp"))
            {
                var managedApp = default(IManagedApp);

                if (app != null && app.ApplicationId != Guid.Empty)
                {
                    managedApp = GetApp(app.ApplicationId);

                    // update or create apps
                    if (managedApp != null)
                    {
                        managedApp = managedApp.AsWritable <ManagedApp>();
                    }
                    else
                    {
                        managedApp = CastEntityHelper.CreateApp();
                        managedApp.ApplicationId = app.ApplicationId;
                    }

                    managedApp.Name         = app.Name;
                    managedApp.Publisher    = app.Publisher;
                    managedApp.PublisherUrl = app.PublisherUrl;
                    managedApp.ReleaseDate  = app.ReleaseDate;
                }

                return((ManagedApp)managedApp);
            }
        }
Ejemplo n.º 3
0
        private bool CheckIfPossible(string scenario, Func <InstalledApplication, AvailableApplication, AppSecurityModel, bool> validationFunction)
        {
            InstalledApplication installedApp = null;
            AvailableApplication availableApp = null;
            AppSecurityModel     security     = AppSecurityModel.Full;

            // Process scenario settings
            ReadScenarioSetttings(scenario, ref installedApp, ref availableApp, ref security);

            // Run test
            bool res = validationFunction(installedApp, availableApp, security);

            return(res);
        }
Ejemplo n.º 4
0
        private IList <AppManagerData> GetAppManagerData(IList <AvailableApplication> availableApps, IList <InstalledApplication> installedApps)
        {
            // Get app security method
            var security = ApplicationSecuritySettings.Current == null
                ? AppSecurityModel.Restricted
                : ApplicationSecuritySettings.Current.AppSecurityModel;

            // Organise data
            var availableDict     = availableApps.ToDictionary(a => a.ApplicationId);
            var installedDict     = installedApps.ToDictionary(a => a.ApplicationId);
            var allApplicationIds = availableDict.Keys.Union(installedDict.Keys);

            // Build result
            List <AppManagerData> response = new List <AppManagerData>( );

            foreach (Guid applicationId in allApplicationIds)
            {
                // Find the apps
                AvailableApplication availableApp;
                InstalledApplication installedApp;
                availableDict.TryGetValue(applicationId, out availableApp);
                installedDict.TryGetValue(applicationId, out installedApp);

                // Check if we can see the app
                bool canSee = AppManagerServiceImpl.CanSee(installedApp, availableApp, security);
                if (!canSee)
                {
                    continue;
                }

                // Create a result entry
                AvailableApplication app = availableApp ?? installedApp;

                if (app != null)
                {
                    AppManagerData appResultData = new AppManagerData
                    {
                        Name = app.Name,
                        ApplicationEntityId  = app.ApplicationEntityId,
                        ApplicationId        = app.ApplicationId,
                        ApplicationVersionId = app.ApplicationVersionId,
                        PackageEntityId      = app.PackageEntityId,
                        PackageVersion       = app.PackageVersion,
                        Publisher            = app.Publisher,
                        PublisherUrl         = app.PublisherUrl,
                        ReleaseDate          = app.ReleaseDate,
                        CanExport            = AppManagerServiceImpl.CanExport(installedApp, availableApp, security),
                        CanPublish           = AppManagerServiceImpl.CanPublish(installedApp, availableApp, security),
                        CanDeploy            = AppManagerServiceImpl.CanDeploy(installedApp, availableApp, security),
                        CanUpgrade           = AppManagerServiceImpl.CanUpgrade(installedApp, availableApp, security),
                        CanRepair            = AppManagerServiceImpl.CanRepair(installedApp, availableApp, security),
                        CanUninstall         = AppManagerServiceImpl.CanUninstall(installedApp, availableApp, security)
                    };
                    if (installedApp != null)
                    {
                        appResultData.SolutionEntityId = installedApp.SolutionEntityId;
                        appResultData.SolutionVersion  = installedApp.SolutionVersion;
                    }

                    response.Add(appResultData);
                }
            }
            return(response);
        }
Ejemplo n.º 5
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);
            }
        }