/// <summary>
 /// Initializes a new instance of the <see cref="T:System.Object"/> class.
 /// </summary>
 public KeenLogger()
 {
     Logger = new LoggingDefaultImplementation();
     if (!ConfigurationManagerHelper.GetValueOnKey("stardust.logToKeen", false))
     {
         return;
     }
     try
     {
         if (keenClient != null)
         {
             return;
         }
         var prjSettings = new ProjectSettingsProvider(GetProjectId(), writeKey: GetProjectKey());
         keenClient = new KeenClient(prjSettings);
         keenClient.AddGlobalProperty("serviceHost", Utilities.GetServiceName());
         keenClient.AddGlobalProperty("environment", "Config");
         keenClient.AddGlobalProperty("configSet", "ALL");
         keenClient.AddGlobalProperty("machine", Environment.MachineName);
         keenClient.AddGlobalProperty("datacenterKey", "cnfpxwe");
         var prjReadSettings = new ProjectSettingsProvider(GetProjectId(), readKey: GetProjectReadKey());
         keenReadClient = new KeenClient(prjReadSettings);
     }
     catch (Exception)
     {
     }
 }
Beispiel #2
0
        public void AddGlobalProperty_CollectionValue_Success()
        {
            var client = new KeenClient(SettingsEnv);

            if (UseMocks)
            {
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                                                                 addEvent: new Action <string, JObject, IProjectSettings>((c, e, p) =>
                {
                    if ((p == SettingsEnv) && (c == "AddEventTest") &&
                        (e["AProperty"].Value <string>() == "AValue") &&
                        (e["AGlobal"].Values <int>().All((x) => (x == 1) || (x == 2) || (x == 3))))
                    {
                        return;
                    }
                    else
                    {
                        throw new Exception("Unexpected value");
                    }
                }));
            }

            Assert.DoesNotThrow(() =>
            {
                client.AddGlobalProperty("AGlobal", new[] { 1, 2, 3, });
                client.AddEvent("AddEventTest", new { AProperty = "AValue" });
            });
        }
        public void AddGlobalProperty_SimpleValue_Success()
        {
            var client = new KeenClient(settingsEnv);

            if (UseMocks)
            {
                client.EventCollection = new EventCollectionMock(settingsEnv,
                                                                 AddEvent: new Action <string, JObject, IProjectSettings>((c, e, p) =>
                {
                    if ((p == settingsEnv) && (c == "AddEventTest") &&
                        (e["AProperty"].Value <string>() == "AValue") &&
                        (e["AGlobal"].Value <string>() == "AValue"))
                    {
                        return;
                    }
                    else
                    {
                        throw new Exception("Unexpected value");
                    }
                }));
            }

            Assert.DoesNotThrow(() =>
            {
                client.AddGlobalProperty("AGlobal", "AValue");
                client.AddEvent("AddEventTest", new { AProperty = "AValue" });
            });
        }
Beispiel #4
0
        public void AddGlobalProperty_DelegateArrayValue_Success()
        {
            var client = new KeenClient(SettingsEnv);

            if (UseMocks)
            {
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                                                                 addEvent: (c, e, p) =>
                {
                    if ((p == SettingsEnv) && (c == "AddEventTest") &&
                        (e["AProperty"].Value <string>() == "AValue") &&
                        (e["AGlobal"].Values <int>().All(x => (x == 1) || (x == 2) || (x == 3))))
                    {
                        return;
                    }
                    throw new Exception("Unexpected value");
                });
            }

            Assert.DoesNotThrow(() =>
            {
                client.AddGlobalProperty("AGlobal", new DynamicPropertyValue(() => new[] { 1, 2, 3 }));
                client.AddEvent("AddEventTest", new { AProperty = "AValue" });
            });
        }
Beispiel #5
0
        public void AddGlobalProperty_DelegateObjectValue_Success()
        {
            var client = new KeenClient(SettingsEnv);

            if (UseMocks)
            {
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                                                                 addEvent: (c, e, p) =>
                {
                    if ((p == SettingsEnv) && (c == "AddEventTest") &&
                        (e["AProperty"].Value <string>() == "AValue") &&
                        (e["AGlobal"].Value <JObject>()["SubProp1"].Value <string>() == "Value"))
                    {
                        return;
                    }
                    throw new Exception("Unexpected value");
                });
            }

            Assert.DoesNotThrow(() =>
            {
                client.AddGlobalProperty("AGlobal", new DynamicPropertyValue(() => new { SubProp1 = "Value", SubProp2 = "Value" }));
                client.AddEvent("AddEventTest", new { AProperty = "AValue" });
            });
        }
Beispiel #6
0
        public void AddGlobalProperty_DelegateValueProviderNullReturn_Throws()
        {
            var client = new KeenClient(SettingsEnv);

            if (UseMocks)
            {
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                                                                 addEvent: (c, e, p) =>
                {
                    if ((p == SettingsEnv) && (c == "AddEventTest") &&
                        (e["AProperty"].Value <string>() == "AValue") &&
                        (e["AGlobal"].Value <string>() == "value"))
                    {
                        return;
                    }
                    throw new Exception("Unexpected value");
                });
            }

            var i = 0;

            // return valid for the first two tests, then null
            client.AddGlobalProperty("AGlobal", new DynamicPropertyValue(() => i++ > 1 ? null : "value"));
            // This is the second test (AddGlobalProperty runs the first)
            Assert.DoesNotThrow(() => client.AddEvent("AddEventTest", new { AProperty = "AValue" }));
            // Third test should fail.
            Assert.Throws <KeenException>(() => client.AddEvent("AddEventTest", new { AProperty = "AValue" }));
        }
Beispiel #7
0
        public void AddGlobalProperty_DelegateSimpleValue_Success()
        {
            var client = new KeenClient(SettingsEnv);

            if (UseMocks)
            {
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                                                                 addEvent: (c, e, p) =>
                {
                    if ((p == SettingsEnv) && (c == "AddEventTest") &&
                        (e["AProperty"].Value <string>() == "AValue") &&
                        (e["AGlobal"] != null))
                    {
                        return;
                    }
                    throw new Exception("Unexpected value");
                });
            }

            Assert.DoesNotThrow(() =>
            {
                client.AddGlobalProperty("AGlobal", new DynamicPropertyValue(() => DateTime.Now.Millisecond));
                client.AddEvent("AddEventTest", new { AProperty = "AValue" });
                client.AddEvent("AddEventTest", new { AProperty = "AValue" });
            });
        }
Beispiel #8
0
        public static void Initialize()
        {
            LocalLogManager.AddLine("Analytics manager initialization");
            var projectSettings = new ProjectSettingsProvider(KeenProjectID, writeKey: KeenWriteKey);

            Client         = new KeenClient(projectSettings);
            DeferredClient = new KeenClient(projectSettings, new EventCacheMemory());

            var playerId = PlayerDataManager.CurrentPlayerId;

            Client.AddGlobalProperty("PlayerID", playerId);

            DeferredClient.AddGlobalProperty("PlayerID", playerId);
        }
Beispiel #9
0
        public void AddGlobalProperty_InvalidValueNameBlank_Throws()
        {
            var client = new KeenClient(SettingsEnv);

            Assert.Throws <KeenException>(() => client.AddGlobalProperty("", "AValue"));
        }
Beispiel #10
0
        public void AddGlobalProperty_InvalidValueNameLength_Throws()
        {
            var client = new KeenClient(SettingsEnv);

            Assert.Throws <KeenException>(() => client.AddGlobalProperty(new String('A', 256), "AValue"));
        }
        public void AddGlobalProperty_DelegateArrayValue_Success()
        {
            var client = new KeenClient(SettingsEnv);
            if (UseMocks)
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                    addEvent: (c, e, p) =>
                    {
                        if ((p == SettingsEnv) && (c == "AddEventTest") 
                            && (e["AProperty"].Value<string>() == "AValue")
                            && (e["AGlobal"].Values<int>().All(x => (x == 1) || (x == 2) || (x == 3))))
                            return;
                        throw new Exception("Unexpected value");
                    });

            Assert.DoesNotThrow(() =>
            {
                client.AddGlobalProperty("AGlobal", new DynamicPropertyValue(() => new[] { 1, 2, 3 }));
                client.AddEvent("AddEventTest", new { AProperty = "AValue" });
            });
        }
        public void AddGlobalProperty_DelegateValueProviderNullReturn_Throws()
        {
            var client = new KeenClient(SettingsEnv);
            if (UseMocks)
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                    addEvent: (c, e, p) =>
                    {
                        if ((p == SettingsEnv) && (c == "AddEventTest") 
                            && (e["AProperty"].Value<string>() == "AValue")
                            && (e["AGlobal"].Value<string>() == "value"))
                            return;
                        throw new Exception("Unexpected value");
                    });

            var i = 0;
            // return valid for the first two tests, then null
            client.AddGlobalProperty("AGlobal", new DynamicPropertyValue(() => i++ > 1 ? null : "value"));
            // This is the second test (AddGlobalProperty runs the first)
            Assert.DoesNotThrow(() => client.AddEvent("AddEventTest", new { AProperty = "AValue" }));
            // Third test should fail.
            Assert.Throws<KeenException>(() => client.AddEvent("AddEventTest", new { AProperty = "AValue" }));
        }
 public void AddGlobalProperty_DelegateValueProviderThrows_Throws()
 {
     var client = new KeenClient(SettingsEnv);
     Assert.Throws<KeenException>(() => client.AddGlobalProperty("AGlobal", new DynamicPropertyValue(() => { throw new Exception("test exception"); })));
 }
 public void AddGlobalProperty_DelegateNullValueProvider_Throws()
 {
     var client = new KeenClient(SettingsEnv);
     Assert.Throws<KeenException>(() => client.AddGlobalProperty("AGlobal", null));
 }
 public void AddGlobalProperty_DelegateNullDynamicValue_Throws()
 {
     var client = new KeenClient(SettingsEnv);
     Assert.Throws<KeenException>(() => client.AddGlobalProperty("AGlobal", new DynamicPropertyValue(() => null)));
 }
        public void AddGlobalProperty_DelegateObjectValue_Success()
        {
            var client = new KeenClient(SettingsEnv);
            if (UseMocks)
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                    addEvent: (c, e, p) =>
                    {
                        if ((p == SettingsEnv) && (c == "AddEventTest") 
                            && (e["AProperty"].Value<string>() == "AValue") 
                            && (e["AGlobal"].Value<JObject>()["SubProp1"].Value<string>() == "Value"))
                            return;
                        throw new Exception("Unexpected value");
                    });

            Assert.DoesNotThrow(() =>
            {
                client.AddGlobalProperty("AGlobal", new DynamicPropertyValue(() => new { SubProp1 = "Value", SubProp2 = "Value" }));
                client.AddEvent("AddEventTest", new { AProperty = "AValue" });
            });
        }
Beispiel #17
0
        public void AddGlobalProperty_DelegateNullDynamicValue_Throws()
        {
            var client = new KeenClient(SettingsEnv);

            Assert.Throws <KeenException>(() => client.AddGlobalProperty("AGlobal", new DynamicPropertyValue(() => null)));
        }
 public void AddGlobalProperty_InvalidValueNameLength_Throws()
 {
     var client = new KeenClient(SettingsEnv);
     Assert.Throws<KeenException>(() => client.AddGlobalProperty(new String('A', 256), "AValue"));
 }
Beispiel #19
0
        public void AddGlobalProperty_DelegateNullValueProvider_Throws()
        {
            var client = new KeenClient(SettingsEnv);

            Assert.Throws <KeenException>(() => client.AddGlobalProperty("AGlobal", null));
        }
 public void AddGlobalProperty_InvalidValueNameBlank_Throws()
 {
     var client = new KeenClient(SettingsEnv);
     Assert.Throws<KeenException>(() => client.AddGlobalProperty("", "AValue"));
 }
Beispiel #21
0
        public void AddGlobalProperty_DelegateValueProviderThrows_Throws()
        {
            var client = new KeenClient(SettingsEnv);

            Assert.Throws <KeenException>(() => client.AddGlobalProperty("AGlobal", new DynamicPropertyValue(() => { throw new Exception("test exception"); })));
        }
        public void AddGlobalProperty_DelegateSimpleValue_Success()
        {
            var client = new KeenClient(SettingsEnv);
            if (UseMocks)
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                    addEvent: (c, e, p) =>
                    {
                        if ((p == SettingsEnv) && (c == "AddEventTest")
                            && (e["AProperty"].Value<string>() == "AValue")
                            && (e["AGlobal"]!=null))
                            return;
                        throw new Exception("Unexpected value");
                    });

            Assert.DoesNotThrow(() =>
            {
                client.AddGlobalProperty("AGlobal", new DynamicPropertyValue(() => DateTime.Now.Millisecond));
                client.AddEvent("AddEventTest", new { AProperty = "AValue" });
                client.AddEvent("AddEventTest", new { AProperty = "AValue" });
            });
        }