예제 #1
0
                public override void PopulateValue(object target, IArgumentList args, IDiagnostics diags)
                {
                    var arg         = args.GetLastArg(OptionId);
                    var valueString = arg?.Value ?? attribute.DefaultValue;

                    if (valueString is null)
                    {
                        return;
                    }

                    var converter = TypeDescriptor.GetConverter(Property.PropertyType);

                    if (!converter.CanConvertFrom(typeof(string)))
                    {
                        diags.ReportError(
                            "Type converter for option '{0}' cannot convert from '{1}'.",
                            arg.Option.PrefixedName, typeof(string).Name);
                        return;
                    }

                    object value;

                    try {
                        value = converter.ConvertFromInvariantString(valueString);
                    } catch (NotSupportedException) {
                        diags.ReportError("Invalid value '{1}' in '{0}{1}'", arg.Spelling, valueString);
                        return;
                    }

                    Property.SetValue(target, value);
                }
예제 #2
0
        public bool EmitCode()
        {
            if (combinedCodeGenManifest == null)
            {
                diags.ReportError("Compilation has no manifests for code generation.");
                return(false);
            }

            var trap = diags.TrapError();

            ICodeGenerator codeGen = opts.CodeGenOptions.CodeGeneratorFactory?.Invoke();

            if (codeGen == null)
            {
                diags.ReportError("Failed to create the code generator instance.");
                return(false);
            }

            using var output = FileUtilities.TryCreateFile(diags, opts.CodeGenOptions.CodeHeaderFile);
            if (output == null)
            {
                return(false);
            }
            codeGen.Generate(combinedCodeGenManifest, output);

            return(!trap.ErrorOccurred);
        }
예제 #3
0
        public void Write(IEnumerable <Message> messages, IDiagnostics diags)
        {
            var uniqueMessages = new List <Message>();
            var messageIds     = new HashSet <uint>();

            foreach (var message in messages.Where(m => m.IsUsed))
            {
                if (messageIds.Contains(message.Id))
                {
                    diags.ReportError(
                        "Message '{0}' has duplicate id 0x{1:X}.",
                        message.Name,
                        message.Id);
                    continue;
                }
                messageIds.Add(message.Id);
                uniqueMessages.Add(message);
            }

            uniqueMessages.StableSortBy(m => m.Id);

            var blocks = BuildBlocks(uniqueMessages);

            WriteResourceData(blocks, uniqueMessages);
        }
예제 #4
0
 public static void ReportError <T, TProperty>(
     T entity,
     LocatedRef <TProperty> value,
     IDiagnostics diags,
     IUniqueConstraint <T> constraint) where TProperty : class
 {
     diags.ReportError(value.Location, constraint.FormatMessage(entity));
 }
예제 #5
0
        public int Execute()
        {
            var msgTableFile = opts.DumpMessageTable;
            var wevtFile     = opts.DumpEventTemplate;
            var d            = new EventTemplateDumper(Console.Out);

            if (msgTableFile != null)
            {
                try {
                    if (IsModule(wevtFile))
                    {
                        d.DumpMessageTableResource(wevtFile);
                    }
                    else
                    {
                        d.DumpMessageTable(msgTableFile);
                    }
                } catch (Exception ex) {
                    diags.ReportError(ex.Message);
                }
            }
            else if (wevtFile != null)
            {
                try {
                    if (IsModule(wevtFile))
                    {
                        d.DumpWevtTemplateResource(wevtFile);
                    }
                    else
                    {
                        d.DumpWevtTemplate(wevtFile);
                    }
                } catch (Exception ex) {
                    diags.ReportError(ex.Message);
                }
            }

            return(ExitCode.Success);
        }
예제 #6
0
        public static FileStream TryCreateFile(
            IDiagnostics diags, string fileName, int?bufferSize = null, FileOptions?options = null)
        {
            try {
                string fullPath = Path.GetFullPath(fileName);
                EnsureDirectoryExists(fullPath);

                if (bufferSize.HasValue && options.HasValue)
                {
                    return(File.Create(fileName, bufferSize.Value, options.Value));
                }

                return(File.Create(fileName));
            } catch (Exception ex) {
                diags.ReportError("Failed to create '{0}': {1}\n{2}", fileName, ex.Message, ex.StackTrace);
                return(null);
            }
        }
        public int Execute()
        {
            if (arguments.DecompilationOptions.InputModule is null &&
                (arguments.DecompilationOptions.InputEventTemplate is null || arguments.DecompilationOptions.InputMessageTable is null))
            {
                diags.ReportError("No input provider specified.");
                Program.ShowBriefHelp();
                return(ExitCode.UserError);
            }

            var decompiler = new EventTemplateDecompiler(
                diags, arguments.DecompilationOptions);

            if (!decompiler.Run())
            {
                return(ExitCode.Error);
            }

            return(ExitCode.Success);
        }
예제 #8
0
        public bool IsSatisfiedBy(Provider provider)
        {
            bool result = true;

            if (string.IsNullOrEmpty(provider.ResourceFileName))
            {
                result = false;
                diags.ReportError(
                    provider.Location,
                    "Provider '{0}' must have a non-empty resourceFileName attribute.",
                    provider.Name.Value);
            }

            if (string.IsNullOrEmpty(provider.MessageFileName))
            {
                result = false;
                diags.ReportError(
                    provider.Location,
                    "Provider '{0}' must have a non-empty messageFileName attribute.",
                    provider.Name.Value);
            }

            if (provider.ControlGuid != null)
            {
                var trailingGuid = ExtractGuidFromProviderName(provider.Name.Value);
                if (trailingGuid == null || trailingGuid != provider.Id)
                {
                    result = false;
                    diags.ReportError(
                        provider.Name.Location,
                        "Invalid provider name '{0}'. When controlGuid is specified, the provider name must end with the provider guid.",
                        provider.Name.Value);
                }
            }

            return(result);
        }
 private static void DefaultReportDiagnostic(
     T entity, TProperty value, IDiagnostics diags, IUniqueConstraint <T> constraint)
 {
     diags.ReportError(new SourceLocation(), constraint.FormatMessage(entity));
 }