public static void CompileClientScript(Assembly a) { var moduleFile = new FileInfo(a.Location); var module = moduleFile.FullName; var dir = new FileInfo(module).Directory; var web = dir.CreateSubdirectory("web"); Environment.CurrentDirectory = dir.FullName; jsc.Program.Main(new[] { module, "-js" }); }
static void Main(string[] args) { Console.WriteLine("This application will help you port an actionscript application to c#."); // fixme: this should be a parameter instead var project = @"C:\work\code.google\dodging-basenji\examples\actionscript\doomedonline\Doomedonline\Doomedonline.csproj"; XNamespace ns = "http://schemas.microsoft.com/developer/msbuild/2003"; var doc = XDocument.Load( project ); const string prefix = @"web\"; const string suffix = ".as"; var SourceFiles = from ItemGroup in doc.Root.Elements(ns + "ItemGroup") from Compile in ItemGroup.Elements(ns + "Compile") let Include = Compile.Attribute("Include").Value where Include.EndsWith(".cs") select new { ItemGroup, Include }; var DefaultSourceFileGroup = SourceFiles.First(); foreach (var h in from ItemGroup in doc.Root.Elements(ns + "ItemGroup") from File in ItemGroup.Elements(ns + "None") let Include = File.Attribute("Include").Value where Include.EndsWith(suffix) where Include.StartsWith(prefix) let FullName = Include.Substring(prefix.Length, Include.Length - prefix.Length - suffix.Length) select new { FullName } ) { var Segments = h.FullName.Split('\\'); var dir = new FileInfo(project).Directory; var Namespace = ""; foreach (var s in Segments.Take(Segments.Length - 1)) { if (Namespace != "") Namespace += "."; Namespace += s; dir = dir.CreateSubdirectory(s); } var TypeName = Segments.Last(); var Writer = new StringWriter(); Writer.WriteLine(@" using ScriptCoreLib; using ScriptCoreLib.ActionScript; using ScriptCoreLib.ActionScript.Extensions; using ScriptCoreLib.ActionScript.flash.display; using ScriptCoreLib.ActionScript.flash.text; using ScriptCoreLib.ActionScript.flash.filters; "); if (Namespace != "") { Writer.WriteLine(@" namespace " + Namespace + @" { "); } Writer.WriteLine(@" [Script(IsNative = true)] public class " + TypeName + @" { // This class is a stub. You should implement it as it is currently implemented by actionscript. } "); if (Namespace != "") { Writer.WriteLine(@" } "); } var TargetFile = Path.Combine(dir.FullName, TypeName + ".cs"); if (!File.Exists(TargetFile)) File.WriteAllText(TargetFile, Writer.ToString()); var TargetSourceFile = SourceFiles.FirstOrDefault(k => k.Include == h.FullName + ".cs"); if (TargetSourceFile != null) { } else { DefaultSourceFileGroup.ItemGroup.Add( new XElement(ns + "Compile", new XAttribute("Include", h.FullName + ".cs")) ); } Console.WriteLine(h); } doc.Save(project); }
private void logging(ErrorType eType, String message) { lock (loggingConsoleLocker) if (errorLevelIsMinRequire(writeToConsole, eType)) Console.Error.WriteLine(message); lock (loggingFileLocker) if (errorLevelIsMinRequire(writeToFile, eType) && logPath != "") { try { var tmp = logPath; DirectoryInfo dir = new FileInfo(tmp).Directory; if (!dir.Exists) dir.CreateSubdirectory(new FileInfo(tmp).Directory.FullName); System.IO.File.AppendAllText(tmp, message); } catch (Exception e) { Console.Error.WriteLine(parseException(e)); } } }
private static bool Build(string projectFilePath, IDictionary<string, string> buildProperties, LoggerVerbosity verbosity, string logPath = null) { var workspace = new FileInfo(projectFilePath).Directory; if (workspace == null) throw new DirectoryNotFoundException( "Somehow the project file is not in a directory. Report this to Icedream!"); // Mono compatibility Environment.SetEnvironmentVariable("MONO_IOMAP", "all"); // Make sure we restore nuget packages automatically and without permissions interfering with /tmp/nuget/ (edge case) var newTempDir = workspace.CreateSubdirectory(".tmp"); Environment.SetEnvironmentVariable("EnableNuGetPackageRestore", "true"); Environment.SetEnvironmentVariable("TEMP", newTempDir.FullName); Environment.SetEnvironmentVariable("TMP", newTempDir.FullName); try { var pc = new ProjectCollection(); pc.RegisterLogger(new ConsoleLogger(verbosity)); var loggers = new List<ILogger>(); if (logPath != null) loggers.Add(new FileLogger { Parameters = string.Format("LogFile={0}", logPath), Verbosity = LoggerVerbosity.Detailed, ShowSummary = true, SkipProjectStartedText = true }); loggers.Add(new ConsoleLogger(verbosity) {ShowSummary = false}); // Import/Update Mozilla certs for NuGet to not fail out on non-Windows machines if (!Environment.OSVersion.IsWin32()) { try { var automaticYesResponder = new Action<string, StreamWriter>((s, writer) => { if (s == null || !s.Contains("X.509 Certificate")) return; writer.WriteLine("yes"); }); // TODO: Make sure this does not fail out by checking if mozroots is installed Console.WriteLine("Updating SSL certificates for NuGet..."); RunProcessThrowOnException("mozroots", "--import --sync --quiet"); RunProcessThrowOnException("certmgr", "-ssl https://go.microsoft.com", lineProcessor: automaticYesResponder); RunProcessThrowOnException("certmgr", "-ssl https://nugetgallery.blob.core.windows.net", lineProcessor: automaticYesResponder); RunProcessThrowOnException("certmgr", "-ssl https://nuget.org", lineProcessor: automaticYesResponder); } catch (Exception error) { Console.Error.WriteLine("ERROR: {0}", error.Message); throw; } } { // The NuGet.exe that is shipped with CitizenMP.Server has a few bugs... var nugetExePath = Path.Combine(workspace.FullName, ".nuget", "NuGet.exe"); Console.WriteLine("Updating NuGet..."); File.Delete(nugetExePath); using (var wc = new WebClient()) { wc.DownloadFile("https://nuget.org/NuGet.exe", nugetExePath); } } // Use a different build route if running on the Mono interpreter if (!Environment.OSVersion.IsWin32()) { Console.WriteLine("Building server binaries..."); #pragma warning disable 618 // Build doesn't work with the new API on Mono, use the deprecated api var engine = Engine.GlobalEngine; // loggers foreach (var logger in loggers) engine.RegisterLogger(logger); // Apply build properties var buildPropertiesConverted = new BuildPropertyGroup(); engine.GlobalProperties = buildPropertiesConverted; foreach (var property in buildProperties) buildPropertiesConverted.SetProperty(property.Key, property.Value); // Load project var result = engine.BuildProjectFile(projectFilePath, new string[0], null, null, BuildSettings.None, null); #pragma warning restore 618 return result; } // Windows build can make use of the new API which is more efficient { Console.WriteLine("Building server binaries..."); var buildReq = new BuildRequestData(projectFilePath, buildProperties, null, new[] {"Build"}, null); var result = BuildManager.DefaultBuildManager.Build( new BuildParameters(pc) { Loggers = loggers.ToArray(), MaxNodeCount = Environment.ProcessorCount }, buildReq); return result.OverallResult == BuildResultCode.Success; } } finally { newTempDir.Delete(true); } }