public void TestGetApp()
        {
            ManagedApp a = null;

            try
            {
                // Arrange
                var ps = new PlatformService();

                // Act
                a = (ManagedApp)ps.GetApp(Guid.Empty);

                // Assert
                a.Should().BeNull();

                a = CreateTestApp();
                a.Save();

                var app = ps.GetApp(TestAppId);
                app.Should().NotBeNull();
                app.Id.Should().Be(a.Id);
                app.ApplicationId.Should().Be(TestAppId);
            }
            finally
            {
                if (a != null)
                {
                    Entity.Delete(a);
                }
            }
        }
示例#2
0
 /// <summary>
 /// Attaches the or detach debugging engine.
 /// </summary>
 /// <param name="selected">The selected.</param>
 private void AttachOrDetachDebuggingEngine(ManagedApp selected)
 {
     if (IsInitialized && selected != null)
     {
         if (selected.Pid == Debuggee?.Pid)
         {
             if (MessageBox.Show($"{selected.ImageName} (Pid:{selected.Pid}) is already being debugged, do you want to detach it?",
                                 "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question).Equals(MessageBoxResult.Yes))
             {
                 Debuggee = null;
                 ManagedAppsVm.Repository.SosManager.AttachOrDetach(DebuggerBehavior.Detach, selected.Pid);
                 RefreshManagedAppCommand_Handler(null);
             }
         }
         else
         {
             if (Debuggee != null) // Let's detach before attaching newly selected process
             {
                 ManagedAppsVm.Repository.SosManager.AttachOrDetach(DebuggerBehavior.Detach, Debuggee.Pid);
             }
             Debuggee = selected;
             ManagedAppsVm.Repository.SosManager.AttachOrDetach(DebuggerBehavior.Attach, selected.Pid);
         }
     }
 }
示例#3
0
文件: AppManager.cs 项目: weeble/ohos
        void RefreshApps()
        {
            HashSet<string> unseenApps = new HashSet<string>(iApps.ItemsByKey.Select(aKvp => aKvp.Key));
            foreach (var app in iAppShell.GetApps())
            {
                // Ignore apps pending delete.
                if (app.PendingDelete)
                {
                    continue;
                }
                unseenApps.Remove(app.Name);
                ManagedApp managedApp;
                if (!iApps.TryGetValueByKey(app.Name, out managedApp))
                {
                    uint handle;
                    managedApp = new ManagedApp();
                    iApps.TryAdd(app.Name, managedApp, out handle);
                    managedApp.Handle = handle;
                }
                if (managedApp.Info != app)
                {
                    managedApp.Info = app;
                    if (managedApp.Info.AutoUpdate)
                    {
                        DateTime? lastModified = managedApp.Info.DownloadLastModified;

                        string appName = managedApp.Info.Name;
                        iDownloadManager.StartPollingForAppUpdate(managedApp.Info.Name, managedApp.Info.UpdateUrl,
                            () => OnAppAvailableForDownload(appName),
                            () => OnAppPollFailed(appName),
                            lastModified ?? new DateTime(1900, 1, 1));
                    }
                    managedApp.SequenceNumber += 1;
                }
            }
            foreach (string missingApp in unseenApps)
            {
                iDownloadManager.StopPollingForAppUpdate(missingApp);
                iApps.TryRemoveByKey(missingApp);
            }
            UpdateHandles();
        }
示例#4
0
文件: AppManager.cs 项目: weeble/ohos
 void DoUpdate(ManagedApp aManagedApp)
 {
     string url = aManagedApp.Info.UpdateUrl;
     string name = aManagedApp.Info.Name;
     if (iUpgradeAppNamesToUrls.Forward.ContainsKey(name))
     {
         return;
     }
     iUpgradeAppNamesToUrls.Forward[name] = url;
     iDownloadManager.StartDownload(
         url,
         (aLocalFile, aLastModified) =>
         {
             lock (iLock)
             {
                 iUpgradeAppNamesToUrls.Forward.Remove(name);
             }
             try
             {
                 iAppShell.Upgrade(name, aLocalFile, url, aLastModified);
             }
             catch (BadPluginException bpe)
             {
                 // TODO: Update download status to record failure.
                 Logger.Warn("Update failed: bad plugin.", bpe);
             }
         },
         () =>
         {
             lock (iLock)
             {
                 iUpgradeAppNamesToUrls.Forward.Remove(name);
             }
         }
         );
     aManagedApp.Downloading = true;
 }
        public void TestUpdateApps()
        {
            // Arrange
            var g1 = new Guid("E94426B3-BD3C-4D74-99F8-6D9B8C753366");
            var g2 = new Guid("36B6ABDA-5259-46D2-A8F4-A98B2042D015");
            var a1 = new Guid("B198B5A1-EC72-4F03-B55B-899083180B1B");

            var p = CreateTestPlatform();

            var app1 = new ManagedApp
            {
                Name          = "MyApp1",
                ApplicationId = a1
            };

            app1.Save();

            p.AvailableAppVersions.Add(new ManagedAppVersion
            {
                Name        = "AppNullVersion",
                Application = app1,
                VersionId   = null
            });
            p.AvailableAppVersions.Add(new ManagedAppVersion
            {
                Name        = "AppEmptyVersion",
                Application = app1,
                VersionId   = Guid.Empty
            });
            p.AvailableAppVersions.Add(new ManagedAppVersion
            {
                Name        = "AppMissingVersion",
                Application = app1,
                VersionId   = new Guid("B4DBC866-0BCF-40C7-8EB3-7406137C1588")
            });
            p.AvailableAppVersions.Add(new ManagedAppVersion
            {
                Name        = "AppMatchedVersion",
                Application = app1,
                VersionId   = g2
            });

            p.Save();
            p.AvailableAppVersions.Count.Should().Be(4);

            var pid = p.Id;

            var ps = new PlatformService();

            // Act
            p = (ManagedPlatform)ps.CreateOrUpdate(new RemotePlatformInfo
            {
                Id             = TestPlatformId,
                FrontEndHost   = "test",
                FrontEndDomain = "platform.co",
                Database       = "db",
                DatabaseServer = "ds",
                Apps           = new List <AvailableApplication>
                {
                    new AvailableApplication
                    {
                        Name                 = "AppIncomingEmptyVersion",
                        ApplicationId        = a1,
                        ApplicationVersionId = Guid.Empty
                    },
                    new AvailableApplication
                    {
                        Name                 = "AppIncomingNewVersion",
                        ApplicationId        = a1,
                        ApplicationVersionId = g1
                    },
                    new AvailableApplication
                    {
                        Name                 = "AppIncomingExistingVersion",
                        ApplicationId        = a1,
                        ApplicationVersionId = g2
                    }
                }
            });

            // Assert
            p.Should().NotBeNull();
            p.Id.Should().Be(pid);

            var result = p.AvailableAppVersions.ToList();

            result.Count.Should().Be(2);

            var v1 = p.AvailableAppVersions.FirstOrDefault(v => v.Name == "AppIncomingNewVersion");

            v1.Should().NotBeNull();
            v1.Application.Should().NotBeNull();
            v1.Application.Id.Should().Be(app1.Id);
            v1.Application.Name.Should().Be(app1.Name);
            v1.VersionId.Should().Be(g1);

            var v2 = p.AvailableAppVersions.FirstOrDefault(v => v.Name == "AppIncomingExistingVersion");

            v2.Should().NotBeNull();
            v2.Application.Should().NotBeNull();
            v2.Application.Id.Should().Be(app1.Id);
            v2.Application.Name.Should().Be(app1.Name);
            v2.VersionId.Should().Be(g2);
        }