Esempio n. 1
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");
                }
            }
        }