Exemplo n.º 1
0
            public void ShouldReturnAScriptResult(
                [Frozen] Mock <IScriptHostFactory> scriptHostFactory,
                [NoAutoProperties] MonoScriptEngine engine,
                ScriptPackSession scriptPackSession)
            {
                // Arrange
                var code = string.Empty;

                scriptHostFactory.Setup(f => f.CreateScriptHost(It.IsAny <IScriptPackManager>(), It.IsAny <string[]>()))
                .Returns <IScriptPackManager, string[]>((p, q) => new ScriptHost(p, new ScriptEnvironment(q)));

                var session = new SessionState <Evaluator> {
                    Session = new Evaluator(new CompilerContext(new CompilerSettings(), new ConsoleReportPrinter()))
                };

                scriptPackSession.State[MonoScriptEngine.SessionKey] = session;
                var refs = new AssemblyReferences();

                refs.PathReferences.Add("System");

                // Act
                var result = engine.Execute(code, new string[0], refs, Enumerable.Empty <string>(), scriptPackSession);

                // Assert
                result.ShouldBeType <ScriptResult>();
            }
Exemplo n.º 2
0
        public ScriptExecutor(
            IFileSystem fileSystem,
            IFilePreProcessor filePreProcessor,
            IScriptEngine scriptEngine,
            ILogProvider logProvider,
            IScriptLibraryComposer composer)
        {
            Guard.AgainstNullArgument("fileSystem", fileSystem);
            Guard.AgainstNullArgumentProperty("fileSystem", "BinFolder", fileSystem.BinFolder);
            Guard.AgainstNullArgumentProperty("fileSystem", "DllCacheFolder", fileSystem.DllCacheFolder);
            Guard.AgainstNullArgument("filePreProcessor", filePreProcessor);
            Guard.AgainstNullArgument("scriptEngine", scriptEngine);
            Guard.AgainstNullArgument("logProvider", logProvider);
            Guard.AgainstNullArgument("composer", composer);

            References = new AssemblyReferences(DefaultReferences);
            Namespaces = new Collection <string>();
            ImportNamespaces(DefaultNamespaces);
            FileSystem       = fileSystem;
            FilePreProcessor = filePreProcessor;
            ScriptEngine     = scriptEngine;
            _log             = logProvider.ForCurrentType();
#pragma warning disable 618
            Logger = new ScriptCsLogger(_log);
#pragma warning restore 618
            ScriptLibraryComposer = composer;
        }
Exemplo n.º 3
0
            public void ShouldAddNewReferencesIfTheyAreProvided(
                [Frozen] Mock <IScriptHostFactory> scriptHostFactory,
                [NoAutoProperties] MonoTestScriptEngine engine,
                ScriptPackSession scriptPackSession)
            {
                // Arrange
                const string Code = "var a = 0;";

                scriptHostFactory.Setup(f => f.CreateScriptHost(It.IsAny <IScriptPackManager>(), It.IsAny <string[]>()))
                .Returns <IScriptPackManager, string[]>((p, q) => new ScriptHost(p, new ScriptEnvironment(q)));

                var session = new SessionState <Evaluator> {
                    Session = new Evaluator(new CompilerContext(new CompilerSettings(), new ConsoleReportPrinter()))
                };

                scriptPackSession.State[MonoScriptEngine.SessionKey] = session;
                var refs = new AssemblyReferences();

                refs.PathReferences.Add("System");

                // Act
                engine.Execute(Code, new string[0], refs, Enumerable.Empty <string>(), scriptPackSession);

                // Assert
                ((SessionState <Evaluator>)scriptPackSession.State[MonoScriptEngine.SessionKey]).References.PathReferences.Count().ShouldEqual(1);
            }
Exemplo n.º 4
0
 private void FixupEntryPoint()
 {
     if (_entryPoint == null)
     {
         _entryPoint = AssemblyReferences.Find(_entryPointIdentity);
     }
 }
Exemplo n.º 5
0
 public void correct_assemblies_are_found()
 {
     AssemblyReferences.ShouldHaveCountOf(3)
     .ShouldHaveAtLeastOne(x => x.AssemblyName.Name == "openfilesystem")
     .ShouldHaveAtLeastOne(x => x.AssemblyName.Name == "sharpziplib")
     .ShouldHaveAtLeastOne(x => x.AssemblyName.Name == "openwrap");
 }
Exemplo n.º 6
0
            public void ShouldSetIsPendingClosingCharToTrueIfCodeIsMissingSquareBracket(
                [Frozen] Mock <IScriptHostFactory> scriptHostFactory,
                [NoAutoProperties] RoslynScriptEngine engine,
                ScriptPackSession scriptPackSession)
            {
                // Arrange
                const string Code = "var x = new[1] { 1 }; var y = x[0";

                scriptHostFactory.Setup(f => f.CreateScriptHost(It.IsAny <IScriptPackManager>(), It.IsAny <string[]>()))
                .Returns <IScriptPackManager, string[]>((p, q) => new ScriptHost(p, new ScriptEnvironment(q)));

                var session = new SessionState <Session> {
                    Session = new ScriptEngine().CreateSession()
                };

                scriptPackSession.State[RoslynScriptEngine.SessionKey] = session;
                var refs = new AssemblyReferences();

                refs.PathReferences.Add("System");

                // Act
                var result = engine.Execute(Code, new string[0], refs, Enumerable.Empty <string>(), scriptPackSession);

                // Assert
                result.IsPendingClosingChar.ShouldBeTrue();
                result.ExpectingClosingChar.ShouldEqual(']');
            }
Exemplo n.º 7
0
            public void ShouldReturnExecuteExceptionIfCodeExecutionThrowsException(
                [Frozen] Mock <IScriptHostFactory> scriptHostFactory,
                [NoAutoProperties] MonoScriptEngine engine,
                ScriptPackSession scriptPackSession)
            {
                // Arrange
                const string Code = "throw new System.Exception(); //this should throw an Exception";

                scriptHostFactory.Setup(f => f.CreateScriptHost(It.IsAny <IScriptPackManager>(), It.IsAny <string[]>()))
                .Returns <IScriptPackManager, string[]>((p, q) => new ScriptHost(p, new ScriptEnvironment(q)));

                var session = new SessionState <Evaluator> {
                    Session = new Evaluator(new CompilerContext(new CompilerSettings(), new ConsoleReportPrinter()))
                };

                scriptPackSession.State[MonoScriptEngine.SessionKey] = session;
                var refs = new AssemblyReferences();

                refs.PathReferences.Add("System");

                // Act
                var result = engine.Execute(Code, new string[0], refs, Enumerable.Empty <string>(), scriptPackSession);

                // Assert
                result.ExecuteExceptionInfo.ShouldNotBeNull();
            }
Exemplo n.º 8
0
 /// <summary>
 /// Adds a reference to the supplied Assembly to the compilers reference collection.
 /// </summary>
 /// <param name="assembly"></param>
 public static void AddAssemblyReference(Assembly assembly)
 {
     if (!AssemblyReferences.Contains(assembly.GetName().Name))
     {
         AssemblyReferences.Add(assembly.GetName().Name);
     }
 }
Exemplo n.º 9
0
        public void ShouldCompileWhenUsingClassesFromAPassedAssemblyInstance(
            [Frozen] Mock <IScriptHostFactory> scriptHostFactory,
            [NoAutoProperties] RoslynScriptEngine engine,
            ScriptPackSession scriptPackSession)
        {
            // Arrange
            const string Code = "var x = new ScriptCs.Tests.TestMarkerClass();";

            scriptHostFactory.Setup(f => f.CreateScriptHost(It.IsAny <IScriptPackManager>(), It.IsAny <string[]>()))
            .Returns <IScriptPackManager, ScriptEnvironment>((p, q) => new ScriptHost(p, q));

            var session = new SessionState <Session> {
                Session = new ScriptEngine().CreateSession()
            };

            scriptPackSession.State[RoslynScriptEngine.SessionKey] = session;
            var refs = new AssemblyReferences();

            refs.PathReferences.Add("System");
            refs.Assemblies.Add(Assembly.GetExecutingAssembly());

            // Act
            var result = engine.Execute(Code, new string[0], refs, Enumerable.Empty <string>(), scriptPackSession);

            // Assert
            result.CompileExceptionInfo.ShouldBeNull();
            result.ExecuteExceptionInfo.ShouldBeNull();
        }
Exemplo n.º 10
0
        private static HashSet <string> GetWebsiteLocalAssemblies(EnvDTE.Project envDTEProject)
        {
            Debug.Assert(ThreadHelper.CheckAccess());

            var assemblies = new HashSet <string>(PathComparer.Default);
            AssemblyReferences references = GetAssemblyReferences(envDTEProject);

            foreach (AssemblyReference reference in references)
            {
                // For websites only include bin assemblies
                if (reference.ReferencedProject == null
                    &&
                    reference.ReferenceKind == AssemblyReferenceType.AssemblyReferenceBin
                    &&
                    File.Exists(reference.FullPath))
                {
                    assemblies.Add(reference.FullPath);
                }
            }

            // For website projects, we always add .refresh files that point to the corresponding binaries in packages. In the event of bin deployed assemblies that are also GACed,
            // the ReferenceKind is not AssemblyReferenceBin. Consequently, we work around this by looking for any additional assembly declarations specified via .refresh files.
            string envDTEProjectPath = EnvDTEProjectInfoUtility.GetFullPath(envDTEProject);

            CollectionsUtility.AddRange(assemblies, RefreshFileUtility.ResolveRefreshPaths(envDTEProjectPath));

            return(assemblies);
        }
Exemplo n.º 11
0
        /// <summary>
        ///     Adds the assembly reference.
        /// </summary>
        /// <param name="assemblyPath">The assembly path.</param>
        public void AddAssemblyReference(string assemblyPath)
        {
            Guard.ArgumentNotNullOrEmptyString(assemblyPath, "assemblyPath");

            if (VsProject != null)
            {
                if (VsProject.Object is VSProject project)
                {
                    References references = project.References;
                    references?.Add(assemblyPath);
                }
                else
                {
                    AssemblyReferences references = (VsProject.Object as VSWebSite)?.References;

                    if (references != null)
                    {
                        if (System.IO.Path.IsPathRooted(assemblyPath))
                        {
                            references.AddFromFile(assemblyPath);
                        }
                        else
                        {
                            references.AddFromGAC(assemblyPath);
                        }
                    }
                }
            }
        }
        public XamarinFormsPortableClassLibraryProject(string assemblyName) : base(assemblyName, "Library", "v4.5")
        {
            AssemblyReferences.Clear();

            this.WithNugetPackage(References.Nuget.XamarinForms_portable45);

            SupportedBuildConfigurations.Add(new SupportedBuildConfiguration("Ad-Hoc", "Any CPU"));
            SupportedBuildConfigurations.Add(new SupportedBuildConfiguration("Ad-Hoc", "iPhone"));
            SupportedBuildConfigurations.Add(new SupportedBuildConfiguration("Ad-Hoc", "iPhoneSimulator"));
            SupportedBuildConfigurations.Add(new SupportedBuildConfiguration("AppStore", "Any CPU"));
            SupportedBuildConfigurations.Add(new SupportedBuildConfiguration("AppStore", "iPhone"));
            SupportedBuildConfigurations.Add(new SupportedBuildConfiguration("AppStore", "iPhoneSimulator"));
            SupportedBuildConfigurations.Add(new SupportedBuildConfiguration("Debug", "Any CPU"));
            SupportedBuildConfigurations.Add(new SupportedBuildConfiguration("Debug", "iPhone"));
            SupportedBuildConfigurations.Add(new SupportedBuildConfiguration("Debug", "iPhoneSimulator"));
            SupportedBuildConfigurations.Add(new SupportedBuildConfiguration("Release", "Any CPU"));
            SupportedBuildConfigurations.Add(new SupportedBuildConfiguration("Release", "iPhone"));
            SupportedBuildConfigurations.Add(new SupportedBuildConfiguration("Release", "iPhoneSimulator"));

            string TargetFrameworkProfile = "Profile259";

            mTargetFrameworkProfile = TargetFrameworkProfile;

            this.AddFileToFolder(new DefaultAppXamlFile(AssemblyName));
            this.AddFileToFolder(new DefaultMainPageXamlFile(AssemblyName));
        }
            public void ShouldNotReturnCompileExceptionIfCodeDoesCompile(
                [Frozen] Mock <IScriptHostFactory> scriptHostFactory,
                [NoAutoProperties] MonoScriptEngine engine,
                ScriptPackSession scriptPackSession)
            {
                // Arrange
                const string Code = "var theNumber = 42; //this should compile";

                scriptHostFactory.Setup(f => f.CreateScriptHost(It.IsAny <IScriptPackManager>(), It.IsAny <string[]>()))
                .Returns <IScriptPackManager, string[]>((p, q) => new ScriptHost(p, new ScriptEnvironment(q, _console, _printers)));

                var session = new SessionState <Evaluator> {
                    Session = new Evaluator(new CompilerContext(new CompilerSettings(), new ConsoleReportPrinter()))
                };

                scriptPackSession.State[MonoScriptEngine.SessionKey] = session;
                var refs = new AssemblyReferences(new[] { "System" });

                // Act
                var result = engine.Execute(Code, new string[0], refs, Enumerable.Empty <string>(), scriptPackSession);

                // Assert
                result.ShouldBeType <ScriptResult>();
                result.CompileExceptionInfo.ShouldBeNull();
                result.ExecuteExceptionInfo.ShouldBeNull();
            }
Exemplo n.º 14
0
        /// <summary>导入某类型,导入程序集引用及命名空间引用,主要处理泛型</summary>
        /// <param name="item"></param>
        /// <param name="type"></param>
        void ImportType(TemplateItem item, Type type)
        {
            String name = null;

            try
            {
                name = type.Assembly.Location;
            }
            catch { }

            if (!String.IsNullOrEmpty(name) && !AssemblyReferences.Contains(name))
            {
                AssemblyReferences.Add(name);
            }
            name = type.Namespace;
            if (!item.Imports.Contains(name))
            {
                item.Imports.Add(name);
            }

            if (type.IsGenericType && !type.IsGenericTypeDefinition)
            {
                Type[] ts = type.GetGenericArguments();
                foreach (Type elm in ts)
                {
                    if (!elm.IsGenericParameter)
                    {
                        ImportType(item, elm);
                    }
                }
            }
        }
Exemplo n.º 15
0
        public void ShouldCompileWhenUsingClassesFromAPassedAssemblyInstance(
            [Frozen] Mock <IScriptHostFactory> scriptHostFactory,
            [Frozen] ScriptPackSession scriptPackSession)
        {
            // Arrange
            const string Code = "var x = new ScriptCs.Tests.TestMarkerClass();";

            scriptHostFactory.Setup(f => f.CreateScriptHost(It.IsAny <IScriptPackManager>(), It.IsAny <string[]>()))
            .Returns <IScriptPackManager, string[]>((p, q) => new ScriptHost(p, new ScriptEnvironment(q)));

            var engine  = new CSharpScriptEngine(scriptHostFactory.Object, new TestLogProvider());
            var session = new SessionState <ScriptState> {
                Session = CSharpScript.Run("")
            };

            scriptPackSession.State[CommonScriptEngine.SessionKey] = session;
            var refs = new AssemblyReferences(new[] { Assembly.GetExecutingAssembly() }, new[] { "System" });

            // Act
            var result = engine.Execute(Code, new string[0], refs, Enumerable.Empty <string>(), scriptPackSession);

            // Assert
            result.CompileExceptionInfo.ShouldBeNull();
            result.ExecuteExceptionInfo.ShouldBeNull();
        }
Exemplo n.º 16
0
            public void ShouldNotReturnReturnValueIfCodeExecutionDoesNotReturnValue(
                [Frozen] Mock <IScriptHostFactory> scriptHostFactory,
                [NoAutoProperties] RoslynScriptEngine engine,
                ScriptPackSession scriptPackSession)
            {
                // Arrange
                const string Code = "var theNumber = 42; //this should not return a value";

                scriptHostFactory.Setup(f => f.CreateScriptHost(It.IsAny <IScriptPackManager>(), It.IsAny <string[]>()))
                .Returns <IScriptPackManager, string[]>((p, q) => new ScriptHost(p, new ScriptEnvironment(q)));

                var session = new SessionState <Session> {
                    Session = new ScriptEngine().CreateSession()
                };

                scriptPackSession.State[RoslynScriptEngine.SessionKey] = session;
                var refs = new AssemblyReferences();

                refs.PathReferences.Add("System");

                // Act
                var result = engine.Execute(Code, new string[0], refs, Enumerable.Empty <string>(), scriptPackSession);

                // Assert
                result.ReturnValue.ShouldBeNull();
            }
Exemplo n.º 17
0
        private static HashSet <string> GetWebsiteLocalAssemblies(Project project, IFileSystemProvider projectFileSystemProvider)
        {
            var assemblies = new HashSet <string>(PathComparer.Default);
            AssemblyReferences references = project.GetAssemblyReferences();

            foreach (AssemblyReference reference in references)
            {
                // For websites only include bin assemblies
                if (reference.ReferencedProject == null &&
                    reference.ReferenceKind == AssemblyReferenceType.AssemblyReferenceBin &&
                    File.Exists(reference.FullPath))
                {
                    assemblies.Add(reference.FullPath);
                }
            }

            // For website projects, we always add .refresh files that point to the corresponding binaries in packages. In the event of bin deployed assemblies that are also GACed,
            // the ReferenceKind is not AssemblyReferenceBin. Consequently, we work around this by looking for any additional assembly declarations specified via .refresh files.
            string projectPath = project.GetFullPath();
            var    fileSystem  = projectFileSystemProvider.GetFileSystem(projectPath);

            assemblies.AddRange(fileSystem.ResolveRefreshPaths());

            return(assemblies);
        }
Exemplo n.º 18
0
 /// <summary>
 /// Removes the supplied assembly from the compilers reference collection.
 /// </summary>
 /// <param name="assembly"></param>
 public static void RemoveAssemblyReference(String assembly)
 {
     if (AssemblyReferences.Contains(assembly))
     {
         AssemblyReferences.Remove(assembly);
     }
 }
Exemplo n.º 19
0
            public void ShouldNotMarkSubmissionsAsIncompleteWhenRunningScript(
                [Frozen] Mock <IScriptHostFactory> scriptHostFactory,
                [NoAutoProperties] RoslynScriptEngine engine,
                ScriptPackSession scriptPackSession)
            {
                // Arrange
                const string Code = "class test {";

                var session = new SessionState <Session> {
                    Session = new ScriptEngine().CreateSession()
                };

                scriptPackSession.State[RoslynScriptEngine.SessionKey] = session;
                var refs = new AssemblyReferences();

                refs.PathReferences.Add("System");
                engine.FileName = "test.csx";

                // Act
                var result = engine.Execute(
                    Code, new string[0], refs, Enumerable.Empty <string>(), scriptPackSession);

                // Assert
                result.IsCompleteSubmission.ShouldBeTrue();
                result.CompileExceptionInfo.ShouldNotBeNull();
            }
Exemplo n.º 20
0
 /// <summary>
 /// Adds a reference to the supplied Assembly name to the compilers reference collection.
 /// </summary>
 /// <param name="assembly"></param>
 public static void AddAssemblyReference(String assembly)
 {
     if (!AssemblyReferences.Contains(assembly))
     {
         AssemblyReferences.Add(assembly);
     }
 }
Exemplo n.º 21
0
            public void ShouldSetIsPendingClosingCharToTrueIfCodeIsMissingParenthesis(
                [Frozen] Mock <IScriptHostFactory> scriptHostFactory,
                [NoAutoProperties] RoslynScriptEngine engine,
                ScriptPackSession scriptPackSession)
            {
                // Arrange
                const string Code = "System.Diagnostics.Debug.WriteLine(\"a\"";

                scriptHostFactory.Setup(f => f.CreateScriptHost(It.IsAny <IScriptPackManager>(), It.IsAny <string[]>()))
                .Returns <IScriptPackManager, string[]>((p, q) => new ScriptHost(p, new ScriptEnvironment(q)));

                var session = new SessionState <Session> {
                    Session = new ScriptEngine().CreateSession()
                };

                scriptPackSession.State[RoslynScriptEngine.SessionKey] = session;
                var refs = new AssemblyReferences();

                refs.PathReferences.Add("System");

                // Act
                var result = engine.Execute(Code, new string[0], refs, Enumerable.Empty <string>(), scriptPackSession);

                // Assert
                result.IsCompleteSubmission.ShouldBeFalse();
            }
            public void ShouldReturnReturnValueIfCodeExecutionReturnsValue(
                [Frozen] Mock <IScriptHostFactory> scriptHostFactory,
                [NoAutoProperties] MonoScriptEngine engine,
                ScriptPackSession scriptPackSession)
            {
                // Mono doesn't support comments after evals as well as Roslyn
                const string Code = "\"Hello\"";  //this should return \"Hello\"";

                // Arrange
                scriptHostFactory.Setup(f => f.CreateScriptHost(It.IsAny <IScriptPackManager>(), It.IsAny <string[]>()))
                .Returns <IScriptPackManager, string[]>((p, q) => new ScriptHost(p, new ScriptEnvironment(q, _console, _printers)));

                var session = new SessionState <Evaluator> {
                    Session = new Evaluator(new CompilerContext(new CompilerSettings(), new ConsoleReportPrinter()))
                };

                scriptPackSession.State[MonoScriptEngine.SessionKey] = session;
                var refs = new AssemblyReferences(new[] { "System" });

                // Act
                var result = engine.Execute(Code, new string[0], refs, Enumerable.Empty <string>(), scriptPackSession);

                // Assert
                result.ReturnValue.ShouldEqual("Hello");
            }
Exemplo n.º 23
0
        public ScriptExecutor(
            IFileSystem fileSystem,
            IFilePreProcessor filePreProcessor,
            IScriptEngine scriptEngine,
            ILogProvider logProvider,
            IScriptLibraryComposer composer,
            IScriptInfo scriptInfo)
        {
            Guard.AgainstNullArgument("fileSystem", fileSystem);
            Guard.AgainstNullArgumentProperty("fileSystem", "BinFolder", fileSystem.BinFolder);
            Guard.AgainstNullArgumentProperty("fileSystem", "DllCacheFolder", fileSystem.DllCacheFolder);
            Guard.AgainstNullArgument("filePreProcessor", filePreProcessor);
            Guard.AgainstNullArgument("scriptEngine", scriptEngine);
            Guard.AgainstNullArgument("logProvider", logProvider);
            Guard.AgainstNullArgument("composer", composer);
            Guard.AgainstNullArgument("scriptInfo", scriptInfo);

            References            = new AssemblyReferences(new[] { GetAssemblyFromName("System.Runtime") }, DefaultReferences);
            Namespaces            = new ReadOnlyCollection <string>(DefaultNamespaces);
            FileSystem            = fileSystem;
            FilePreProcessor      = filePreProcessor;
            ScriptEngine          = scriptEngine;
            _log                  = logProvider.ForCurrentType();
            ScriptLibraryComposer = composer;
            ScriptInfo            = scriptInfo;
        }
Exemplo n.º 24
0
 private void AddDefaultAssemblyReferences()
 {
     AssemblyReferences.Add(Core.References.Assemblies.System);
     AssemblyReferences.Add(Core.References.Assemblies.System_Xml);
     AssemblyReferences.Add(Core.References.Assemblies.System_Core);
     AssemblyReferences.Add(Xamarin.References.Assemblies.Xamarin_iOS);
 }
Exemplo n.º 25
0
        public virtual void Reset()
        {
            References = new AssemblyReferences(DefaultReferences);
            Namespaces.Clear();
            ImportNamespaces(DefaultNamespaces);

            ScriptPackSession.State.Clear();
        }
 private void AddDefaultAssemblyReferences()
 {
     AssemblyReferences.Add(SlnGen.Xamarin.References.Assemblies.Mono_Android);
     AssemblyReferences.Add(SlnGen.Core.References.Assemblies.System);
     AssemblyReferences.Add(SlnGen.Core.References.Assemblies.System_Core);
     AssemblyReferences.Add(SlnGen.Core.References.Assemblies.System_Xml_Linq);
     AssemblyReferences.Add(SlnGen.Core.References.Assemblies.System_Xml);
 }
        public AssemblyReferencesViewModel(AssemblyReferences assemblyReferences)
        {
            this.assemblyReferences = assemblyReferences;
            DisplayName             = "References";

            assemblyReferences.CollectionChanged += AssemblyReferencesOnCollectionChanged;
            Reload();
        }
        public AssemblyReferencesViewModel(AssemblyReferences assemblyReferences)
        {
            this.assemblyReferences = assemblyReferences;
            DisplayName = "References";

            assemblyReferences.CollectionChanged += AssemblyReferencesOnCollectionChanged;
            Reload();
        }
Exemplo n.º 29
0
        private Assembly PluginManagerOnAssemblyResolve(object sender, ResolveEventArgs args)
        {
            try
            {
                //  AssemblyName name = new AssemblyName(args.Name);
                AssemblyNameReference name = AssemblyNameReference.Parse(args.Name);
                if (IsLoaded(name, out Assembly loadedPluginAssembly))
                {
                    lock (_pluginLock)
                    {
                        if (!AssemblyReferences.ContainsKey(name.Name))
                        {
                            AssemblyReferences.TryAdd(name.Name, loadedPluginAssembly);
                        }
                    }

                    return(loadedPluginAssembly);
                }

                string rootPath = "";
                if (args.RequestingAssembly != null && !string.IsNullOrWhiteSpace(args.RequestingAssembly.Location))
                {
                    rootPath = Path.GetDirectoryName(args.RequestingAssembly.Location);
                }

                Assembly result = null;
                if (TryFindAssemblyPath(name, rootPath, out string resultPath))
                {
                    result = Assembly.LoadFile(resultPath);
                }
                else
                {
                    var assembly = AppDomain.CurrentDomain.GetAssemblies()
                                   .FirstOrDefault(x => x.GetName().Name == args.Name);
                    if (assembly != null)
                    {
                        result = assembly;
                    }
                }

                if (result != null)
                {
                    AssemblyReferences.TryAdd(name.Name, result);
                }
                else
                {
                    Log.Warn($"Failed to resolve assembly: {name}");
                }

                return(result);
            }
            catch (Exception ex)
            {
                Log.Error($"Failed to resolve!", ex);
                return(null);
            }
        }
Exemplo n.º 30
0
 /// <summary>
 /// Adds the default assembly references.
 /// This method is called in the project constructor. Override to customize.
 /// </summary>
 protected virtual void AddDefaultAssemblyReferences()
 {
     AssemblyReferences.Add(References.Assemblies.System);
     AssemblyReferences.Add(References.Assemblies.System_Core);
     AssemblyReferences.Add(References.Assemblies.System_Xml_Linq);
     AssemblyReferences.Add(References.Assemblies.Microsoft_CSharp);
     AssemblyReferences.Add(References.Assemblies.System_Data);
     AssemblyReferences.Add(References.Assemblies.System_Net_Http);
     AssemblyReferences.Add(References.Assemblies.System_Xml);
 }
Exemplo n.º 31
0
        /// <summary>
        /// Defines a new .NET module that references mscorlib version 4.0.0.0.
        /// </summary>
        /// <param name="name">The name of the module.</param>
        public ModuleDefinition(string name)
            : this(new MetadataToken(TableIndex.Module, 0))
        {
            Name = name;

            CorLibTypeFactory = CorLibTypeFactory.CreateMscorlib40TypeFactory(this);
            AssemblyReferences.Add((AssemblyReference)CorLibTypeFactory.CorLibScope);
            MetadataResolver = new DefaultMetadataResolver(new DotNetFrameworkAssemblyResolver());

            TopLevelTypes.Add(new TypeDefinition(null, "<Module>", 0));
        }
Exemplo n.º 32
0
        internal Workspace(string cshellFile)
        {
            CShellFile = Path.GetFullPath(cshellFile);
            CShellFileName = Path.GetFileNameWithoutExtension(cshellFile);
            this.engine = new ScriptingEngine();

            assemblies = new AssemblyReferences(engine);
            //files = new FileReferences("Files");
            RootFolder = Path.GetDirectoryName(cshellFile);
            RootFolder = Path.GetFullPath(RootFolder);

            //make sure we add the CShell assembly
            var cshellCoreAssembly = Assembly.GetExecutingAssembly();
            assemblies.Add(new AssemblyReference(cshellCoreAssembly) { Removable = false });
            engine.Evaluate("using CShell; using CShell.Sinks;");
        }
Exemplo n.º 33
0
 public AssemblyReferenceViewModel(AssemblyReference assemblyReference, AssemblyReferences references)
 {
     this.assemblyReference = assemblyReference;
     this.references = references;
 }
Exemplo n.º 34
0
 public AddReferencesResult(AssemblyReferences references, string file)
 {
     this.references = references;
     this.files = new [] {file};
 }
Exemplo n.º 35
0
 public AddReferencesResult(AssemblyReferences references, IEnumerable<string> files)
 {
     this.references = references;
     this.files = files;
 }
Exemplo n.º 36
0
 public AddReferencesResult(AssemblyReferences references, IEnumerable<AssemblyName> assemblyNames)
 {
     this.references = references;
     this.assemblyNames = assemblyNames;
 }
Exemplo n.º 37
0
 public AddReferencesResult(AssemblyReferences references, AssemblyName assemblyName)
 {
     this.references = references;
     this.assemblyNames = new []{assemblyName};
 }