示例#1
0
        public static void PreloadFromHtmlList(string filename)
        {
            if (versions.Count == 0)
            {
                if (File.Exists(filename))
                {
                    string[] lines = File.ReadAllLines(filename);
                    CompilerVersion ver;
                    for (int i = 0; i < lines.Length; i++)
                    {
                        int idx1 = lines[i].IndexOf("dmd.1.");
                        int idx2 = lines[i].IndexOf("dmd.2.");
                        if (idx1 > 0 || idx2 > 0)
                        {
                            ver = new CompilerVersion();
                            if (ver.FromHtml(lines[i]))
                            {
                                if (!versions.ContainsKey(ver.Version) || versions[ver.Version].SubVersion < ver.SubVersion)
                                {
                                    versions[ver.Version] = ver;
                                }
                            }
                        }
                    }

                    if (!DataFile.Exists && versions.Count == 2)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (CompilerVersion v in versions.Values) sb.Append(v.ToString()).Append("\r\n");
                        File.WriteAllText(DataFile.FullName, sb.ToString());
                        DataFile.Refresh();
                    }
                }
            }
        }
示例#2
0
		public static CodeDomProvider CreateProvider(Language language, CompilerVersion version)
		{
			var providerOptions = GetProviderOptions(version);
			var provider = CodeDomProvider.CreateProvider(language.ToString(), providerOptions);

			return provider;
		}
示例#3
0
        public override void UpgradeProject(CompilerVersion newVersion, TargetFramework newFramework)
        {
            PortableTargetFramework newFx = newFramework as PortableTargetFramework;

            if (newFx != null)
            {
                // Convert to portable library
                Core.AnalyticsMonitorService.TrackFeature(GetType(), "ConvertToPortableLibrary");
                var project = (CompilableProject)Project;
                lock (project.SyncRoot) {
                    if (newVersion != null && GetAvailableCompilerVersions().Contains(newVersion))
                    {
                        project.SetToolsVersion(newVersion.MSBuildVersion.Major + "." + newVersion.MSBuildVersion.Minor);
                    }
                    project.SetProperty(null, null, "TargetFrameworkProfile", newFx.TargetFrameworkProfile, PropertyStorageLocations.Base, true);
                    project.SetProperty(null, null, "TargetFrameworkVersion", newFx.TargetFrameworkVersion, PropertyStorageLocations.Base, true);
                    // Convert <Imports>
                    project.PerformUpdateOnProjectFile(
                        delegate {
                        foreach (var import in project.MSBuildProjectFile.Imports)
                        {
                            if (import.Project.EndsWith(PortableLibraryProjectBehavior.NormalCSharpTargets, StringComparison.OrdinalIgnoreCase))
                            {
                                import.Project = PortableLibraryProjectBehavior.PortableTargetsPath + PortableLibraryProjectBehavior.PortableCSharpTargets;
                                break;
                            }
                            else if (import.Project.EndsWith(PortableLibraryProjectBehavior.NormalVBTargets, StringComparison.OrdinalIgnoreCase))
                            {
                                import.Project = PortableLibraryProjectBehavior.PortableTargetsPath + PortableLibraryProjectBehavior.PortableVBTargets;
                                break;
                            }
                        }
                    });
                    // Remove references
                    foreach (var referenceItem in project.GetItemsOfType(ItemType.Reference).ToArray())
                    {
                        // get short assembly name:
                        string assemblyName = referenceItem.Include;
                        if (assemblyName.IndexOf(',') >= 0)
                        {
                            assemblyName = assemblyName.Substring(0, assemblyName.IndexOf(','));
                        }
                        assemblyName += ",";
                        if (KnownFrameworkAssemblies.FullAssemblyNames.Any(fullName => fullName.StartsWith(assemblyName, StringComparison.OrdinalIgnoreCase)))
                        {
                            // If it's a framework assembly, remove the reference
                            // (portable libraries automatically reference all available framework assemblies)
                            ProjectService.RemoveProjectItem(project, referenceItem);
                        }
                    }
                    project.AddProjectType(ProjectTypeGuids.PortableLibrary);
                    project.Save();
                    ProjectBrowserPad.RefreshViewAsync();
                }
            }
            else
            {
                base.UpgradeProject(newVersion, newFramework);
            }
        }
示例#4
0
 public virtual void UpgradeProject(CompilerVersion newVersion, TargetFramework newFramework)
 {
     if (!IsReadOnly)
     {
         GetOrCreateBehavior().UpgradeProject(newVersion, newFramework);
     }
 }
示例#5
0
 public virtual void UpgradeProject(CompilerVersion newVersion, TargetFramework newFramework)
 {
     if (this.next != null)
     {
         next.UpgradeProject(newVersion, newFramework);
     }
 }
示例#6
0
        public override void UpgradeProject(CompilerVersion newVersion, TargetFramework newFramework)
        {
            if (!Project.ReadOnly)
            {
                lock (Project.SyncRoot)
                {
                    TargetFramework oldFramework = Project.CurrentTargetFramework;
                    if (newVersion != null && GetAvailableCompilerVersions().Contains(newVersion))
                    {
                        Project.SetToolsVersion(newVersion.MSBuildVersion.Major + "." + newVersion.MSBuildVersion.Minor);
                    }
                    if (newFramework != null)
                    {
                        UpdateAppConfig(newFramework);

                        ClientProfileTargetFramework clientProfile = newFramework as ClientProfileTargetFramework;
                        if (clientProfile != null)
                        {
                            newFramework = clientProfile.FullFramework;
                            ((MSBuildBasedProject)Project).SetProperty(null, null, "TargetFrameworkProfile", "Client", PropertyStorageLocations.Base, true);
                        }
                        else
                        {
                            ((MSBuildBasedProject)Project).SetProperty(null, null, "TargetFrameworkProfile", "", PropertyStorageLocations.Base, true);
                        }
                        ((MSBuildBasedProject)Project).SetProperty(null, null, "TargetFrameworkVersion", newFramework.Name, PropertyStorageLocations.Base, true);

                        if (oldFramework is ClientProfileTargetFramework)
                        {
                            oldFramework = ((ClientProfileTargetFramework)oldFramework).FullFramework;
                        }

                        if (oldFramework != null && !oldFramework.IsBasedOn(TargetFramework.Net35) && newFramework.IsBasedOn(TargetFramework.Net35))
                        {
                            AddDotnet35References();
                        }
                        else if (oldFramework != null && oldFramework.IsBasedOn(TargetFramework.Net35) && !newFramework.IsBasedOn(TargetFramework.Net35))
                        {
                            RemoveDotnet35References();
                        }

                        if (oldFramework != null && !oldFramework.IsBasedOn(TargetFramework.Net40) && newFramework.IsBasedOn(TargetFramework.Net40))
                        {
                            AddDotnet40References();
                        }
                        else if (oldFramework != null && oldFramework.IsBasedOn(TargetFramework.Net40) && !newFramework.IsBasedOn(TargetFramework.Net40))
                        {
                            RemoveDotnet40References();
                        }
                    }
                    AddOrRemoveExtensions();
                    Project.Save();
                    //TODO: Uncomment
                    // ResXConverter.UpdateResourceFiles(Project);
                }
            }
        }
示例#7
0
		public static Dictionary<string, string> GetProviderOptions(CompilerVersion version)
		{
			Dictionary<string, string> providerOptions = new Dictionary<string, string>();

			var str = GetCompilerVersion(version);
			if (str != null)
				providerOptions.Add("CompilerVersion", str);

			return providerOptions;
		}
示例#8
0
    private static Process CreateCompilerProcess(CompilerVersion version, string unityEditorDataDir, string responseFile)
    {
        string processPath;
        string processArguments;

        var systemDllPath     = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/System.dll");
        var systemCoreDllPath = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/System.Core.dll");
        var systemXmlDllPath  = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/System.Xml.dll");

        switch (version)
        {
        case CompilerVersion.Version3:
            processPath = Path.Combine(unityEditorDataDir, @"Mono/bin/mono.exe");
            var compilerPath = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/gmcs.exe");
            processArguments = $"\"{compilerPath}\" {responseFile}";
            break;

        case CompilerVersion.Version5:
            processPath      = Path.Combine(unityEditorDataDir, @"MonoBleedingEdge/lib/mono/4.5/mcs.exe");
            processArguments = $"-sdk:2 -langversion:Future -r:\"{systemCoreDllPath}\" {responseFile}";
            break;

        case CompilerVersion.Version6Mono:
            processPath      = Path.Combine(Directory.GetCurrentDirectory(), "mcs.exe");
            processArguments = $"-sdk:2 -r:\"{systemCoreDllPath}\" {responseFile}";
            break;

        case CompilerVersion.Version6Microsoft:
            processPath = Path.Combine(Directory.GetCurrentDirectory(), @"Roslyn/csc.exe");
            var mscorlib = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/mscorlib.dll");
            processArguments =
                $"-nostdlib+ -noconfig -r:\"{mscorlib}\" -r:\"{systemDllPath}\" -r:\"{systemCoreDllPath}\" -r:\"{systemXmlDllPath}\" {responseFile}";
            break;

        default:
            throw new ArgumentOutOfRangeException(nameof(version), version, null);
        }

        var process = new Process
        {
            StartInfo =
            {
                FileName               = processPath,
                Arguments              = processArguments,
                RedirectStandardError  = true,
                RedirectStandardOutput = true,
                UseShellExecute        = false
            }
        };

        process.OutputDataReceived += Process_OutputDataReceived;
        process.ErrorDataReceived  += Process_ErrorDataReceived;

        return(process);
    }
示例#9
0
        public virtual void UpgradeProject(CompilerVersion newVersion, TargetFramework newFramework)
        {
            if (!this.ReadOnly)
            {
                lock (SyncRoot) {
                    TargetFramework oldFramework = this.CurrentTargetFramework;
                    if (newVersion != null && GetAvailableCompilerVersions().Contains(newVersion))
                    {
                        SetToolsVersion(newVersion.MSBuildVersion.Major + "." + newVersion.MSBuildVersion.Minor);
                    }
                    if (newFramework != null)
                    {
                        UpdateAppConfig(newFramework);

                        ClientProfileTargetFramework clientProfile = newFramework as ClientProfileTargetFramework;
                        if (clientProfile != null)
                        {
                            newFramework = clientProfile.FullFramework;
                            SetProperty(null, null, "TargetFrameworkProfile", "Client", PropertyStorageLocations.Base, true);
                        }
                        else
                        {
                            SetProperty(null, null, "TargetFrameworkProfile", "", PropertyStorageLocations.Base, true);
                        }
                        SetProperty(null, null, "TargetFrameworkVersion", newFramework.Name, PropertyStorageLocations.Base, true);

                        if (oldFramework is ClientProfileTargetFramework)
                        {
                            oldFramework = ((ClientProfileTargetFramework)oldFramework).FullFramework;
                        }

                        if (oldFramework != null && !oldFramework.IsBasedOn(TargetFramework.Net35) && newFramework.IsBasedOn(TargetFramework.Net35))
                        {
                            AddDotnet35References();
                        }
                        else if (oldFramework != null && oldFramework.IsBasedOn(TargetFramework.Net35) && !newFramework.IsBasedOn(TargetFramework.Net35))
                        {
                            RemoveDotnet35References();
                        }

                        if (oldFramework != null && !oldFramework.IsBasedOn(TargetFramework.Net40) && newFramework.IsBasedOn(TargetFramework.Net40))
                        {
                            AddDotnet40References();
                        }
                        else if (oldFramework != null && oldFramework.IsBasedOn(TargetFramework.Net40) && !newFramework.IsBasedOn(TargetFramework.Net40))
                        {
                            RemoveDotnet40References();
                        }
                    }
                    AddOrRemoveExtensions();
                    Save();
                }
            }
        }
示例#10
0
        CompileFromFile(
            String InSourcePath, ExecutableType InExecType,
            GenerateAssemblyIn InGenerateIn,
            CompilerVersion CompilerVersion)
        {
            List <string>     addnReferencedAssemblies = new List <string>();
            AcCompilerResults results = Compile_Actual(
                InSourcePath, null, InExecType, InGenerateIn,
                addnReferencedAssemblies,
                CompilerVersion);

            return(results);
        }
示例#11
0
        CompileFromSource(
            string InSourceLines, ExecutableType InExecType,
            GenerateAssemblyIn InGenerateIn,
            List <string> InAddnReferencedAssemblies,
            CompilerVersion CompilerVersion)
        {
            AcCompilerResults results = Compile_Actual(
                null, InSourceLines, InExecType, InGenerateIn,
                InAddnReferencedAssemblies,
                CompilerVersion);

            return(results);
        }
示例#12
0
        public static string ToCodeDomString(this CompilerVersion CompilerVersion)
        {
            switch (CompilerVersion)
            {
            case Enums.CompilerVersion.v35:
                return("v3.5");

            case Enums.CompilerVersion.v40:
                return("v4.0");

            default:
                throw new ApplicationException("unsupported CompilerVersion " + CompilerVersion.ToString());
            }
        }
示例#13
0
        public override void UpgradeProject(CompilerVersion newVersion, TargetFramework newFramework)
        {
            var project = (CompilableProject)Project;
            var newFx   = newFramework as PortableTargetFramework;

            if (newFramework != null && newFx == null)
            {
                // convert to normal .NET project (not portable)
                SD.AnalyticsMonitor.TrackFeature(GetType(), "DowngradePortableLibrary");
                project.PerformUpdateOnProjectFile(
                    delegate {
                    foreach (var import in project.MSBuildProjectFile.Imports)
                    {
                        if (import.Project.EndsWith(PortableCSharpTargets, StringComparison.OrdinalIgnoreCase))
                        {
                            import.Project = NormalTargetsPath + NormalCSharpTargets;
                            break;
                        }
                        else if (import.Project.EndsWith(PortableVBTargets, StringComparison.OrdinalIgnoreCase))
                        {
                            import.Project = NormalTargetsPath + NormalVBTargets;
                            break;
                        }
                    }
                });
                project.RemoveProjectType(ProjectTypeGuids.PortableLibrary);
                AddReferenceIfNotExists("System");
                AddReferenceIfNotExists("System.Xml");
                if (newFramework.Version >= Versions.V3_5)
                {
                    AddReferenceIfNotExists("System.Core");
                }
                base.UpgradeProject(newVersion, newFramework);
                return;
            }
            lock (project.SyncRoot) {
                if (newVersion != null && GetAvailableCompilerVersions().Contains(newVersion))
                {
                    project.ToolsVersion = newVersion.MSBuildVersion.Major + "." + newVersion.MSBuildVersion.Minor;
                }
                if (newFx != null)
                {
                    project.SetProperty(null, null, "TargetFrameworkProfile", newFx.TargetFrameworkProfile, PropertyStorageLocations.Base, true);
                    project.SetProperty(null, null, "TargetFrameworkVersion", newFx.TargetFrameworkVersion, PropertyStorageLocations.Base, true);
                }
                project.Save();
                ProjectBrowserPad.RefreshViewAsync();
            }
        }
        public override void UpgradeProject(CompilerVersion newVersion, TargetFramework newFramework)
        {
//			PortableTargetFramework newFx = newFramework as PortableTargetFramework;
//			if (newFx != null) {
//				// Convert to portable library
//				SD.AnalyticsMonitor.TrackFeature(GetType(), "ConvertToPortableLibrary");
//				var project = (CompilableProject)Project;
//				lock (project.SyncRoot) {
//					var oldTargetFramework = project.CurrentTargetFramework;
//					if (newVersion != null && GetAvailableCompilerVersions().Contains(newVersion)) {
//						project.ToolsVersion = newVersion.MSBuildVersion.Major + "." + newVersion.MSBuildVersion.Minor;
//					}
//					project.SetProperty(null, null, "TargetFrameworkProfile", newFx.TargetFrameworkProfile, PropertyStorageLocations.Base, true);
//					project.SetProperty(null, null, "TargetFrameworkVersion", newFx.TargetFrameworkVersion, PropertyStorageLocations.Base, true);
//					// Convert <Imports>
//					project.PerformUpdateOnProjectFile(
//						delegate {
//							foreach (var import in project.MSBuildProjectFile.Imports) {
//								if (import.Project.EndsWith(PortableLibraryProjectBehavior.NormalCSharpTargets, StringComparison.OrdinalIgnoreCase)) {
//									import.Project = PortableLibraryProjectBehavior.PortableTargetsPath + PortableLibraryProjectBehavior.PortableCSharpTargets;
//									break;
//								} else if (import.Project.EndsWith(PortableLibraryProjectBehavior.NormalVBTargets, StringComparison.OrdinalIgnoreCase)) {
//									import.Project = PortableLibraryProjectBehavior.PortableTargetsPath + PortableLibraryProjectBehavior.PortableVBTargets;
//									break;
//								}
//							}
//						});
//					// Remove references
//					foreach (var referenceItem in project.GetItemsOfType(ItemType.Reference).ToArray()) {
//						// get short assembly name:
//						string assemblyName = referenceItem.Include;
//						if (assemblyName.IndexOf(',') >= 0)
//							assemblyName = assemblyName.Substring(0, assemblyName.IndexOf(','));
//						if (oldTargetFramework.ReferenceAssemblies.Any(fullName => string.Equals(fullName.ShortName, assemblyName, StringComparison.OrdinalIgnoreCase))) {
//							// If it's a framework assembly, remove the reference
//							// (portable libraries automatically reference all available framework assemblies)
//							ProjectService.RemoveProjectItem(project, referenceItem);
//						}
//					}
//					project.AddProjectType(ProjectTypeGuids.PortableLibrary);
//					project.Save();
//					ProjectBrowserPad.RefreshViewAsync();
//				}
//			} else {
//				base.UpgradeProject(newVersion, newFramework);
//			}
        }
示例#15
0
		public static string GetCompilerVersion(CompilerVersion version)
		{
			// attach to enum via description attribute instead... ?

			switch (version)
			{
				case CompilerVersion.v20:
					return "v2.0";
				case CompilerVersion.v30:
					return "v3.0";
				case CompilerVersion.v35:
					return "v3.5";
				case CompilerVersion.v40:
					return "v4.0";
				default:
					return null;
			}
		}
示例#16
0
        public override void UpgradeProject(CompilerVersion newVersion, TargetFramework newFramework)
        {
            if (!Project.IsReadOnly)
            {
                lock (Project.SyncRoot) {
                    TargetFramework oldFramework = Project.CurrentTargetFramework;
                    if (newVersion != null && GetAvailableCompilerVersions().Contains(newVersion))
                    {
                        Project.ToolsVersion = newVersion.MSBuildVersion.Major + "." + newVersion.MSBuildVersion.Minor;
                    }
                    if (newFramework != null)
                    {
                        UpdateAppConfig(newFramework);

                        ((MSBuildBasedProject)Project).SetProperty(null, null, "TargetFrameworkVersion", newFramework.TargetFrameworkVersion, PropertyStorageLocations.Base, true);
                        ((MSBuildBasedProject)Project).SetProperty(null, null, "TargetFrameworkProfile", newFramework.TargetFrameworkProfile, PropertyStorageLocations.Base, true);

                        if (oldFramework != null && oldFramework.Version < Versions.V3_5 && newFramework.Version >= Versions.V3_5)
                        {
                            AddDotnet35References();
                        }
                        else if (oldFramework != null && oldFramework.Version >= Versions.V3_5 && newFramework.Version < Versions.V3_5)
                        {
                            RemoveDotnet35References();
                        }

                        if (oldFramework != null && oldFramework.Version < Versions.V4_0 && newFramework.Version >= Versions.V4_0)
                        {
                            AddDotnet40References();
                        }
                        else if (oldFramework != null && oldFramework.Version >= Versions.V4_0 && newFramework.Version < Versions.V4_0)
                        {
                            RemoveDotnet40References();
                        }
                    }
                    AddOrRemoveExtensions();
                    Project.Save();
                    ResXConverter.UpdateResourceFiles(Project);
                }
            }
        }
示例#17
0
        public static void PreloadFromHtmlList(string filename)
        {
            if (versions.Count == 0)
            {
                if (File.Exists(filename))
                {
                    string[]        lines = File.ReadAllLines(filename);
                    CompilerVersion ver;
                    for (int i = 0; i < lines.Length; i++)
                    {
                        int idx1 = lines[i].IndexOf("dmd.1.");
                        int idx2 = lines[i].IndexOf("dmd.2.");
                        if (idx1 > 0 || idx2 > 0)
                        {
                            ver = new CompilerVersion();
                            if (ver.FromHtml(lines[i]))
                            {
                                if (!versions.ContainsKey(ver.Version) || versions[ver.Version].SubVersion < ver.SubVersion)
                                {
                                    versions[ver.Version] = ver;
                                }
                            }
                        }
                    }

                    if (!DataFile.Exists && versions.Count == 2)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (CompilerVersion v in versions.Values)
                        {
                            sb.Append(v.ToString()).Append("\r\n");
                        }
                        File.WriteAllText(DataFile.FullName, sb.ToString());
                        DataFile.Refresh();
                    }
                }
            }
        }
示例#18
0
 public virtual bool IsCompatibleWith(CompilerVersion compilerVersion)
 {
     return(MinimumMSBuildVersion <= compilerVersion.MSBuildVersion);
 }
示例#19
0
	private static Process CreateCompilerProcess(CompilerVersion version, string unityEditorDataDir, string responseFile)
	{
		string processPath;
		string processArguments;

		var systemDllPath = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/System.dll");
		var systemCoreDllPath = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/System.Core.dll");
		var systemXmlDllPath = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/System.Xml.dll");

		switch (version)
		{
			case CompilerVersion.Version3:
				processPath = Path.Combine(unityEditorDataDir, @"Mono/bin/mono.exe");
				var compilerPath = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/gmcs.exe");
				processArguments = $"\"{compilerPath}\" {responseFile}";
				break;

			case CompilerVersion.Version5:
				processPath = Path.Combine(unityEditorDataDir, @"MonoBleedingEdge/lib/mono/4.5/mcs.exe");
				processArguments = $"-sdk:2 -langversion:Future -r:\"{systemCoreDllPath}\" {responseFile}";
				break;

			case CompilerVersion.Version6Mono:
				processPath = Path.Combine(Directory.GetCurrentDirectory(), "mcs.exe");
				processArguments = $"-sdk:2 -r:\"{systemCoreDllPath}\" {responseFile}";
				break;

			case CompilerVersion.Version6Microsoft:
				processPath = Path.Combine(Directory.GetCurrentDirectory(), @"Roslyn/csc.exe");
				var mscorlib = Path.Combine(unityEditorDataDir, @"Mono/lib/mono/2.0/mscorlib.dll");
				processArguments =
					$"-nostdlib+ -noconfig -r:\"{mscorlib}\" -r:\"{systemDllPath}\" -r:\"{systemCoreDllPath}\" -r:\"{systemXmlDllPath}\" {responseFile}";
				break;

			default:
				throw new ArgumentOutOfRangeException(nameof(version), version, null);
		}

		var process = new Process
		{
			StartInfo =
						  {
							  FileName = processPath,
							  Arguments = processArguments,
							  RedirectStandardError = true,
							  RedirectStandardOutput = true,
							  UseShellExecute = false
						  }
		};

		process.OutputDataReceived += Process_OutputDataReceived;
		process.ErrorDataReceived += Process_ErrorDataReceived;

		return process;
	}
示例#20
0
        private static void GetDMDInfo()
        {
            if (versions.Count == 0)
            {
                bool hasError = false;
                if (DataFile.Exists)
                {
                    string[] lines = File.ReadAllLines(DataFile.FullName);
                    CompilerVersion ver;
                    for (int i = 0; i < lines.Length; i++)
                    {
                        ver = new CompilerVersion();
                        if (ver.FromString(lines[i]))
                            versions[ver.Version] = ver;
                        else
                            hasError = true;
                        if (ver.HasError) hasError = true;
                    }

                    if (hasError)
                    {
                        DataFile.CopyTo(DataFile.FullName + "." + DateTime.Now.ToBinary() + ".log");
                        DataFile.Delete();
                        DataFile.Refresh();
                    }
                }

                if (!DataFile.Exists)
                {
                    CompilerVersion ver1 = new CompilerVersion(), ver2 = new CompilerVersion();
                    int latestVer1 = 56, latestVer2 = 41, subVersion = 0;
                    string url1 = "", url2 = "";
                    ver1.Version = 1;
                    ver2.Version = 2;
                    try
                    {
                        FtpWebRequest request = WebRequest.Create(DIGITAL_MARS_FTP) as FtpWebRequest;
                        request.Method = WebRequestMethods.Ftp.ListDirectory;

                        using (FtpWebResponse response = request.GetResponse() as FtpWebResponse)
                        {
							/*
							 * Enum all files in the ftp root. While scan through all of them, extract the version number, get the highest version number, and finally download the appropriate zip
							 */
                            Console.WriteLine(response.StatusDescription);
                            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                            {
                                while (!reader.EndOfStream)
                                {
                                    string line = reader.ReadLine();
                                    if (line.StartsWith("dmd.1."))
                                    {
                                        string[] tokens = line.Split('.');
                                        if (tokens.Length > 2 && !int.TryParse(tokens[2], out subVersion)) subVersion = latestVer1;

                                        if (tokens[tokens.Length - 1].Equals("zip", StringComparison.CurrentCultureIgnoreCase))
                                        {
                                            if (latestVer1 < subVersion)
                                            {
                                                latestVer1 = subVersion;
                                                url1 = DIGITAL_MARS_HTTP + line;
                                            }
                                        }
                                    }
                                    else if (line.StartsWith("dmd.2."))
                                    {
                                        string[] tokens = line.Split('.');
                                        if (tokens.Length > 2 && !int.TryParse(tokens[2], out subVersion)) subVersion = latestVer2;

                                        if (tokens[tokens.Length - 1].Equals("zip", StringComparison.CurrentCultureIgnoreCase))
                                        {
                                            if (latestVer2 < subVersion)
                                            {
                                                latestVer2 = subVersion;
                                                url2 = DIGITAL_MARS_HTTP + line;
                                            }
                                        }
                                    }
                                }
                            }
                            response.Close();
                        }
                        ver1.SubVersion = latestVer1;
                        ver1.Url = url1;
                        ver2.SubVersion = latestVer2;
                        ver2.Url = url2;
                    }
                    catch (Exception ex)
                    {
                        ver1.Error = ERROR_PREFIX + ex.Message + Environment.NewLine + ex.StackTrace;
                        ver2.Error = ERROR_PREFIX + ex.Message + Environment.NewLine + ex.StackTrace;
                    }
                    versions[1] = ver1;
                    versions[2] = ver2;

                    StringBuilder sb = new StringBuilder();
                    foreach (CompilerVersion ver in versions.Values) sb.Append(ver.ToString()).Append("\r\n");
                    File.WriteAllText(DataFile.FullName, sb.ToString());
                }
            }
        }
示例#21
0
 public CSharpProjectCompiler(ILogger logger, IEnumerable<string> referencedAssemblies, CompilerVersion compilerVersion)
 {
     this.logger = logger;
     codeProvider = new CSharpCodeProvider(new Dictionary<string, string> {{"CompilerVersion", compilerVersion.CodePoviderName}});
     this.referencedAssemblies = referencedAssemblies.Union(DefaultAssemblies);
 }
示例#22
0
 public override void UpgradeProject(CompilerVersion newVersion, TargetFramework newFramework)
 {
     throw new NotSupportedException();
 }
示例#23
0
        Compile_Actual(
            string InSourcePath,
            string InSourceLines,
            ExecutableType InExecType,
            GenerateAssemblyIn InGenerateIn,
            List <string> InAddnReferencedAssemblies,
            CompilerVersion CompilerVersion
            )
        {
            System.Reflection.Assembly assem = null;
            List <string>   results          = new List <string>();
            CodeDomProvider provider         = null;
            // Microsoft.CSharp.CSharpCodeProvider provider = null;
            string               exeName = null;
            WipCompilerResults   wipCr   = new WipCompilerResults();
            AcCompilerParameters cp      = new AcCompilerParameters();

            // compile from lines in a source array or source file
            if (InSourceLines != null)
            {
                cp.SourceLines = InSourceLines;
            }
            else
            {
                cp.SourceFileInfo = new FileInfo(InSourcePath);
            }

            // Select the code provider based on the input file extension.
            if (cp.SourceLines != null)
            {
                Dictionary <string, string> provOpts =
                    new Dictionary <string, string>()
                {
                    { "CompilerVersion", "v3.5" }
                };
                provider = new Microsoft.CSharp.CSharpCodeProvider(provOpts);
//        provider = CodeDomProvider.CreateProvider("CSharp");
            }
            else if (cp.SourceFileInfo.Extension.ToUpper(CultureInfo.InvariantCulture) == ".CS")
            {
                Dictionary <string, string> provOpts =
                    new Dictionary <string, string>()
                {
                    { "CompilerVersion", "v3.5" }
                };
                provider = new Microsoft.CSharp.CSharpCodeProvider(provOpts);
//        provider = CodeDomProvider.CreateProvider("CSharp");
            }
            else
            {
                results.Add("Source file must have a .cs or .vb extension");
            }

            if (provider != null)
            {
                //  type of executable: Windows, Console, ClassLibrary
                cp.ExecutableType     = InExecType;
                cp.GenerateAssemblyIn = InGenerateIn;

                // setup name and path of the executable file to be created.
                if (cp.GenerateAssemblyIn == GenerateAssemblyIn.File)
                {
                    if (cp.ExecutableType == ExecutableType.ClassLibrary)
                    {
                        exeName = AcFilePath.NameSansExtension(cp.SourceFileInfo.Name) + ".dll";
                    }
                    else
                    {
                        exeName = AcFilePath.NameSansExtension(cp.SourceFileInfo.Name) + ".exe";
                    }
                    string exePath = AcFilePath.AddTo(cp.SourceFileInfo.DirectoryName, exeName);
                    cp.OutputAssembly = exePath;
                }

                // Set whether to treat all warnings as errors.
                cp.TreatWarningsAsErrors = false;
                cp.ReferencedAssemblies.Add("System.Dll");
                cp.ReferencedAssemblies.Add("System.Drawing.Dll");
                cp.ReferencedAssemblies.Add("System.Xml.Dll");
                cp.ReferencedAssemblies.Add("System.Windows.Forms.dll");

                // additional assemblies
                foreach (string s1 in InAddnReferencedAssemblies)
                {
                    cp.ReferencedAssemblies.Add(s1);
                }

                // Invoke compilation of the source file.
                CompilerResults cr = null;
                if (cp.SourceLines != null)
                {
                    cr = provider.CompileAssemblyFromSource(cp, cp.SourceLines);
                }
                else
                {
                    cr = provider.CompileAssemblyFromFile(cp, cp.SourceFileInfo.FullName);
                }
                wipCr.SetCompilerResults(cr);
                wipCr.SetCompilerParameters(cp);

                // completion message
                results.Add(wipCr.CompletionMessage);

                if (wipCr.Errors.Count > 0)
                {
                    foreach (CompilerError ce in wipCr.Errors)
                    {
                        results.Add("   " + ce.ToString());
                    }
                }

                // Return the results of the compilation.
                if (wipCr.Errors.Count > 0)
                {
                    assem = null;
                }

                else
                {
                    assem = wipCr.CompiledAssembly;
                }
            }
            return(wipCr);
        }
示例#24
0
        private static void GetDMDInfo()
        {
            if (versions.Count == 0)
            {
                bool hasError = false;
                if (DataFile.Exists)
                {
                    string[]        lines = File.ReadAllLines(DataFile.FullName);
                    CompilerVersion ver;
                    for (int i = 0; i < lines.Length; i++)
                    {
                        ver = new CompilerVersion();
                        if (ver.FromString(lines[i]))
                        {
                            versions[ver.Version] = ver;
                        }
                        else
                        {
                            hasError = true;
                        }
                        if (ver.HasError)
                        {
                            hasError = true;
                        }
                    }

                    if (hasError)
                    {
                        DataFile.CopyTo(DataFile.FullName + "." + DateTime.Now.ToBinary() + ".log");
                        DataFile.Delete();
                        DataFile.Refresh();
                    }
                }

                if (!DataFile.Exists)
                {
                    CompilerVersion ver1 = new CompilerVersion(), ver2 = new CompilerVersion();
                    int             latestVer1 = 56, latestVer2 = 41, subVersion = 0;
                    string          url1 = "", url2 = "";
                    ver1.Version = 1;
                    ver2.Version = 2;
                    try
                    {
                        FtpWebRequest request = WebRequest.Create(DIGITAL_MARS_FTP) as FtpWebRequest;
                        request.Method = WebRequestMethods.Ftp.ListDirectory;

                        using (FtpWebResponse response = request.GetResponse() as FtpWebResponse)
                        {
                            /*
                             * Enum all files in the ftp root. While scan through all of them, extract the version number, get the highest version number, and finally download the appropriate zip
                             */
                            Console.WriteLine(response.StatusDescription);
                            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                            {
                                while (!reader.EndOfStream)
                                {
                                    string line = reader.ReadLine();
                                    if (line.StartsWith("dmd.1."))
                                    {
                                        string[] tokens = line.Split('.');
                                        if (tokens.Length > 2 && !int.TryParse(tokens[2], out subVersion))
                                        {
                                            subVersion = latestVer1;
                                        }

                                        if (tokens[tokens.Length - 1].Equals("zip", StringComparison.CurrentCultureIgnoreCase))
                                        {
                                            if (latestVer1 < subVersion)
                                            {
                                                latestVer1 = subVersion;
                                                url1       = DIGITAL_MARS_HTTP + line;
                                            }
                                        }
                                    }
                                    else if (line.StartsWith("dmd.2."))
                                    {
                                        string[] tokens = line.Split('.');
                                        if (tokens.Length > 2 && !int.TryParse(tokens[2], out subVersion))
                                        {
                                            subVersion = latestVer2;
                                        }

                                        if (tokens[tokens.Length - 1].Equals("zip", StringComparison.CurrentCultureIgnoreCase))
                                        {
                                            if (latestVer2 < subVersion)
                                            {
                                                latestVer2 = subVersion;
                                                url2       = DIGITAL_MARS_HTTP + line;
                                            }
                                        }
                                    }
                                }
                            }
                            response.Close();
                        }
                        ver1.SubVersion = latestVer1;
                        ver1.Url        = url1;
                        ver2.SubVersion = latestVer2;
                        ver2.Url        = url2;
                    }
                    catch (Exception ex)
                    {
                        ver1.Error = ERROR_PREFIX + ex.Message + Environment.NewLine + ex.StackTrace;
                        ver2.Error = ERROR_PREFIX + ex.Message + Environment.NewLine + ex.StackTrace;
                    }
                    versions[1] = ver1;
                    versions[2] = ver2;

                    StringBuilder sb = new StringBuilder();
                    foreach (CompilerVersion ver in versions.Values)
                    {
                        sb.Append(ver.ToString()).Append("\r\n");
                    }
                    File.WriteAllText(DataFile.FullName, sb.ToString());
                }
            }
        }