Beispiel #1
0
 public void GetCustomMetrics()
 {
     Google.Apis.Analytics.v3.ManagementResource.CustomMetricsResource.ListRequest request = analyticsService.Management.CustomMetrics.List(DefaultAccount.Id, DefaultProfile.WebPropertyId);
     try
     {
         var dimensions = request.Execute();
         if (CustomMetrics == null)
         {
             CustomMetrics = new List <Google.Apis.Analytics.v3.Data.CustomMetric>();
         }
         foreach (var item in dimensions.Items)
         {
             CustomMetrics.Add(item);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Beispiel #2
0
 public Management.Data.CustomMetric CreateCustomMetric(string name, bool isActive)
 {
     Google.Apis.Analytics.v3.Data.CustomMetric dimension = new Google.Apis.Analytics.v3.Data.CustomMetric()
     {
         Active = isActive, AccountId = DefaultAccount.Id, Name = name, Scope = "HIT", WebPropertyId = DefaultProfile.WebPropertyId
     };
     Google.Apis.Analytics.v3.ManagementResource.CustomMetricsResource.InsertRequest request = analyticsService.Management.CustomMetrics.Insert(dimension, DefaultAccount.Id, DefaultProfile.WebPropertyId);
     try
     {
         dimension = request.Execute();
         CustomMetrics.Add(dimension);
         Management.Data.CustomMetric d = new Management.Data.CustomMetric()
         {
             Id = dimension.Id, Index = dimension.Index, Name = dimension.Name
         };
         return(d);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
     return(null);
 }
        public ToolViewViewModel(
            IKCVDBClient client,
            string sessionId,
            IDispatcher dispatcher)
            : base(dispatcher)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            if (sessionId == null)
            {
                throw new ArgumentNullException(nameof(sessionId));
            }
            Client    = client;
            SessionId = sessionId;

            // Register metrics
            CustomMetrics.Add(new StartedTimeMetrics(DateTimeOffset.Now));
            CustomMetrics.Add(new TransferredApiCountMetrics(Client));
            CustomMetrics.Add(new SuccessCountMetrics(Client));
            CustomMetrics.Add(new FailureCountMetrics(Client));
            CustomMetrics.Add(new TransferredDataAmountMetrics(Client));
            CustomMetrics.Add(new TransferredDataAmountPerHourMetrics(Client));


            // Register a listener to update history
            Observable.FromEventPattern <ApiDataSentEventArgs>(Client, nameof(Client.ApiDataSent))
            .Select(x => x.EventArgs)
            .Select(x => {
                var now = DateTimeOffset.Now;
                return(x.ApiData.Select(apiData => new HistoryItem {
                    Time = now,
                    Body = apiData.RequestUri.PathAndQuery,
                    Success = true,
                }));
            })
            .SubscribeOnDispatcher(System.Windows.Threading.DispatcherPriority.Normal)
            .Subscribe(historyItems => {
                try {
                    HistoryItems = new ObservableCollection <HistoryItem>(
                        historyItems.Reverse().Concat(HistoryItems).Take(MaxHistoryCount));
                }
                catch (Exception ex) {
                    TelemetryClient.TrackException("Failed to update history.", ex);
                    if (ex.IsCritical())
                    {
                        throw;
                    }
                }
            });

            // Register a listener to notify chinese option chaning
            Subscriptions.Add(Observable.FromEventPattern <PropertyChangedEventArgs>(Settings.Default, nameof(Settings.PropertyChanged))
                              .Where(x => x.EventArgs.PropertyName == nameof(Settings.ShowTraditionalChinese))
                              .SubscribeOnDispatcher()
                              .Subscribe(_ => {
                try {
                    RaisePropertyChanged(nameof(EnableSendingTelemetry));
                    RaisePropertyChanged(nameof(ShowTraditionalChinese));
                }
                catch (Exception ex) {
                    TelemetryClient.TrackException("Failed to raise property chaning of show traditional chinese option", ex);
                    if (ex.IsCritical())
                    {
                        throw;
                    }
                }
            }));

            // Register a listener to receive language switching event
            Subscriptions.Add(Observable.FromEventPattern <PropertyChangedEventArgs>(ResourceHolder.Instance, nameof(ResourceHolder.PropertyChanged))
                              .Where(x => x.EventArgs.PropertyName == nameof(ResourceHolder.Culture))
                              .SubscribeOnDispatcher()
                              .Subscribe(_ => {
                try {
                    CurrentLanguageTwoLetterName = ResourceHolder.Instance.Culture?.TwoLetterISOLanguageName;
                }
                catch (Exception ex) {
                    TelemetryClient.TrackException("Failed to update current language two letter name.", ex);
                    if (ex.IsCritical())
                    {
                        throw;
                    }
                }
            }));

            CurrentLanguageTwoLetterName = ResourceHolder.Instance.Culture?.TwoLetterISOLanguageName;
        }