public void LoadAndRestoreCurrentRuntimeTestAsync()
        {
            AssemblyManagementRepository assManRepo = GetTestRepo(nameof(LoadAndRestoreCurrentRuntimeTestAsync));
            DaoRepository fileRepo = new DaoRepository()
            {
                Database = assManRepo.Database
            };

            fileRepo.AddTypes(typeof(ChunkedFileDescriptor),
                              typeof(ChunkDataDescriptor),
                              typeof(ChunkData));
            fileRepo.EnsureDaoAssemblyAndSchema();
            FileService fmSvc = new FileService(fileRepo);

            AssemblyService          svc    = new AssemblyService(DataProvider.Current, fmSvc, assManRepo, DefaultConfigurationApplicationNameProvider.Instance);
            ProcessRuntimeDescriptor prd1   = svc.CurrentProcessRuntimeDescriptor;
            ProcessRuntimeDescriptor prd2   = svc.CurrentProcessRuntimeDescriptor;
            ProcessRuntimeDescriptor byName = assManRepo.OneProcessRuntimeDescriptorWhere(c => c.ApplicationName == prd1.ApplicationName);

            Message.PrintLine("AppName: {0}", ConsoleColor.Cyan, prd1.ApplicationName);
            Expect.AreEqual(prd1.Cuid, prd2.Cuid);
            Expect.AreEqual(prd1.Cuid, byName.Cuid);
            bool?fired = false;

            svc.RuntimeRestored += (o, a) =>
            {
                fired = true;
                OutLine(((ProcessRuntimeDescriptorEventArgs)a).DirectoryPath);
            };
            svc.RestoreApplicationRuntime(byName.ApplicationName, $".\\{nameof(LoadAndRestoreCurrentRuntimeTestAsync)}");
            Expect.IsTrue(fired.Value);
        }
        public void ProcessRuntimeDescriptorSaveTest()
        {
            AssemblyManagementRepository repo = GetAssemblyManagementRepository(GetConsoleLogger(), nameof(ProcessRuntimeDescriptorSaveTest));

            repo.SetDaoNamespace <ProcessRuntimeDescriptor>();
            repo.Database.TryEnsureSchema <Dao.AssemblyDescriptor>();
            List <AssemblyDescriptor> descriptors = AssemblyDescriptor.GetCurrentAppDomainDescriptors().ToList();
            ProcessRuntimeDescriptor  current     = ProcessRuntimeDescriptor.PersistCurrentToRepo(repo);

            Expect.AreEqual(descriptors.Count, current.AssemblyDescriptors.Length, "Number of descriptors didn't match");

            ProcessRuntimeDescriptor retrieved = repo.Retrieve <ProcessRuntimeDescriptor>(current.Id);

            Expect.AreEqual(descriptors.Count, retrieved.AssemblyDescriptors.Length, "Number of retrieved descriptors didn't match");

            foreach (AssemblyDescriptor descriptor in retrieved.AssemblyDescriptors)
            {
                AssemblyDescriptor retrievedDescriptor = repo.Retrieve <AssemblyDescriptor>(descriptor.Uuid);
                Message.PrintLine("Checking {0}", ConsoleColor.DarkBlue, retrievedDescriptor.AssemblyFullName);
                AssemblyDescriptor actual = descriptors.FirstOrDefault(d =>
                                                                       d.Name.Equals(retrievedDescriptor.Name) &&
                                                                       d.FileHash.Equals(retrievedDescriptor.FileHash) &&
                                                                       d.AssemblyFullName.Equals(retrievedDescriptor.AssemblyFullName)
                                                                       );

                Expect.AreEqual(actual.AssemblyReferenceDescriptors?.Count, retrievedDescriptor.AssemblyReferenceDescriptors?.Count);
                Message.PrintLine("ProcessRuntimeDescriptors count {0}", retrievedDescriptor.ProcessRuntimeDescriptors.Count);
            }
        }
Beispiel #3
0
 public ProcessRuntimeDescriptor LoadRuntimeDescriptor(string filePath, string commandLine, string machineName, string applicationName)
 {
     return(AssemblyManagementRepository.ProcessRuntimeDescriptorsWhere(c =>
                                                                        c.FilePath == filePath &&
                                                                        c.CommandLine == commandLine &&
                                                                        c.MachineName == machineName &&
                                                                        c.ApplicationName == applicationName)
            .FirstOrDefault());
 }
Beispiel #4
0
        private AssemblyService GetAssemblyService(Database db)
        {
            FileService fmSvc = GetFileService(db);
            AssemblyManagementRepository assManRepo = new AssemblyManagementRepository()
            {
                Database = db
            };

            return(new AssemblyService(DataProvider.Instance, fmSvc, assManRepo, DefaultConfigurationApplicationNameProvider.Instance));
        }
        private AssemblyManagementRepository GetTestRepo(string databaseName)
        {
            AssemblyManagementRepository repo = GetAssemblyManagementRepository(GetConsoleLogger(), databaseName);

            repo.SetDaoNamespace <ProcessRuntimeDescriptor>();
            repo.Database.TryEnsureSchema <Dao.AssemblyDescriptor>();
            Dao.AssemblyDescriptor.LoadAll(repo.Database).Delete(repo.Database);
            repo.Creating += (o, a) => { Output("Creating", o, (RepositoryEventArgs)a); };
            repo.Created  += (o, a) => { Output("Created", o, (RepositoryEventArgs)a); };
            repo.Updating += (o, a) => { Output("Updating", o, (RepositoryEventArgs)a); };
            repo.Updated  += (o, a) => { Output("Updated", o, (RepositoryEventArgs)a); };
            return(repo);
        }
        public void SaveDescriptorDoesntDuplicate()
        {
            AssemblyManagementRepository repo = GetTestRepo(nameof(SaveDescriptorDoesntDuplicate));

            AssemblyDescriptor descriptor = new AssemblyDescriptor(Assembly.GetExecutingAssembly());

            AssemblyDescriptor one = repo.Save(descriptor);
            AssemblyDescriptor two = repo.Save(descriptor);

            Expect.IsNotNull(one, "first save returned null");
            Expect.IsNotNull(two, "second save returned null");
            Expect.AreEqual(one.Id, two.Id, "Ids didn't match");
            Expect.AreEqual(one.Uuid, two.Uuid, "Uuids didn't match");

            Dao.AssemblyDescriptorCollection descriptors = Dao.AssemblyDescriptor
                                                           .Where(q =>
                                                                  q.AssemblyFullName == descriptor.AssemblyFullName &&
                                                                  q.FileHash == descriptor.FileHash &&
                                                                  q.Name == descriptor.Name, repo.Database);

            Expect.AreEqual(1, descriptors.Count);
        }
        public void SaveDescriptorSavesReferences()
        {
            AssemblyManagementRepository repo = GetAssemblyManagementRepository(GetConsoleLogger(), nameof(SaveDescriptorSavesReferences));

            repo.Database.TryEnsureSchema <Dao.AssemblyDescriptor>();
            AssemblyDescriptor[] descriptors = AssemblyDescriptor.GetCurrentAppDomainDescriptors().ToArray();

            foreach (AssemblyDescriptor descriptor in descriptors)
            {
                int?referenceCount = descriptor.AssemblyReferenceDescriptors?.Count;
                if (referenceCount > 0)
                {
                    AssemblyDescriptor wrapped   = repo.Save(descriptor);
                    AssemblyDescriptor retrieved = repo.Retrieve <AssemblyDescriptor>(wrapped.Id);
                    Expect.AreEqual(referenceCount, retrieved.AssemblyReferenceDescriptors?.Count);
                    Pass(descriptor.AssemblyFullName + " " + referenceCount.ToString());
                }
                else
                {
                    Message.PrintLine("No references: {0}", ConsoleColor.Cyan, descriptor.AssemblyFullName);
                }
            }
        }