public async Task ShouldThrowException(int errorCode, Type type) { var response = "{\"requestID\":\"eb8a8d08-9e25-4473-81f8-6565c51a43d9\",\"signature\":{\"*\": \"*\"},\"errors\":[{\"code\":XXXX,\"msg\":\"Some error\"}],\"status\": \"fatal\"}"; var httpClient = new HttpClient( FakeHttpMessageHandler.Create(request => new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent(response.Replace("XXXX", errorCode.ToString())) })); var httpClientFactory = new MockHttpClientFactory(httpClient); var mockServiceUriProvider = new Mock <IServiceUriProvider>(); mockServiceUriProvider .Setup(m => m.GetRandomAnalyticsUri()) .Returns(new Uri("http://localhost:8096")); var serializer = new DefaultSerializer(); var client = new AnalyticsClient(httpClientFactory, mockServiceUriProvider.Object, serializer, new Mock <ILogger <AnalyticsClient> >().Object, NoopRequestTracer.Instance); try { await client.QueryAsync <dynamic>("SELECT * FROM `default`;", new AnalyticsOptions()).ConfigureAwait(false); } catch (Exception ex) { if (ex.GetType() != type) { throw; } } }
internal AnalyticsPageViewRequest(AnalyticsClient analyticsClient, string page, string title) { m_analyticsClient = analyticsClient; m_page = page; m_title = title; m_customVariables = new CustomVariableBag(); }
public static async Task <KeyPhrasesResult> GetKeyPhrasesAsync(string input, string language = "en") { KeyPhrasesResult keyPhrasesResult = new KeyPhrasesResult() { KeyPhrases = Enumerable.Empty <string>() }; if (!string.IsNullOrEmpty(input)) { KeyPhraseBatchResult result = await AnalyticsClient.KeyPhrasesAsync(new MultiLanguageBatchInput( new List <MultiLanguageInput>() { new MultiLanguageInput(language, "0", input) })); if (result.Documents != null) { List <string> phrases = new List <string>(); foreach (string keyPhrase in result.Documents[0].KeyPhrases) { phrases.Add(keyPhrase); } keyPhrasesResult.KeyPhrases = phrases; } if (result.Errors != null) { // Just return the empty IEnumerable } } return(keyPhrasesResult); }
private async void InitAsync() { await AnalyticsClient.OpenSessionAsync(); Observable.Timer(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5)) .Subscribe(SendLiveMatches); }
protected override void ProcessRecord() { base.ProcessRecord(); try { client?.Dispose(); int timeout = GetPreferredTimeout(); WriteDebug($"Cmdlet Timeout : {timeout} milliseconds."); client = new AnalyticsClient(AuthProvider, new Oci.Common.ClientConfiguration { RetryConfiguration = retryConfig, TimeoutMillis = timeout, ClientUserAgent = PSUserAgent }); string region = GetPreferredRegion(); if (region != null) { WriteDebug("Choosing Region:" + region); client.SetRegion(region); } if (Endpoint != null) { WriteDebug("Choosing Endpoint:" + Endpoint); client.SetEndpoint(Endpoint); } } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }
public async Task QueryAsync_Sets_LastActivity() { var options = new ClusterOptions().WithServers("http://localhost"); var context = new ClusterContext(null, options); context.AddNode(new ClusterNode(new ClusterContext(null, new ClusterOptions())) { AnalyticsUri = new Uri("http://localhost:8094/query"), EndPoint = new IPEndPoint(IPAddress.Loopback, 8091), NodesAdapter = new NodeAdapter { Analytics = 8094 } }); var httpClient = new HttpClient( FakeHttpMessageHandler.Create(request => new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("{}") }) ); var client = new AnalyticsClient(httpClient, new JsonDataMapper(new DefaultSerializer()), context); Assert.Null(client.LastActivity); var queryRequest = new AnalyticsRequest("SELECT * FROM `default`;"); await client.QueryAsync <dynamic>(queryRequest, CancellationToken.None).ConfigureAwait(false); Assert.NotNull(client.LastActivity); }
public async Task QueryAsync_Sets_LastActivity() { var httpClient = new CouchbaseHttpClient( FakeHttpMessageHandler.Create(request => new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("{}") }) ); var mockServiceUriProvider = new Mock <IServiceUriProvider>(); mockServiceUriProvider .Setup(m => m.GetRandomAnalyticsUri()) .Returns(new Uri("http://localhost:8096")); var serializer = new DefaultSerializer(); var client = new AnalyticsClient(httpClient, mockServiceUriProvider.Object, serializer, new Mock <ILogger <AnalyticsClient> >().Object, NoopRequestTracer.Instance); Assert.Null(client.LastActivity); var queryRequest = new AnalyticsRequest("SELECT * FROM `default`;"); await client.QueryAsync <dynamic>(queryRequest, CancellationToken.None).ConfigureAwait(false); Assert.NotNull(client.LastActivity); }
/// <summary> /// Sends an analytics request to the server. /// </summary> /// <typeparam name="T">The <see cref="Type" /> T of the body for each row (or document) result.</typeparam> /// <param name="analyticsRequest">The analytics request.</param> /// <returns></returns> public IAnalyticsResult <T> Send <T>(IAnalyticsRequest analyticsRequest) { IAnalyticsResult <T> result; if (_isDown) { result = HandleNodeUnavailable <T>(analyticsRequest); } else { try { result = AnalyticsClient.Query <T>(analyticsRequest); } catch (Exception exception) { result = new AnalyticsResult <T> { Exception = exception, Message = exception.Message, Success = false, }; } } return(result); }
/// <summary> /// Asynchronously sends an analytics request to the server. /// </summary> /// <typeparam name="T">The <see cref="Type" /> T of the body for each row (or document) result.</typeparam> /// <param name="analyticsRequest">The analytics request.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public Task <IAnalyticsResult <T> > SendAsync <T>(IAnalyticsRequest analyticsRequest, CancellationToken cancellationToken) { Task <IAnalyticsResult <T> > result; if (_isDown) { result = Task.FromResult(HandleNodeUnavailable <T>(analyticsRequest)); } else { try { result = AnalyticsClient.QueryAsync <T>(analyticsRequest, cancellationToken); } catch (Exception exception) { result = Task.FromResult <IAnalyticsResult <T> >(new AnalyticsResult <T> { Exception = exception, Message = exception.Message, Success = false, }); } } return(result); }
public async Task SignOutAsync([FromServices] AnalyticsClient analyticsClient) { await signInManager_.SignOutAsync(); logger_.LogInformation("User logged out."); analyticsClient.SendLogoutEvent(); }
public static async Task <SentimentResult> GetTextSentimentAsync(string input, string language = "en") { SentimentResult sentimentResult = new SentimentResult() { Score = 0.5 }; if (!string.IsNullOrEmpty(input)) { SentimentBatchResult result = await AnalyticsClient.SentimentAsync(new MultiLanguageBatchInput( new List <MultiLanguageInput>() { new MultiLanguageInput(language, "0", input) })); if (result.Documents != null) { sentimentResult.Score = (double)result.Documents[0].Score; } if (result.Errors != null) { // Just return the neutral value } } return(sentimentResult); }
public void When_deferred_is_true_query_result_is_DeferredAnalyticsResult() { var resultJson = JsonConvert.SerializeObject(new { status = "Success", handle = "handle" }); var context = ContextFactory.GetCouchbaseContext(); context.AnalyticsUris.Add(new FailureCountingUri("http://localhost")); var httpClient = new HttpClient( FakeHttpMessageHandler.Create(request => new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(resultJson) }) ); var client = new AnalyticsClient(httpClient, new JsonDataMapper(context.ClientConfig), context); var queryRequest = new AnalyticsRequest("SELECT * FROM `default`;"); var result = client.Query <dynamic>(queryRequest); Assert.IsInstanceOf <AnalyticsDeferredResultHandle <dynamic> >(result.Handle); Assert.AreEqual(QueryStatus.Success, result.Status); var deferredResult = (AnalyticsDeferredResultHandle <dynamic>)result.Handle; Assert.AreEqual("handle", deferredResult.HandleUri); }
public void Client_sets_AnalyticsPriority_Header(bool priority) { var context = ContextFactory.GetCouchbaseContext(); context.AnalyticsUris.Add(new FailureCountingUri("http://localhost")); var httpClient = new HttpClient( FakeHttpMessageHandler.Create(request => { if (priority) { Assert.IsTrue(request.Headers.TryGetValues(AnalyticsClient.AnalyticsPriorityHeaderName, out var values)); Assert.AreEqual("-1", values.First()); } else { Assert.IsFalse(request.Headers.TryGetValues(AnalyticsClient.AnalyticsPriorityHeaderName, out _)); } return(new HttpResponseMessage(HttpStatusCode.OK)); }) ); var client = new AnalyticsClient(httpClient, new JsonDataMapper(context.ClientConfig), context); var queryRequest = new AnalyticsRequest("SELECT * FROM `default`;"); queryRequest.Priority(priority); client.Query <dynamic>(queryRequest); }
public void Client_sets_AnalyticsPriority_Header(bool priority) { var configuration = new Configuration().WithServers("http://localhost"); var httpClient = new HttpClient( FakeHttpMessageHandler.Create(request => { if (priority) { Assert.True(request.Headers.TryGetValues(AnalyticsClient.AnalyticsPriorityHeaderName, out var values)); Assert.Equal("-1", values.First()); } else { Assert.False(request.Headers.TryGetValues(AnalyticsClient.AnalyticsPriorityHeaderName, out _)); } return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("{}") }); }) ); var client = new AnalyticsClient(httpClient, new JsonDataMapper(new DefaultSerializer()), configuration); var queryRequest = new AnalyticsRequest("SELECT * FROM `default`;"); queryRequest.Priority(priority); client.Query <dynamic>(queryRequest); }
public async Task Client_sets_AnalyticsPriority_Header(bool priority) { var httpClient = new CouchbaseHttpClient( FakeHttpMessageHandler.Create(request => { if (priority) { Assert.True(request.Headers.TryGetValues(AnalyticsClient.AnalyticsPriorityHeaderName, out var values)); Assert.Equal("-1", values.First()); } else { Assert.False(request.Headers.TryGetValues(AnalyticsClient.AnalyticsPriorityHeaderName, out _)); } return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("{}") }); }) ); var mockServiceUriProvider = new Mock <IServiceUriProvider>(); mockServiceUriProvider .Setup(m => m.GetRandomAnalyticsUri()) .Returns(new Uri("http://localhost:8096")); var serializer = new DefaultSerializer(); var client = new AnalyticsClient(httpClient, mockServiceUriProvider.Object, serializer, new Mock <ILogger <AnalyticsClient> >().Object, NoopRequestTracer.Instance); await client.QueryAsync <dynamic>("SELECT * FROM `default`;", new AnalyticsOptions().Priority(priority)); }
public void Query_Sets_LastActivity() { var configuration = new ClusterOptions().WithServers("http://localhost"); configuration.GlobalNodes.Add(new ClusterNode { AnalyticsUri = new Uri("http://localhost:8094/query") }); var httpClient = new HttpClient( FakeHttpMessageHandler.Create(request => new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("{}") }) ); var client = new AnalyticsClient(httpClient, new JsonDataMapper(new DefaultSerializer()), configuration); Assert.Null(client.LastActivity); var queryRequest = new AnalyticsRequest("SELECT * FROM `default`;"); client.Query <dynamic>(queryRequest); Assert.NotNull(client.LastActivity); }
public void When_deferred_is_true_query_result_is_DeferredAnalyticsResult() { var resultJson = JsonConvert.SerializeObject(new { status = "Success", handle = "handle" }); var configuration = new ClusterOptions().WithServers("http://localhost"); configuration.GlobalNodes.Add(new ClusterNode { AnalyticsUri = new Uri("http://localhost:8094/query") }); var httpClient = new HttpClient( FakeHttpMessageHandler.Create(request => new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(resultJson) }) ); var client = new AnalyticsClient(httpClient, new JsonDataMapper(new DefaultSerializer()), configuration); var queryRequest = new AnalyticsRequest("SELECT * FROM `default`;"); var result = client.Query <dynamic>(queryRequest); Assert.IsType <AnalyticsDeferredResultHandle <dynamic> >(result.Handle); Assert.Equal(QueryStatus.Success, result.MetaData.Status); var deferredResult = (AnalyticsDeferredResultHandle <dynamic>)result.Handle; Assert.Equal("handle", deferredResult.HandleUri); }
public static async Task <DetectLanguageResult> GetDetectedLanguageAsync(string input) { DetectLanguageResult languageResult = new DetectLanguageResult() { Language = new Dictionary <string, string>() }; if (!string.IsNullOrEmpty(input)) { LanguageBatchResult result = await AnalyticsClient.DetectLanguageAsync(new BatchInput( new List <Input>() { new Input("0", input) })); if (result.Documents != null) { languageResult.Language.Add("iso6391Name", result.Documents[0].DetectedLanguages[0].Iso6391Name); languageResult.Language.Add("name", result.Documents[0].DetectedLanguages[0].Name); languageResult.Language.Add("score", result.Documents[0].DetectedLanguages[0].Score.ToString()); } if (result.Errors != null) { // Just return the empty Dictionary } } return(languageResult); }
public void Setup() { TestHelper.CheckEnvironmentVariable(); SearchClient = new SearchClient(TestHelper.ApplicationId1, TestHelper.AdminKey1); SearchClient2 = new SearchClient(TestHelper.ApplicationId2, TestHelper.AdminKey2); McmClient = new SearchClient(TestHelper.McmApplicationId, TestHelper.McmAdminKey); AnalyticsClient = new AnalyticsClient(TestHelper.ApplicationId1, TestHelper.AdminKey1); }
private static void PerformAnalyticsFour() { var analyticsFour = AnalyticsClient <DimensionsFour> .GetData(); var fctSessionHitses = Mapper.MapFour(analyticsFour); Dao.SaveAnalyticsFour(fctSessionHitses); }
private static void PerformAnalyticsThree() { var analyticsThree = AnalyticsClient <DimensionsThree> .GetData(); var fctSessionChannels = Mapper.MapThree(analyticsThree); Dao.SaveAnalyticsThree(fctSessionChannels); }
private static void PerformAnalyticsOne() { var analyticsOne = AnalyticsClient <DimensionsOne> .GetData(); var bufferDicClients = Mapper.MapOne(analyticsOne); Dao.SaveAnalyticsOne(bufferDicClients); }
private static void PerformAnalyticsTwo() { var analyticsTwo = AnalyticsClient <DimensionsTwo> .GetData(); var fctSessions = Mapper.MapTwo(analyticsTwo); Dao.SaveAnalyticsTwo(fctSessions); }
public LunoClient(ApiKeyConnection connection) : base(connection) { Analytics = new AnalyticsClient(connection); ApiAuthentication = new ApiAuthenticationClient(connection); Event = new EventClient(connection); Session = new SessionClient(connection); User = new UsersClient(connection); }
public LogoutModel( SignInManager <ApplicationUser> signInManager, ILogger <LogoutModel> logger, AnalyticsClient analyticsClient) { _signInManager = signInManager; _logger = logger; _analyticsClient = analyticsClient; }
private static void ProccessReportWithTariff() { //Logger.Info("Start GA ProccessReportWithTariff"); var reportWithTariff = AnalyticsClient <DimensionsReportWithTariff> .GetData(); var mappedReportWithTariff = UserActivityMapper.MapReportWithTariff(reportWithTariff); SaveReport(mappedReportWithTariff); //Logger.Info($"End GA ProccessReportWithTariff: count={mappedReportWithTariff.Count}."); }
private static void ProccessReportWithConvertions() { //Logger.Info("Start GA ProccessReportWithConvertions"); var reportWithConvertions = AnalyticsClient <DimensionsReportWithConversions> .GetData(); var mappedReportWithConvertions = UserActivityMapper.MapReportWithConversions(reportWithConvertions); SaveReport(mappedReportWithConvertions); //Logger.Info($"End GA ProccessReportWithConvertions: count={reportWithConvertions.Count}."); }
private static void ProccessReportWithCompanyId() { //Logger.Info("Start GA ProccessReportWithCompanyId"); var reportWithCompanyId = AnalyticsClient <DimensionsReportWithCompanyId> .GetData(); var mappedReportWithCompanyId = UserActivityMapper.MapReportWithCompaynyId(reportWithCompanyId); SaveReport(mappedReportWithCompanyId); //Logger.Info($"End GA ProccessReportWithCompanyId: count={mappedReportWithCompanyId.Count}."); }
public void InitializesEndpoint() { var coreSettings = new CoreSettings { EnableAutomaticReports = true }; var endpoint = Substitute.For <IAnalyticsEndpoint>(); var client = new AnalyticsClient(endpoint); client.Initialize(coreSettings); endpoint.Received().Initialize(); }
private static void ProccessReportWithAccountRegDate() { //Logger.Info("Start GA ProccessReportWithAccountRegDate"); var reportWithAccountRegDate = AnalyticsClient <DimensionsReportWithAccountRegDate> .GetData(); var mappedReportWithAccountRegDate = UserActivityMapper.MapReportWithAccountRegDate(reportWithAccountRegDate); SaveReport(mappedReportWithAccountRegDate); //Logger.Info($"End GA ProccessReportWithAccountRegDate: count={mappedReportWithAccountRegDate.Count}."); }
/// <summary> /// Start CSharpAnalytics by restoring the session state, starting the background sender, /// hooking up events to track and firing the application start event and home page view to analytics. /// Call this just before Window.Current.Activate() in your App.OnLaunched method. /// </summary> /// <param name="configuration">Configuration to use, must at a minimum specify your Google Analytics ID and app name.</param> /// <param name="appName">Application name to use for the user agent tracking.</param> /// <param name="uploadInterval">How often to upload to the server. Lower times = more traffic but realtime. Defaults to 5 seconds.</param> /// <returns>A Task that will complete once CSharpAnalytics is available.</returns> /// <example>await AutoAnalytics.StartAsync(new Configuration("UA-123123123-1", "myapp.someco.com"));</example> public static async Task StartAsync(Configuration configuration, string appName, TimeSpan? uploadInterval = null) { currentAppName = appName; await StartRequesterAsync(uploadInterval ?? TimeSpan.FromSeconds(5)); await RestoreSessionAsync(configuration.SessionTimeout); Client = new AnalyticsClient(configuration, sessionManager, new WindowsStoreEnvironment(), requester.Add); Client.TrackEvent("ApplicationLifecycle", "Start"); Client.TrackPageView("Home", "/"); HookEvents(Application.Current); }
public static void Init(string trackingId, string clientId, string appName, string appVersion) { _web = new AnalyticsClient(trackingId, clientId, appName, appVersion); }
public AnalyticsSession(string domain, string trackingCode) { m_analyticsClient = new AnalyticsClient(domain, trackingCode); }