コード例 #1
0
        public static string CreateTableFromDatabase(ManagementObjectCollection results, List <string> keys, List <string> names, string errorMessage)
        {
            if (SCCM.HasValues(results))
            {
                HTMLTableHelper tableHelper = new HTMLTableHelper(names.ToArray());

                foreach (ManagementObject o in results) //Has one!
                {
                    List <string> properties = new List <string>();
                    foreach (var p in keys)
                    {
                        string temp = o.Properties[p].Value.ToString();
                        if (o.Properties[p].Type.ToString() == "DateTime")
                        {
                            temp = DateTimeConverter.Convert(temp);
                        }
                        properties.Add(temp);
                    }
                    tableHelper.AddRow(properties.ToArray());
                }

                return(tableHelper.GetTable());
            }
            else
            {
                return(errorMessage);
            }
        }
コード例 #2
0
        private static string CreateGroupTable(List <string> group)
        {
            HTMLTableHelper groupTableHelper = new HTMLTableHelper(new string[] { "Domain", "Name" });

            createGroupTableRows(group, groupTableHelper, null);

            return(groupTableHelper.GetTable());
        }
コード例 #3
0
        private static StringBuilder PrintTableOfCases(object jsonO, Func <string, bool> filter)
        {
            dynamic json   = jsonO;
            var     helper = new HTMLTableHelper(new string[] { "ID", "Title", "Status", "Last Change" });


            for (int i = 0; i < json["MyRequest"].Count; i++)
            {
                var temp = json["MyRequest"][i];
                var name = json["MyRequest"][i]["Status"]["Name"];
                if (filter(json["MyRequest"][i]["Status"]["Name"].Value))
                {
                    string id = json["MyRequest"][i]["Id"].Value;
                    string link;
                    if (id.StartsWith("IR"))
                    {
                        link = "https://service.aau.dk/Incident/Edit/" + id;

                        //Filter away if its closed as converted to SR
                        if ((idForConvertedToSR.Equals(json["MyRequest"][i]["ResolutionCategory"]["Id"].Value)))
                        {
                            continue;
                        }
                    }
                    else //if (id.StartsWith("SR"))
                    {
                        link = "https://service.aau.dk/ServiceRequest/Edit/" + id;
                    }
                    string   sID         = "<a href=\"" + link + "\" target=\"_blank\">" + json["MyRequest"][i]["Id"].Value + "</a><br/>";
                    string   sTitle      = json["MyRequest"][i]["Title"].Value;
                    string   sStatus     = json["MyRequest"][i]["Status"]["Name"].Value;
                    DateTime tmp         = json["MyRequest"][i]["LastModified"].Value;
                    string   sLastChange = Convert.ToDateTime(tmp).ToString("yyyy-MM-dd HH:mm");

                    helper.AddRow(new String[] { sID, sTitle, sStatus, sLastChange });
                }
            }


            return(new StringBuilder(helper.GetTable()));
        }
コード例 #4
0
        public static string CreateVerticalTableFromDatabase(ManagementObjectCollection results, List <string> keys, List <string> names, string errorMessage)
        {
            HTMLTableHelper tableHelper = new HTMLTableHelper(2);
            var             sb          = new StringBuilder();

            if (SCCM.HasValues(results))
            {
                int i = 0;
                var o = results.OfType <ManagementObject>().FirstOrDefault();

                foreach (var p in keys)
                {
                    var property = o.Properties[p];
                    if (o.Properties[p].Value == null)
                    {
                        tableHelper.AddRow(new string[] { names[i], "not found" });
                    }
                    else if (o.Properties[p].Name == "Size" || o.Properties[p].Name == "FreeSpace")
                    {
                        tableHelper.AddRow(new string[] { names[i], (int.Parse(o.Properties[p].Value.ToString()) / 1024).ToString() });
                    }
                    else if (property.Type.ToString() == "DateTime")
                    {
                        tableHelper.AddRow(new string[] { names[i], DateTimeConverter.Convert(o.Properties[p].Value.ToString()) });
                    }
                    else
                    {
                        tableHelper.AddRow(new string[] { names[i], o.Properties[p].Value.ToString() });
                    }
                    i++;
                }
            }
            else
            {
                return(errorMessage);
            }

            return(tableHelper.GetTable());
        }
コード例 #5
0
ファイル: Loginscript.cs プロジェクト: mathgaming/AAUWebMgmt
        //Returns a html table displaying loginscript data and raw data parition
        public string parseAndDisplayLoginScript(string loginscript)
        {
            var sb = new StringBuilder();

            var lines = loginscript.Split('\n');

            //Remote comment
            var linesNetUse          = lines.Where <string>(s => s.StartsWith("net use", StringComparison.CurrentCultureIgnoreCase)).ToArray <string>();
            var linesNetUseNotDelete = linesNetUse.Where <string>(s => !s.ToLower().Contains(" /d")).ToArray <string>();

            var table = new HTMLTableHelper(new string[] { "Drive Letter", "share" });

            sb.Append("<h3>Networkdrives</h3>");;

            foreach (string line in linesNetUseNotDelete)
            {
                //net use S: \\adm.aau.dk\Fileshares\DRIFTSDB

                Regex pattern = new Regex(@"net use (?<drive>.): (?<share>.*)");
                Match match   = pattern.Match(line.ToLower());

                string drive = match.Groups["drive"].Value;
                string share = match.Groups["share"].Value;

                table.AddRow(new string[] { drive, share });
            }

            sb.Append(table.GetTable());
            sb.Append("<h3>Raw<h3>");
            foreach (string line in lines)
            {
                sb.Append(String.Format("<code>{0}</code><br/>", line.Replace("\r", "")));
            }

            return(sb.ToString());
        }
コード例 #6
0
        public static Tuple <string, string> CreateTableAndRawFromDatabase(ManagementObjectCollection results, List <string> keys, string errorMessage)
        {
            HTMLTableHelper tableHelper = new HTMLTableHelper(2);
            var             sb          = new StringBuilder();

            if (SCCM.HasValues(results))
            {
                foreach (ManagementObject o in results) //Has one!
                {
                    //OperatingSystemNameandVersion = Microsoft Windows NT Workstation 6.1

                    foreach (var property in o.Properties)
                    {
                        string key   = property.Name;
                        object value = property.Value;

                        if (keys.Contains(key))
                        {
                            if (value != null)
                            {
                                if (value.GetType().Equals(typeof(string[])))
                                {
                                    string joinedValues = string.Join(", ", (string[])value);
                                    tableHelper.AddRow(new string[] { key, joinedValues });
                                }
                                else if (property.Type.ToString() == "DateTime")
                                {
                                    tableHelper.AddRow(new string[] { key, DateTimeConverter.Convert(value.ToString()) });
                                }
                                else
                                {
                                    tableHelper.AddRow(new string[] { key, value.ToString() });
                                }
                            }
                            else
                            {
                                tableHelper.AddRow(new string[] { key, "" });
                            }
                        }

                        int      i    = 0;
                        string[] arry = null;
                        if (value != null && value.GetType().IsArray)
                        {
                            if (value is string[])
                            {
                                arry = (string[])value;
                            }
                            else
                            {
                                arry = new string[] { "none-string value" }; //XXX get the byte value
                            }
                            foreach (string f in arry)
                            {
                                sb.Append(string.Format("{0}[{2}]: {1}<br />", key, f, i));
                                i++;
                            }
                        }
                        else
                        {
                            sb.Append(string.Format("{0}: {1}<br />", key, property.Value));
                        }
                    }
                }
            }
            else
            {
                sb.Append(errorMessage);
            }

            return(Tuple.Create(tableHelper.GetTable(), sb.ToString()));
        }