public static string GetStringFormat(IDeviceReport report)
        {
            StringBuilder sb = new StringBuilder();

            if (report is ITabletReport tabletReport)
            {
                sb.AppendLines(GetStringFormat(tabletReport));
            }
            if (report is IAuxReport auxReport)
            {
                sb.AppendLines(GetStringFormat(auxReport));
            }
            if (report is IEraserReport eraserReport)
            {
                sb.AppendLines(GetStringFormat(eraserReport));
            }
            if (report is IProximityReport proximityReport)
            {
                sb.AppendLines(GetStringFormat(proximityReport));
            }
            if (report is ITiltReport tiltReport)
            {
                sb.AppendLines(GetStringFormat(tiltReport));
            }

            return(sb.ToString());
        }
Beispiel #2
0
        public static void AddGroups(this StringBuilder sb, int groupSize, string groupName, List <string> lines)
        {
            if (lines.Count == 0)
            {
                return;
            }
            else if (lines.Count <= groupSize)
            {
                if (groupName != string.Empty)
                {
                    sb.Append(groupName + "\n");
                }
                sb.AppendLines(lines);
            }
            else
            {
                int i = 0;
                int j = 1;
                for (i = 0; (i + 1) * groupSize < lines.Count; i++)
                {
                    if (groupName != string.Empty)
                    {
                        sb.Append(string.Format("{0} (part {1})\n", groupName, j++));
                    }
                    sb.AppendLines(lines.Sub(i * groupSize, (i + 1) * groupSize - 1));
                }

                if (groupName != string.Empty)
                {
                    sb.Append(string.Format("{0} (part {1})\n", groupName, j++));
                }
                sb.AppendLines(lines.Sub(i * groupSize, lines.Count - 1));
            }
        }
Beispiel #3
0
        /// <summary>
        /// Extension to provide a loggable string representing all information about an exception and its inner exceptions.
        /// </summary>
        /// <param name="ex">The exception to log</param>
        /// <param name="additionalMessage"> An optional additional message to log</param>
        /// <returns> a loggable string representing all information about an exception and its inner exceptions.</returns>
        public static string ToLogString(this Exception ex, string additionalMessage = "")
        {
            var msg = new StringBuilder();

            if (!string.IsNullOrEmpty(additionalMessage))
            {
                msg.AppendLine(additionalMessage);
            }

            if (ex == null)
            {
                return(msg.ToString());
            }

            var orgEx = ex;

            msg.AppendLine("Exception:");
            while (orgEx != null)
            {
                msg.AppendLine(orgEx.Message);
                orgEx = orgEx.InnerException;
            }

            foreach (var i in ex.Data)
            {
                msg.Append("Data :");
                msg.AppendLine(i.ToString());
            }

            if (ex.StackTrace != null)
            {
                msg.AppendLines("StackTrace:", ex.StackTrace);
            }

            if (ex.Source != null)
            {
                msg.AppendLines("Source:", ex.Source);
            }

            if (ex.TargetSite != null)
            {
                msg.AppendLines("TargetSite:", ex.TargetSite.ToString());
            }

            msg.AppendLine("BaseException:");
            msg.Append(ex.GetBaseException());
            return(msg.ToString());
        }
        public void TestAppendLinesMultiple()
        {
            var sB = new StringBuilder();

            sB.AppendLines("a", "b", "c");
            sB.ToString().ShouldEqual("a" + Environment.NewLine + "b" + Environment.NewLine + "c" + Environment.NewLine);
        }
        public void TestAppendLinesMultiple()
        {
            var sB = new StringBuilder();

            sB.AppendLines("a", "b", "c");
            sB.ToString().ShouldEqual("a" + Environment.NewLine + "b" + Environment.NewLine + "c" + Environment.NewLine);
        }
Beispiel #6
0
        public static string GetStringFormat(IDeviceReport report)
        {
            StringBuilder sb = new StringBuilder();

            if (report is IAbsolutePositionReport absolutePositionReport)
            {
                sb.AppendLines(GetStringFormat(absolutePositionReport));
            }
            if (report is ITabletReport tabletReport)
            {
                sb.AppendLines(GetStringFormat(tabletReport));
            }
            if (report is IAuxReport auxReport)
            {
                sb.AppendLines(GetStringFormat(auxReport));
            }
            if (report is IEraserReport eraserReport)
            {
                sb.AppendLines(GetStringFormat(eraserReport));
            }
            if (report is IProximityReport proximityReport)
            {
                sb.AppendLines(GetStringFormat(proximityReport));
            }
            if (report is ITiltReport tiltReport)
            {
                sb.AppendLines(GetStringFormat(tiltReport));
            }
            if (report is ITouchReport touchReport)
            {
                sb.AppendLines(GetStringFormat(touchReport));
            }
            if (report is IMouseReport mouseReport)
            {
                sb.AppendLines(GetStringFormat(mouseReport));
            }
            if (report is IToolReport toolReport)
            {
                sb.AppendLines(GetStringFormat(toolReport));
            }
            if (report is OutOfRangeReport oorReport)
            {
                sb.AppendLines(GetStringFormat(oorReport));
            }

            return(sb.ToString());
        }
Beispiel #7
0
            public void WhenEnumerableIsNull_ThenDoNothing()
            {
                var sut = new StringBuilder();

                sut.AppendLines(null as IEnumerable <string>);

                Assert.That(sut.ToString(), Is.Empty);
            }
        public void AppendLines_ES()
        {
            var b = new StringBuilder();
            var nl = Environment.NewLine;

            var items = new List<string> { "", "", "", "" };
            var buf = b.AppendLines(items).ToString();

            Expect(buf.ToString(), Is.EqualTo(nl+nl+nl+nl));
        }
Beispiel #9
0
            public void WhenTwoValues_ThenAppend()
            {
                var sut = new StringBuilder();

                sut.AppendLines("This is ", "a test");

                var result = sut.ToString().ToLines().ToList();

                Assert.That(result.First(), Is.EqualTo("This is "));
                Assert.That(result.Second(), Is.EqualTo("a test"));
            }
Beispiel #10
0
            public void WhenContainsNullValue_ThenAppend()
            {
                var sut = new StringBuilder();

                sut.AppendLines("This is ", null, "a test");

                var result = sut.ToString().ToLines().ToList();

                Assert.That(result.First(), Is.EqualTo("This is "));
                Assert.That(result.Second(), Is.Empty);
                Assert.That(result.Third(), Is.EqualTo("a test"));
            }
        /// <summary>
        /// Extension to provide a loggable string representing all information about an exception and its inner exceptions.
        /// </summary>
        /// <param name="ex">The exception to log</param>
        /// <param name="additionalMessage"> An optional additional message to log</param>
        /// <returns> a loggable string representing all information about an exception and its inner exceptions.</returns>
        public static string ToLogString(this Exception ex, string additionalMessage = "")
        {
            var msg = new StringBuilder();

            if (!string.IsNullOrEmpty(additionalMessage))
                msg.AppendLine(additionalMessage);

            if (ex == null)
                return msg.ToString();

            var orgEx = ex;
            msg.AppendLine("Exception:");
            while (orgEx != null)
            {
                msg.AppendLine(orgEx.Message);
                orgEx = orgEx.InnerException;
            }

            foreach (var i in ex.Data)
            {
                msg.Append("Data :");
                msg.AppendLine(i.ToString());
            }

            if (ex.StackTrace != null)
                msg.AppendLines("StackTrace:", ex.StackTrace);

            if (ex.Source != null)
                msg.AppendLines("Source:", ex.Source);

            if (ex.TargetSite != null)
                msg.AppendLines("TargetSite:", ex.TargetSite.ToString());

            msg.AppendLine("BaseException:");
            msg.Append(ex.GetBaseException());
            return msg.ToString();
        }
        public void AppendLines()
        {
            // Arrange
            var lines = new List <string>
            {
                "a", "b", "c"
            };
            var stringBuilder = new StringBuilder();

            // Act
            stringBuilder.AppendLines(lines);
            var result = stringBuilder.ToString();

            // Assert
            Assert.Equal($"{string.Join(Environment.NewLine, lines)}{Environment.NewLine}", result);
        }
Beispiel #13
0
        private static string GenerateCheckingCode(int numberOfMasks, int numberOfHashesPerKey, uint[] Bitmask, uint[] Pattern, int numberOfPatterns)
        {
            StringBuilder builder = new StringBuilder();

            // Makes the checking code do a simple 3-word check for a single pattern
            // instead of using the hashtable (about 8% faster)
            if (numberOfMasks == 1 && numberOfHashesPerKey == 1 && numberOfPatterns == 1)
            {
                builder.AppendLine("if(((H[0] & {0}u) == {1}u) && ((H[1] & {2}u) == {3}u) && ((H[2] & {4}u) == {5}u))",
                                   Bitmask[0], Pattern[0], Bitmask[1], Pattern[1], Bitmask[2], Pattern[2]);
                builder.AppendLine("        Results[get_local_id(0) % ResultsArraySize] = exp;");
            }
            else
            {
                for (int m = 0; m < numberOfMasks; m++)
                {
                    builder.AppendLine("BEGIN_MASK({0})", m);
                    builder.AppendLines(Util.Range(numberOfHashesPerKey)
                                        .Select(i => string.Format("    CHECK_HASH({0})", i)));
                }
            }
            return(builder.ToString());
        }
Beispiel #14
0
		private static string GenerateCheckingCode(int numberOfMasks, int numberOfHashesPerKey, uint[] Bitmask, uint[] Pattern, int numberOfPatterns)
		{
			StringBuilder builder = new StringBuilder();

			// Makes the checking code do a simple 3-word check for a single pattern
			// instead of using the hashtable (about 8% faster)
            if(numberOfMasks == 1 && numberOfHashesPerKey == 1 && numberOfPatterns == 1)
            {
                builder.AppendLine("if(((H[0] & {0}u) == {1}u) && ((H[1] & {2}u) == {3}u) && ((H[2] & {4}u) == {5}u))",
                    Bitmask[0],Pattern[0], Bitmask[1],Pattern[1], Bitmask[2],Pattern[2] );
                builder.AppendLine("        Results[get_local_id(0) % ResultsArraySize] = exp;");
            }
            else
            {
                for (int m = 0; m < numberOfMasks; m++)
                {
                    builder.AppendLine("BEGIN_MASK({0})", m);
                    builder.AppendLines(Util.Range(numberOfHashesPerKey)
                        .Select(i => string.Format("    CHECK_HASH({0})", i)));
                }
            }
			return builder.ToString();
		}
Beispiel #15
0
        /// <summary>
        /// Adds lines of text in groups of a specified size to the StringBuilder.
        /// </summary>
        /// <param name="groupSize">Number of strings in each group</param>
        /// <param name="groupName">What to name each group.</param>
        /// <param name="lines">Lines to add</param>
        private static void AddGroups(StringBuilder sb, int groupSize, string groupName, IList<string> lines)
        {
            if (lines.Count == 0)
            {
                return;
            }
            else if (lines.Count <= groupSize)
            {
                if (groupName != string.Empty)
                    sb.Append(groupName + "\n");
                sb.AppendLines(lines);
            }
            else
            {
                int i = 0;
                int j = 1;
                for (i = 0; (i + 1) * groupSize < lines.Count; i++)
                {
                    if (groupName != string.Empty)
                        sb.Append(string.Format("{0}\\(part {1})\n", groupName, j++));
                    sb.AppendLines(lines.Sub(i * groupSize, (i + 1) * groupSize - 1));
                }

                if (groupName != string.Empty)
                    sb.Append(string.Format("{0}\\(part {1})\n", groupName, j++));
                sb.AppendLines(lines.Sub(i * groupSize, lines.Count - 1));
            }
        }
 public void TestAppendLinesNulls()
 {
     var sB = new StringBuilder();
     sB.AppendLines("a", null, "c");
 }
        public void TestAppendLinesNulls()
        {
            var sB = new StringBuilder();

            sB.AppendLines("a", null, "c");
        }
        private static async Task DisplayCommandHelp(CommandContext ctx, Command cmd)
        {
            //Setup the embed.
            var aliases = string.Join(", ", cmd.Aliases.Select(alias => $"`{alias}`"));
            var embed   = new DiscordEmbedBuilder()
                          .WithTitle($"`{cmd.Name}`" + (aliases.Length > 0 ? $" (or {aliases})" : ""))
                          .WithDescription(cmd.Description)
                          .WithAuthor(name: tagline, iconUrl: ctx.Client.CurrentUser.AvatarUrl);
            //Prepare ourselves for usage
            var usage = new StringBuilder();
            //The total count of subcommands and overloads.
            //LITERALLY THE CMD IS COMMANDGROUP THING IS ONLY HERE BECAUSE VS HATED WHEN I TRIED TO DO ANYTHING ELSE.
            var count = cmd.Overloads.Count + (cmd is CommandGroup ? (cmd as CommandGroup).Children.Count : 0);

            //The following loop handles overloads.
            foreach (var ovrld in cmd.Overloads)
            {
                if (ovrld.Priority >= 0)
                {
                    AppendOverload(ovrld);
                }
            }

            //Do we have any subcommands?
            if (cmd is CommandGroup group)
            {
                //The following loop handles subcommands and their appropriate usage.
                foreach (var subcmd in group.Children)
                {
                    if (subcmd.Overloads.Count > 1 || subcmd is CommandGroup)
                    {
                        usage.AppendLine($"`{cmd.Name} {subcmd.Name}`: Visit `help {cmd.Name} {subcmd.Name}` for more information.");
                    }
                    else
                    {
                        AppendOverload(subcmd.Overloads.Single(), subcmd);
                    }
                }
            }

            //I heard you like methods, so I put a method in your method.
            void AppendOverload(CommandOverload ovrld, Command?subcmd = null)
            {
                var ovrldHasArgs = ovrld.Arguments.Count > 0;

                usage.Append("`");
                usage.Append(cmd.Name);
                if (subcmd != null)
                {
                    usage.Append($" {subcmd.Name}");
                }
                //Make sure we actually have arguments, otherwise don't bother adding a space for them.
                if (ovrldHasArgs)
                {
                    usage.Append(" ");
                    //We have arguments, let's print them.
                    usage.AppendJoin(" ", ovrld.Arguments.Select(arg => (arg.IsOptional && !arg.IsCustomRequired()) ? $"({arg.Name})" : $"[{arg.Name}]"));
                }
                usage.Append("`");

                if (subcmd != null)
                {
                    usage.Append($": {subcmd.Description}");
                }
                usage.AppendLine();
                //Is the count of subcommands and overloads short?
                if (count <= 6)
                {
                    //Second argument loop for descriptions (if count is short)
                    if (ovrldHasArgs)
                    {
                        usage.AppendLines(ovrld.Arguments.Select(arg => $"`{arg.Name}`: {arg.Description}"));
                    }
                    usage.AppendLine();
                }
            }

            embed.AddField("Usage:", usage.ToString(), inline: false);
            await ctx.RespondAsync(embed : embed);
        }
Beispiel #19
0
        public Response ENV(dynamic parameters)
        {
            var sb = new StringBuilder("<html><body><pre>");

            RequestHeaders hdrs = Request.Headers;

            sb.AppendLine("Accept:");
            sb.AppendLines(hdrs.Accept);
            sb.AppendLine();

            sb.AppendLine();
            sb.AppendLine("AcceptCharset:");
            sb.AppendLines(hdrs.AcceptCharset);
            sb.AppendLine();

            sb.AppendLine();
            sb.AppendLine("AcceptEncoding:");
            sb.AppendLines(hdrs.AcceptEncoding);
            sb.AppendLine();

            sb.AppendLine();
            sb.AppendLine("AcceptLanguage:");
            sb.AppendLines(hdrs.AcceptLanguage);
            sb.AppendLine();

            sb.AppendLine();
            sb.Append("Authorization: ");
            sb.AppendLine(hdrs.Authorization);
            sb.AppendLine();

            sb.AppendLine();
            sb.AppendLine("CacheControl:");
            sb.AppendLines(hdrs.CacheControl);
            sb.AppendLine();

            sb.AppendLine();
            sb.Append("ContentType: ");
            sb.AppendLine(hdrs.ContentType);
            sb.AppendLine();

            sb.AppendLine();
            sb.Append("Date: ");
            sb.AppendLine(hdrs.Date.ToString());
            sb.AppendLine();

            sb.AppendLine();
            sb.Append("Host: ");
            sb.AppendLine(hdrs.Host);
            sb.AppendLine();

            sb.AppendLine();
            sb.Append("MaxForwards: ");
            sb.AppendLine(hdrs.MaxForwards.ToString());
            sb.AppendLine();

            sb.AppendLine();
            sb.Append("Referrer: ");
            sb.AppendLine(hdrs.Referrer);
            sb.AppendLine();

            sb.AppendLine();
            sb.AppendLine("UserAgent:");
            sb.AppendLine(hdrs.UserAgent);
            sb.AppendLine();

            sb.AppendLine();
            sb.Append("Server Host Name: ");
            sb.AppendLine(HostName);
            sb.AppendLine();

            sb.AppendLine();
            sb.AppendLine("Server IP Addresses:");
            var ips = GetLocalIPAddresses().Select(i => i.ToString());

            sb.AppendLines(ips);
            sb.AppendLine();

            sb.AppendLine();
            sb.AppendLine("Server AppSettings:");
            foreach (var key in ConfigurationManager.AppSettings.AllKeys)
            {
                string value = ConfigurationManager.AppSettings[key];

                sb.AppendFormat("Key: {0} ", key);

                if (key.StartsWith("VCAP_"))
                {
                    try
                    {
                        JObject parsed = JObject.Parse(value);
                        sb.AppendFormat("JSON: {0}", parsed.ToString(Formatting.Indented));
                    }
                    catch
                    {
                        sb.AppendFormat("Value: {0}", value);
                    }
                }
                else
                {
                    sb.AppendFormat("Value: {0}", value);
                }
                sb.AppendLine();
            }

            sb.Append("</pre></body></html>");
            return(sb.ToString());
        }
Beispiel #20
0
        public Response ENV(dynamic parameters)
        {
            var sb = new StringBuilder("<html><body><pre>");

            RequestHeaders hdrs = Request.Headers;

            sb.AppendLine("Accept:");
            sb.AppendLines(hdrs.Accept);
            sb.AppendLine();

            sb.AppendLine();
            sb.AppendLine("AcceptCharset:");
            sb.AppendLines(hdrs.AcceptCharset);
            sb.AppendLine();

            sb.AppendLine();
            sb.AppendLine("AcceptEncoding:");
            sb.AppendLines(hdrs.AcceptEncoding);
            sb.AppendLine();

            sb.AppendLine();
            sb.AppendLine("AcceptLanguage:");
            sb.AppendLines(hdrs.AcceptLanguage);
            sb.AppendLine();

            sb.AppendLine();
            sb.Append("Authorization: ");
            sb.AppendLine(hdrs.Authorization);
            sb.AppendLine();

            sb.AppendLine();
            sb.AppendLine("CacheControl:");
            sb.AppendLines(hdrs.CacheControl);
            sb.AppendLine();

            sb.AppendLine();
            sb.Append("ContentType: ");
            sb.AppendLine(hdrs.ContentType);
            sb.AppendLine();

            sb.AppendLine();
            sb.Append("Date: ");
            sb.AppendLine(hdrs.Date.ToString());
            sb.AppendLine();

            sb.AppendLine();
            sb.Append("Host: ");
            sb.AppendLine(hdrs.Host);
            sb.AppendLine();

            sb.AppendLine();
            sb.Append("MaxForwards: ");
            sb.AppendLine(hdrs.MaxForwards.ToString());
            sb.AppendLine();

            sb.AppendLine();
            sb.Append("Referrer: ");
            sb.AppendLine(hdrs.Referrer);
            sb.AppendLine();

            sb.AppendLine();
            sb.AppendLine("UserAgent:");
            sb.AppendLine(hdrs.UserAgent);
            sb.AppendLine();

            sb.AppendLine();
            sb.Append("Server Host Name: ");
            sb.AppendLine(HostName);
            sb.AppendLine();

            sb.AppendLine();
            sb.AppendLine("Server IP Addresses:");
            var ips = GetLocalIPAddresses().Select(i => i.ToString());
            sb.AppendLines(ips);
            sb.AppendLine();

            sb.AppendLine();
            sb.AppendLine("Server AppSettings:");
            foreach (var key in ConfigurationManager.AppSettings.AllKeys)
            {
                string value = ConfigurationManager.AppSettings[key];

                sb.AppendFormat("Key: {0} ", key);

                if (key.StartsWith("VCAP_"))
                {
                    try
                    {
                        JObject parsed = JObject.Parse(value);
                        sb.AppendFormat("JSON: {0}", parsed.ToString(Formatting.Indented));
                    }
                    catch
                    {
                        sb.AppendFormat("Value: {0}", value);
                    }
                }
                else
                {
                    sb.AppendFormat("Value: {0}", value);
                }
                sb.AppendLine();
            }

            sb.Append("</pre></body></html>");
            return sb.ToString();
        }