コード例 #1
0
        private int GetPurchaseCount(IList <ErshPurchase> purchases, int allCount, int defaultCount)
        {
            var count = 0;

            try
            {
                if (purchases == null || !purchases.Any())
                {
                    return(0);
                }
                foreach (var purchase in purchases)
                {
                    if (purchase.IsAll)
                    {
                        return(allCount - defaultCount);
                    }
                    count += purchase.Count;
                }
                return(count);
            }
            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, "GetPurchaseCount", exception, false);
                return(count);
            }
        }
コード例 #2
0
        private async Task TaskScoreRefreshAsync()
        {
            try
            {
                await DataBaseConnection.CreateTableAsync <TaskTable>();

                var currentTasks = await DataBaseConnection.Table <TaskTable>().ToListAsync();

                if (currentTasks.Count == 0)
                {
                    return;
                }
                var tasks = GetTable <TaskTable>();
                foreach (var task in tasks)
                {
                    var currentTask = currentTasks.FirstOrDefault(x => x.Id == task.Id);
                    if (currentTask == null)
                    {
                        continue;
                    }
                    currentTask.Score = task.Score;
                }
                await DataBaseConnection.UpdateAllAsync(currentTasks);
            }
            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, "TaskScoreRefreshAsync", exception, false);
            }
        }
コード例 #3
0
        private async Task RefreshTableAsync <T>() where T : ITable, new()
        {
            try
            {
                switch (new T().TableName)
                {
                case StringConst.CategoryTable:
                    break;

                case StringConst.BonusTable:
                    Bonuses = await DataBaseConnection.Table <BonusTable>().Where(product => product.IsEnabled).ToListAsync();

                    break;

                case StringConst.TaskTable:
                    await TaskRefreshAsync(); break;

                default: throw new NotImplementedException();
                }
            }
            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, string.Format("RefreshTableAsync<{0}>", new T().TableName), exception, false);
            }
        }
コード例 #4
0
        private static void HandlerOnOnGetProductsError(int responseCode, Bundle ownedItems)
        {
            var obj           = Enum.ToObject(typeof(BillingResult), responseCode);
            var exceptionName = obj == null ? "Response code = " + responseCode : obj.ToString();

            GaService.TrackAppException("Extensions", "HandlerOnOnGetProductsError", exceptionName, "Get owned items in bundle", false);
        }
コード例 #5
0
        private IEnumerable <T> GetTable <T>(Func <string, T> creator, Func <int, bool> isEnabled, Stream stream) where T : ITable, new()
        {
            var list = new List <T>();

            try
            {
                using (stream)
                {
                    using (var reader = new StreamReader(stream, System.Text.Encoding.UTF8))
                    {
                        var index = 0;
                        while (!reader.EndOfStream)
                        {
                            var line = reader.ReadLine();
                            if (line == null)
                            {
                                continue;
                            }
                            var product = creator(line);
                            product.IsEnabled = isEnabled(index);
                            list.Add(product);
                            index++;
                        }
                    }
                }
                return(list);
            }
            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, string.Format("GetTable<{0}>", new T().TableName), exception, false);
                return(list);
            }
        }
コード例 #6
0
        private static void HandlerOnOnPurchaseConsumedError(int responseCode, string token)
        {
            var obj           = Enum.ToObject(typeof(BillingResult), responseCode);
            var exceptionName = obj == null ? "Response code = " + responseCode : obj.ToString();
            var message       = "Token = " + token;

            GaService.TrackAppException("Extensions", "HandlerOnOnPurchaseConsumedError", exceptionName, message, false);
        }
コード例 #7
0
        private static void HandlerOnBuyProductError(int responseCode, string sku)
        {
            var obj           = Enum.ToObject(typeof(BillingResult), responseCode);
            var exceptionName = obj == null ? "Response code = " + responseCode : obj.ToString();
            var message       = "Sku = " + sku;

            GaService.TrackAppException("Extensions", "HandlerOnBuyProductError", exceptionName, message, false);
        }
コード例 #8
0
        private static void HandlerOnOnPurchaseFailedValidation(Purchase purchase, string purchaseData, string purchaseSignature)
        {
            var message = string.Format("Id={0}, developerPayload={1}, state={2}, orderId={3}, time={4}, data={5}",
                                        purchase.ProductId, purchase.DeveloperPayload, purchase.PurchaseState,
                                        purchase.OrderId, purchase.PurchaseTime, purchaseData);

            GaService.TrackAppException("Extensions", "HandlerOnOnPurchaseFailedValidation", string.Empty, message, false);
        }
コード例 #9
0
 public async Task SaveTaskContextAsync()
 {
     try
     {
         await DataBaseConnection.UpdateAllAsync(Tasks.Tasks);
     }
     catch (Exception exception)
     {
         GaService.TrackAppException(this.Class, "SaveTaskContextAsync", exception, false);
     }
 }
コード例 #10
0
 public static void SaveAsStartupActivity(this Activity activity, string activityName)
 {
     try
     {
         var editorX = activity.GetSharedPreferences("X", FileCreationMode.Private).Edit();
         editorX.PutString("lastActivity", activityName);
         editorX.Commit();
     }
     catch (Exception ex)
     {
         GaService.TrackAppException(activity.Class, "SaveAsStartupActivity", ex, false);
     }
 }
コード例 #11
0
 public async Task ResetAsync()
 {
     try
     {
         Tasks.Clear();
         await SaveTaskContextAsync();
         await TaskRefreshAsync();
     }
     catch (Exception exception)
     {
         GaService.TrackAppException(this.Class, "ResetAsync", exception, false);
     }
 }
コード例 #12
0
        private async Task RefreshAllAsync()
        {
            try
            {
                await TaskRefreshAsync();

                Bonuses = await DataBaseConnection.Table <BonusTable>().Where(product => product.IsEnabled).ToListAsync();
            }
            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, "RefreshAllAsync", exception, false);
            }
        }
コード例 #13
0
 public async Task SaveTaskContextAsync(TaskTable taskTable)
 {
     try
     {
         await DataBaseConnection.UpdateAsync(taskTable);
     }
     catch (Exception exception)
     {
         var activityName = string.Format("SaveTaskContextAsync: tableId={0}, talbePosition={1}",
                                          taskTable == null ? (object)null : taskTable.Id,
                                          taskTable == null ? (object)null : taskTable.Position);
         GaService.TrackAppException(this.Class, activityName, exception, false);
     }
 }
コード例 #14
0
        public async override void OnUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
        {
            try
            {
                await DataBaseConnection.DropTableAsync <TaskTable>();

                await DataBaseConnection.DropTableAsync <BonusTable>();

                await DataBaseConnection.DropTableAsync <CategoryTable>();
                await CreateOrOpenDataBaseAsync();
            }
            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, "OnUpgrade", exception, false);
            }
        }
コード例 #15
0
        private async Task TaskRefreshAsync()
        {
            try
            {
                var categoryList = await DataBaseConnection.Table <CategoryTable>().ToListAsync();

                var taskList = await DataBaseConnection.Table <TaskTable>().Where(product => product.IsEnabled).ToListAsync();

                int currentPosition;
                var sortedTaskList = taskList.CustomSort(out currentPosition);
                Tasks = new TaskList(sortedTaskList, categoryList, currentPosition);
            }
            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, "TaskRefreshAsync", exception, false);
            }
        }
コード例 #16
0
        private async Task AddProductAsync <T>(int count) where T : class, ITable, new()
        {
            try
            {
                var list = await DataBaseConnection.Table <T>().Where(p => p.IsEnabled == false).Take(count).ToListAsync();

                foreach (var table in list)
                {
                    table.IsEnabled = true;
                }
                await DataBaseConnection.UpdateAllAsync(list);
                await RefreshTableAsync <T>();
            }
            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, string.Format("AddProductAsync<{0}>", new T()), exception, true);
            }
        }
コード例 #17
0
        private async Task CreateIfNotExistTable <T>() where T : ITable, new()
        {
            try
            {
                await DataBaseConnection.CreateTableAsync <T>();

                var count = await DataBaseConnection.Table <T>().CountAsync();

                if (count == 0)
                {
                    var elements = GetTable <T>();
                    await DataBaseConnection.InsertAllAsync(elements);
                }
            }
            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, string.Format("CreateIfNotExistTable<{0}>", new T()), exception, false);
            }
        }
コード例 #18
0
        public async Task AddProductAsync(ErshPurchase purchase)
        {
            try
            {
                switch (purchase.ProductType)
                {
                case StringConst.Task:
                    AddProductAsync <TaskTable>(purchase.IsAll ? IntConst.AllTaskCount - Tasks.Count : purchase.Count);
                    break;

                case StringConst.Bonus:
                    AddProductAsync <BonusTable>(purchase.IsAll ? IntConst.AllBonusCount - Bonuses.Count : purchase.Count);
                    break;
                }
            }
            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, "AddProductAsync", exception, true);
            }
        }
コード例 #19
0
        public async Task CreateOrOpenDataBaseAsync()
        {
            try
            {
                await CreateIfNotExistTable <BonusTable>();
                await CreateIfNotExistTable <TaskTable>();
                await CreateIfNotExistTable <CategoryTable>();

                if (await DataBaseConnection.Table <CategoryTable>().Where(category => category.Image == null).CountAsync() != 0)
                {
                    await RecreateTable <CategoryTable>();
                    await TaskScoreRefreshAsync();
                }

                await RefreshAllAsync();

                OnDataBaseCreatedOrOpened();
            }
            catch (Exception exception)
            {
                GaService.TrackAppException(_context.Class.SimpleName, "CreateOrOpenDataBaseAsync", exception, true);
            }
        }
コード例 #20
0
        private async Task RemoveTableAsync <T>(int count) where T : class, ITable, new()
        {
            try
            {
                var list = await DataBaseConnection.Table <T>().Where(p => p.IsEnabled).Take(count).ToListAsync();

                foreach (var table in list)
                {
                    table.IsEnabled = false;
                    var taskTable = table as TaskTable;
                    if (taskTable != null)
                    {
                        taskTable.Position = 0;
                    }
                }
                await DataBaseConnection.UpdateAllAsync(list);
                await RefreshTableAsync <T>();
            }
            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, "RemoveBonusAsync", exception, false);
            }
        }
コード例 #21
0
        private async Task CorrectingPurchaseAsync(int currentPurchase, int realPurchase, Func <int, Task> addFunc, Func <int, Task> removeFunc)
        {
            try
            {
                if (currentPurchase == realPurchase)
                {
                    return;
                }
                var difference = Math.Abs(currentPurchase - realPurchase);

                if (currentPurchase > realPurchase)
                {
                    await removeFunc(difference);
                }
                else if (currentPurchase < realPurchase)
                {
                    await addFunc(difference);
                }
            }
            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, "CorrectingPurchaseAsync", exception, false);
            }
        }
コード例 #22
0
        //Refresh and check if
        public async Task CheckAndRefreshPurshases(IList <ErshPurchase> ershPurchases, bool isConnected)
        {
            try
            {
                _taskPurchases  = ershPurchases.Where(purchase => purchase.ProductType == StringConst.Task).ToList();
                _bonusPurchases = ershPurchases.Where(purchase => purchase.ProductType == StringConst.Bonus).ToList();
                if (!isConnected)
                {
                    return;
                }

                var currentPurchaseTaskCount = Tasks.Count - IntConst.DefaultTaskCount;
                var purchaseTaskCount        = GetPurchaseCount(_taskPurchases, IntConst.AllTaskCount, IntConst.DefaultTaskCount);
                await CorrectingPurchaseAsync(currentPurchaseTaskCount, purchaseTaskCount, AddProductAsync <TaskTable>, RemoveTableAsync <TaskTable>);

                var currentPurchaseBonusCount = Bonuses.Count - IntConst.DefaultBonusCount;
                var purchaseBonusCount        = GetPurchaseCount(_bonusPurchases, IntConst.AllBonusCount, IntConst.DefaultBonusCount);
                await CorrectingPurchaseAsync(currentPurchaseBonusCount, purchaseBonusCount, AddProductAsync <BonusTable>, RemoveTableAsync <BonusTable>);
            }
            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, "CheckAndRefreshPurshases", exception, false);
            }
        }
コード例 #23
0
        private IEnumerable <T> GetTable <T>() where T : ITable, new()
        {
            try
            {
                switch (new T().TableName)
                {
                case StringConst.BonusTable:
                    return((IEnumerable <T>)GetTable(Parser.ParseBonus, i => i < IntConst.DefaultBonusCount, _context.Assets.Open("Bonus.csv")));

                case StringConst.TaskTable:
                    return((IEnumerable <T>)GetTable(Parser.ParseTask, i => i < IntConst.DefaultTaskCount, _context.Assets.Open("Task.csv")));

                case StringConst.CategoryTable:
                    return((IEnumerable <T>)GetTable(Parser.ParseCategory, i => true, _context.Assets.Open("Category.csv")));

                default: throw new NotImplementedException();
                }
            }
            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, string.Format("GetTable<{0}>", new T().TableName), exception, false);
                throw;
            }
        }
コード例 #24
0
 private static void HandlerOnOnInvalidOwnedItemsBundleReturned(Bundle ownedItems)
 {
     GaService.TrackAppException("Extensions", "HandlerOnOnInvalidOwnedItemsBundleReturned", string.Empty, "Get owned items in bundle", false);
 }
コード例 #25
0
 private static void HandlerOnInAppBillingProcesingError(string message)
 {
     GaService.TrackAppException("Extensions", "HandlerOnInAppBillingProcesingError", string.Empty, message, false);
 }
コード例 #26
0
 private static void ConnectionOnOnInAppBillingError(InAppBillingErrorType error, string message)
 {
     GaService.TrackAppException("Extensions", "ConnectionOnOnInAppBillingError", error.ToString(), message, false);
 }