private static void LoadAssemblyDescriptors(ProcessRuntimeDescriptor value, IRepository repo)
        {
            List <AssemblyDescriptor> descriptors = new List <AssemblyDescriptor>();

            foreach (AssemblyDescriptor descriptor in value.AssemblyDescriptors)
            {
                descriptors.Add(repo.Retrieve <AssemblyDescriptor>(descriptor.Uuid));
            }
            value.AssemblyDescriptors = descriptors.ToArray();
        }
 /// <summary>
 /// Gets the current ProcessRuntimeDescriptor from
 /// the currently running process
 /// </summary>
 /// <returns></returns>
 public static ProcessRuntimeDescriptor GetCurrent()
 {
     return(_currentLock.DoubleCheckLock(ref _current, () =>
     {
         ProcessRuntimeDescriptor descriptor = new ProcessRuntimeDescriptor()
         {
             AssemblyDescriptors = AssemblyDescriptor.AllCurrent
         };
         return descriptor;
     }));
 }
        public static ProcessRuntimeDescriptor LoadFromRepo(string cuid, IRepository repo)
        {
            ProcessRuntimeDescriptor value = repo.Query <ProcessRuntimeDescriptor>(new { Cuid = cuid }).FirstOrDefault();

            if (value != null)
            {
                value = repo.Retrieve <ProcessRuntimeDescriptor>(value.Id);
                LoadAssemblyDescriptors(value, repo);
            }

            return(value);
        }
        /// <summary>
        /// Persist to the specified repository the specified ProcessRuntimeDescriptor
        /// and return the result
        /// </summary>
        /// <param name="repo"></param>
        /// <param name="descriptor"></param>
        /// <returns></returns>
        public static ProcessRuntimeDescriptor PersistToRepo(IRepository repo, ProcessRuntimeDescriptor descriptor)
        {
            Args.ThrowIfNull(repo, "repo");
            Args.ThrowIfNull(descriptor, "descriptor");

            List <AssemblyDescriptor> descriptors = new List <AssemblyDescriptor>();

            foreach (AssemblyDescriptor assDescriptor in descriptor.AssemblyDescriptors)
            {
                AssemblyDescriptor saved = repo.Save(assDescriptor);
                descriptors.Add(saved);
            }
            descriptor.AssemblyDescriptors = descriptors.ToArray();
            return(repo.Save(descriptor));
        }
        public static ProcessRuntimeDescriptor LoadByAppName(string appName, IRepository repo, string machineName = null)
        {
            machineName = machineName ?? Environment.MachineName;
            ProcessRuntimeDescriptor value = repo.Query <ProcessRuntimeDescriptor>(new { ApplicationName = appName, MachineName = machineName }).FirstOrDefault();

            if (value == null)
            {
                value = repo.Query <ProcessRuntimeDescriptor>(new { ApplicationName = appName }).FirstOrDefault();
            }
            if (value != null)
            {
                value = repo.Retrieve <ProcessRuntimeDescriptor>(value.Uuid);
                LoadAssemblyDescriptors(value, repo);
            }
            return(value);
        }
        /// <summary>
        /// Persist the current ProcessRuntimeDescriptor to the specified
        /// repo and return the result
        /// </summary>
        /// <param name="repo"></param>
        /// <returns></returns>
        public static ProcessRuntimeDescriptor PersistCurrentToRepo(IRepository repo)
        {
            ProcessRuntimeDescriptor current = GetCurrent();

            return(PersistToRepo(repo, current));
        }