Example #1
0
        /// <summary>
        /// Gets list of the applications usage history.
        /// </summary>
        /// <param name="option">Specifies which range should be considered.</param>
        /// <returns>List of applications usage history.</returns>
        public List <ApplicationStatisticsItem> QueryApplicationsUsageHistory(Range option)
        {
            DateTime range = new DateTime();

            if (option == Range.LastDay)
            {
                range = DateTime.Now.AddDays(-1);
            }
            else if (option == Range.LastWeek)
            {
                range = DateTime.Now.AddDays(-7);
            }
            else if (option == Range.LastMonth)
            {
                range = DateTime.Now.AddMonths(-1);
            }
            else if (option == Range.Livetime)
            {
                range = new DateTime(1970, 1, 1);
            }

            try
            {
                var usageStats = new UsageStatistics(UsageStatistics.SortOrderType.LastLaunchTimeNewest);

                var usageStatsResult = usageStats.Query(range, DateTime.Now);

                List <ApplicationStatisticsItem> result = new List <ApplicationStatisticsItem>();

                int id = 0;

                foreach (var record in usageStatsResult)
                {
                    using (var appInfo = new ApplicationInfo(record.AppId))
                    {
                        string name = (!appInfo.Label.Equals(string.Empty)) ? appInfo.Label : record.AppId;

                        ApplicationStatisticsItem applicationItem = new ApplicationStatisticsItem()
                        {
                            ID             = id,
                            Name           = name,
                            LastLaunchTime = record.LastLaunchTime.ToString(),
                            LaunchCount    = record.LaunchCount,
                            Duration       = record.Duration
                        };

                        result.Add(applicationItem);
                        id++;
                    }
                }

                return(result);
            }
            catch (Exception e)
            {
                Log.Error("AppStatistics", e.Message);
            }

            return(null);
        }
        /// <summary>
        /// Query top 10 frequently used applications during the last 3 days
        /// </summary>
        /// <returns>List of application history information</returns>
        public List <StatsInfoItem> QueryFrequentlyUsedApplications()
        {
            try
            {
                // Create an UsageStatistics instance
                var usageStats = new UsageStatistics(UsageStatistics.SortOrderType.LaunchCountMost);
                // Query top 10 frequently used applications during the last 3 days
                var usageStatsResult = usageStats.Query(DateTime.Now.AddDays(-3), DateTime.Now, 10);

                List <StatsInfoItem> result = new List <StatsInfoItem>();
                foreach (var record in usageStatsResult)
                {
                    var appInfo = new ApplicationInfo(record.AppId);

                    string name = (!appInfo.Label.Equals(string.Empty)) ? appInfo.Label : record.AppId;
                    string info = "LaunchCount: " + record.LaunchCount + "\r\n";
                    info += "LastLaunchTime: " + record.LastLaunchTime + "\r\n";
                    info += "Duration: " + record.Duration + " secs";

                    // Add each record to the result list
                    result.Add(new StatsInfoItem(name, info));

                    appInfo.Dispose();
                }

                return(result);
            }
            catch (Exception e)
            {
                LogImplementation.DLog(e.Message.ToString());
            }

            return(null);
        }
Example #3
0
        /// <summary>
        /// This method calculates the total purchase cost in a country
        /// </summary>
        /// <param name="country"></param>
        /// <param name="analyticsDataList"></param>
        /// <param name="buildings"></param>
        /// <returns>The total purchase cost in the country</returns>
        private double calculateTotalPurchaseCostInACountry(String country, AnalyticsData[] analyticsDataList, Building[] buildings)
        {
            double totalPurchaseCost = 0;

            foreach (Building building in buildings)
            {
                if (building.country == country)
                {
                    int buildingId = building.building_id;
                    foreach (AnalyticsData analyticsData in analyticsDataList)
                    {
                        UsageStatistics    usage_statistics = analyticsData.usage_statistics;
                        List <SessionInfo> sessionInfos     = usage_statistics.session_infos;
                        foreach (SessionInfo sessionInfo in sessionInfos)
                        {
                            if (sessionInfo.building_id == buildingId)
                            {
                                List <Purchase> purchases = sessionInfo.purchases;
                                foreach (Purchase purchase in purchases)
                                {
                                    totalPurchaseCost = totalPurchaseCost + purchase.cost;
                                }
                            }
                        }
                    }
                }
            }
            totalPurchaseCost = Math.Round(totalPurchaseCost, 2);
            return(totalPurchaseCost);
        }
        /// <summary>
        /// Query top 5 recently used applications during the last 5 hours
        /// </summary>
        /// <returns>List of application history information</returns>
        public List <StatsInfoItem> QueryRecentlyUsedApplications()
        {
            try
            {
                // Create a UsageStatistics
                var usageStats = new UsageStatistics(UsageStatistics.SortOrderType.LastLaunchTimeNewest);

                // Query top 5 recently used applications during the last 5 hours
                var usageStatsResult = usageStats.Query(DateTime.Now.AddHours(-5), DateTime.Now, 5);

                List <StatsInfoItem> result = new List <StatsInfoItem>();
                foreach (var record in usageStatsResult)
                {
                    var appInfo = new ApplicationInfo(record.AppId);

                    string name = (!appInfo.Label.Equals(string.Empty)) ? appInfo.Label : record.AppId;
                    string info = "LastLaunchTime:\r\n" + record.LastLaunchTime + "\r\n";
                    info += "LaunchCount: " + record.LaunchCount + "\r\n";
                    info += "Duration: " + record.Duration + " secs";

                    // Add each record to the result list
                    result.Add(new StatsInfoItem(name, info));

                    appInfo.Dispose();
                }

                return(result);
            }
            catch (Exception e)
            {
                log.Log(e.Message.ToString());
            }

            return(null);
        }
Example #5
0
        private ActionResult DisplayIndex()
        {
            var model = new CourseSearchStatsAdminModel();

            model.Populate(UsageStatistics.GetAll(true));
            this.ViewBag.FolderNames = new SelectList(model.FolderNames, "Key", "Value");
            return(this.View(model));
        }
Example #6
0
        protected override object DoDeserializeValue(XmlReader reader, bool isSimpleValue)
        {
            reader.ReadStartElement(); // Read start of enclosing element
            UsageStatistics result = UsageStatistics.Deserialize(reader);

            reader.ReadEndElement(); // End of enclosing element
            return(result);
        }
Example #7
0
 public async Task SaveAsync(UsageStatistics usageStatistics)
 {
     using (await IsolatedDatabaseAccess.Open())
     {
         _context.UsageStatistics = usageStatistics.Clone();
         _context.Commit();
     }
 }
Example #8
0
 public bool Equals(TrafficData other)
 {
     return(string.Equals(DataUrl, other.DataUrl) &&
            string.Equals(Asin, other.Asin) &&
            Rank == other.Rank &&
            Equals(RankByCountry, other.RankByCountry) &&
            UsageStatistics.ListsAreEqual(other.UsageStatistics) &&
            ContributingSubdomains.ListsAreEqual(other.ContributingSubdomains));
 }
Example #9
0
        /// <summary>
        /// Gets the usage statistics and writes the to the console.
        /// </summary>
        /// <param name="authenticationKey">The authentication key for the DeepL API.</param>
        /// <param name="useFreeApi">Determines whether the free or the pro DeepL API is used.</param>
        private static async Task GetUsageStatisticsAsync(string authenticationKey, bool useFreeApi)
        {
            using (DeepLClient client = new DeepLClient(authenticationKey, useFreeApi))
            {
                UsageStatistics usageStatistics = await client.GetUsageStatisticsAsync();

                Console.WriteLine($"Currently billed characters: {usageStatistics.CharacterCount}");
                Console.WriteLine($"Character limit:             {usageStatistics.CharacterLimit}");
            }
        }
Example #10
0
 public InitializeEvent(
     ApplicationSettings applicationSettings,
     IEnumerable <Game> games,
     Guid?lastEditedGameProfileId,
     TextureManagementSettings textureManagementSettings,
     UsageStatistics usageStatistics)
 {
     ApplicationSettings = applicationSettings;
     Games = games;
     LastEditedGameProfileId   = lastEditedGameProfileId;
     TextureManagementSettings = textureManagementSettings;
     UsageStatistics           = usageStatistics;
 }
Example #11
0
 public ActionResult DeleteFile(string id, string filename)
 {
     try
     {
         UsageStatistics.DeleteFile(id, filename);
         ShowGenericSavedMessage();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
     }
 }
Example #12
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (DataUrl != null ? DataUrl.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Asin != null ? Asin.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ Rank;
         hashCode = (hashCode * 397) ^ (RankByCountry != null ? RankByCountry.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (UsageStatistics != null ? UsageStatistics.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ContributingSubdomains != null ? ContributingSubdomains.GetHashCode() : 0);
         return(hashCode);
     }
 }
Example #13
0
 public ActionResult GetFile(string id, string filename)
 {
     try
     {
         return(File(
                    UsageStatistics.GetFile(id, filename),
                    System.Net.Mime.MediaTypeNames.Application.Octet,
                    filename));
     }
     catch
     {
         return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
     }
 }
        public void TestTopUsed()
        {
            var usageStatistics = new UsageStatistics();

            for (var i = 0; i < UsageStatistics.MAX_STORED_ENTRIES; i++)
            {
                for (var j = 0; j <= i; j++)
                {
                    usageStatistics.SetUsed("Unit Test-" + (i + 1));
                }
            }

            var newStat = usageStatistics.LimitEntries(UsageStatistics.MAX_RETURNED_ENTRIES);

            Assert.AreEqual(UsageStatistics.MAX_RETURNED_ENTRIES, newStat.TopUsed.Count);
            Assert.AreEqual(UsageStatistics.MAX_RETURNED_ENTRIES, newStat.LastUsed.Count);

            Assert.AreEqual(20, newStat.TopUsed[0].CountUsed);
            Assert.AreEqual(15, newStat.TopUsed[5].CountUsed);
        }
Example #15
0
        /// <summary>
        /// Calculate the number of times an item is purchased
        /// </summary>
        /// <param name="itemId"></param>
        /// <param name="analyticsDataList"></param>
        /// <returns>Number of times the item is purchased</returns>
        private int calculateTimesOfAnItemIsPurchased(int itemId, AnalyticsData[] analyticsDataList)
        {
            int noOftimes = 0;

            foreach (AnalyticsData analyticsData in analyticsDataList)
            {
                UsageStatistics    usage_statistics = analyticsData.usage_statistics;
                List <SessionInfo> sessionInfos     = usage_statistics.session_infos;
                foreach (SessionInfo sessionInfo in sessionInfos)
                {
                    List <Purchase> purchases = sessionInfo.purchases;
                    foreach (Purchase purchase in purchases)
                    {
                        if (purchase.item_id == itemId)
                        {
                            noOftimes++;
                        }
                    }
                }
            }
            return(noOftimes);
        }
Example #16
0
        /// <summary>
        /// This method calculates the total purchase cost of all items in a category.
        /// </summary>
        /// <param name="itemCategoryId"></param>
        /// <param name="analyticsDataList"></param>
        /// <returns>Total purchase cost of all items in the category</returns>
        private double calculatePurchaseCostForAnItemCategory(int itemCategoryId, AnalyticsData[] analyticsDataList)
        {
            double totalPurchaseCost = 0;

            foreach (AnalyticsData analyticsData in analyticsDataList)
            {
                UsageStatistics    usage_statistics = analyticsData.usage_statistics;
                List <SessionInfo> sessionInfos     = usage_statistics.session_infos;
                foreach (SessionInfo sessionInfo in sessionInfos)
                {
                    List <Purchase> purchases = sessionInfo.purchases;
                    foreach (Purchase purchase in purchases)
                    {
                        if (purchase.item_category_id == itemCategoryId)
                        {
                            totalPurchaseCost = totalPurchaseCost + purchase.cost;
                        }
                    }
                }
            }
            totalPurchaseCost = Math.Round(totalPurchaseCost, 2);
            return(totalPurchaseCost);
        }
Example #17
0
        /// <summary>
        /// This method is used to find the total purchase cost for a building id
        /// </summary>
        /// <param name="buildingId"></param>
        /// <param name="analyticsDataList"></param>
        /// <returns>The total purchase cost for the building id</returns>
        private double calculateTotalPurchaseCostForABuilding(int buildingId, AnalyticsData[] analyticsDataList)
        {
            double totalPurchaseCost = 0;

            foreach (AnalyticsData analyticsData in analyticsDataList)
            {
                UsageStatistics    usage_statistics = analyticsData.usage_statistics;
                List <SessionInfo> sessionInfos     = usage_statistics.session_infos;
                foreach (SessionInfo sessionInfo in sessionInfos)
                {
                    if (sessionInfo.building_id == buildingId)
                    {
                        List <Purchase> purchases = sessionInfo.purchases;
                        foreach (Purchase purchase in purchases)
                        {
                            totalPurchaseCost = totalPurchaseCost + purchase.cost;
                        }
                    }
                }
            }
            totalPurchaseCost = Math.Round(totalPurchaseCost, 2);
            return(totalPurchaseCost);
        }
Example #18
0
        /// <summary>
        /// This method is used to calculate the  total cost for passed manufacturer.
        /// </summary>
        /// <param name="manufacturer"></param>
        /// <param name="analyticsDataList"></param>
        /// <returns>Total cost for passed manufacturer</returns>
        private double calculateTotalCostForAManufacturer(String manufacturer, AnalyticsData[] analyticsDataList)
        {
            // Total purchase cost for a manufacture devices
            double totalSamsungCost = 0;

            foreach (AnalyticsData analyticsData in analyticsDataList)
            {
                if (analyticsData.manufacturer == manufacturer)
                {
                    UsageStatistics    usage_statistics = analyticsData.usage_statistics;
                    List <SessionInfo> sessionInfos     = usage_statistics.session_infos;
                    foreach (SessionInfo sessionInfo in sessionInfos)
                    {
                        List <Purchase> purchases = sessionInfo.purchases;
                        foreach (Purchase purchase in purchases)
                        {
                            totalSamsungCost = totalSamsungCost + purchase.cost;
                        }
                    }
                }
            }
            totalSamsungCost = Math.Round(totalSamsungCost, 2);
            return(totalSamsungCost);
        }
Example #19
0
        public ActionResult Index(CourseSearchStatsAdminModel model)
        {
            if (Request.Form["CreateFolder"] != null)
            {
                DateTime date;
                if (!DateTime.TryParse(model.NewFolderName, out date))
                {
                    ModelState.AddModelError(
                        "",
                        AppGlobal.Language.GetText(this, "InvalidDateError", "Not a valid name for a new folder"));
                }
                if (ModelState.IsValid)
                {
                    UsageStatistics.CreateFolder(date);
                    ModelState.SetModelValue(
                        "NewFolderName",
                        new ValueProviderResult(null, string.Empty, CultureInfo.InvariantCulture));
                    ShowGenericSavedMessage();
                }
            }

            if (Request.Form["UploadFile"] != null)
            {
                if (model.UploadToFolder == null)
                {
                    ModelState.AddModelError(
                        "",
                        AppGlobal.Language.GetText(
                            this,
                            "NoUploadFolderError",
                            "Cannot upload a file without selecting a folder to upload into."));
                }
                if (model.FileUpload == null)
                {
                    ModelState.AddModelError(
                        "",
                        AppGlobal.Language.GetText(
                            this,
                            "NoUploadFileError",
                            "Cannot upload without selecting a file."));
                }
                if (ModelState.IsValid)
                {
                    try
                    {
                        UsageStatistics.AddFile(model.UploadToFolder, model.FileUpload);
                        ModelState.SetModelValue(
                            "UploadToFolder",
                            new ValueProviderResult(null, string.Empty, CultureInfo.InvariantCulture));
                        ShowGenericSavedMessage();
                    }
                    catch (TimeoutException)
                    {
                        AppGlobal.Log.WriteWarning("Virus scanner timed out scanning file " + model.FileUpload.FileName);
                        ModelState.AddModelError(
                            "",
                            AppGlobal.Language.GetText(
                                this,
                                "VirusScanTimeOut",
                                "File could not be uploaded, because the virus scan operation timed out."));
                    }
                    catch (InvalidDataException)
                    {
                        ModelState.AddModelError(
                            "",
                            AppGlobal.Language.GetText(
                                this,
                                "VirusDetectedWarning",
                                "File has been rejected by the virus scanner."));
                    }
                    catch (ArgumentException ex)
                    {
                        string message;
                        switch (ex.Message)
                        {
                        case "DuplicateFileWarning":
                            message = AppGlobal.Language.GetText(
                                this,
                                "DuplicateFileWarning",
                                "A file with that name already exists in that folder.");
                            break;

                        case "FileExtensionNotAllowed":
                            message = AppGlobal.Language.GetText(
                                this,
                                "FileExtensionNotAllowed",
                                "Invalid file type. Permitted file types are "
                                + String.Join(", ", UsageStatistics.FileExtensionWhitelist));
                            break;

                        case "InvalidFolderName":
                            message = AppGlobal.Language.GetText(
                                this,
                                "InvalidFolderName",
                                "Invalid folder specified.");
                            break;

                        default:
                            message = ex.Message;
                            break;
                        }
                        ModelState.AddModelError("", message);
                    }
                }
            }

            return(this.DisplayIndex());
        }
Example #20
0
        protected override void DoSerializeValue(object value, bool forceSimpleValue, XmlWriter writer)
        {
            UsageStatistics usageStatistics = (UsageStatistics)value;

            usageStatistics.Serialize(UsageStatistics.MAX_RETURNED_ENTRIES, writer);
        }