示例#1
0
        private static void InternalReportError(string folder, string itemType, string bankKey, string itemId, ErrorCategory category, ErrorSeverity severity, string msg, string detail)
        {
            // If deduplicate, find out if this error has already been reported for this particular item.
            if (DeDuplicate)
            {
                // Create a hash of the itemId and message
                var errHash = new ShaHash(string.Concat(itemType, bankKey, itemId, msg));

                // If it's aready in the set then exit
                if (!s_ErrorsReported.Add(errHash))
                {
                    return; // Already reported an error of this type on this item
                }
            }

            if (m_ErrorReport == null)
            {
                InitErrorReport();
            }

            if (CurrentPackageName != null)
            {
                folder = string.Concat(CurrentPackageName, "/", folder);
            }

            // "Folder,ItemType,BankKey,ItemId,Category,Severity,ErrorMessage,Detail"
            m_ErrorReport.WriteLine(string.Join(",", Tabulator.CsvEncode(folder),
                                                Tabulator.CsvEncode(bankKey), Tabulator.CsvEncode(itemId), Tabulator.CsvEncode(itemType),
                                                category.ToString(), severity.ToString(), Tabulator.CsvEncode(msg), Tabulator.CsvEncode(detail)));

            ++ErrorCount;
        }
示例#2
0
    private Species GetKey(Vector3 worldPos)
    {
        var sqr   = radius * radius;
        var nears = lifes
                    .Where(v => (v.transform.position - worldPos).sqrMagnitude < sqr);
        var count = nears.Count();

        int modelIndex = -1;
        int colorIndex = -1;

        if (count > 0 && !Interfered())
        {
            var modelTabs = new Tabulator <int, float>();
            foreach (var n in nears.Select(v => v.CurrentKey))
            {
                modelTabs[n.model]++;
            }

            var max = modelTabs.Values.Max();
            int valueIndex;
            if (RouletteWheelSelection.Sample(out valueIndex, 100, max, modelTabs.ValuesAsList))
            {
                modelIndex = modelTabs.KeysAsList[valueIndex];
            }

            var colors     = nears.Where(v => v.CurrentKey.model == modelIndex);
            var colorCount = colors.Count();
            if (colorCount > 0 && !Interfered())
            {
                var colorTabs = new Tabulator <int, float>();
                foreach (var n in colors.Select(v => v.CurrentKey))
                {
                    colorTabs[n.color]++;
                }

                var maxColor = colorTabs.Values.Max();
                int colorTabIndex;
                if (RouletteWheelSelection.Sample(out colorTabIndex, 100, maxColor, colorTabs.ValuesAsList))
                {
                    colorIndex = colorTabs.KeysAsList[colorTabIndex];
                }
            }
        }

        if (modelIndex < 0)
        {
            modelIndex = Random.Range(0, LifeStrage.Instance.models.Length);
        }
        var model = LifeStrage.Instance.GetModel(modelIndex);

        if (colorIndex < 0)
        {
            colorIndex = Random.Range(0, model.colors.Length);
        }

        var spec = new Species(modelIndex, colorIndex);

        Debug.LogFormat("Chosen key={0} neighbors={1}", spec, count);
        return(spec);
    }
示例#3
0
        public Form1()
        {
            InitializeComponent();

            /*
             * var factory = TestDll.CreateTestFactory();
             * var args = factory.CreateUpdateArgs();
             * var sys = factory.CreateTestSystem();
             *
             * var time = args.GetElapsedTime();
             * args.SetElapsedTime(0.1f);
             * time = args.GetElapsedTime();
             * sys.Update(args);
             */

            var input  = File.ReadAllText(@"C:\_faust\FaustGamesTools\PInvokeGenerator\include\TestHeader.h");
            var parser = new ParserCpp();
            var result = parser.Parse("TestDll.dll", "TestHeader.h", input);

            result.Build();
            var pInvoke   = result.CreatePInvokeCpp();
            var formatter = new FormatProviderCppPInvoke();
            var tabulator = new Tabulator();

            formatter.Format(pInvoke, tabulator);
            File.WriteAllText(@"C:\_faust\FaustGamesTools\PInvokeGenerator\gen\TestHeaderPInvoke.cpp", tabulator.Build());

            var pInvokeCSharp   = result.CreatePInvokeCSharp();
            var formatterCSharp = new FormatProviderCSharpPInvoke();
            var tabulatorCSharp = new Tabulator();

            formatterCSharp.Format(pInvokeCSharp, tabulatorCSharp);
            File.WriteAllText(@"C:\_faust\FaustGamesTools\PInvokeGenerator\gen\TestHeaderPInvoke.cs", tabulatorCSharp.Build());
        }
        private void WriteProcessList(IList <IProcessInfo> processes, ConsoleLog console)
        {
            if (!processes.Any())
            {
                return;
            }
            var tabulator = new Tabulator(
                new Column("Pid")
            {
                Width = 5, RightAlign = true
            },
                new Column("Name")
            {
                Width = 20
            },
                new Column("Memory")
            {
                Width = 12, RightAlign = true
            },
                new Column("CLR Versions")
            {
                Width = 12
            },
                new Column("App Pool"))
            {
                Defaults = { Padding = 2 }
            };

            console.WriteLine($"{processes.Count} matching {ProcessArchitecture.FromCurrentProcess().Describe()} processes were found:");
            console.WriteLine(tabulator.GetHeader());
            foreach (var candidate in processes.OrderBy(c => c.Pid))
            {
                console.WriteLine(tabulator.Tabulate(candidate.Pid, candidate.Name, $"{candidate.WorkingSetSizeBytes.InKilobytes()} KB", DescribeCLRVersions(candidate), candidate.IISAppPoolName));
            }
        }
示例#5
0
 public override void Format(CodeFile file, Tabulator tabulator)
 {
     _file = file;
     tabulator.AppendFormatLine("using System;");
     tabulator.AppendFormatLine("using System.Runtime.InteropServices;");
     tabulator.AppendLine("");
     base.Format(file, tabulator);
 }
示例#6
0
 protected override void BeforeAppendStaticMethod(Tabulator tabulator, Method value)
 {
     tabulator.AppendLine("[DllImport(Version.Dll)]");
     if (value.ResulTypeName == "bool")
     {
         tabulator.AppendLine("[return: MarshalAs(UnmanagedType.I1)]");
     }
 }
示例#7
0
        protected void BeforeConvert(Tabulator.Core.Table t)
        {
            if( t.Count < 1 || t[0].Count < 1 )
                throw new Exception("Empty table can not be converted.");

            this.buffer.Clear();
            this.optionalWidths = t.MaxWidths( this.options.MaxColWidth );
        }
示例#8
0
 protected override void BeforeFillNamespace(Tabulator tabulator, Namespace value)
 {
     BeginCodeBlock(tabulator, FormatPatterns.PatternClass, "Version");
     tabulator.AppendFormatLineWithoutTabs("#if __UNIFIED__");
     tabulator.AppendFormatLine("public const string Dll = \"{0}\";", "__Internal");
     tabulator.AppendFormatLineWithoutTabs("#else");
     tabulator.AppendFormatLine("public const string Dll = \"{0}\";", _file.LibraryName);
     tabulator.AppendFormatLineWithoutTabs("#endif");
     EndCodeBlock(tabulator);
 }
示例#9
0
        private void WriteHeapStatistics(IList <RawTypeInfo> allHeapInfo, TextWriter output)
        {
            var stats = allHeapInfo.Select(t => new {
                t.TypeName,
                SizeInBytes = Statistics.CalculateInPlace(t.SizesInBytes)
            })
                        .OrderByDescending(s => s.SizeInBytes.Total)
                        .ToList();

            var tabulator = new Tabulator(
                new Column("Total")
            {
                Width = 10, RightAlign = true
            },
                new Column("Count")
            {
                Width = 10, RightAlign = true
            },
                new Column("Mean")
            {
                Width = 10, RightAlign = true
            },
                new Column("StdDev")
            {
                Width = 10, RightAlign = true
            },
                new Column("Median")
            {
                Width = 10, RightAlign = true
            },
                new Column("Max")
            {
                Width = 10, RightAlign = true
            },
                new Column("Type")
                )
            {
                Defaults = { Padding = 2 }
            };

            output.WriteLine("Heap object types:");
            output.WriteLine(tabulator.GetHeader());
            foreach (var s in stats)
            {
                tabulator.Tabulate(output,
                                   s.SizeInBytes.Total,
                                   s.SizeInBytes.Count,
                                   Math.Round(s.SizeInBytes.Mean),
                                   s.SizeInBytes.StandardDeviation.ToString("0.0"),
                                   Math.Round(s.SizeInBytes.Median),
                                   s.SizeInBytes.Maximum,
                                   s.TypeName);
                output.WriteLine();
            }
        }
示例#10
0
        private static void InitErrorReport()
        {
            if (m_ErrorReport != null)
            {
                return;
            }
            m_ErrorReport = new StreamWriter(ErrorReportPath, false, Encoding.UTF8);
            m_ErrorReport.WriteLine("Folder,BankKey,ItemId,ItemType,Category,Severity,ErrorMessage,Detail");

            var    application = System.Reflection.Assembly.GetExecutingAssembly();
            string detail      = $"version='{application.GetName().Version}' options='{Program.Options}'";

            m_ErrorReport.WriteLine(string.Join(",", string.Empty,
                                                string.Empty, string.Empty, string.Empty,
                                                ErrorCategory.System.ToString(), ErrorSeverity.Message.ToString(),
                                                "Tabulator Start", Tabulator.CsvEncode(detail)));
        }
示例#11
0
        public override string Convert(Tabulator.Core.Table t)
        {
            BeforeConvert(t);

            if( t.Caption.Length > 0 ) {
                Console.Error.WriteLine("Caption is not posible in csv format.");
            }

            foreach( Line line in t )
            {
                if( line.isEmpty() ) continue;
                ConvertLine( line );
                buffer.AppendLine();
            }

            return buffer.ToString();
        }
示例#12
0
        public void HeaderAlignmentMatchesColumn()
        {
            var tabulator = new Tabulator(
                new Column("A")
            {
                Width = 4
            },
                new Column("B")
            {
                Width = 4, RightAlign = true
            }
                )
            {
                Defaults = { Padding = 0 }
            };

            var header = tabulator.GetHeader();

            Assert.That(header, Is.EqualTo("A      B"));
        }
示例#13
0
        public void HeaderDoesNotHaveTrailingLineBreak()
        {
            var tabulator = new Tabulator(
                new Column("A")
            {
                Width = 4
            },
                new Column("B")
            {
                Width = 4
            }
                )
            {
                Defaults = { Padding = 0 }
            };

            var header = tabulator.GetHeader();

            Assert.That(header, Does.Not.Contain("\n"));
        }
示例#14
0
        public override string Convert(Tabulator.Core.Table t)
        {
            BeforeConvert(t);

            buffer.AppendLine("<table>");
            buffer.AppendLine("<thead>");
            buffer.AppendLine("</thead>");

            buffer.AppendLine("<tbody>");
            foreach( Line l in t ) {
                if( l.isEmpty() ) continue;
                buffer.Append("<tr><td>");
                ConvertLine( l );
                buffer.TrimLineEnd();					// remove white spaces
                buffer.Remove( buffer.Length - 5, 4);	// remove last "<td>"
                buffer.AppendLine("</tr>" );
            }
            buffer.AppendLine("</tbody>");
            buffer.AppendLine("</table>");

            return buffer.ToString();
        }
示例#15
0
        private static void Main(string[] args)
        {
#if DEBUG
            if (Directory.Exists("include"))
            {
                var headers = Directory.GetFiles("include", "*.h");
                foreach (var a in headers)
                {
                    Console.WriteLine("processing '" + a + "'");
                    var ext = Path.GetExtension(a);
                    if (ext == null)
                    {
                        continue;
                    }
                    if (ext.ToLower() != ".h")
                    {
                        continue;
                    }
                    var name = Path.GetFileNameWithoutExtension(a);
                    if (name == null)
                    {
                        continue;
                    }
                    var dir = Path.GetDirectoryName(a);
                    if (dir == null)
                    {
                        continue;
                    }

                    var input  = File.ReadAllText(a);
                    var parser = new ParserCpp();
                    var result = parser.Parse(name, name + ".h", input);
                    result.Build();
                    var pInvoke   = result.CreatePInvokeCpp();
                    var formatter = new FormatProviderCppPInvoke();
                    var tabulator = new Tabulator();
                    formatter.Format(pInvoke, tabulator);
                    Console.WriteLine("save '" + @"gen\" + name + "PInvoke.cpp" + "'");
                    File.WriteAllText(@"gen\" + name + "PInvoke.cpp", tabulator.Build());

                    var pInvokeCSharp   = result.CreatePInvokeCSharp();
                    var formatterCSharp = new FormatProviderCSharpPInvoke();
                    var tabulatorCSharp = new Tabulator();
                    formatterCSharp.Format(pInvokeCSharp, tabulatorCSharp);
                    Console.WriteLine("save '" + @"gen\" + name + "PInvoke.cs" + "'");
                    File.WriteAllText(@"gen\" + name + "PInvoke.cs", tabulatorCSharp.Build());
                }
            }
#endif
            if (args.Length == 0)
            {
                // todo: display help
            }

            foreach (var a in args)
            {
                //if (!Directory.Exists(a)) continue;

                var ext = Path.GetExtension(a);
                if (ext == null)
                {
                    continue;
                }
                if (ext.ToLower() != ".h")
                {
                    continue;
                }
                var name = Path.GetFileNameWithoutExtension(a);
                if (name == null)
                {
                    continue;
                }
                var dir = Path.GetDirectoryName(a);
                if (dir == null)
                {
                    continue;
                }

                var arg    = Path.Combine(dir, name);
                var input  = File.ReadAllText(arg + ".h");
                var parser = new ParserCpp();
                var result = parser.Parse(arg, arg + ".h", input);
                result.Build();

                SaveGeneratedFile <FormatProviderCppPInvoke, Tabulator>(result.CreatePInvokeCpp(), arg + "PInvoke.cpp");
                SaveGeneratedFile <FormatProviderCppJni, Tabulator>(result.CreateJniCpp(), arg + "JniBridge.cpp");
                SaveGeneratedFile <FormatProviderCSharpPInvoke, Tabulator>(result.CreatePInvokeCSharp(), arg + "PInvoke.cs");
            }
        }
示例#16
0
 protected override void BeforeAppendStruct(Tabulator tabulator, Struct value)
 {
     tabulator.AppendLine("[StructLayout(LayoutKind.Sequential)]");
 }