Example #1
0
        public async Task ShouldWriteData()
        {
            var service = CreateUsageService();

            var target = new UsageTracker(
                CreateServiceProvider(),
                service,
                CreatePackageSettings());

            await target.IncrementCounter(x => x.NumberOfClones);

            await service.Received(1).WriteLocalData(Arg.Is <UsageData>(data =>
                                                                        data.Reports.Count == 1 &&
                                                                        data.Reports[0].Dimensions.Date.Date == DateTimeOffset.Now.Date &&
                                                                        //data.Reports[0].Dimensions.AppVersion == AssemblyVersionInformation.Version &&
                                                                        data.Reports[0].Dimensions.Lang == CultureInfo.InstalledUICulture.IetfLanguageTag &&
                                                                        data.Reports[0].Dimensions.CurrentLang == CultureInfo.CurrentCulture.IetfLanguageTag &&
                                                                        data.Reports[0].Measures.NumberOfClones == 1
                                                                        ));
        }
Example #2
0
        /// <summary>
        /// Opens the link in the browser.
        /// </summary>
        public async override Task Execute()
        {
            var isgithub = await IsGitHubRepo();

            if (!isgithub)
            {
                return;
            }

            var link = await GenerateLink(LinkType.Blob);

            if (link == null)
            {
                return;
            }
            var browser = ServiceProvider.TryGetService <IVisualStudioBrowser>();

            browser?.OpenUrl(link.ToUri());

            await UsageTracker.IncrementCounter(x => x.NumberOfOpenInGitHub);
        }
Example #3
0
        public async void Activate([AllowNull] object data = null)
        {
            var isgithub = await IsGitHubRepo();

            if (!isgithub)
            {
                return;
            }

            var link = await GenerateLink();

            if (link == null)
            {
                return;
            }
            var browser = ServiceProvider.TryGetService <IVisualStudioBrowser>();

            browser?.OpenUrl(link.ToUri());

            await UsageTracker.IncrementOpenInGitHubCount();
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="previousStatus"></param>
        /// <param name="newStatus"></param>
        /// <param name="item"></param>
        protected void OnCallStatusChange(CodecActiveCallItem item)
        {
            var handler = CallStatusChange;

            if (handler != null)
            {
                handler(this, new CodecCallStatusItemChangeEventArgs(item));
            }

            if (UsageTracker != null)
            {
                if (IsInCall && !UsageTracker.UsageTrackingStarted)
                {
                    UsageTracker.StartDeviceUsage();
                }
                else if (UsageTracker.UsageTrackingStarted && !IsInCall)
                {
                    UsageTracker.EndDeviceUsage();
                }
            }
        }
Example #5
0
        public void LoadingWorks()
        {
            InitializeEnvironment(TestBasePath, false, false);
            var userId       = Guid.NewGuid().ToString();
            var appVersion   = ApplicationInfo.Version;
            var unityVersion = "2017.3f1";
            var instanceId   = Guid.NewGuid().ToString();
            var usageStore   = new UsageStore();

            usageStore.Model.Guid = userId;
            var usageTracker = new UsageTracker(Substitute.For <IMetricsService>(), Substitute.For <ISettings>(),
                                                Environment, userId, unityVersion, instanceId);

            usageTracker.IncrementNumberOfStartups();
            var storePath = Environment.UserCachePath.Combine(Constants.UsageFile);

            Assert.IsTrue(storePath.FileExists());
            var json       = storePath.ReadAllText(Encoding.UTF8);
            var savedStore = json.FromJson <UsageStore>(lowerCase: true);

            Assert.AreEqual(1, savedStore.GetCurrentMeasures(appVersion, unityVersion, instanceId).NumberOfStartups);
        }
Example #6
0
        public ProcessingResult PostRx([FromHeader] string UsageDetails)
        {
            ProcessingResult result = new ProcessingResult();

            try
            {
                JObject       JSON     = JObject.Parse(UsageDetails);
                List <JToken> JSONList = JSON.SelectToken("Usage").ToList();

                foreach (JToken Token in JSONList)
                {
                    string UUID        = Token["UUID"].ToString();
                    string Timestamp   = Token["Timestamp"].ToString();
                    string Description = Token["Description"].ToString();

                    CreatorEntities   db = new CreatorEntities();
                    MobileConnections mobileconnection = db.MobileConnections.Single(mc => mc.UUID == UUID);

                    UsageTracker newusage = new UsageTracker();
                    newusage.MobileConnections = mobileconnection;
                    newusage.Timestamp         = DateTime.Parse(Timestamp);
                    newusage.Description       = Description;

                    db.UsageTracker.Add(newusage);
                    db.SaveChanges();
                }

                result.Message = "Sucessfully added";
                result.Status  = "Usage Tracking";
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Status  = "Usage Tracking";
            }

            return(result);
        }
Example #7
0
        public async Task ShouldIncrementCounter()
        {
            var model = new UsageModel {
                Dimensions = new UsageModel.DimensionsModel {
                    Date = DateTimeOffset.Now
                },
                Measures = new UsageModel.MeasuresModel
                {
                    NumberOfClones = 4
                }
            };
            var usageService = CreateUsageService(model);
            var target       = new UsageTracker(
                CreateServiceProvider(),
                usageService,
                CreatePackageSettings());

            await target.IncrementCounter(x => x.NumberOfClones);

            UsageData result = usageService.ReceivedCalls().First(x => x.GetMethodInfo().Name == "WriteLocalData").GetArguments()[0] as UsageData;

            Assert.AreEqual(5, result.Reports[0].Measures.NumberOfClones);
        }
        async Task DoOpenFile(IPullRequestFileNode file, bool workingDirectory)
        {
            try
            {
                var fullPath = ViewModel.GetLocalFilePath(file);
                var fileName = workingDirectory ? fullPath : await ViewModel.ExtractFile(file, true);

                using (workingDirectory ? null : OpenInProvisionalTab())
                {
                    var window = GitHub.VisualStudio.Services.Dte.ItemOperations.OpenFile(fileName);
                    window.Document.ReadOnly = !workingDirectory;

                    var buffer = GetBufferAt(fileName);

                    if (!workingDirectory)
                    {
                        AddBufferTag(buffer, ViewModel.Session, fullPath, null);

                        var textView = NavigationService.FindActiveView();
                        EnableNavigateToEditor(textView, file);
                    }
                }

                if (workingDirectory)
                {
                    await UsageTracker.IncrementCounter(x => x.NumberOfPRDetailsOpenFileInSolution);
                }
                else
                {
                    await UsageTracker.IncrementCounter(x => x.NumberOfPRDetailsViewFile);
                }
            }
            catch (Exception e)
            {
                ShowErrorInStatusBar("Error opening file", e);
            }
        }
        async Task DoDiffFile(IPullRequestFileNode file, bool workingDirectory)
        {
            try
            {
                var rightPath = System.IO.Path.Combine(file.DirectoryPath, file.FileName);
                var leftPath  = file.OldPath ?? rightPath;
                var rightFile = workingDirectory ? ViewModel.GetLocalFilePath(file) : await ViewModel.ExtractFile(file, true);

                var leftFile = await ViewModel.ExtractFile(file, false);

                var leftLabel  = $"{leftPath};{ViewModel.TargetBranchDisplayName}";
                var rightLabel = workingDirectory ? rightPath : $"{rightPath};PR {ViewModel.Model.Number}";
                var caption    = $"Diff - {file.FileName}";
                var options    = __VSDIFFSERVICEOPTIONS.VSDIFFOPT_DetectBinaryFiles |
                                 __VSDIFFSERVICEOPTIONS.VSDIFFOPT_LeftFileIsTemporary;

                if (!workingDirectory)
                {
                    options |= __VSDIFFSERVICEOPTIONS.VSDIFFOPT_RightFileIsTemporary;
                }

                IVsWindowFrame frame;
                using (OpenInProvisionalTab())
                {
                    var tooltip = $"{leftLabel}\nvs.\n{rightLabel}";

                    // Diff window will open in provisional (right hand) tab until document is touched.
                    frame = GitHub.VisualStudio.Services.DifferenceService.OpenComparisonWindow2(
                        leftFile,
                        rightFile,
                        caption,
                        tooltip,
                        leftLabel,
                        rightLabel,
                        string.Empty,
                        string.Empty,
                        (uint)options);
                }

                object docView;
                frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out docView);
                var diffViewer = ((IVsDifferenceCodeWindow)docView).DifferenceViewer;

                var session = ViewModel.Session;
                AddBufferTag(diffViewer.LeftView.TextBuffer, session, leftPath, DiffSide.Left);

                if (!workingDirectory)
                {
                    AddBufferTag(diffViewer.RightView.TextBuffer, session, rightPath, DiffSide.Right);
                    EnableNavigateToEditor(diffViewer.LeftView, file);
                    EnableNavigateToEditor(diffViewer.RightView, file);
                    EnableNavigateToEditor(diffViewer.InlineView, file);
                }

                if (workingDirectory)
                {
                    await UsageTracker.IncrementCounter(x => x.NumberOfPRDetailsCompareWithSolution);
                }
                else
                {
                    await UsageTracker.IncrementCounter(x => x.NumberOfPRDetailsViewChanges);
                }
            }
            catch (Exception e)
            {
                ShowErrorInStatusBar("Error opening file", e);
            }
        }