예제 #1
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            int        timeoutMinutes    = TimeOutMinutes.Get(context);
            string     configurationFile = ConfigurationFile.Get(context);
            StringList layerCodes        = LayerCodes.Get(context);
            string     labelFilesFolder  = LabelFilesFolder.Get(context);

            if (!Directory.Exists(labelFilesFolder))
            {
                context.TrackBuildWarning(string.Format("Label file folder {0} not found.", labelFilesFolder));

                // TODO Is there a better way with this? can we just return null or something?
                Func <int, int, Exception> bogusDelegate = new Func <int, int, Exception>(CommandContext.WaitForProcess);
                context.UserState = new CommandContext {
                    Delegate = bogusDelegate, Process = null, AutoRun = null, AutoRunFile = null
                };
                return(bogusDelegate.BeginInvoke(0, 0, callback, state));
            }

            string modelName;
            string publisher;
            string layer;
            string layerCode;
            string modelManifest = ModelManifestFile.Get(context);

            Helper.ExtractClientLayerModelInfo(configurationFile, layerCodes, modelManifest, out modelName, out publisher, out layer, out layerCode);

            var clientConfig = Helper.GetClientConfig(configurationFile);

            Client.AutoRun.AxaptaAutoRun autoRun = new Client.AutoRun.AxaptaAutoRun()
            {
                ExitWhenDone = true, LogFile = string.Format(@"{0}\LabelFlushLog-{1}.xml", Environment.ExpandEnvironmentVariables(clientConfig.LogDirectory), Guid.NewGuid())
            };
            Client.Commands.ImportLabelFile importCommand = new Client.Commands.ImportLabelFile()
            {
                ConfigurationFile = configurationFile, Layer = layer, LayerCode = layerCode, Model = modelName, ModelPublisher = publisher
            };

            foreach (string filename in Directory.GetFiles(labelFilesFolder, "*.ald"))
            {
                if (!IsEmptyLabelFile(filename))
                {
                    context.TrackBuildMessage(string.Format("Importing label file {0} into model {1} ({2})", filename, modelName, publisher));
                    importCommand.Filename = filename;
                    Client.Client.ExecuteCommand(importCommand, timeoutMinutes);

                    string labelFile     = Path.GetFileNameWithoutExtension(filename).Substring(2, 3);
                    string labelLanguage = Path.GetFileNameWithoutExtension(filename).Substring(5);

                    autoRun.Steps.Add(new Client.AutoRun.Run()
                    {
                        Type = Client.AutoRun.RunType.@class, Name = "Global", Method = "info", Parameters = string.Format("strFmt(\"Flush label {0} language {1}: %1\", Label::flush(\"{0}\",\"{1}\"))", labelFile, labelLanguage)
                    });
                }
            }

            string autoRunFile = string.Format(@"{0}\AutoRun-LabelFlush-{1}.xml", Environment.GetEnvironmentVariable("temp"), Guid.NewGuid());

            Client.AutoRun.AxaptaAutoRun.SerializeAutoRun(autoRun, autoRunFile);
            context.TrackBuildMessage(string.Format("Flushing imported label files"));
            Process process = Client.Client.StartCommand(new Client.Commands.AutoRun()
            {
                ConfigurationFile = configurationFile, Layer = layer, LayerCode = layerCode, Model = modelName, ModelPublisher = publisher, Filename = autoRunFile
            });

            Func <int, int, Exception> processWaitDelegate = new Func <int, int, Exception>(CommandContext.WaitForProcess);

            context.UserState = new CommandContext {
                Delegate = processWaitDelegate, Process = process, AutoRun = autoRun, AutoRunFile = autoRunFile, LogFile = autoRun.LogFile
            };
            return(processWaitDelegate.BeginInvoke(process.Id, timeoutMinutes, callback, state));
        }
예제 #2
0
        protected override void EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
        {
            CommandContext userState = context.UserState as CommandContext;

            if (userState != null)
            {
                Func <int, int, Exception> processWaitDelegate = userState.Delegate;
                Exception processWaitException = processWaitDelegate.EndInvoke(result);

                if (processWaitException != null)
                {
                    throw processWaitException;
                }

                Client.CILGenerationOutput output = null;
                try
                {
                    output = Client.CILGenerationOutput.CreateFromFile(userState.LogFile);
                }
                catch (FileNotFoundException)
                {
                    throw new Exception("CIL generation log could not be found");
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Format("Error parsing CIL generation log: {0}", ex.Message));
                }

                bool hasErrors = false;
                foreach (var item in output.Output)
                {
                    string compileMessage;

                    if (item.LineNumber > 0)
                    {
                        compileMessage = string.Format("Object {0} method {1}, line {2} : {3}", item.ElementName, item.MethodName, item.LineNumber, item.Message);
                    }
                    else
                    {
                        compileMessage = string.Format("Object {0} method {1} : {2}", item.ElementName, item.MethodName, item.Message);
                    }

                    switch (item.Severity)
                    {
                    // Compile Errors
                    case 0:
                        context.TrackBuildError(compileMessage);
                        hasErrors = true;
                        break;

                    // Compile Warnings
                    case 1:
                        context.TrackBuildWarning(compileMessage);
                        break;

                    // "Other"
                    case 4:
                    default:
                        context.TrackBuildMessage(item.Message);
                        break;
                    }
                }
                if (hasErrors)
                {
                    throw new Exception("CIL error(s) found");
                }
            }
        }