Exemplo n.º 1
0
        private Dictionary <string, ColumnHeaderWrapper <SenseLogInfo> > CreateHeaders()
        {
            var helper  = new ModelFilterHelper();
            var headers = new Dictionary <string, ColumnHeaderWrapper <SenseLogInfo> >
            {
                { "Name", helper.CreateColumnHeaderWrapper <SenseLogInfo, string>("Name", "Name") },
                { "LogFilePath", helper.CreateColumnHeaderWrapper <SenseLogInfo, string>("Path", "LogFilePath") },
                { "LastModified", helper.CreateColumnHeaderWrapper <SenseLogInfo, DateTime?>("Modified date", "LastModified") }
            };

            return(headers);
        }
        private async Task <bool> LoadStuff()
        {
            var helper  = new ModelFilterHelper();
            var headers = new Dictionary <string, ColumnHeaderWrapper <EventLogEntryShort> >
            {
                { "Level", helper.CreateColumnHeaderWrapper <EventLogEntryShort, string>("Level", "Level") },
                { "Source", helper.CreateColumnHeaderWrapper <EventLogEntryShort, string>("Source", "Source") },
                { "Event Id", helper.CreateColumnHeaderWrapper <EventLogEntryShort, long?>("Event Id", "InstanceId") },
                { "Message", helper.CreateColumnHeaderWrapper <EventLogEntryShort, string>("Message", "Message").IgnoreInGrid() },
                { "User", helper.CreateColumnHeaderWrapper <EventLogEntryShort, string>("User", "User").IgnoreInGrid() },
                { "Date and time", helper.CreateColumnHeaderWrapper <EventLogEntryShort, DateTime?>("Date and time", "Logged") }
            };


            List <EventLogEntryShort> res = new List <EventLogEntryShort>();

            _gridAndData = new Dictionary <string, DataWrapper>();



            if (Switchboard.Instance.LogCollectorOutput?.GroupedServerInfo != null)
            {
                //var splash = SplashManager.Loader.ShowFloatingSplash(this,"Opening Windows logs..");
                ShowSplash("Opening Windows logs..");
                try
                {
                    _validationErrors = new List <string>();
                    res = await Switchboard.Instance.LogCollectorOutput.WindowsEventLogItems(JsonErrors);

                    if (_validationErrors.Any())
                    {
                        string err = _validationErrors.Take(5).Aggregate((curr, next) => curr + "\r\n" + next);
                        Mbox.Show($"We had problems parsing this Windows event log. We found {_validationErrors.Count} errors\r\n\r\n{err}", "Problems in parsing Windows event log");
                    }
                }
                catch (Exception e)
                {
                    Mbox.Show($"The Windows log is invalid.\r\n\r\n{e}", "Sorry we can't read this");
                }
                finally
                {
                    HideSplash();
                }
            }

            if (res == null)
            {
                return(false);
            }
            foreach (var item in res)
            {
                if (item.LogName == null)
                {
                    continue;
                }
                if (!_gridAndData.ContainsKey(item.LogName))
                {
                    _gridAndData.Add(item.LogName, new DataWrapper());
                    _gridAndData[item.LogName].GridAndDataWrapper.Data    = new List <EventLogEntryShort>();
                    _gridAndData[item.LogName].GridAndDataWrapper.Headers = headers;
                }
                _gridAndData[item.LogName].GridAndDataWrapper.Data.Add(item);
            }
            InvokeGrid(CtrlGridTabs.SelectedTab);
            return(true);
        }