public string Resolve(object source, object destination, Trace sourceMember, string destMember,
                              ResolutionContext context)
        {
            var builder = new StringBuilder();

            builder.Append("<p style=\"white-space: nowrap;\">Start request </p>");
            builder.Append($"<p style=\"white-space: nowrap;\">Identity {sourceMember.CallerIdentity}, Url {sourceMember.Url}, Verb {sourceMember.Verb}, Status {sourceMember.StatusCode}, Duration {sourceMember.CallDuration}</p>");
            builder.Append($"<p style=\"white-space: nowrap;\">With request headers {sourceMember.RequestHeaders}</p>");
            if (!string.IsNullOrEmpty(sourceMember.RequestPayload))
            {
                builder.Append($"<p style=\"white-space: nowrap;\">With request payload: </p>");
                string beautified = (JsonUtils.IsValidJson(sourceMember.RequestPayload)
                    ? $"<pre class=\"prettyprint lang-json\">{JsonPrettifier.BeautifyJson(sourceMember.RequestPayload)}</pre>"
                    : sourceMember.RequestPayload);

                builder.Append(beautified);
            }

            builder.Append($"<p style=\"white-space: nowrap;\">With response headers {sourceMember.ResponseHeaders}</p>");

            if (!string.IsNullOrEmpty(sourceMember.ResponsePayload))
            {
                builder.Append($"<p style=\"white-space: nowrap;\">With request payload: </p>");
                string beautified = (JsonUtils.IsValidJson(sourceMember.ResponsePayload)
                    ? $"<pre class=\"prettyprint lang-json\">{JsonPrettifier.BeautifyJson(sourceMember.ResponsePayload)}</pre>"
                    : sourceMember.ResponsePayload);

                builder.Append(beautified);
            }

            builder.Append("<p style=\"white-space: nowrap;\">End request </p>");
            return(builder.ToString());
        }
Esempio n. 2
0
        private async void MainForm_Shown(object sender, EventArgs e)
        {
            this.SetVersion();
            this.currentTitleStatusLabel.Text = string.Empty;

            if (!File.Exists(Files.DbPath))
            {
                var result = MessageBox.Show(
                    Properties.Resources.Disclaimer,
                    "boo",
                    MessageBoxButtons.OKCancel,
                    MessageBoxIcon.Warning);

                if (result == DialogResult.Cancel)
                {
                    Environment.Exit(0);
                }

                this.statusProgressbar.Style = ProgressBarStyle.Marquee;
                this.UpdateAction("Downloading database...");
                await Task.Run(() => DatabaseParser.DownloadDatabase(Files.DbPath));

                this.UpdateAction($"Prettifying JSON in \"{Files.DbPath}\"...");
                File.WriteAllText(Files.DbPath, JsonPrettifier.FormatJson(File.ReadAllText(Files.DbPath)));
            }

            if (!File.Exists(Files.SizesPath))
            {
                this.UpdateAction("Downloading sizes data...");
                await Task.Run(() => DatabaseParser.DownloadSizes(Files.SizesPath));
            }

            this.UpdateAction($"Reading data from \"{Files.DbPath}\" and \"{Files.SizesPath}\"...");
            this.allTitles = DatabaseParser.ParseFromDatabase(Files.DbPath, Files.SizesPath);

            if (File.Exists(Files.FilterPath))
            {
                this.titleFilter = TitleFilterStorage.ParseFilterSettings(Files.FilterPath);
            }

            this.titles = new SortableBindingList <Nintendo3DSTitle>(TitleFilter.FilterTitles(this.allTitles, this.titleFilter));

            this.titlesDataGrid.DoubleBuffered(true);
            this.titlesDataGrid.DataSource = this.titles;
            this.SortDataGrid();

            this.UpdateAction(string.Empty);
            this.currentTitleStatusLabel.Text = string.Empty;
            this.titlesCountLabel.Text        = this.titles.Count + " titles";
            this.statusProgressbar.Style      = ProgressBarStyle.Blocks;

            this.generateAllTicketsButton.Enabled = true;
            this.filterButton.Enabled             = true;
            this.generateQrCodeButton.Enabled     = true;
        }
Esempio n. 3
0
        private async void checkUpdatesButton_Click(object sender, EventArgs e)
        {
            var result = MessageBox.Show("Check for updates?", "Update", MessageBoxButtons.YesNo);

            if (result == DialogResult.No)
            {
                return;
            }

            this.statusProgressbar.Style = ProgressBarStyle.Marquee;

            const string tempPath  = Files.DbPath + "_temp";
            const string tempSizes = Files.SizesPath + "_temp";

            this.UpdateAction("Downloading new database...");
            using (var client = new WebClient())
            {
                await Task.Run(() => client.DownloadFile("https://3ds.titlekeys.com/json_enc", tempPath));
            }

            this.UpdateAction("Downloading new sizes...");
            using (var client = new WebClient())
            {
                await Task.Run(() => client.DownloadFile("http://housebreaker.net/sizes.json", tempSizes));
            }

            this.UpdateAction("Done!");

            this.UpdateAction("Parsing...");

            var downloadedTitles = DatabaseParser.ParseFromDatabase(tempPath, tempSizes);

            var newTitles     = downloadedTitles.Except(this.allTitles).ToList();
            var newTitleCount = newTitles.Count;

            var newSizes = false;

            foreach (var title in downloadedTitles)
            {
                if (this.allTitles.Where(a => a.TitleId == title.TitleId).Any(otherTitle => otherTitle.Size != title.Size))
                {
                    newSizes = true;
                }
            }

            this.statusProgressbar.Style = ProgressBarStyle.Blocks;

            if (newTitleCount == 0 && !newSizes)
            {
                File.Delete(tempPath);
                File.Delete(tempSizes);

                this.UpdateAction(string.Empty);
                MessageBox.Show("Database is up to date.", "Good news!");
                return;
            }

            if (newTitles.Except(this.allTitles).Count() > 10)
            {
                newTitles = newTitles.Take(10).ToList();
            }

            var more = newTitleCount != newTitles.Count ? $"\r\n and {newTitleCount - 10} more" : string.Empty;

            var parseResult = MessageBox.Show(
                newTitles.Count > 0
                                        ? $"New titles:\r\n{string.Join("\r\n", newTitles)}{more}. Update?"
                                        : "New title size info found. Update?",
                "New titles found",
                MessageBoxButtons.YesNo);

            if (parseResult == DialogResult.Yes)
            {
                var titles = JsonPrettifier.FormatJson(File.ReadAllText(tempPath));
                File.WriteAllText(Files.DbPath, titles);
                File.WriteAllText(Files.SizesPath, File.ReadAllText(tempSizes));

                File.Delete(tempPath);
                File.Delete(tempSizes);

                this.allTitles = downloadedTitles;
                this.FilterTitlesAndUpdate();

                this.UpdateAction("Database updated successfully!");
            }
        }
        public static void Main()
        {
            var html = new HtmlDocument();

            html.Load("tmds.htm");

            var titlesFromTmds = html.DocumentNode
                                 .Descendants("table")
                                 .ToArray()[1]
                                 .Descendants("tr")
                                 .Select(title => title.Descendants("td"))
                                 .Select(a => a.ToArray()[0].InnerText)
                                 .Where(a => a.StartsWith("0004"))
                                 .ToArray();

            var titlesFromDatabase = JObject.FromObject(JsonConvert.DeserializeObject(File.ReadAllText(Files.SizesPath)))
                                     .Properties()
                                     .Select(a => a.Name)
                                     .ToArray();

            var missingTitles = titlesFromTmds.Except(titlesFromDatabase).ToArray();

            Console.WriteLine(titlesFromTmds.Length);
            Console.WriteLine(titlesFromDatabase.Length);
            Console.WriteLine(missingTitles.Length);

            const string bigJsonInvalid = "sizes_invalid.json";

            ////var titles = DatabaseParser.ParseFromDatabase(Files.DbPath, Files.SizesPath);

            ////var titlesWithKeys = DatabaseParser.ParseFromDatabase(Files.DbPath, Files.SizesPath);
            ////var bigJsonForComparison = JObject.FromObject(JsonConvert.DeserializeObject(File.ReadAllText(bigJson)));
            // var titles = // ParseDatabase("community.xml");

            ////// test
            ////var missingTitles = titles.Except(titlesWithKeys).ToList();
            ////Console.WriteLine(missingTitles.Count);
            ////Console.WriteLine(string.Join("\r\n", missingTitles));
            ////Environment.Exit(0);
            ////// test

            ////// test
            ////var sizes = JObject.FromObject(JsonConvert.DeserializeObject(File.ReadAllText(bigJson)));
            ////var totalSize = sizes.Properties().Select(a => long.Parse(a.Value.ToString())).Sum();
            ////Console.WriteLine("Total size of all the eShop: " + DatabaseParser.HumanReadableFileSize(totalSize));
            ////Environment.Exit(0);
            ////// test

            var processed = 0;

            foreach (var title in missingTitles)
            {
                Console.Write($"\r{processed++}/{missingTitles.Length} ({(double)processed / missingTitles.Length * 100:F2}%)");

                var sizesJson = JObject.FromObject(JsonConvert.DeserializeObject(File.ReadAllText(Files.SizesPath)));

                var sizesJsonInvalid = JObject.FromObject(JsonConvert.DeserializeObject(File.ReadAllText(bigJsonInvalid)));

                if (sizesJson[title] == null && sizesJsonInvalid[title] == null)
                {
                    long size;

                    try
                    {
                        size = CDNUtils.GetTitleSize(title);
                    }
                    catch (WebException ex)
                    {
                        Console.Write("\r" + new string(' ', Console.WindowWidth - 1) + "\r");

                        var statusCode = (int)((HttpWebResponse)ex.Response).StatusCode;

                        sizesJsonInvalid[title] = statusCode;

                        File.WriteAllText(bigJsonInvalid, JsonConvert.SerializeObject(sizesJsonInvalid));
                        Console.WriteLine(title + ": " + statusCode);

                        continue;
                    }

                    sizesJson[title] = size;

                    Console.Write("\r" + new string(' ', Console.WindowWidth - 1) + "\r");

                    // File.WriteAllText(Files.SizesPath, JsonConvert.SerializeObject(sizesJson));
                    // File.AppendAllText("titles.txt", title.TitleId + ": " + size + Environment.NewLine);

                    File.WriteAllText(Files.SizesPath, JsonConvert.SerializeObject(sizesJson));
                    Console.WriteLine(title + ": " + DatabaseParser.HumanReadableFileSize(size));
                }
            }

            var json        = File.ReadAllText(Files.SizesPath);
            var invalidJson = File.ReadAllText(bigJsonInvalid);

            File.WriteAllText(Files.SizesPath, JsonPrettifier.FormatJson(json));
            File.WriteAllText(bigJsonInvalid, JsonPrettifier.FormatJson(invalidJson));

            Console.WriteLine("Finished at " + DateTime.Now);
            Console.Beep(300, 2000);
        }
Esempio n. 5
0
        public JsonResult GetTracesPaged(int offset, int limit, string search, string sort, string order)
        {
            // get logs newer than 7 days
            var nowUtc = _now.UtcNow;

            var traces =
                _context.AsQueryable <LogEntry>().Include(x => x.Steps)
                .Where(x => DbFunctions.AddHours(x.Timestamp, LogLimit) > nowUtc)
                .AsQueryable();

            IOrderedQueryable <LogEntry> pagedTraces;

            switch (order)
            {
            case LogsSortAscendingKey:
                pagedTraces = traces.OrderAscending(sort);
                break;

            case LogsSortDescendingKey:
                pagedTraces = traces.OrderDescending(sort);
                break;

            default:
                pagedTraces = traces.OrderDescending(sort);
                break;
            }

            List <LogEntry> pagedTracesList;

            if (string.IsNullOrEmpty(search))
            {
                pagedTracesList = pagedTraces
                                  .Skip((offset / limit) * limit)
                                  .Take(limit).ToList();
            }
            else
            {
                string searchLikeExpression = string.Format("%{0}%", search);
                Expression <Func <LogEntry, bool> > searchExpression =
                    entry => SqlFunctions.PatIndex(searchLikeExpression, entry.RequestUri) > 0 ||
                    entry.Steps.Any(x => SqlFunctions.PatIndex(searchLikeExpression, x.Frame) > 0 ||
                                    SqlFunctions.PatIndex(searchLikeExpression, x.Message) > 0 ||
                                    SqlFunctions.PatIndex(searchLikeExpression, x.Name) > 0 ||
                                    SqlFunctions.PatIndex(searchLikeExpression, x.Metadata) > 0);

                pagedTracesList = pagedTraces.AsExpandable().Where(searchExpression).Skip((offset / limit) * limit).Take(limit).ToList();
            }

            var tracesVms = new List <TraceViewModel>();

            foreach (var trace in pagedTracesList)
            {
                var traceSteps = trace.Steps.OrderBy(x => x.Index).ToList();

                var builder = new StringBuilder();
                builder.Append("<p style=\"white-space: nowrap;\">Start request </p>");

                foreach (var tracestep in traceSteps)
                {
                    builder.Append(string.Format("<p style=\"white-space: nowrap;\">{0}</p>", string.Format("From {0} method located in frame {1} {2} {3} \r\n", tracestep.Source,
                                                                                                            string.Format("<pre class=\"prettyprint lang-cs\">{0}</pre>", tracestep.Frame),
                                                                                                            (!string.IsNullOrEmpty(tracestep.Name) ? string.Format(" (which processes {0}) ", tracestep.Name) : ""),
                                                                                                            (!string.IsNullOrEmpty(tracestep.Message) ? string.Format(" (with message {0}) ", tracestep.Message) : ""))));

                    if (string.IsNullOrEmpty(tracestep.Metadata))
                    {
                        continue;
                    }

                    builder.Append("<p style=\"white-space: nowrap;\">With metadata: </p>");

                    string beautified;
                    if (XmlUtils.IsValidXml(tracestep.Metadata))
                    {
                        // xml
                        // operation metadata is xml in our case
                        beautified = XmlPrettifyHelper.Prettify(tracestep.Metadata.Replace(XmlHeader8, "").Replace(XmlHeader16, ""));
                    }
                    else if (JsonUtils.IsValidJson(tracestep.Metadata))
                    {
                        beautified = string.Format("<pre class=\"prettyprint lang-json\">{0}</pre>",
                                                   JsonPrettifier.BeautifyJson(tracestep.Metadata));
                    }
                    else
                    {
                        beautified = tracestep.Metadata;
                    }

                    builder.Append(beautified);
                }

                builder.Append("<p style=\"white-space: nowrap;\">End request </p>");

                var traceString = HttpUtility.HtmlEncode(builder.ToString());

                var captureDuration = trace.ResponseTimestamp.HasValue && trace.RequestTimestamp.HasValue;

                var item = new TraceViewModel
                {
                    Duration = captureDuration ? string.Format("{0} seconds",
                                                               (trace.ResponseTimestamp.Value - trace.RequestTimestamp.Value).TotalSeconds.ToString("#.##")) : "Duration not captured",
                    Timestamp = trace.Timestamp.ToString(CultureInfo.InvariantCulture),
                    Uri       = trace.RequestUri,
                    Workflow  = new HtmlString(HttpUtility.HtmlDecode(traceString)).ToHtmlString()
                };

                tracesVms.Add(item);
            }

            var model = new
            {
                total = traces.Count(),
                rows  = tracesVms
            };

            return(Json(model, JsonRequestBehavior.AllowGet));
        }
Esempio n. 6
0
        public static void WriteFilterSettings(TitleFilter filter, string filterPath)
        {
            var output = JsonPrettifier.FormatJson(JsonConvert.SerializeObject(filter));

            File.WriteAllText(filterPath, output);
        }