Example #1
0
        private string GetStringHelper(StringResourceReference resourceReference, out LoadingResult result, out AssemblyBindingStatus bindingStatus)
        {
            result        = LoadingResult.AssemblyNotFound;
            bindingStatus = AssemblyBindingStatus.NotFound;
            AssemblyLoadResult result2 = null;

            if (this._resourceReferenceToAssemblyCache.Contains(resourceReference))
            {
                result2       = this._resourceReferenceToAssemblyCache[resourceReference] as AssemblyLoadResult;
                bindingStatus = result2.status;
            }
            else
            {
                bool flag;
                result2 = new AssemblyLoadResult {
                    a = this.LoadAssemblyFromResourceReference(resourceReference, out flag)
                };
                if (result2.a == null)
                {
                    result2.status = AssemblyBindingStatus.NotFound;
                }
                else
                {
                    result2.status = flag ? AssemblyBindingStatus.FoundInGac : AssemblyBindingStatus.FoundInPath;
                }
                this._resourceReferenceToAssemblyCache.Add(resourceReference, result2);
            }
            bindingStatus = result2.status;
            if (result2.a == null)
            {
                result = LoadingResult.AssemblyNotFound;
                return(null);
            }
            try
            {
                string str = ResourceManagerCache.GetResourceString(result2.a, resourceReference.baseName, resourceReference.resourceId);
                if (str == null)
                {
                    result = LoadingResult.StringNotFound;
                    return(null);
                }
                result = LoadingResult.NoError;
                return(str);
            }
            catch (InvalidOperationException)
            {
                result = LoadingResult.ResourceNotFound;
            }
            catch (MissingManifestResourceException)
            {
                result = LoadingResult.ResourceNotFound;
            }
            catch (Exception)
            {
                throw;
            }
            return(null);
        }
 private string GetStringHelper(StringResourceReference resourceReference, out LoadingResult result, out AssemblyBindingStatus bindingStatus)
 {
     result = LoadingResult.AssemblyNotFound;
     bindingStatus = AssemblyBindingStatus.NotFound;
     AssemblyLoadResult result2 = null;
     if (this._resourceReferenceToAssemblyCache.Contains(resourceReference))
     {
         result2 = this._resourceReferenceToAssemblyCache[resourceReference] as AssemblyLoadResult;
         bindingStatus = result2.status;
     }
     else
     {
         bool flag;
         result2 = new AssemblyLoadResult {
             a = this.LoadAssemblyFromResourceReference(resourceReference, out flag)
         };
         if (result2.a == null)
         {
             result2.status = AssemblyBindingStatus.NotFound;
         }
         else
         {
             result2.status = flag ? AssemblyBindingStatus.FoundInGac : AssemblyBindingStatus.FoundInPath;
         }
         this._resourceReferenceToAssemblyCache.Add(resourceReference, result2);
     }
     bindingStatus = result2.status;
     if (result2.a == null)
     {
         result = LoadingResult.AssemblyNotFound;
         return null;
     }
     try
     {
         string str = ResourceManagerCache.GetResourceString(result2.a, resourceReference.baseName, resourceReference.resourceId);
         if (str == null)
         {
             result = LoadingResult.StringNotFound;
             return null;
         }
         result = LoadingResult.NoError;
         return str;
     }
     catch (InvalidOperationException)
     {
         result = LoadingResult.ResourceNotFound;
     }
     catch (MissingManifestResourceException)
     {
         result = LoadingResult.ResourceNotFound;
     }
     catch (Exception)
     {
         throw;
     }
     return null;
 }
Example #3
0
        private void CreateNavigationPage(AssemblyLoadResult loadResult)
        {
            this.NavigationPage = new NavigationPage();
            Control control = null;

            switch (loadResult)
            {
            case AssemblyLoadResult.AssemblyFailed:
                control = new ucError("Could not create instance");
                break;

            case AssemblyLoadResult.AssemblyMissing:
                control = new ucError("No assembly defined");
                break;

            case AssemblyLoadResult.AssemblyNotFound:
                control = new ucError("File not found");
                break;

            case AssemblyLoadResult.AssemblyLoaded:
                if (this.Assembly != null && this.Assembly.UserControl != null)
                {
                    this.Assembly.UserControl.Dock = DockStyle.Fill;
                    control = this.Assembly.UserControl;
                }
                break;

            default:
                control = new ucError("Undefined error");
                break;
            }

            if (control != null)
            {
                this.NavigationPage.Controls.Add(control);
            }
        }
Example #4
0
        private string GetStringHelper(StringResourceReference resourceReference, out LoadingResult result, out AssemblyBindingStatus bindingStatus)
        {
            result        = LoadingResult.AssemblyNotFound;
            bindingStatus = AssemblyBindingStatus.NotFound;

            AssemblyLoadResult loadResult = null;

            // try first to see if we have an assembly reference in the cache
            if (_resourceReferenceToAssemblyCache.Contains(resourceReference))
            {
                loadResult    = _resourceReferenceToAssemblyCache[resourceReference] as AssemblyLoadResult;
                bindingStatus = loadResult.status;
            }
            else
            {
                loadResult = new AssemblyLoadResult();
                // we do not have an assembly, we try to load it
                bool foundInGac;
                loadResult.a = LoadAssemblyFromResourceReference(resourceReference, out foundInGac);
                if (loadResult.a == null)
                {
                    loadResult.status = AssemblyBindingStatus.NotFound;
                }
                else
                {
                    loadResult.status = foundInGac ? AssemblyBindingStatus.FoundInGac : AssemblyBindingStatus.FoundInPath;
                }

                // add to the cache even if null
                _resourceReferenceToAssemblyCache.Add(resourceReference, loadResult);
            }

            bindingStatus = loadResult.status;

            if (loadResult.a == null)
            {
                // we failed the assembly loading
                result = LoadingResult.AssemblyNotFound;
                return(null);
            }
            else
            {
                resourceReference.assemblyLocation = loadResult.a.Location;
            }

            // load now the resource from the resource manager cache
            try
            {
                string val = ResourceManagerCache.GetResourceString(loadResult.a, resourceReference.baseName, resourceReference.resourceId);
                if (val == null)
                {
                    result = LoadingResult.StringNotFound;
                    return(null);
                }
                else
                {
                    result = LoadingResult.NoError;
                    return(val);
                }
            }
            catch (InvalidOperationException)
            {
                result = LoadingResult.ResourceNotFound;
            }
            catch (MissingManifestResourceException)
            {
                result = LoadingResult.ResourceNotFound;
            }
            catch (Exception e) // will rethrow
            {
                Diagnostics.Assert(false, "ResourceManagerCache.GetResourceString unexpected exception " + e.GetType().FullName);
                throw;
            }

            return(null);
        }
Example #5
0
 public NamedAssemblyLoadResult(string assemblyFilename, AssemblyLoadResult assemblyLoadResult)
 {
     AssemblyFilename   = assemblyFilename;
     AssemblyLoadResult = assemblyLoadResult;
 }
Example #6
0
        public AssemblyLoadResult Load(LoadContext loadContext)
        {
            string name = loadContext.AssemblyName;

            CompiledAssembly compiledAssembly;

            if (_compiledAssemblies.TryGetValue(name, out compiledAssembly))
            {
                return(new AssemblyLoadResult(compiledAssembly.Assembly));
            }

            string  path = Path.Combine(_rootPath, name);
            Project project;

            // Can't find a project file with the name so bail
            if (!Project.TryGetProject(path, out project))
            {
                return(null);
            }

            _watcher.WatchFile(project.ProjectFilePath);

            TargetFrameworkConfiguration targetFrameworkConfig = project.GetTargetFrameworkConfiguration(loadContext.TargetFramework);

            Trace.TraceInformation("[{0}]: Found project '{1}' framework={2}", GetType().Name, project.Name, loadContext.TargetFramework);

            var references = new List <MetadataReference>();

            if (project.Dependencies.Count > 0 ||
                targetFrameworkConfig.Dependencies.Count > 0)
            {
                Trace.TraceInformation("[{0}]: Loading dependencies for '{1}'", GetType().Name, project.Name);
                var dependencyStopWatch = Stopwatch.StartNew();

                var errors = new List <string>();

                foreach (var dependency in project.Dependencies.Concat(targetFrameworkConfig.Dependencies))
                {
                    MetadataReference reference;
                    if (TryResolveDependency(dependency, loadContext, errors, out reference))
                    {
                        references.Add(reference);
                    }
                }

                if (errors.Count > 0)
                {
                    return(new AssemblyLoadResult(errors));
                }

                dependencyStopWatch.Stop();
                Trace.TraceInformation("[{0}]: Completed loading dependencies for '{1}' in {2}ms", GetType().Name, project.Name, dependencyStopWatch.ElapsedMilliseconds);
            }

            references.AddRange(_resolver.GetDefaultReferences(loadContext.TargetFramework));

            Trace.TraceInformation("[{0}]: Compiling '{1}'", GetType().Name, name);
            var sw = Stopwatch.StartNew();

            try
            {
                _watcher.WatchDirectory(path, ".cs");

                var trees = new List <SyntaxTree>();

                bool hasAssemblyInfo = false;

                var sourceFiles = project.SourceFiles.ToList();

                var parseOptions = new CSharpParseOptions(preprocessorSymbols: targetFrameworkConfig.Defines.AsImmutable());

                foreach (var sourcePath in sourceFiles)
                {
                    if (!hasAssemblyInfo && Path.GetFileNameWithoutExtension(sourcePath).Equals("AssemblyInfo"))
                    {
                        hasAssemblyInfo = true;
                    }

                    _watcher.WatchFile(sourcePath);
                    trees.Add(CSharpSyntaxTree.ParseFile(sourcePath, parseOptions));
                }

                if (!hasAssemblyInfo)
                {
                    trees.Add(CSharpSyntaxTree.ParseText("[assembly: System.Reflection.AssemblyVersion(\"" + project.Version.Version + "\")]"));
                    trees.Add(CSharpSyntaxTree.ParseText("[assembly: System.Reflection.AssemblyInformationalVersion(\"" + project.Version + "\")]"));
                }

                foreach (var directory in System.IO.Directory.EnumerateDirectories(path, "*.*", SearchOption.AllDirectories))
                {
                    _watcher.WatchDirectory(directory, ".cs");
                }

                Compilation compilation = CSharpCompilation.Create(
                    name,
                    targetFrameworkConfig.CompilationOptions,
                    syntaxTrees: trees,
                    references: references);

                IList <ResourceDescription> resources = _resourceProvider.GetResources(project.Name, path);

                // If the output path is null then load the assembly from memory
                if (loadContext.OutputPath == null)
                {
                    return(CompileInMemory(name, compilation, resources));
                }

                string assemblyPath = Path.Combine(loadContext.OutputPath, name + ".dll");
                string pdbPath      = Path.Combine(loadContext.OutputPath, name + ".pdb");

                // Add to the list of generated artifacts
                if (loadContext.ArtifactPaths != null)
                {
                    loadContext.ArtifactPaths.Add(assemblyPath);
                    loadContext.ArtifactPaths.Add(pdbPath);
                }

                // If we're not loading from the output path then compile in memory
                if (!loadContext.CreateArtifacts)
                {
                    return(CompileInMemory(name, compilation, resources));
                }

                // Ensure there's an output directory
                System.IO.Directory.CreateDirectory(loadContext.OutputPath);

                AssemblyLoadResult loadResult = CompileToDisk(assemblyPath, pdbPath, compilation, resources);

                if (loadResult != null && loadResult.Errors == null)
                {
                    // Attempt to build packages for this project
                    BuildPackages(loadContext, project, assemblyPath, pdbPath, sourceFiles);
                }

                return(loadResult);
            }
            finally
            {
                Trace.TraceInformation("[{0}]: Compiled '{1}' in {2}ms", GetType().Name, name, sw.ElapsedMilliseconds);
            }
        }
Example #7
0
 private SerializableAssemblyLoadResult(AssemblyLoadResult result)
 {
     Path         = result.Path;
     OriginalPath = result.OriginalPath;
     IsSuccessful = result.IsSuccessful;
 }
 public static Result CreateResultObject(string command)
 {
     Result result = null;
         switch (command) {
             case "attach":
                 result = new AttachResult();
                 break;
             case "detach":
                 result = new DetachResult();
                 break;
             case "getthreads":
                 result = new ThreadsResult();
                 break;
             case "appdomains":
                 result = new AppDomainsResult();
                 break;
             case "assemblies":
                 result = new AssembliesResult();
                 break;
             case "callstack":
                 result = new CallStackResult();
                 break;
             case "setbreakpoint":
                 result = new BreakPointResult();
                 break;
             case "exception":
                 result = new ExceptionResult();
                 break;
             case "go":
                 result = new GoResult();
                 break;
             case "assemblyloadevent":
                 result = new AssemblyLoadResult();
                 break;
             case "removebreakpoint":
                 result = new RemoveBreakPointResult();
                 break;
             case "arguments":
                 result = new ArgumentsResult();
                 break;
             case "members":
                 result = new MembersResult();
                 break;
             case "value":
                 result = new MemberValueResult();
                 break;
         }
         return result;
 }
        private string GetStringHelper(StringResourceReference resourceReference, out LoadingResult result, out AssemblyBindingStatus bindingStatus)
        {
            result = LoadingResult.AssemblyNotFound;
            bindingStatus = AssemblyBindingStatus.NotFound;

            AssemblyLoadResult loadResult = null;
            // try first to see if we have an assembly reference in the cache
            if (_resourceReferenceToAssemblyCache.Contains(resourceReference))
            {
                loadResult = _resourceReferenceToAssemblyCache[resourceReference] as AssemblyLoadResult;
                bindingStatus = loadResult.status;
            }
            else
            {
                loadResult = new AssemblyLoadResult();
                // we do not have an assembly, we try to load it
                bool foundInGac;
                loadResult.a = LoadAssemblyFromResourceReference(resourceReference, out foundInGac);
                if (loadResult.a == null)
                {
                    loadResult.status = AssemblyBindingStatus.NotFound;
                }
                else
                {
                    loadResult.status = foundInGac ? AssemblyBindingStatus.FoundInGac : AssemblyBindingStatus.FoundInPath;
                }

                // add to the cache even if null
                _resourceReferenceToAssemblyCache.Add(resourceReference, loadResult);
            }

            bindingStatus = loadResult.status;

            if (loadResult.a == null)
            {
                // we failed the assembly loading
                result = LoadingResult.AssemblyNotFound;
                return null;
            }


            // load now the resource from the resource manager cache
            try
            {
                string val = ResourceManagerCache.GetResourceString(loadResult.a, resourceReference.baseName, resourceReference.resourceId);
                if (val == null)
                {
                    result = LoadingResult.StringNotFound;
                    return null;
                }
                else
                {
                    result = LoadingResult.NoError;
                    return val;
                }
            }
            catch (InvalidOperationException)
            {
                result = LoadingResult.ResourceNotFound;
            }
            catch (MissingManifestResourceException)
            {
                result = LoadingResult.ResourceNotFound;
            }
            catch (Exception e) // will rethrow
            {
                Diagnostics.Assert(false, "ResourceManagerCache.GetResourceString unexpected exception " + e.GetType().FullName);
                throw;
            }
            return null;
        }
Example #10
0
 public void LoadAssembly(string assemblyFile, string nameSpace)
 {
     this.LoadResult = this.InitializeAssembly(assemblyFile, nameSpace);
     this.CreateNavigationPage(this.LoadResult);
 }