Ejemplo n.º 1
0
        public override void WriteApp(AppProfile app)
        {
            // Store the results here temporarily building up a list of items in the desired order etc.
            Dictionary <string, object> itemList = new Dictionary <string, object>();;

            if (app.SimpleTagsOnly)
            {
                List <string> keys = new List <string>(app.MetaData.UniqueTags);
                itemList.Add("tags", keys);
                keys.Sort();
            }
            else
            {
                if (!app.ExcludeRollup)
                {
                    itemList.Add("AppProfile", app);
                }

                //matches are added this way to avoid output of entire set of MatchItem properties which include full rule/patterns/cond.
                List <MatchItems> matches = new List <MatchItems>();

                foreach (MatchRecord match in app.MatchList)
                {
                    MatchItems matchItem = new MatchItems(match);
                    matches.Add(matchItem);
                }

                itemList.Add("matchDetails", matches);
            }

            jsonResult.Add(itemList);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Registers datatypes with html framework liquid and sets up data for use within it and used
        /// with html partial.liquid files that are embedded as resources
        /// </summary>
        /// <param name="app"></param>
        public override void WriteApp(AppProfile app)
        {
            var      htmlTemplateText = File.ReadAllText("html/index.html");
            Assembly test             = Assembly.GetEntryAssembly();

            Template.FileSystem = new EmbeddedFileSystem(Assembly.GetEntryAssembly(), "ApplicationInspector.html.partials");

            RegisterSafeType(typeof(AppProfile));
            RegisterSafeType(typeof(AppMetaData));

            var htmlTemplate = Template.Parse(htmlTemplateText);
            var data         = new Dictionary <string, object>();

            data["AppProfile"] = app;

            //matchitems rather than records created to exclude full rule/patterns/cond.
            List <MatchItems> matches = new List <MatchItems>();

            foreach (MatchRecord match in app.MatchList)
            {
                MatchItems matchItem = new MatchItems(match);
                matches.Add(matchItem);
            }

            data["matchDetails"] = matches;

            var hashData = new Hash();

            hashData["json"] = JsonConvert.SerializeObject(data, Formatting.Indented);
            hashData["application_version"] = Program.GetVersionString();

            //add dynamic sets of groups of taginfo read from preferences for Profile page
            List <TagGroup> tagGroupList = app.GetCategoryTagGroups("profile");

            hashData["groups"] = tagGroupList;

            //add summary values for sorted tags lists of taginfo
            foreach (string outerKey in app.KeyedSortedTagInfoLists.Keys)
            {
                hashData.Add(outerKey, app.KeyedSortedTagInfoLists[outerKey]);
            }

            //add summary metadata lists
            hashData["cputargets"]   = app.MetaData.CPUTargets;
            hashData["apptypes"]     = app.MetaData.AppTypes;
            hashData["packagetypes"] = app.MetaData.PackageTypes;
            hashData["ostargets"]    = app.MetaData.OSTargets;
            hashData["outputs"]      = app.MetaData.Outputs;
            hashData["filetypes"]    = app.MetaData.FileExtensions;
            hashData["tagcounters"]  = app.MetaData.TagCountersUI;

            var htmlResult = htmlTemplate.Render(hashData);

            File.WriteAllText("output.html", htmlResult);

            //writes out json report for convenience and linking to from report page(s)
            String jsonReportPath = Path.Combine("output.json");
            Writer jsonWriter     = WriterFactory.GetWriter("json", jsonReportPath);

            jsonWriter.TextWriter = File.CreateText(jsonReportPath);
            jsonWriter.WriteApp(app);
            jsonWriter.FlushAndClose();

            Utils.OpenBrowser("output.html");
        }