예제 #1
0
        private static string CmdJSONString(string miningLocation, string username, params string[] uuids)
        {
            const string DEVICE   = @"		{""id"":3,""method"":""worker.add"",""params"":[""daggerhashimoto"",""_DEV_ID_""]}";
            const string TEMPLATE = @"
[
	{""time"":0,""commands"":[
		{""id"":1,""method"":""subscribe"",""params"":[""nhmp._MINING_LOCATION_.nicehash.com:3200"",""_PUT_YOUR_BTC_HERE_""]}
	]},
	{""time"":1,""commands"":[
        {""id"":1,""method"":""algorithm.add"",""params"":[""daggerhashimoto""]}
    ]},
	{""time"":2,""commands"":[
_DEVICES_
	]},
	{""time"":10,""commands"":[
		{""id"":1,""method"":""worker.reset"",""params"":[""0""]}
	]},
	{""time"":15,""loop"":15,""commands"":[
		{""id"":1,""method"":""algorithm.print.speeds"",""params"":[]},
		{""id"":1,""method"":""worker.reset"",""params"":[""0""]}
	]}
]";
            var          devices  = string.Join(",\n", uuids.Select(uuid => DEVICE.Replace("_DEV_ID_", uuid)));

            return(TEMPLATE
                   .Replace("_MINING_LOCATION_", miningLocation)
                   .Replace("_PUT_YOUR_BTC_HERE_", username)
                   .Replace("_DEVICES_", devices));
        }
예제 #2
0
        private static (string templateStr, bool oldTemplate) CmdJSONString(string pluginUUID, string miningLocation, string username, params string[] uuids)
        {
            var templatePath          = CmdConfig.CommandFileTemplatePath(pluginUUID);
            var miningServiceLocation = GetServiceLocation(miningLocation);
            var str = CmdConfig.CreateCommandFileWithTemplate(miningServiceLocation, username, uuids, templatePath);

            if (str != null)
            {
                return(str, false);
            }
            const string DEVICE         = @"		{""id"":3,""method"":""worker.add"",""params"":[""daggerhashimoto"",""_DEV_ID_""]}";
            const string TEMPLATE       = @"
[
	{""time"":0,""commands"":[
		{""id"":1,""method"":""subscribe"",""params"":[""_MINING_SERVICE_LOCATION_"",""_PUT_YOUR_BTC_HERE_""]}
	]},
	{""time"":1,""commands"":[
        {""id"":1,""method"":""algorithm.add"",""params"":[""daggerhashimoto""]}
    ]},
	{""time"":2,""commands"":[
_DEVICES_
	]}
]";
            var          devices        = string.Join(",\n", uuids.Select(uuid => DEVICE.Replace("_DEV_ID_", uuid)));
            var          oldTemplateStr = TEMPLATE
                                          .Replace("_MINING_SERVICE_LOCATION_", miningServiceLocation)
                                          .Replace("_PUT_YOUR_BTC_HERE_", username)
                                          .Replace("_DEVICES_", devices);

            return(oldTemplateStr, true);
        }
예제 #3
0
        public override string ToString()
        {
            var          code     = String.Concat(Labels.Select(x => x.Name));
            float        conf     = Confidence;
            const String TEMPLATE = "{\"code\":\"{{CODE}}\",\"time\":{{TIME}},\"confidence\":{{CONFIDENCE}}}";

            return(TEMPLATE.Replace("{{CODE}}", code)
                   .Replace("{{TIME}}", Time.ToString("F3"))
                   .Replace("{{CONFIDENCE}}", conf.ToString("F3")));
        }
예제 #4
0
        public void TestFormatPathNotFoundDefaultNull()
        {
            /* Given: Ein Template mit zwei Platzhaltern, von denen im Model nur ein Pfad gefunden werden kann. */
            const string TEMPLATE = "Heute ist der {today:d}. Weltuntergang ist am {doomsday:d}";
            DateTime     now      = DateTime.Now;
            string       expected = TEMPLATE.Replace("{today:d}", now.ToString("d"));
            ModelMap     model    = new ModelMap();

            model.Add("today", now);
            /* When: Das Template ersetzt werden soll */
            string result = new Templater().FormatTemplate(TEMPLATE, model);

            /* Then: Muss das gefundene ersetzt werden und das andere so belassen werden. */
            Assert.AreEqual(expected, result);
        }
예제 #5
0
        public void TestFormat()
        {
            /* Given: Ein Template, in welches ein Datum eingefügt werden soll. */
            const string TEMPLATE = "Heute ist der {today:d}";
            DateTime     now      = DateTime.Now;
            string       expected = TEMPLATE.Replace("{today:d}", now.ToString("d"));
            ModelMap     model    = new ModelMap();

            model.Add("today", now);
            /* When: Die Platzhalter ersetzt werden sollen */
            string result = new Templater().FormatTemplate(TEMPLATE, model);

            /* Then: Muss das korrekte Datum im richtigen Format eingefügt wurden sein. */
            Assert.AreEqual(expected, result);
        }
예제 #6
0
        public void TestSimpleTemplate()
        {
            /* Given: Ein einfacher String mit einem Platzhalter */
            const string TEMPLATE           = "Das ist ein {value} Template";
            const string PLACE_HOLDER_VALUE = "einfaches";
            string       expectedString     = TEMPLATE.Replace("{value}", PLACE_HOLDER_VALUE);
            ModelMap     model = new ModelMap();

            model.Add("value", PLACE_HOLDER_VALUE);
            /* When: Das Template mit dem Platzhalter gefüllt werden soll */
            string result = new Templater().FormatTemplate(TEMPLATE, model);

            /* Then: Muss der Platzhalter korrekt ersetzt werden. */
            Assert.AreEqual(expectedString, result);
        }
예제 #7
0
        public void TestFormatCulture()
        {
            /* Given: Eine Zeichenfolge, in welches ein Datum im englischen Format eingefügt werden soll. */
            const string TEMPLATE       = "Heute ist der {today:d}";
            DateTime     now            = DateTime.Now;
            CultureInfo  englishCulture = CultureInfo.GetCultureInfo("en");
            string       expected       = TEMPLATE.Replace("{today:d}", now.ToString("d", englishCulture));
            ModelMap     model          = new ModelMap();

            model.Add("today", now);
            /* When: Die Platzhalter ersetzt werden sollen */
            string result = new Templater(englishCulture).FormatTemplate(TEMPLATE, model);

            /* Then: Muss das Datum korrekt im englischen Datumsformat eingefügt sein. */
            Assert.AreEqual(expected, result);
        }
예제 #8
0
        public void TestReplaceTwice()
        {
            /* Given: Ein Template in dem ein Platzhalter mehrfach vorkommt. */
            const string TEMPLATE    = "{hello}, {hello}, {hello}. Wie geht's?";
            const string HELLO_VALUE = "Hi";

            string   expected = TEMPLATE.Replace("{hello}", HELLO_VALUE);
            ModelMap model    = new ModelMap();

            model.Add("hello", HELLO_VALUE);
            /* When: Die Platzhalter ersetzt werden sollen */
            string result = new Templater().FormatTemplate(TEMPLATE, model);

            /* Then: Müssen alle Platzhalter ersetzt werden. */
            Assert.AreEqual(expected, result);
        }
예제 #9
0
        public void TestDeepPathTemplate()
        {
            /* Given: Ein Template mit einem 3-teiligen Platzhalter-Pfad */
            const string TEMPLATE           = "Das ist ein {user.name.firstname} Template";
            const string PLACE_HOLDER_VALUE = "Tobias";
            string       expectedString     = TEMPLATE.Replace("{user.name.firstname}", PLACE_HOLDER_VALUE);

            /* When: Das Template gefüllt werden soll */
            var name = new { firstname = PLACE_HOLDER_VALUE };
            // ReSharper disable once RedundantAnonymousTypePropertyName : Readability
            var user = new { name = name };

            ModelMap model = new ModelMap();

            model.Add("user", user);
            string result = new Templater().FormatTemplate(TEMPLATE, model);

            /* Then: Müssen die Platzhalter korrekt ersetzt werden. */
            Assert.AreEqual(expectedString, result);
        }