/// <summary>
 /// Recupera as informações do assembly pelo nome informado.
 /// </summary>
 /// <param name="assemblyName"></param>
 /// <param name="assemblyInfo"></param>
 /// <param name="exception">Error ocorrido.</param>
 /// <returns>True se as informações do assembly forem recuperadas com sucesso.</returns>
 public bool TryGet(string assemblyName, out AssemblyInfo assemblyInfo, out Exception exception)
 {
     try
     {
         CheckInitialize();
         AssemblyInfoEntry entry = null;
         if (_assemblies.TryGetValue(assemblyName, out entry))
         {
             assemblyInfo = entry.Info;
             exception    = null;
             return(true);
         }
         assemblyInfo = null;
         exception    = null;
         return(false);
     }
     catch (Exception ex)
     {
         assemblyInfo = null;
         exception    = ex;
         return(false);
     }
 }
        /// <summary>
        /// Atualiza os dados do repositório.
        /// </summary>
        /// <param name="executeAnalyzer">Identifica se é para executar o analizador.</param>
        public void Refresh(bool executeAnalyzer)
        {
            var isInitializing = false;

            lock (_lock)
            {
                string[]      originalFiles = null;
                List <string> files         = null;
                OnLoadingAssemblyFiles();
                try
                {
                    originalFiles = System.IO.Directory.GetFiles(_assembliesDirectory, "*.dll").Concat(System.IO.Directory.GetFiles(_assembliesDirectory, "*.exe")).Select(f => System.IO.Path.GetFileName(f)).ToArray();
                    Array.Sort <string>(originalFiles, StringComparer.InvariantCulture);
                    files = new List <string>(originalFiles);
                }
                catch
                {
                    files = new List <string>();
                }
                bool manifestExists = ManifestExists();
                isInitializing = _assemblies == null || IsManifestFileChanged;
                if (isInitializing)
                {
                    _assemblies = new Dictionary <string, AssemblyInfoEntry>();
                    if (!manifestExists && !executeAnalyzer)
                    {
                        foreach (var file in originalFiles)
                        {
                            var entry = new AssemblyInfoEntry {
                                FileName = file,
                                Info     = new AssemblyInfo {
                                    Name          = System.IO.Path.GetFileNameWithoutExtension(file),
                                    References    = new string[0],
                                    LastWriteTime = System.IO.File.GetLastWriteTime(System.IO.Path.Combine(_assembliesDirectory, file))
                                }
                            };
                            _assemblies.Add(entry.Info.Name, entry);
                        }
                    }
                    else
                    {
                        foreach (var i in GetManifest())
                        {
                            _assemblies.Add(i.Info.Name, i);
                        }
                    }
                }
                var removeNames = new Queue <string>();
                foreach (var i in _assemblies)
                {
                    var index = files.BinarySearch(i.Value.FileName, StringComparer.InvariantCulture);
                    if (index < 0)
                    {
                        removeNames.Enqueue(i.Key);
                    }
                    else
                    {
                        files.RemoveAt(index);
                    }
                }
                while (removeNames.Count > 0)
                {
                    _assemblies.Remove(removeNames.Dequeue());
                }
                var newInfos = new List <AssemblyInfoEntry>();
                if (manifestExists || executeAnalyzer)
                {
                    foreach (var i in _assemblies)
                    {
                        try
                        {
                            var lastWriteTime = System.IO.File.GetLastWriteTime(System.IO.Path.Combine(_assembliesDirectory, i.Value.FileName));
                            if (i.Value.Info.LastWriteTime != lastWriteTime)
                            {
                                removeNames.Enqueue(i.Key);
                                if (executeAnalyzer)
                                {
                                    files.Add(i.Value.FileName);
                                }
                                else
                                {
                                    i.Value.Info.LastWriteTime = lastWriteTime;
                                    newInfos.Add(i.Value);
                                }
                            }
                        }
                        catch
                        {
                            if (executeAnalyzer)
                            {
                                files.Add(i.Value.FileName);
                            }
                            removeNames.Enqueue(i.Key);
                        }
                    }
                    while (removeNames.Count > 0)
                    {
                        _assemblies.Remove(removeNames.Dequeue());
                    }
                }
                string tempDirectory = null;
                if (files.Count > 0)
                {
                    try
                    {
                        tempDirectory = System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetRandomFileName()));
                        System.IO.Directory.CreateDirectory(tempDirectory);
                        var copyFiles = new string[files.Count];
                        for (var i = 0; i < files.Count; i++)
                        {
                            var destFileName = System.IO.Path.Combine(tempDirectory, files[i]);
                            System.IO.File.Copy(System.IO.Path.Combine(_assembliesDirectory, files[i]), destFileName);
                            copyFiles[i] = destFileName;
                        }
                        for (var i = 0; i < files.Count; i++)
                        {
                            OnAnalysisAssemblyProgressChanged(("Analyzing " + files[i] + " ...").GetFormatter(), ((100 * i) / files.Count));
                            try
                            {
                                var data = _assemblyAnalyzer.AnalyzeRootAssembly(copyFiles[i], false);
                                newInfos.Add(new AssemblyInfoEntry {
                                    FileName = files[i],
                                    Info     = ConvertAssemblyInfo(data, System.IO.Path.Combine(_assembliesDirectory, files[i]))
                                });
                            }
                            catch
                            {
                            }
                        }
                    }
                    finally
                    {
                        if (tempDirectory != null)
                        {
                            var files2 = System.IO.Directory.GetFiles(tempDirectory);
                            foreach (var i in files2)
                            {
                                try
                                {
                                    System.IO.File.Delete(i);
                                }
                                catch
                                {
                                }
                            }
                            try
                            {
                                System.IO.Directory.Delete(tempDirectory, true);
                            }
                            catch
                            {
                            }
                        }
                    }
                }
                foreach (var i in newInfos)
                {
                    _assemblies.Add(i.Info.Name, i);
                }
                if (newInfos.Count > 0)
                {
                    SaveManifest();
                }
            }
            if (isInitializing)
            {
                OnLoaded();
            }
        }