/// <summary> /// Returns the locations of non-framework assemblies on which the assembly with the given filename depends. /// </summary> /// <param name="source">The filename of the assembly</param> /// <returns>An array of filenames for non-framework assemblies on which the given assembly depends</returns> private static DependencyState ListAssemblyDependencies(string assemblyFilename, string binPath, HashSet <string> visited) { Assembly source = Assembly.LoadFrom(assemblyFilename); AppDomainSetup setup = new AppDomainSetup(); setup.ApplicationBase = Path.GetDirectoryName(source.Location); setup.ApplicationName = Path.GetFileName(source.Location); setup.PrivateBinPath = Path.GetDirectoryName(source.Location); setup.LoaderOptimization = LoaderOptimization.SingleDomain; string configFileName = source.Location + ".config"; if (File.Exists(configFileName)) { setup.ConfigurationFile = configFileName; } AppDomain dependencyDomain = AppDomain.CreateDomain("DependencyLister", null, setup); string listerAssembly = typeof(Microsoft.Research.Peloponnese.Shared.DependencyLister.Lister).Assembly.Location; DependencyLister.Lister lister = (DependencyLister.Lister)dependencyDomain.CreateInstanceFromAndUnwrap(listerAssembly, "Microsoft.Research.Peloponnese.Shared.DependencyLister.Lister"); DependencyState ret = lister.ListLoadedDependencies(source.Location, binPath, visited); AppDomain.Unload(dependencyDomain); return(ret); }
public static IEnumerable <string> ListDependencies(string assemblyFilename) { if (Path.GetDirectoryName(assemblyFilename) == "") { assemblyFilename = @".\" + assemblyFilename; } string binPath = Path.GetFullPath(Path.GetDirectoryName(assemblyFilename)).ToLower(); HashSet <string> visited = new HashSet <string>(); Queue <string> assemblyQueue = new Queue <string>(); assemblyQueue.Enqueue(assemblyFilename); while (assemblyQueue.Count > 0) { string currentAssemblyFilename = assemblyQueue.Dequeue(); if (!visited.Contains(currentAssemblyFilename)) { DependencyState newState = ListAssemblyDependencies(currentAssemblyFilename, binPath, visited); visited = newState.visited; foreach (string newAssembly in newState.additionalAssemblies) { assemblyQueue.Enqueue(newAssembly); } } } return(visited); }
public Dependency(string name, DependencyState state, bool scenario, bool route) { Name = name; State = state; IsScenario = scenario; IsRoute = route; }
public Dependency(string name, DependencyState state, bool scenario, bool route, int?pkgId) { Name = name; State = state; IsScenario = scenario; IsRoute = route; PkgID = pkgId; }
/// <summary> /// Mark the dependency as invalid. /// </summary> public void MarkAsInvalid() { this.state = DependencyState.Invalid; if (this.IsItemwise) { this.InvalidIndex = Utils.ANull(); } }
/// <summary> /// Resolve dependencies. /// </summary> /// <param name="resolutionComplete">Delegate called when resolution is complete.</param> /// <param name="forceResolution">Whether resolution should be executed when no dependencies /// have changed. This is useful if a dependency specifies a wildcard in the version /// expression.</param> public static void Resolve(System.Action resolutionComplete = null, bool forceResolution = false) { if (!buildConfigChanged) { DeleteFiles(Resolver.OnBuildSettings()); } if (forceResolution) { DeleteLabeledAssets(); } else { // Only resolve if user specified dependencies changed or the output files // differ to what is present in the project. var currentState = DependencyState.GetState(); var previousState = DependencyState.ReadFromFile(); if (previousState != null) { if (currentState.Equals(previousState)) { if (resolutionComplete != null) { resolutionComplete(); } return; } // Delete all labeled assets to make sure we don't leave any stale transitive // dependencies in the project. DeleteLabeledAssets(); } } System.IO.Directory.CreateDirectory(GooglePlayServices.SettingsDialog.PackageDir); Resolver.DoResolution(svcSupport, GooglePlayServices.SettingsDialog.PackageDir, (oldDependency, newDependency) => { return(Resolver.ShouldReplaceDependency(oldDependency, newDependency)); }, () => { System.Action complete = () => { AssetDatabase.Refresh(); DependencyState.GetState().WriteToFile(); if (resolutionComplete != null) { resolutionComplete(); } }; updateQueue.Enqueue(complete); }); }
/// <summary> /// Set a dependency at the next state from the loader thread. /// </summary> /// <param name="descriptor">Dependency descriptor.</param> public void SetDependency(DescriptorType descriptor) { if (!validation.ContainsKey(descriptor.DescriptorID)) { throw new InvalidOperationException("This dependency is not avaiable."); } DependencyState nextState = DependencyState.NotLoaded; switch (descriptor.State) { case DependencyState.NotLoaded: case DependencyState.Loaded: case DependencyState.Modified: nextState = DependencyState.Loaded; break; case DependencyState.Disposed: nextState = DependencyState.Disposed; break; } // - Delete dependency if (nextState == DependencyState.NotLoaded) { DependencyType t; dependencies.TryRemove(descriptor.DescriptorID, out t); DescriptorValidation d; validation.TryRemove(descriptor.DescriptorID, out d); return; } validation[descriptor.DescriptorID] = new DescriptorValidation { State = nextState }; dependencies[descriptor.DescriptorID].State = DependencyState.Loaded; }
private void AppendDependencyState( ref List <DependencyState> dependenciesState, DependencyDefinition definition, PackageRepo[] targets, bool anyInstalled, bool transitive = false ) { Upbring upbring = Upbring.Instance(); DependencyState state = new DependencyState { definition = definition, latest = PackageList.Instance().GetLatestPackage(definition.Name) }; state.bestMatch = targets.First(pr => pr.Package.PackageName == definition.Name); if (anyInstalled && upbring.InstalledPackage.Any(ip => ip.Name == definition.Name)) { state.installed = upbring.InstalledPackage.First(ip => ip.Name == definition.Name); } state.transitive = transitive; dependenciesState.Add(state); if (state.bestMatch.Package.Dependencies != null) { foreach (DependencyDefinition dependency in state.bestMatch.Package.Dependencies) { AppendDependencyState( ref dependenciesState, dependency, targets, anyInstalled, true ); } } }
internal async void RW_CrawlingComplete() { crawlingComplete = true; Dispatcher.Invoke(() => { DownloadMissing.IsEnabled = false; ScanRailworks.IsEnabled = false; TotalProgress.Value = 100; TotalProgress.IsIndeterminate = true; }); HashSet <string> globalDeps = new HashSet <string>(); try { for (int i = 0; i < RW.Routes.Count; i++) { RW.Routes[i].AllDependencies = RW.Routes[i].Dependencies.Union(RW.Routes[i].ScenarioDeps).ToArray(); globalDeps.UnionWith(RW.Routes[i].AllDependencies); } HashSet <string> existing = await RW.GetMissing(globalDeps); globalDeps.ExceptWith(existing); HashSet <string> downloadable = await PM.GetDownloadableDependencies(globalDeps, existing, this); HashSet <string> paid = await PM.GetPaidDependencies(globalDeps); RW.Routes.Sort(delegate(RouteInfo x, RouteInfo y) { return(x.AllDependencies.Length.CompareTo(y.AllDependencies.Length)); }); // BUG: NullReferenceException int maxThreads = Math.Min(Environment.ProcessorCount, RW.Routes.Count); Parallel.For(0, maxThreads, workerId => { int max = RW.Routes.Count * (workerId + 1) / maxThreads; for (int i = RW.Routes.Count * workerId / maxThreads; i < max; i++) { List <Dependency> deps = new List <Dependency>(); int _i = ((i & 1) != 0) ? (i - 1) / 2 : (RW.Routes.Count - 1) - i / 2; for (int j = 0; j < RW.Routes[_i].AllDependencies.Length; j++) { string dep = RW.Routes[_i].AllDependencies[j]; if (dep != string.Empty) { bool isRoute = RW.Routes[_i].Dependencies.Contains(dep); bool isScenario = RW.Routes[_i].ScenarioDeps.Contains(dep); DependencyState state = DependencyState.Unknown; if (existing.Contains(dep)) { state = DependencyState.Downloaded; } else if (downloadable.Contains(dep)) { state = DependencyState.Available; } else if (paid.Contains(dep)) { state = DependencyState.Paid; } else { state = DependencyState.Unavailable; } deps.Add(new Dependency(dep, state, isScenario, isRoute)); } } RW.Routes[_i].AllDependencies = null; RW.Routes[_i].ParsedDependencies = new DependenciesList(deps); RW.Routes[_i].Redraw(); } }); loadingComplete = true; Dispatcher.Invoke(() => { TotalProgress.IsIndeterminate = false; if (downloadable.Count + PM.PkgsToDownload.Count > 0) { DownloadMissing.IsEnabled = true; } ScanRailworks.IsEnabled = true; ScanRailworks.Content = "Rescan assets..."; }); } catch (Exception e) { if (e.GetType() != typeof(ThreadInterruptedException) && e.GetType() != typeof(ThreadAbortException)) { Trace.Assert(false, e.ToString()); } } new Task(() => { PM.RunQueueWatcher(); }).Start(); }
/// <summary> /// Resolve dependencies. /// </summary> /// <param name="resolutionComplete">Delegate called when resolution is complete /// with a parameter that indicates whether it succeeded or failed.</param> /// <param name="forceResolution">Whether resolution should be executed when no dependencies /// have changed. This is useful if a dependency specifies a wildcard in the version /// expression.</param> private static void ResolveUnsafe(Action <bool> resolutionComplete = null, bool forceResolution = false) { JavaUtilities.CheckJdkForApiLevel(); if (!buildConfigChanged) { DeleteFiles(Resolver.OnBuildSettings()); } xmlDependencies.ReadAll(logger); if (forceResolution) { DeleteLabeledAssets(); } else { // Only resolve if user specified dependencies changed or the output files // differ to what is present in the project. var currentState = DependencyState.GetState(); var previousState = DependencyState.ReadFromFile(); if (previousState != null) { if (currentState.Equals(previousState)) { if (resolutionComplete != null) { resolutionComplete(true); } return; } // Delete all labeled assets to make sure we don't leave any stale transitive // dependencies in the project. DeleteLabeledAssets(); } } System.IO.Directory.CreateDirectory(GooglePlayServices.SettingsDialog.PackageDir); PlayServicesSupport.Log("Resolving...", verbose: true); lastError = ""; Resolver.DoResolution(svcSupport, GooglePlayServices.SettingsDialog.PackageDir, (oldDependency, newDependency) => { return(Resolver.ShouldReplaceDependency(oldDependency, newDependency)); }, () => { System.Action complete = () => { bool succeeded = String.IsNullOrEmpty(lastError); AssetDatabase.Refresh(); DependencyState.GetState().WriteToFile(); PlayServicesSupport.Log(String.Format( "Resolution {0}.\n\n{1}", succeeded ? "Succeeded" : "Failed", lastError), verbose: true); if (resolutionComplete != null) { resolutionComplete(succeeded); } }; updateQueue.Enqueue(complete); }); }
public void MarkAsRegistered() { State = DependencyState.Registered; }
/// <summary> /// Mark the dependency. /// </summary> /// <param name="state"></param> public void Mark(DependencyState state) { this.state = state; }
internal void RW_CrawlingComplete() { crawlingComplete = true; PM.StopMSMQ = true; Dispatcher.Invoke(() => { DownloadMissing.IsEnabled = false; ScanRailworks.IsEnabled = false; TotalProgress.Value = 100; TotalProgress.IsIndeterminate = true; }); try { for (int i = 0; i < RW.Routes.Count; i++) { RW.Routes[i].AllDependencies = RW.Routes[i].Dependencies.Union(RW.Routes[i].ScenarioDeps).ToArray(); RW.AllRequiredDeps.UnionWith(RW.Routes[i].AllDependencies); } RW.Routes.Sort(delegate(RouteInfo x, RouteInfo y) { return(x.AllDependencies.Length.CompareTo(y.AllDependencies.Length)); }); // BUG: NullReferenceException RW.getAllInstalledDepsEvent.WaitOne(); RW.AllMissingDeps = RW.AllRequiredDeps.Except(RW.AllInstalledDeps); PM.GetPackagesToDownload(RW.AllMissingDeps); dlcReportFinishedHandler.WaitOne(); int maxThreads = Math.Min(Environment.ProcessorCount, RW.Routes.Count); Parallel.For(0, maxThreads, workerId => { int max = RW.Routes.Count * (workerId + 1) / maxThreads; for (int i = RW.Routes.Count * workerId / maxThreads; i < max; i++) { List <Dependency> deps = new List <Dependency>(); int _i = ((i & 1) != 0) ? (i - 1) / 2 : (RW.Routes.Count - 1) - i / 2; for (int j = 0; j < RW.Routes[_i].AllDependencies.Length; j++) { string dep = RW.Routes[_i].AllDependencies[j]; if (dep != string.Empty) { bool isRoute = RW.Routes[_i].Dependencies.Contains(dep); bool isScenario = RW.Routes[_i].ScenarioDeps.Contains(dep); int?pkgId = null; DependencyState state = DependencyState.Unknown; if (RW.AllInstalledDeps.Contains(dep)) { state = DependencyState.Downloaded; if (PM.DownloadableDeps.Contains(dep)) { pkgId = PM.DownloadableDepsPackages[dep]; } else if (PM.DownloadablePaidDeps.Contains(dep)) { pkgId = PM.DownloadablePaidDepsPackages[dep]; } //pkgId = PM.CachedPackages.FirstOrDefault(x => x.FilesContained.Contains(dep))?.PackageId; } else if (PM.DownloadableDeps.Contains(dep)) { state = DependencyState.Available; pkgId = PM.DownloadableDepsPackages[dep]; } else if (PM.DownloadablePaidDeps.Contains(dep)) { state = DependencyState.Paid; pkgId = PM.DownloadablePaidDepsPackages[dep]; } else { state = DependencyState.Unavailable; } deps.Add(new Dependency(dep, state, isScenario, isRoute, pkgId)); } } RW.Routes[_i].AllDependencies = null; RW.Routes[_i].ParsedDependencies = new DependenciesList(deps); RW.Routes[_i].Redraw(); } }); loadingComplete = true; Dispatcher.Invoke(() => { TotalProgress.IsIndeterminate = false; PM.StopMSMQ = false; ScanRailworks.IsEnabled = true; ScanRailworks.Content = Localization.Strings.MainRescan; }); } catch (Exception e) { if (e.GetType() != typeof(ThreadInterruptedException) && e.GetType() != typeof(ThreadAbortException)) { Trace.Assert(false, e.ToString()); } } new Task(async() => { await PM.ResolveConflicts(); PM.CheckUpdates(); Dispatcher.Invoke(() => { if (PM.PkgsToDownload.Count > 0) { DownloadMissing.IsEnabled = true; } }); PM.RunQueueWatcher(); }).Start(); }
set => SetValue(DependencyState, value);
public DependencyPackage(string name, DependencyState state, int id) { Name = name; State = state; ID = id; }
public DependencyPackage(string name, DependencyState state) : this(name, state, -1) { }