コード例 #1
0
        /// <summary>
        /// When overridden in a derived class, executes the task.
        /// </summary>
        /// <returns>
        /// true if the task successfully executed; otherwise, false.
        /// </returns>
        public override bool Execute()
        {
            base.Execute();
            Stopwatch sw = Stopwatch.StartNew();

            // Open DB
            Log.LogMessageFromResources(MessageImportance.Low, "OpenDatabase", _repositoryFileName);
            IEntitiesAccessor entitiesAccessor = EntitiesAccessor.Instance;

            ConfigurationContainer configContainer = entitiesAccessor.LoadConfiguration(_repositoryFileName);

            if (configContainer.Concerns.Count == 0)
            {
                Log.LogMessageFromResources("MasterSkipNoConcerns");
                return(!Log.HasLoggedErrors);
            }

            Log.LogMessageFromResources("MasterStartText");

            // Place debuglevel
            Log.LogMessageFromResources("StoreDebugLevel", _debugLevel);

            // Set the Common Configuration
            string debugLevelValue = "";

            if (!string.IsNullOrEmpty(_debugLevel))
            {
                try
                {
                    CurrentDebugMode = (DebugLevel)Enum.Parse(typeof(DebugLevel), _debugLevel);
                    debugLevelValue  = DebugLevelToLog4j(CurrentDebugMode);
                }
                catch (ArgumentException)
                {
                    Log.LogErrorFromResources("CouldNotConvertDebugLevel", _debugLevel);
                    return(false);
                }
            }

            if (!String.IsNullOrEmpty(debugLevelValue))
            {
                configContainer.AddSetting("buildDebugLevel", debugLevelValue);
            }
            configContainer.AddSetting("IntermediateOutputPath", _intermediateOutputPath);
            configContainer.AddSetting("InstallFolder", StarLightSettings.Instance.StarLightInstallFolder);

            //michielh: disabled for now, not used in FILTH
            //configContainer.AddSetting("FILTH.outputEnabled", _filthOutput.ToString(CultureInfo.InvariantCulture));

            if (!String.IsNullOrEmpty(_bookKeepingMode))
            {
                configContainer.AddSetting("INLINE.bookkeeping", _bookKeepingMode);
            }

            // Save common config
            entitiesAccessor.SaveConfiguration(_repositoryFileName, configContainer);

            // Create a process to execute the StarLight Master.
            Process process = new Process();

            process.StartInfo.CreateNoWindow         = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardError  = true;

            // Determine filename
            if (!string.IsNullOrEmpty(StarLightSettings.Instance.JavaLocation))
            {
                process.StartInfo.FileName = Path.Combine(StarLightSettings.Instance.JavaLocation, JavaExecutable);
            }
            else
            {
                process.StartInfo.FileName = JavaExecutable;                 // In path
            }
            // Create command line
            string jarFile = Path.Combine(StarLightSettings.Instance.StarLightInstallFolder, StarLightJar);

            IList <string> args = new List <string>();

            args.Add(StarLightSettings.Instance.JavaOptions);
            args.Add("-jar " + Quote(jarFile));
            args.Add(Quote(_repositoryFileName));

            process.StartInfo.Arguments = Join(args, " ");
            Log.LogMessageFromResources("JavaStartMessage", process.StartInfo.Arguments);

            // Start the process
            try
            {
                process.Start();

                using (StreamReader outputReader = process.StandardOutput)
                {
                    while (!outputReader.EndOfStream)
                    {
                        ParseMasterOutput(outputReader.ReadLine());
                    }
                }

                process.WaitForExit();
                if (process.ExitCode == 0)
                {
                    sw.Stop();
                    Log.LogMessageFromResources("MasterCompleted", sw.Elapsed.TotalSeconds);
                    return(!Log.HasLoggedErrors);
                }
                else
                {
                    Log.LogMessagesFromStream(process.StandardError, MessageImportance.High);
                    Log.LogErrorFromResources("MasterRunFailed", process.ExitCode);
                    return(false);
                }
            }
            catch (Win32Exception e)
            {
                if (e.NativeErrorCode == ErrorFileNotFound)
                {
                    Log.LogErrorFromResources("JavaExecutableNotFound", process.StartInfo.FileName);
                }
                else if (e.NativeErrorCode == ErrorAccessDenied)
                {
                    Log.LogErrorFromResources("JavaExecutableAccessDenied", process.StartInfo.FileName);
                }
                else
                {
                    Log.LogErrorFromResources("ExecutionException", e.ToString());
                }
                return(false);
            }
            finally
            {
                if (sw.IsRunning)
                {
                    sw.Stop();
                }
            }
        }