Наследование: IDisposable, IProjectOwner
Пример #1
0
        private void Start(string[] args) {
            CurrentTask.Events += new SourceError((code, location, message, objects) => {
                location = location ?? SourceLocation.Unknowns;
                Console.WriteLine("{0}:Error {1}:{2}", location.FirstOrDefault(), code, message.format(objects));
                return true;
            });

            CurrentTask.Events += new SourceWarning((code, location, message, objects) => {
                location = location ?? SourceLocation.Unknowns;
                Console.WriteLine("{0}:Warning {1}:{2}", location.FirstOrDefault(), message.format(objects));
                return false;
            });

            CurrentTask.Events += new SourceDebug((code, location, message, objects) => {
                location = location ?? SourceLocation.Unknowns;
                Console.WriteLine("{0}:DebugMessage {1}:{2}", location.FirstOrDefault(), code, message.format(objects));
                return false;
            });

            CurrentTask.Events += new Error((code, message, objects) => {
                Console.WriteLine("{0}:Error {1}", code, message.format(objects));
                return true;
            });

            CurrentTask.Events += new Warning((code, message, objects) => {
                Console.WriteLine("{0}:Warning {1}", code, message.format(objects));
                return false;
            });

            CurrentTask.Events += new Debug((code, message, objects) => {
                Console.WriteLine("{0}:DebugMessage {1}", code, message.format(objects));
                return false;
            });

            CurrentTask.Events += new Verbose((code, message, objects) => {
                Console.WriteLine("{0}:Verbose {1}", code, message.format(objects));
                return false;
            });
            CurrentTask.Events += new Message((code, message, objects) => {
                Console.WriteLine("{0}:Message {1}", code, message.format(objects));
                return false;
            });

#if true

            try {
                Environment.CurrentDirectory = @"C:\root\V2\coapp-packages\openssl\copkg";
                Console.WriteLine("Package script");
                using(var script = new PackageScript("openssl.autopkg")) {

                    IEnumerable<string> overlayFiles;
                    var pkgFile = script.Save(PackageTypes.NuGet, false, false, out overlayFiles);
                }
                Console.WriteLine();
            } catch (Exception e) {
                Console.WriteLine("{0} =>\r\n\r\nat {1}", e.Message, e.StackTrace.Replace("at ClrPlus.Scripting.Languages.PropertySheetV3.PropertySheetParser", "PropertySheetParser"));
            }
#else
            try {
                // Environment.CurrentDirectory = @"C:\project";
                Console.WriteLine("Build script");
                using (var script = new BuildScript("test.buildinfo")) {
                    script.Execute();
                }
            } catch (Exception e) {
                Console.WriteLine("{0} =>\r\n\r\nat {1}", e.Message, e.StackTrace.Replace("at ClrPlus.Scripting.Languages.PropertySheetV3.PropertySheetParser", "PropertySheetParser"));
            }

#endif
            return;
            //
        }
        protected override void BeginProcessing() {
#if USING_RESTABLE_CMDLET
            if (Remote) {
                ProcessRecordViaRest();
                return;
            }
#endif 
            using (new PushDirectory(Path.Combine(SessionState.Drive.Current.Root, SessionState.Drive.Current.CurrentLocation) )) {

                // Invoking a ptk script.
                if (string.IsNullOrWhiteSpace(ScriptFile)) {
                    // search for it.
                    ScriptFile = new[] {
                        @"copkg\.buildinfo", @"contrib\.buildinfo", @"contrib\coapp\.buildinfo", @".buildinfo"
                    }.WalkUpPaths();

                    if (string.IsNullOrEmpty(ScriptFile)) {
                        throw new ClrPlusException(@"Unable to find .buildinfo file anywhere in the current directory structure.");
                    }
                }

                using (var local = LocalEventSource) {
                    local.Events += new SourceError((code, location, message, objects) => {
                        location = location.IsNullOrEmpty() ? SourceLocation.Unknowns : location;
                        Host.UI.WriteErrorLine("{0}:{1}:{2}".format(location.FirstOrDefault(), code, message.format(objects)));
                        return true;
                    });

                    if (!NoWarnings) {
                        local.Events += new SourceWarning((code, location, message, objects) => {
                            WriteWarning(message);
                            return false;
                        });
                    }

                    local.Events += new SourceDebug((code, location, message, objects) => {
                        WriteVerbose(message);
                        return false;
                    });

                    local.Events += new MSBuildMessage((obj) => {
                        switch (obj.EventType) {

                            case "BuildWarning":
                                if (!NoWarnings) {
                                    Host.UI.WriteLine("{0}:{1}:{2}".format(obj.File, obj.Code, obj.Message));
                                }
                                break;

                            case "BuildError":
                                Host.UI.WriteErrorLine("{0}:{1}:{2}".format(obj.File, obj.Code, obj.Message));
                             
                                break;

                            case "ProjectStarted":
                            case "ProjectFinished":
                            case "TaskStarted":
                            case "TaskFinished":
                            case "TargetStarted":
                            case "TargetFinished":
                            case "BuildStarted":
                            case "BuildFinished":
                                WriteVerbose(obj.Message);
                                break;

                            case "BuildMessage":
                                if (filterMessages.Any(each => obj.Message.IndexOf(each) > -1)) {
                                    WriteVerbose(obj.Message);
                                }
                                else {
                                    Host.UI.WriteLine(obj.Message);
                                }

                                break;

                            default:
                                WriteVerbose(obj.Message);
                                break;
                        }
                        return false;
                    });

                    using (buildScript = new BuildScript(ScriptFile)) {
                        if (Defines != null) {
                            foreach (var i in Defines) {
                                var p = i.IndexOf("=");
                                var k = p > -1 ? i.Substring(0, p) : i;
                                var v = p > -1 ? i.Substring(p + 1) : "";
                                buildScript.AddMacro(k, v);
                            }
                        }
                        if (Define != null) {
                            foreach (var i in Define) {
                                var p = i.IndexOf("=");
                                var k = p > -1 ? i.Substring(0, p) : i;
                                var v = p > -1 ? i.Substring(p + 1) : "";
                                buildScript.AddMacro(k, v);
                            }
                        }
                        if (Targets.IsNullOrEmpty()) {
                            Targets = new string[] {
                                "default"
                            };
                        }

                        if (SaveScript) {
                            WriteObject("Script Saved To: {0}".format( buildScript.EmitScript()));
                            return;
                        } 

                        if (DumpScript) {
                            WriteObject(buildScript.ScriptText());
                            return;
                        }

                        Environment.SetEnvironmentVariable("MaxThreads", ""+MaxThreads);
                        buildScript.MaxThreads = MaxThreads;
                        buildScript.Execute(Targets);
                    }
                }
            }
        }