示例#1
0
        private async void hammer_StartButton_Click(object sender, EventArgs e)
        {
            this.hammer?.Stop();
            if (Guid.TryParse(this.apiKeyTextBox.Text, out Guid key))
            {
                Properties.Settings.Default.telemetryKey = this.apiKeyTextBox.Text;
                Properties.Settings.Default.Save();
                this.Telimena = TelimenaFactory.Construct(new TelimenaStartupInfo(key
                                                                                  , telemetryApiBaseUrl: new Uri(this.apiUrlTextBox.Text))) as Telimena;
            }
            else
            {
                MessageBox.Show("Api key missing, cannot run hammer");
                return;
            }

            this.hammer = new TelimenaHammer(key, this.apiUrlTextBox.Text
                                             , Convert.ToInt32(this.hammer_AppNumberSeedBox.Text)
                                             , Convert.ToInt32(this.hammer_numberOfApps_TextBox.Text)
                                             , Convert.ToInt32(this.hammer_numberOfFuncs_TextBox.Text)
                                             , Convert.ToInt32(this.hammer_numberOfUsers_TextBox.Text)
                                             , Convert.ToInt32(this.hammer_delayMinTextBox.Text), Convert.ToInt32(this.hammer_delayMaxTextBox.Text)
                                             , Convert.ToInt32(this.hammer_DurationTextBox.Text), this.UpdateText);

            await this.hammer.Hit().ConfigureAwait(true);
        }
示例#2
0
        private void setAppButton_Click(object sender, EventArgs e)
        {
            var si = new TelimenaStartupInfo(Guid.Empty, telemetryApiBaseUrl: new Uri(this.apiUrlTextBox.Text))
            {
                InstrumentationKey = "1a14064b-d326-4ce3-939e-8cba4d08c255"
            };

            if (!string.IsNullOrEmpty(this.userNameTextBox.Text))
            {
                si.UserInfo = new UserInfo {
                    UserIdentifier = this.userNameTextBox.Text
                };
            }



            if (Guid.TryParse(this.apiKeyTextBox.Text, out Guid key))
            {
                si.TelemetryKey = key;
                Properties.Settings.Default.telemetryKey = this.apiKeyTextBox.Text;
                Properties.Settings.Default.Save();
                this.Telimena = TelimenaFactory.Construct(si) as Telimena;
                ;
            }
            else
            {
                MessageBox.Show("Api key missing, cannot run teli");
            }
            Properties.Settings.Default.baseUri = this.apiUrlTextBox.Text;
            Properties.Settings.Default.Save();
        }
        public void Test_OnlyUpdaterUpdates()
        {
            ITelimena sut = TelimenaFactory.Construct(new TelimenaStartupInfo(Guid.NewGuid(), Helpers.TeliUri)
            {
                SuppressAllErrors = false
            });


            UpdateResponse latestVersionResponse = new UpdateResponse
            {
                UpdatePackages = new List <UpdatePackageData> {
                    new UpdatePackageData {
                        FileName = DefaultToolkitNames.UpdaterFileName, Version = "1.2"
                    }
                }
            };

            Helpers.SetupMockHttpClient(sut, this.GetMockClientForCheckForUpdates(sut.Properties.TelemetryKey, new UpdateResponse(), latestVersionResponse));

            UpdateCheckResult response = sut.Update.CheckForUpdatesAsync().GetAwaiter().GetResult();

            Assert.IsFalse(response.IsUpdateAvailable);
            Assert.AreEqual(0, response.ProgramUpdatesToInstall.Count);
            Assert.AreEqual("1.2", response.UpdaterUpdate.Version);
            Assert.IsNull(response.Exception);
        }
示例#4
0
        private void HandleInitialize(ITelimena telimena)
        {
            Console.WriteLine("Sending Initialize request");
            TelemetryInitializeResponse result = (telimena as Telimena).Initialize().GetAwaiter().GetResult();

            Console.WriteLine("Received Initialize response");
            Console.WriteLine(JsonConvert.SerializeObject(result));
        }
        private async Task CheckIfUserIdIsGuid(ITelimena telimena)
        {
            await Task.Delay(3000);

            if (telimena.Properties.UserInfo.UserIdentifier == "NOT YET COMPUTED")
            {
                await Task.Delay(3000);
            }
            Assert.DoesNotThrow(() => Guid.Parse(telimena.Properties.UserInfo.UserIdentifier), "But was " + telimena.Properties.UserInfo.UserIdentifier);
        }
示例#6
0
        private void HandleUpdates(ITelimena telimena, bool takeBeta)
        {
            Console.WriteLine("Starting update handling...");

            UpdateInstallationResult result = telimena.Update.HandleUpdates(takeBeta);

            Console.WriteLine("Finished update handling...");
            JsonSerializerSettings settings = new JsonSerializerSettings {
                ContractResolver = new MyJsonContractResolver(), TypeNameHandling = TypeNameHandling.Auto
            };

            Console.WriteLine(JsonConvert.SerializeObject(result, settings));

            Console.WriteLine("Updating done");
        }
        private void ValidateFaultyTeli(ITelimena teli)
        {
            Assert.IsTrue(teli.GetType() == typeof(NullObjectTelimena));
            teli.Track.Event("There should be no error here even though it is not working");
            teli.Track.View("There should be no error here even though it is not working");
            teli.Track.Log(LogLevel.Warn, "There should be no error here even though it is not working");
            teli.Track.SendAllDataNow();

            UpdateCheckResult result = teli.Update.CheckForUpdates();

            Assert.AreEqual("Update check handled by NullObjectTelemetryModule", result.Exception.Message);
            UpdateInstallationResult result2 = teli.Update.HandleUpdatesAsync(true).Result;

            Assert.IsNotNull(teli.Properties);
        }
示例#8
0
        private async Task StartReporting(UserInfo userInfo)
        {
            Random random = new Random();

            while (this.timeoutStopwatch.IsRunning && this.timeoutStopwatch.ElapsedMilliseconds < this.duration.TotalMilliseconds)
            {
                ProgramInfo prg  = this.apps[random.Next(0, this.apps.Count)];
                ITelimena   teli = (Telimena)TelimenaFactory.Construct(new TelimenaStartupInfo(this.telemetryKey, new Uri(this.url))
                {
                    ProgramInfo = prg,
                    UserInfo    = userInfo
                });
                int operation = random.Next(6);
                if (operation == 1)
                {
                    teli.Track.Event("SomeEvent");
                    this.progressReport("Done");
                }
                else if (operation == 2)
                {
                    var result = await(teli as Telimena).Initialize().ConfigureAwait(false);
                    this.progressReport(this.PresentResponse(result));
                }
                else if (operation == 3)
                {
                    teli.Track.Log(LogLevel.Critical, "Log messagess");
                }
                else if (operation == 4)
                {
                    teli.Track.Exception(new InvalidCastException("BOO"));
                }
                else
                {
                    if (random.Next(2) == 1)
                    {
                        teli.Track.View(this.funcs[random.Next(0, this.funcs.Count)]);
                        this.progressReport("Done");
                    }
                    else
                    {
                        teli.Track.View(this.funcs[random.Next(0, this.funcs.Count)], this.GetRandomData());
                        this.progressReport("Done");
                    }
                }

                await Task.Delay(random.Next(this.delayMin, this.delayMax)).ConfigureAwait(false);
            }
        }
        public void Test_NoUpdates()
        {
            ITelimena sut = TelimenaFactory.Construct(new TelimenaStartupInfo(Guid.NewGuid(), Helpers.TeliUri)
            {
                SuppressAllErrors = false
            });

            Helpers.SetupMockHttpClient(sut, this.GetMockClientForCheckForUpdates(sut.Properties.TelemetryKey, new UpdateResponse(), new UpdateResponse()));

            UpdateCheckResult response = sut.Update.CheckForUpdatesAsync().GetAwaiter().GetResult();

            Assert.IsFalse(response.IsUpdateAvailable);
            Assert.AreEqual(0, response.ProgramUpdatesToInstall.Count);
            Assert.IsNull(response.UpdaterUpdate);
            Assert.IsNull(response.Exception);
        }
示例#10
0
        private void useCurrentAppButton_Click(object sender, EventArgs e)
        {
            if (Guid.TryParse(this.apiKeyTextBox.Text, out Guid key))
            {
                Properties.Settings.Default.telemetryKey = this.apiKeyTextBox.Text;
                Properties.Settings.Default.Save();
                this.Telimena = TelimenaFactory.Construct(new TelimenaStartupInfo(key
                                                                                  , telemetryApiBaseUrl: new Uri(this.apiUrlTextBox.Text))) as Telimena;
            }
            else
            {
                MessageBox.Show("Api key missing, cannot run teli");
            }

            Properties.Settings.Default.baseUri = this.apiUrlTextBox.Text;
            Properties.Settings.Default.Save();
        }
示例#11
0
        public void Test_RegistrationFunc(ITelimena telimena, Func <TelemetryInitializeResponse> func, bool skipFlagExpectedValue)
        {
            try
            {
                TelemetryInitializeResponse result = func();
                Assert.Fail("Exception expected");
            }
            catch (Exception e)
            {
                TelimenaException ex = e as TelimenaException;
                Assert.AreEqual(1, ex.InnerExceptions.Count);

                StringAssert.Contains("An error occurred while posting to [api/v1/telemetry/initialize]", ex.InnerExceptions[0].Message);
                TelemetryInitializeRequest jObj = ex.RequestObjects[0].Value as TelemetryInitializeRequest;
                ((Telimena)telimena).Properties.StaticProgramInfo.ThrowIfPublicPropertiesNotEqual(jObj.ProgramInfo, true);
            }
        }
        public static void Work(Arguments arguments)
        {
            Console.WriteLine("Starting update handling...");
            ITelimena teli = TelimenaFactory.Construct(new TelimenaStartupInfo(arguments.TelemetryKey, new Uri(arguments.ApiUrl)));

            teli.Properties.UpdatePromptingMode = UpdatePromptingModes.PromptBeforeDownload;
            Console.WriteLine("Telimena created... Handling updates");
            UpdateInstallationResult result = teli.Update.HandleUpdates(false);

            Console.WriteLine("Finished update handling");
            JsonSerializerSettings settings = new JsonSerializerSettings {
                ContractResolver = new MyJsonContractResolver()
            };

            Console.WriteLine(JsonConvert.SerializeObject(result, settings));

            Console.WriteLine("All done");
        }
示例#13
0
        private async Task Initialize()
        {
            Random rnd = new Random();

            this.users = new List <UserInfo>();
            for (int i = 0; i < this.numberOfUsers; i++)
            {
                UserInfo user = new UserInfo
                {
                    Email = this.GetRandomName("Email@", i), UserIdentifier = this.GetRandomName("User", i), MachineName = this.GetRandomName("Machine", i)
                };
                this.users.Add(user);
            }

            this.apps = new List <ProgramInfo>();
            for (int i = this.appIndexSeed; i < this.numberOfApps + this.appIndexSeed; i++)
            {
                ProgramInfo programInfo = new ProgramInfo
                {
                    Name = "Program_" + i
                    , PrimaryAssembly = new AssemblyInfo
                    {
                        Name          = "PrimaryAssembly_Program_" + i
                        , VersionData = new VersionData($"{1}.{DateTime.UtcNow.Month}.{DateTime.UtcNow.Day}.{rnd.Next(10)}"
                                                        , $"{1 + 1}.{DateTime.UtcNow.Month}.{DateTime.UtcNow.Day}.{rnd.Next(10)}")
                    }
                };
                this.apps.Add(programInfo);
                ITelimena teli = TelimenaFactory.Construct(new TelimenaStartupInfo(this.telemetryKey, new Uri(this.url))
                {
                    ProgramInfo = programInfo
                });

                await(teli as Telimena).Initialize().ConfigureAwait(false);
            }

            this.funcs = new List <string>();

            for (int i = 0; i < this.numberOfFuncs; i++)
            {
                this.funcs.Add(this.GetRandomName("View", i));
            }
        }
示例#14
0
        private void CheckAndInstallUpdates(ITelimena telimena, bool takeBeta)
        {
            Console.WriteLine($"Starting {MethodBase.GetCurrentMethod().Name}...");

            UpdateCheckResult result = telimena.Update.CheckForUpdates();

            Console.WriteLine($"Finished update check. Update available: {result.IsUpdateAvailable}...");

            JsonSerializerSettings settings = new JsonSerializerSettings {
                ContractResolver = new MyJsonContractResolver(), TypeNameHandling = TypeNameHandling.Auto
            };

            Console.WriteLine(JsonConvert.SerializeObject(result, settings));

            UpdateInstallationResult installationResult = telimena.Update.InstallUpdates(result, takeBeta);


            Console.WriteLine($"Finished {MethodBase.GetCurrentMethod().Name}");
        }
示例#15
0
        public void Work()
        {
            Console.WriteLine("Starting worker");

            ITelimena telimena = this.GetTelimena(this.arguments.TelemetryKey);

            try
            {
                switch (this.arguments.Action)
                {
                case Actions.Initialize:
                    this.HandleInitialize(telimena);
                    break;

                case Actions.ReportViewUsage:
                    this.HandleReportViewUsage(telimena);
                    break;

                case Actions.HandleUpdates:
                    this.HandleUpdates(telimena, false);
                    break;

                case Actions.CheckAndInstallUpdates:
                    this.CheckAndInstallUpdates(telimena, false);
                    break;

                case Actions.HandleUpdatesWithBeta:
                    this.HandleUpdates(telimena, true);
                    break;
                }
                Thread.Sleep(7 * 1000);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            Console.WriteLine("Done");
        }
示例#16
0
        public void Test_CheckForUpdates_Program_AndUpdater()
        {
            var si = new TelimenaStartupInfo(Guid.NewGuid(), Helpers.TeliUri)
            {
                SuppressAllErrors = false
            };

            ITelimena sut = TelimenaFactory.Construct(si);

            Assert.AreEqual("Telimena.Client.Tests", sut.Properties.StaticProgramInfo.PrimaryAssembly.Name);
            UpdateResponse latestVersionResponse = new UpdateResponse
            {
                UpdatePackages = new List <UpdatePackageData>
                {
                    new UpdatePackageData {
                        FileSizeBytes = 666, PublicId = Guid.NewGuid(), IsBeta = true, Version = "3.1.0.0"
                    }
                }
            };
            UpdateResponse updaterResponse = new UpdateResponse
            {
                UpdatePackages = new List <UpdatePackageData> {
                    new UpdatePackageData {
                        FileName = DefaultToolkitNames.UpdaterFileName, Version = "1.2"
                    }
                }
            };

            Helpers.SetupMockHttpClient(sut, this.GetMockClientForCheckForUpdates(sut.Properties.TelemetryKey, latestVersionResponse, updaterResponse));

            UpdateCheckResult response = sut.Update.CheckForUpdatesAsync().GetAwaiter().GetResult();

            Assert.IsTrue(response.IsUpdateAvailable);
            Assert.AreEqual(1, response.ProgramUpdatesToInstall.Count);
            Assert.IsNotNull(response.ProgramUpdatesToInstall.SingleOrDefault(x => x.Version == "3.1.0.0" && x.IsBeta));
            Assert.AreEqual("1.2", response.UpdaterUpdate.Version);
            Assert.IsNull(response.Exception);
        }
示例#17
0
        private void HandleReportViewUsage(ITelimena telimena)
        {
            Console.WriteLine("Sending View usage report");

            Dictionary <string, string> customData = new Dictionary <string, string>();

            customData.Add("Time", DateTime.Now.ToShortTimeString());
            customData.Add("RandomNumber", new Random().Next(0, 10).ToString());
            if (this.arguments.ViewName != null)
            {
                telimena.Track.View(this.arguments.ViewName, customData);
            }
            else
            {
                telimena.Track.View("DefaultView", customData);
            }
            Console.WriteLine("Received View usage response..");

            JsonSerializerSettings settings = new JsonSerializerSettings {
                ContractResolver = new MyJsonContractResolver(), TypeNameHandling = TypeNameHandling.Auto
            };
            //todo - some result - Console.WriteLine(JsonConvert.SerializeObject(result, settings));
        }
示例#18
0
 public PluginTwo()
 {
     this.teli = Telimena.Construct(new TelimenaStartupInfo(Guid.Parse("aeb21d70-a645-4666-b2f7-c34391997032")));
 }
示例#19
0
 public PluginTwo()
 {
     this.teli = Telimena.Construct(new TelimenaStartupInfo(Guid.Parse("aeb21d70-a645-4666-b2f7-c34391997032"), new Uri("http://localhost:7757/")));
 }
示例#20
0
 public PluginOne()
 {
     this.teli = Telimena.Construct(new TelimenaStartupInfo(Guid.Parse("b1ad5308-43f2-4600-a851-d7cbd0f7b374"), new Uri("http://localhost:7757/")));
 }
示例#21
0
 public PluginOne()
 {
     this.teli = Telimena.Construct(new TelimenaStartupInfo(Guid.Parse("b1ad5308-43f2-4600-a851-d7cbd0f7b374")));
 }
示例#22
0
 public static void SetupMockHttpClient(ITelimena telimena, Mock <ITelimenaHttpClient> client)
 {
     ((Telimena)telimena).Messenger = new Messenger(((Telimena)telimena)?.Serializer, client.Object);
 }