当前位置: 首页>>代码示例>>C#>>正文


C# ILog.AddError方法代码示例

本文整理汇总了C#中ILog.AddError方法的典型用法代码示例。如果您正苦于以下问题:C# ILog.AddError方法的具体用法?C# ILog.AddError怎么用?C# ILog.AddError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ILog的用法示例。


在下文中一共展示了ILog.AddError方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Assemble

        public static void Assemble(string inputFile, string outputFile, string languageName, ILog messageLog)
        {
            TextReader reader;
            bool close;
            if (inputFile != null)
            {
                reader = File.OpenText(inputFile);
                close = true;
            }
            else
            {
                reader = Console.In;
                close = false;
            }

            EACodeLanguage language = languages[languageName];

            if (outputFile != null)
            {
                if (File.Exists(outputFile))
                {
                    if (File.GetAttributes(outputFile).HasFlag(FileAttributes.ReadOnly))
                    {
                        messageLog.AddError("outputFile is read-only.");
                        goto end;
                    }
                }

                var cache = new ChangeStream();
                using (BinaryWriter writer = new BinaryWriter(cache))
                {
                    Assemble(language, reader, writer, messageLog);
                    if (messageLog.ErrorCount == 0)
                    {
                        using (Stream stream = File.OpenWrite(outputFile))
                        {
                            cache.WriteToFile(stream);
                        }
                    }
                }
            }
            else
            {
                messageLog.AddError("outputFile needs to be specified for assembly.");
            }
            end:

            if (close)
                reader.Close();
        }
开发者ID:TimoVesalainen,项目名称:Event-Assembler,代码行数:50,代码来源:Program.cs

示例2: SecondPass

        private static void SecondPass(IEnumerable<KeyValuePair<INamed<string>, string[]>> codes, 
            Context assemblyContext, ILog log, BinaryWriter output)
        {
            foreach (var code in codes)
            {
                //Insert labels and currentOffsetCode
                for (int i = 1; i < code.Value.Length; i++)
                {
                    int offset;
                    if (code.Value[i].Equals(currentOffsetCode, StringComparison.OrdinalIgnoreCase))
                    {
                        code.Value[i] = assemblyContext.Offset.ToString();
                    }
                    else if (assemblyContext.TryGetLabelOffset(code.Value[i], out offset))
                    {
                        code.Value[i] = offset.ToString();
                    }
                }

                if (code.Key is IBuiltInCode)
                {
                    var error = ((IBuiltInCode)code.Key).SecondPass(code.Value, assemblyContext);
                    if (error)
                    {
                        log.AddError(error.ErrorMessage);
                    }
                    else if (error.Result)
                    {
                        output.Seek(assemblyContext.Offset, SeekOrigin.Begin);
                    }
                }
                else if (code.Key is ICodeTemplate)
                {
                    output.Write(((ICodeTemplate)code.Key).GetData(code.Value, log));
                    assemblyContext.Offset = (int)output.BaseStream.Position;
                }
            }
        }
开发者ID:Diegoisawesome,项目名称:AwesomeMapEditor-old,代码行数:38,代码来源:EACodeLanguageAssembler.cs

示例3: Disassemble

        public static void Disassemble(string inputFile, string outputFile, string languageName,
            bool addEndGuards, DisassemblyMode mode, int offset, Priority priority, int size, ILog messageLog)
        {
            if (!File.Exists(inputFile))
            {
                messageLog.AddError("File " + inputFile + " doesn't exist.");
                return;
            }
            else if (File.Exists(outputFile))
            {
                if (File.GetAttributes(outputFile).HasFlag(FileAttributes.ReadOnly))
                {
                    messageLog.AddError("Output cannot be written to. It is read-only.");
                    return;
                }
            }

            EACodeLanguage language = languages[languageName];
            byte[] data = File.ReadAllBytes(inputFile);

            if (offset > data.Length)
            {
                messageLog.AddError("Offset is larger than size of file.");
            }
            else
            {
                if (size <= 0 || size + offset > data.Length)
                {
                    size = data.Length - offset;
                }
                IEnumerable<string[]> code;
                string[] defaultLines;
                switch (mode)
                {
                    case DisassemblyMode.Block:
                        code = language.Disassemble(data, offset, size, priority, addEndGuards, messageLog);
                        defaultLines = CoreInfo.DefaultLines(language.Name,
                            Path.GetFileName(inputFile), offset, size);
                        break;
                    case DisassemblyMode.ToEnd:
                        code = language.DisassembleToEnd(data, offset, priority, addEndGuards, messageLog);
                        defaultLines = CoreInfo.DefaultLines(language.Name,
                            Path.GetFileName(inputFile), offset, null);
                        break;
                    case DisassemblyMode.Structure:
                        code = language.DisassembleChapter(data, offset, addEndGuards, messageLog);
                        defaultLines = CoreInfo.DefaultLines(language.Name,
                            Path.GetFileName(inputFile), offset, null);
                        break;
                    default:
                        throw new ArgumentException();
                }

                if (messageLog.ErrorCount == 0)
                {
                    using (StreamWriter sw = new StreamWriter(outputFile))
                    {
                        sw.WriteLine();
                        sw.WriteLine(Frame(defaultLines, "//", 1));
                        sw.WriteLine();

                        foreach (string[] line in code)
                        {
                            sw.WriteLine(line.ToElementWiseString(" ", "", ""));
                        }
                    }
                }
            }
        }
开发者ID:TimoVesalainen,项目名称:Event-Assembler,代码行数:69,代码来源:Program.cs

示例4: HandleLabels

 private string[] HandleLabels(IPositionableInputStream input, Context assemblyContext, ILog log, string[] code)
 {
     string labelName = code[0].TrimEnd(':');
     if (IsValidLableName(labelName))
     {
         assemblyContext.AddLabel(labelName);
     }
     else
     {
         log.AddError(input.GetErrorString(
             string.Format("Invalid label name {0}", labelName)));
     }
     string[] temp = new string[code.Length - 1];
     Array.Copy(code, 1, temp, 0, temp.Length);
     code = temp;
     return code;
 }
开发者ID:Diegoisawesome,项目名称:AwesomeMapEditor-old,代码行数:17,代码来源:EACodeLanguageAssembler.cs

示例5: FirstPass

        private IEnumerable<KeyValuePair<INamed<string>, string[]>> FirstPass(IPositionableInputStream input, 
            Context assemblyContext, ILog log)
        {
            while (true)
            {
                string line = input.ReadLine();
                if (line == null)
                    break;

                string[] code = Nintenlord.Utility.Parser.SplitToParameters(line);

                if (code.Length > 0)
                {
                    if (code[0].EndsWith(":"))
                    {
                        code = HandleLabels(input, assemblyContext, log, code);
                    }

                    if (code.Length == 0) continue;

                    IBuiltInCode builtIn;
                    if (buildInCodes.TryGetValue(code[0], out builtIn))
                    {
                        string error;
                        if (builtIn.Matches("Code " + code[0], code.Length - 1, out error))
                        {
                            var causedError = builtIn.FirstPass(code, assemblyContext);
                            if (causedError)
                            {
                                log.AddError(input.GetErrorString(causedError.ErrorMessage));
                            }
                            yield return new KeyValuePair<INamed<string>, string[]>(builtIn, code);
                        }
                        else
                        {
                            log.AddError(input.GetErrorString(error));
                        }
                    }
                    else
                    {
                        ICodeTemplate template = codeStorage.FindTemplate(code);

                        if (template != null)
                        {
                            if (assemblyContext.Offset % template.OffsetMod != 0)
                            {
                                log.AddError(input.GetErrorString(
                                    string.Format(
                                    "Code {0}'s offset {1} is not divisible by {2}",
                                    template.Name,
                                    assemblyContext.Offset,
                                    template.OffsetMod
                                    )));
                            }
                            assemblyContext.Offset += template.GetLengthBytes(code);
                            yield return new KeyValuePair<INamed<string>, string[]>(template, code);
                        }
                        else
                        {
                            log.AddError(input.GetErrorString(string.Format(
                                    "No code named {0} with {1} parameters found",
                                    code[0],
                                    code.Length - 1
                                    )));
                        }
                    }
                }
            }
        }
开发者ID:Diegoisawesome,项目名称:AwesomeMapEditor-old,代码行数:69,代码来源:EACodeLanguageAssembler.cs

示例6: DisassembleChapter

        public IEnumerable<string[]> DisassembleChapter(byte[] code, int offset, ILog log, bool addEndingLines)
        {
            List<int> pointerlistValues = new List<int>();
            SortedDictionary<int, Code> lines = new SortedDictionary<int, Code>();
            SortedDictionary<int, string> labels = new SortedDictionary<int, string>();
            labels[offset] = "PointerList";

            foreach (var item in this.pointerList.Flatten().Index())
            {
                int pointerOffset = offset + 4 * item.Item1;
                int pointer = BitConverter.ToInt32(code, pointerOffset);
                if (this.pointerMaker.IsAValidPointer(pointer))
                {
                    int offsetVal = this.pointerMaker.MakeOffset(pointer);
                    pointerlistValues.Add(offsetVal);
                    if (offsetVal > 0 && !labels.ContainsKey(offsetVal))
                    {
                        labels.Add(offsetVal, item.Item2.Item1);
                        FindTemplatesUntil(code, offsetVal, lines,
                            item.Item2.Item2, x => x.EndingCode, log);
                    }
                }
                else
                {
                    log.AddError("Invalid pointer at pointer list: " + pointer.ToHexString("$"));
                    return Enumerable.Empty<string[]>();
                }
            }

            FindPointedCodes(code, lines, log);

            FindLables(lines, labels);

            MergeRepeatableCodes(lines, x => !labels.ContainsKey(x));//Can cause labels to get omitted, needs to be fixed.

            //After merging because I want custom format
            AddPointerListCodes(offset, pointerlistValues.ToArray(), lines, log);

            KeyValuePair<int, Code> last = lines.Last();

            int length = last.Key + last.Value.Length - offset;

            return GetLines(lines, labels, addEndingLines);
        }
开发者ID:Diegoisawesome,项目名称:AwesomeMapEditor-old,代码行数:44,代码来源:EACodeLanguageDisassembler.cs

示例7: FindTemplatesUntil

 private void FindTemplatesUntil(byte[] code, int offset,
     SortedDictionary<int, Code> lines, IEnumerable<Priority> prioritiesToUse,
     Predicate<ICodeTemplate> predicate, ILog log)
 {
     int currOffset = offset;
     while (currOffset < code.Length)
     {
         Code ccode;
         ICodeTemplate template;
         int length;
         if (!lines.TryGetValue(currOffset, out ccode))
         {
             var templateResult = codeStorage.FindTemplate(code, currOffset, prioritiesToUse);
             if (templateResult.CausedError)
             {
                 log.AddError(templateResult.ErrorMessage);
                 break;
             }
             else
             {
                 template = templateResult.Result;
                 length = template.GetLengthBytes(code, currOffset);
                 var line = template.GetAssembly(code, currOffset);
                 if (line.CausedError)
                 {
                     log.AddError(line.ErrorMessage);
                 }
                 else
                 {
                     lines.Add(currOffset, new Code(line.Result, template, length));
                 }
             }
         }
         else
         {
             template = ccode.Template;
             length = template.GetLengthBytes(code, currOffset);
         }
         if (predicate(template))
         {
             break;
         }
         currOffset += length;
     }
 }
开发者ID:Diegoisawesome,项目名称:AwesomeMapEditor-old,代码行数:45,代码来源:EACodeLanguageDisassembler.cs

示例8: AddPointerListCodes

 private void AddPointerListCodes(int offset, int[] pointerList,
     SortedDictionary<int, Code> lines, ILog log)
 {
     var pointerTemplateResult = codeStorage.FindTemplate("POIN", Priority.pointer);
     if (pointerTemplateResult.CausedError)
     {
         log.AddError(pointerTemplateResult.ErrorMessage);
     }
     else
     {
         var pointerTemplate = pointerTemplateResult.Result;
         int totalIndex = 0;
         for (int i = 0; i < this.pointerList.Length; i++)
         {
             List<string> line = new List<string>();
             line.Add(pointerTemplate.Name);
             int thisOffset = offset + 4 * totalIndex;
             for (int j = 0; j < this.pointerList[i].Length; j++)
             {
                 line.Add(pointerList[totalIndex].ToHexString("$"));
                 totalIndex++;
             }
             lines[thisOffset] = new Code(line.ToArray(), pointerTemplate, this.pointerList[i].Length * 4);
         }
     }
 }
开发者ID:Diegoisawesome,项目名称:AwesomeMapEditor-old,代码行数:26,代码来源:EACodeLanguageDisassembler.cs


注:本文中的ILog.AddError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。