Exemplo n.º 1
0
        async public Task <int> AddLog(EntryLog entrylog)
        {
            int maxID; int minID; //minID for offline mode -ID creation
            //Determine max ID already pulled from server
            var internalcount = _connection.Table <EntryLog>().ToListAsync().Result;

            if (internalcount.Count == 0)
            {
                maxID = 0; minID = 0;
            }
            else
            {
                maxID = internalcount.Select(c => c.EntryID).Max();
                minID = internalcount.Select(c => c.EntryID).Min();
                if (minID > 0)
                {
                    minID = -1;
                }
            }

            if (Globals.OfflineMode == false)
            {
                //Add unit and retrieve assigned ID
                int newID = await APIServer.AddLog(entrylog);

                if (newID == maxID + 1) //New ID is provided by Db, no error handling similar to worker flags.
                {
                    //Add worker to local database
                    entrylog.EntryID = newID;
                    await _connection.InsertAsync(entrylog);
                }
                if (newID > maxID + 1) //Missing entries added by another user
                {
                    IEnumerable <EntryLog> tempE = await APIServer.GetAllEntryLogs(maxID.ToString());

                    await _connection.InsertAllAsync(tempE);
                }
                return(newID);
            }
            else
            {
                //For offline mode, do not update online db and use negative ID#s
                entrylog.EntryID = minID - 1;
                await _connection.InsertAsync(entrylog);

                return(1);
            }
        }
Exemplo n.º 2
0
        async public Task <List <EntryLog> > GetLogsAPI() //Get workerrequest forcing update from database
        {
            //Determine max ID already pulled from server
            var internallogs = _connection.Table <EntryLog>().ToListAsync().Result;
            int maxID;

            try { maxID = internallogs.Select(c => c.EntryID).Max(); }
            catch { maxID = 0; }

            //Pull only new entries from server
            IEnumerable <EntryLog> tempE = await APIServer.GetAllEntryLogs(maxID.ToString());

            await _connection.InsertAllAsync(tempE); //insert database entries into local db (if any)

            return(await _connection.Table <EntryLog>().ToListAsync());
        }
Exemplo n.º 3
0
        async public Task <int> AddAnalyticsLog(AnalyticsLog analyticlog)
        {
            if (Globals.OfflineMode == false)
            {
                //Determine max ID already pulled from server
                var internalcount = _connection.Table <AnalyticsLog>().ToListAsync().Result;
                int maxID;
                if (internalcount.Count == 0)
                {
                    maxID = 0;
                }
                else
                {
                    maxID = internalcount.Select(c => c.EntryID).Max();
                }

                //Add unit and retrieve assigned ID
                int newID = await APIServer.AddRecord(analyticlog);

                if (newID == maxID + 1) //New ID is provided by Db, no error handling similar to worker flags.
                {
                    //Add worker to local database
                    analyticlog.EntryID = newID;
                    await _connection.InsertAsync(analyticlog);
                }
                if (newID > maxID + 1) //Missing entries added by another user
                {
                    IEnumerable <EntryLog> tempE = await APIServer.GetAllEntryLogs(maxID.ToString());

                    await _connection.InsertAllAsync(tempE);
                }

                return(newID);
            }
            else
            {
                analyticlog.EntryID = -1;
                await _connection.InsertAsync(analyticlog);

                return(1);
            }
        }