Ejemplo n.º 1
0
        public static void WriteError(this ILogger logger, string msg, Exception exp, Dictionary <string, object> srcProps = null)
        {
            var _msg = $"{msg}";
            Dictionary <string, object> props = new Dictionary <string, object>();

            if (exp != null)
            {
                props = SaveExceptionProperties(exp);
            }

            if (srcProps != null && srcProps.Count > 0)
            {
                foreach (var item in srcProps)
                {
                    if (!props.ContainsKey(item.Key) && item.Value != null)
                    {
                        props[item.Key] = item.Value;
                    }
                }
            }

            if (props != null && props.Count > 0)
            {
                _msg = $"{_msg}, Props: {props.Dump()}";
            }
            logger.LogError(_msg);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Save the settings object to a .bbs file
        /// </summary>
        public static void SaveSettings()
        {
            PABXFile <Dictionary <string, SettingsStore> > .SaveObject("config.bbs", Settings);

#if DEBUG
            Settings.Dump();
#endif
        }
Ejemplo n.º 3
0
        public void Dump_Writes_Dictionary_Correct()
        {
            Options.Instance.ColorizeConsoleOutput = false;
            var testValue = new Dictionary <int, TestWithSameName>()
            {
                { 1, new TestWithSameName()
                  {
                      Name = "Nothing"
                  } },
                { 2, new TestWithSameName()
                  {
                      Name = "Much"
                  } }
            };

            var expected =
                @"System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[Evands.Pellucid.DumpTests+TestWithSameName, Evands.Pellucid.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] (2 Items)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Key0   = 1
| Value0 = Evands.Pellucid.DumpTests+TestWithSameName (1 Property)
|          -------------------------------------------------------
|          | Name = ""Nothing""
|          -------------------------------------------------------
| Key1   = 2
| Value1 = Evands.Pellucid.DumpTests+TestWithSameName (1 Property)
|          -------------------------------------------------------
|          | Name = ""Much""
|          -------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
";

            testValue.Dump(true);

            Assert.IsTrue(ContainsText(expected), "Complex Object Dictionary Failed.");

            writer.Messages.Clear();

            var testValue2 = new Dictionary <int, string>()
            {
                { 1, "Value 1" }, { 2, "Value 2" }, { 3, "Value 3" }
            };

            expected =
                @"Dictionary`2 (3 Items)
----------------------
| Key0   = 1
| Value0 = ""Value 1""
| Key1   = 2
| Value1 = ""Value 2""
| Key2   = 3
| Value2 = ""Value 3""
----------------------
";

            testValue2.Dump();

            Assert.IsTrue(ContainsText(expected), "Simple Object Dictionary Failed.");
        }
 public static void DictionaryOldWay()
 {
     var dict = new Dictionary<string, int>()
     {
         {"answer", 42},
         {"year", 1984},
         {"bicycles", 9000000}
     };
     dict.Dump("Old way");
 }
        public static void DictionaryNewWay()
        {
            var dict = new Dictionary<string, int>
            {
                ["answer"] = 42,
                ["year"] = 1984,
                ["bicycles"] = 9000000
            };

            dict.Dump("New way");
        }
Ejemplo n.º 6
0
        public static async void LoadSettings()
        {
            Settings = await PABXFile <Dictionary <string, SettingsStore> > .LoadObjectAsync("config.bbs") ?? new Dictionary <string, SettingsStore>();

            if (!Settings.ContainsKey(CurrentUser.login.ToString()))
            {
                Settings[CurrentUser.login.ToString()] = new SettingsStore();
            }
#if DEBUG
            Settings.Dump();
#endif
        }
        public static void LoadAndCacheStorage()
        {
            Paused = true;

            EmptyCacheCollectors();
            {
                Debug("Clearing Cache... Success");
                Debug("");
            }

            Debug($"Loading Client Templates...");

            LoadMaps();
            LoadSkillTemplates();
            LoadSpellTemplates();
            LoadItemTemplates();
            LoadMonsterTemplates();
            LoadMundaneTemplates();
            LoadWarpTemplates();
            LoadPopupTemplates();
            LoadWorldMapTemplates();
            CacheCommunityAssets();
            BindTemplates();
            LoadMetaDatabase();
            LoadExtensions();

            Paused = false;

            Insight("Loaded {0} Boards Loaded from Cache ({1})", GlobalBoardCache.Count, GlobalBoardCache.Dump());
            Insight("Loaded {0} Monster Templates Loaded from Cache ({1})", GlobalMonsterTemplateCache.Count,
                    GlobalMonsterTemplateCache.Dump());
            Insight("Loaded {0} Item Templates Loaded from Cache ({1})", GlobalItemTemplateCache.Count,
                    GlobalItemTemplateCache.Dump());
            Insight("Loaded {0} Mundane Templates Loaded from Cache ({1})", GlobalMundaneTemplateCache.Count,
                    GlobalMundaneTemplateCache.Dump());
            Insight("Loaded {0} Warp Templates Loaded from Cache ({1})", GlobalWarpTemplateCache.Count,
                    GlobalWarpTemplateCache.Dump());
            Insight("Loaded {0} Area Templates Loaded from Cache ({1})", GlobalMapCache.Count, GlobalMapCache.Dump());
            Insight("Loaded {0} Popup Templates Loaded from Cache ({1})", GlobalPopupCache.Count,
                    GlobalPopupCache.Dump());
            Insight("Loaded {0} Buff Templates Loaded from Cache ({1})", GlobalBuffCache.Count, GlobalBuffCache.Dump());
            Insight("Loaded {0} DeBuff Templates Loaded from Cache ({1})", GlobalDeBuffCache.Count,
                    GlobalDeBuffCache.Dump());
            Insight("Loaded {0} Skill Templates Loaded from Cache ({1})", GlobalSkillTemplateCache.Count,
                    GlobalSkillTemplateCache.Dump());
            Insight("Loaded {0} Spell Templates Loaded from Cache ({1})", GlobalSpellTemplateCache.Count,
                    GlobalSpellTemplateCache.Dump());
            Insight("Loaded {0} WorldMap Templates Loaded from Cache ({1})", GlobalWorldMapTemplateCache.Count,
                    GlobalWorldMapTemplateCache.Dump());
            Insight("Loaded {0} Reactor Templates Loaded from Cache ({1})", GlobalReactorCache.Count,
                    GlobalReactorCache.Dump());
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            new List <Test>
            {
                Test.New(123, "Test", Test.New(124, "Test", Test.New(125, "Test",
                                                                     Test.New(126, "Test", Test.New(127, "Test",
                                                                                                    Test.New(128, "Test", Test.New(129, "Test",
                                                                                                                                   Test.New(130, "Test", Test.New(131, "Test")))))))))
            }.Dump();

            new List <Test>
            {
                Test.New(123, "Test"),
                Test.New(123, "Test"),
                Test.New(123, "Test"),
                Test.New(123, "Test"),
                Test.New(123, "Test"),
                Test.New(123, "Test"),
                Test.New(123, "Test"),
                Test.New(123, "Test"),
                Test.New(123, "Test"),
            }.Dump();

            var dictionary = new Dictionary <int, Test>
            {
                { 0, Test.New(123, "Test") },
                { 1, Test.New(123, "Test") },
                { 2, Test.New(123, "Test") },
                { 3, Test.New(123, "Test") },
                { 4, Test.New(123, "Test") },
                { 5, Test.New(123, "Test") },
                { 6, Test.New(123, "Test") },
            };

            dictionary.Dump();
        }
Ejemplo n.º 9
0
    public static List <VssInfo> GetVssInfoViaWmi(string driveLetter)
    {
        if (driveLetter == null)
        {
            driveLetter = string.Empty;
        }

        if (driveLetter.Length > 1)
        {
            driveLetter = driveLetter.Substring(0, 1);
        }

        var loggerConsole = LogManager.GetLogger("Console");

        var vss = new List <VssInfo>();

        loggerConsole.Debug("Running WMI queries to get VSC info");

        var volInfo = new Dictionary <string, string>();

        using (var con = new WmiConnection())
        {
            foreach (var vol in con.CreateQuery("SELECT caption,DeviceID FROM Win32_volume"))
            {
                volInfo.Add(vol["DeviceID"].ToString(), vol["caption"].ToString());
            }
        }

        loggerConsole.Trace($"Volume info from WMI: {volInfo.Dump()}");

        using (var con = new WmiConnection())
        {
            foreach (var scInfo in con.CreateQuery(
                         "SELECT DeviceObject,ID,InstallDate,OriginatingMachine,VolumeName,ServiceMachine FROM Win32_ShadowCopy")
                     )
            {
                var devObj      = scInfo["DeviceObject"].ToString();
                var id          = scInfo["ID"].ToString();
                var installDate = scInfo["InstallDate"].ToString();

                var idd = ManagementDateTimeConverter.ToDateTime(installDate);
                idd = DateTime.SpecifyKind(idd, DateTimeKind.Local);

                var instDateTimeOffset = new DateTimeOffset(idd).ToUniversalTime();

                var origMachine    = scInfo["OriginatingMachine"].ToString();
                var serviceMachine = scInfo["ServiceMachine"].ToString();
                var origVolume     = scInfo["VolumeName"].ToString();

                var volLetter = volInfo[origVolume].Substring(0, 1);

                var vsI = new VssInfo(instDateTimeOffset, id, devObj, origMachine, serviceMachine, volLetter,
                                      origVolume);

                if (!volLetter.ToUpperInvariant().StartsWith(driveLetter.ToUpperInvariant()) &&
                    driveLetter.Trim().Length != 0)
                {
                    continue;
                }

                loggerConsole.Trace($"Adding VSC: {vsI.Dump()}");
                vss.Add(vsI);
            }
        }

        loggerConsole.Debug($"Found {vss.Count:N0} VSCs");

        return(vss);
    }
Ejemplo n.º 10
0
 public void DumpProperties()
 {
     _properties.Dump();
 }
Ejemplo n.º 11
0
        public static void LoadAndCacheStorage()
        {
            Paused = true;

            EmptyCacheCollectors();
            {
                Logger?.Info(string.Format("Clearing Cache... Success"));
                Logger?.Info(string.Format(""));
            }

            Logger?.Trace(string.Format("Loading Server Templates..."));

            LoadMaps();
            LoadSkillTemplates();
            LoadSpellTemplates();
            LoadItemTemplates();
            LoadMonsterTemplates();
            LoadMundaneTemplates();
            LoadWarpTemplates();
            LoadPopupTemplates();
            LoadWorldMapTemplates();
            CacheCommunityAssets();
            BindTemplates();
            LoadMetaDatabase();
            LoadExtensions();

            Paused = false;

            Logger?.Trace(string.Format("Server Ready!, Listening for Connections..."));

            ServerContext.Log("Loaded {0} Boards Loaded from Cache ({1})", GlobalBoardCache.Count, GlobalBoardCache.Dump());
            ServerContext.Log("Loaded {0} Monster Templates Loaded from Cache ({1})", GlobalMonsterTemplateCache.Count, GlobalMonsterTemplateCache.Dump());
            ServerContext.Log("Loaded {0} Item Templates Loaded from Cache ({1})", GlobalItemTemplateCache.Count, GlobalItemTemplateCache.Count);
            ServerContext.Log("Loaded {0} Mundane Templates Loaded from Cache ({1})", GlobalMundaneTemplateCache, GlobalMundaneTemplateCache.Dump());
            ServerContext.Log("Loaded {0} Warp Templates Loaded from Cache ({1})", GlobalWarpTemplateCache.Count, GlobalWarpTemplateCache.Dump());
            ServerContext.Log("Loaded {0} Area Templates Loaded from Cache ({1})", GlobalMapCache.Count, GlobalMapCache.Dump());
            ServerContext.Log("Loaded {0} Popup Templates Loaded from Cache ({1})", GlobalPopupCache.Count, GlobalPopupCache.Dump());
            ServerContext.Log("Loaded {0} Buff Templates Loaded from Cache ({1})", GlobalBuffCache.Count, GlobalBuffCache.Dump());
            ServerContext.Log("Loaded {0} DeBuff Templates Loaded from Cache ({1})", GlobalDeBuffCache.Count, GlobalDeBuffCache.Dump());
            ServerContext.Log("Loaded {0} Skill Templates Loaded from Cache ({1})", GlobalSkillTemplateCache.Count, GlobalSkillTemplateCache.Dump());
            ServerContext.Log("Loaded {0} Spell Templates Loaded from Cache ({1})", GlobalSpellTemplateCache.Count, GlobalSpellTemplateCache.Dump());
            ServerContext.Log("Loaded {0} WorldMap Templates Loaded from Cache ({1})", GlobalWorldMapTemplateCache.Count, GlobalWorldMapTemplateCache.Dump());
            ServerContext.Log("Loaded {0} Reactor Templates Loaded from Cache ({1})", GlobalReactorCache.Count, GlobalReactorCache.Dump());
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Scan a DAT file and look for signatures
        /// </summary>
        static void SearchDat(string filename)
        {
            Console.WriteLine($"Searching {filename} for valid entries...");

            // Statistics:
            HashSet <string>          unhandled    = new HashSet <string>();
            Dictionary <string, long> entryTypes   = new Dictionary <string, long>();
            Dictionary <int, long>    messageTypes = new Dictionary <int, long>();
            DateTime         earliest   = DateTime.MaxValue;
            DateTime         latest     = DateTime.MinValue;
            HashSet <string> properties = new HashSet <string>();
            int duplicateContacts       = 0;
            int duplicateMessages       = 0;

            var datFile = new DatFile();
            var rdr     = new FileReader();

            Parser.DefaultDumpFormat = DumpFormat.Hex;
            //Parser.Debug = true;

            HexDumperConsole console = new HexDumperConsole();

            Parser.Dumper.Console = console;

            rdr.Open(filename);

            datFile.MainHeader.Read(rdr);

            FileImport fi = new FileImport()
            {
                Filename = filename, ImportDate = DateTime.Now
            };

            _context.FileImports.Add(fi);
            _context.SaveChanges();

            var fileImportId = fi.Id;

            byte prev0 = 0;
            byte prev1 = 0;
            long ix    = 0;

            //rdr.GoTo(0x265280);
            //console.ColorSpan = new ColorSpan(ConsoleColor.Green, 0x265290, 0x265290 + 4 + 146);

            try
            {
                while (true)
                {
                    Data8 d = new Data8();
                    d.Read(rdr);

                    if (prev0 == 0x23 && d.Value == 0xA3)
                    {
                        string code = prev1.ToString("X2");
                        Parser.Dumper.OnInfo($"Found sig with code: {code}");
                        entryTypes[code] = entryTypes.GetValueOrDefault(code) + 1;

                        if (datFile.ValidSigs.Contains(prev1))
                        {
                            var pos = rdr.Position;
                            rdr.GoTo(pos - (4 + 4 + 4 + 3));

                            datFile.PolyChunk.Read(rdr);

                            if (datFile.PolyChunk.CurrentType == typeof(E0Entry))
                            {
                                E0Entry entry = ((E0Entry)datFile.PolyChunk.CurrentChunk);
                                int     mtype = entry.entrySubtype.Value;
                                messageTypes[mtype] = messageTypes.GetValueOrDefault(mtype) + 1;
                                if (entry.timestamp.Value < earliest)
                                {
                                    earliest = entry.timestamp.Value;
                                }
                                if (entry.timestamp.Value > latest)
                                {
                                    latest = entry.timestamp.Value;
                                }

                                var msg = ToMessage((E0Entry)datFile.PolyChunk.CurrentChunk);

                                if (_context.Messages.Any(m => m.Hash == msg.Hash))
                                {
                                    duplicateMessages++;
                                }
                                else
                                {
                                    msg.FileImportId = fileImportId;
                                    _context.Messages.Add(msg);
                                    _context.SaveChanges();
                                }
                            }

                            if (datFile.PolyChunk.CurrentType == typeof(E5Entry))
                            {
                                E5Entry e = (E5Entry)datFile.PolyChunk.CurrentChunk;

                                e.Properties.Keys.ToList().ForEach(p => properties.Add(p));

                                var ct = ToContact(e);

                                if (_context.Contacts.Any(c => c.Hash == ct.Hash))
                                {
                                    duplicateContacts++;
                                }
                                else
                                {
                                    foreach (var pv in e.Properties)
                                    {
                                        var ctp = new ContactProperty()
                                        {
                                            UIN   = e.UIN,
                                            Name  = pv.Key,
                                            Value = pv.Value,
                                        };
                                        _context.ContactProperties.Add(ctp);
                                    }

                                    ct.FileImportId = fileImportId;
                                    _context.Contacts.Add(ct);
                                    _context.SaveChanges();
                                }
                            }

                            prev0 = prev1 = 0;
                            d.StartNew();
                        }
                        else
                        {
                            if (!unhandled.Contains(code))
                            {
                                unhandled.Add(code);
                                Parser.Dumper.OnInfo("Unhandled signatures: " + string.Join(", ", unhandled.ToArray()));
                            }
                        }
                    }

                    if (prev1 == 0x50 && prev0 == 0x3B && d.Value == 0xC1)
                    {
                        // Long message format
                        var pos = rdr.Position;
                        rdr.GoTo(pos - (4 + 4 + 4 + 3));

                        datFile.LongMessage.Read(rdr);

                        string code = "Long";
                        entryTypes[code] = entryTypes.GetValueOrDefault(code) + 1;

                        int mtype = datFile.LongMessage.entrySubtype.Value;
                        messageTypes[mtype] = messageTypes.GetValueOrDefault(mtype) + 1;

                        if (datFile.LongMessage.timestamp.Value < earliest)
                        {
                            earliest = datFile.LongMessage.timestamp.Value;
                        }
                        if (datFile.LongMessage.timestamp.Value > latest)
                        {
                            latest = datFile.LongMessage.timestamp.Value;
                        }

                        var msg = ToMessage(datFile.LongMessage);
                        if (_context.Messages.Any(m => m.Hash == msg.Hash))
                        {
                            duplicateMessages++;
                        }
                        else
                        {
                            msg.FileImportId = fileImportId;
                            _context.Messages.Add(msg);
                            _context.SaveChanges();
                        }

                        prev0 = prev1 = 0;
                        d.StartNew();
                    }

                    // Go on scanning
                    prev1 = prev0;
                    prev0 = d.Value;
                    ix++;

                    if (ix % 256 * 16 == 0)
                    {
                        Parser.Dumper.OnInfo("");
                    }
                }
            }
            catch (ParserEOFException)
            {
                Parser.Dumper.OnInfo("End of file.");
            }
            catch (Exception ex)
            {
                Parser.Dumper.OnInfo("Unhandled Exception: " + ex.Message);
            }

            StringBuilder sb = new StringBuilder();

            Console.WriteLine("");
            Console.WriteLine("Statistics for file: " + filename);
            sb.Append("Statistics for file: " + filename + Environment.NewLine);

            Console.WriteLine("");
            Console.WriteLine("Unhandled signatures: " + string.Join(", ", unhandled.ToArray()));
            sb.Append("Unhandled signatures: " + string.Join(", ", unhandled.ToArray()));

            Console.WriteLine("");
            Console.WriteLine("Duplicated Contacts: " + duplicateContacts);
            sb.Append("Duplicated Contacts: " + duplicateContacts);

            Console.WriteLine("");
            Console.WriteLine("Duplicated Messages: " + duplicateMessages);
            sb.Append("Duplicated Messages: " + duplicateMessages);

            Console.WriteLine("");
            Console.WriteLine("Earliest message: " + earliest.ToString("yyyy-MM-dd HH:mm:ss"));
            Console.WriteLine("Latest message  : " + latest.ToString("yyyy-MM-dd HH:mm:ss"));
            sb.Append("Latest message  : " + latest.ToString("yyyy-MM-dd HH:mm:ss") + "\n");
            sb.Append("Earliest message: " + earliest.ToString("yyyy-MM-dd HH:mm:ss") + "\n");

            Console.WriteLine("Entry types:\n" + entryTypes.Dump());
            sb.Append("Entry types:\n" + entryTypes.Dump());

            Console.WriteLine("");
            Console.WriteLine("Message types:\n" + messageTypes.Dump());
            sb.Append("Message types:\n" + messageTypes.Dump());

            Console.WriteLine("");
            Console.WriteLine("Contact properties: " + string.Join(", ", properties.ToArray()));

            fi.Statistics            = sb.ToString();
            _context.Entry(fi).State = EntityState.Modified;
            _context.SaveChanges();
        }