Exemple #1
0
        public async Task <int> SavePowerTimeToSql(PowerPC powerpc)
        {
            int result = 0;

            if (powerpc == null)
            {
                return(result);
            }
            try
            {
                if (sqliteService == null)
                {
                    sqliteService = new SQLiteService <PowerPCSQL>(sqlitePlatform, await fileSystemService.GetPath(configuration.SqlDatabaseName));
                }
            }
            catch (Exception exp)
            {
                result        = -1;
                sqliteService = null;
            }
            if (sqliteService != null)
            {
                try
                {
                    //only for new guid insert new records, for old GUID only update timeOff
                    List <PowerPCSQL> oldpowerpc = await sqliteService.GetWhere <PowerPCSQL>(x => x.GUID.Equals(powerpc.GUID) && x.IsActive);

                    if (oldpowerpc != null && oldpowerpc.Count != 0)
                    {
                        foreach (var ppc in oldpowerpc)
                        {
                            ppc.dateTimeOffPC  = ConverterHelper.ConvertDateTimeToMillisec(powerpc.dateTimeOffPC).ToString();
                            ppc.IsSynchronized = false;
                            result             = await sqliteService.Update(ppc);
                        }
                    }
                    else
                    {
                        result = await sqliteService.Insert(converter.ConvertToPowerPCSQL(powerpc));
                    }
                }
                catch (Exception ex)
                {
                    result = -1;
                    var err = ex.Message;
                    throw ex;
                }
            }
            return(result);
        }
Exemple #2
0
        private async Task <int> UpdateSynchToSql(List <PowerPC> listPowerPC)
        {
            int result = 0;

            try
            {
                if (sqliteService == null)
                {
                    sqliteService = new SQLiteService <PowerPCSQL>(sqlitePlatform, await fileSystemService.GetPath(configuration.SqlDatabaseName));
                }
            }
            catch (Exception exp)
            {
                result        = -1;
                sqliteService = null;
            }
            if (sqliteService != null)
            {
                try
                {
                    foreach (var powerpc in listPowerPC)
                    {
                        List <PowerPCSQL> oldpowerpc = await sqliteService.GetWhere <PowerPCSQL>(x => x.GUID.Equals(powerpc.GUID));

                        if (oldpowerpc != null && oldpowerpc.Count != 0)
                        {
                            foreach (var ppc in oldpowerpc)
                            {
                                ppc.IsSynchronized = true;
                                result            += await sqliteService.Update(ppc);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    result = -1;
                    var err = ex.Message;
                    throw ex;
                }
            }
            return(result);
        }
        private async Task <int> UpdateSynchToSql(List <ScreenShot> listScreenShot)
        {
            int result = 0;

            try
            {
                if (sqliteService == null)
                {
                    sqliteService = new SQLiteService <ScreenShotSQL>(sqlitePlatform, await fileSystemService.GetPath(configuration.SqlDatabaseName));
                }
            }
            catch (Exception exp)
            {
                result        = -1;
                sqliteService = null;
            }
            if (sqliteService != null)
            {
                try
                {
                    foreach (var screenshot in listScreenShot)
                    {
                        List <ScreenShotSQL> oldscreenshot = await sqliteService.GetWhere <ScreenShotSQL>(x => x.GUID.Equals(screenshot.GUID));

                        if (oldscreenshot != null && oldscreenshot.Count != 0)
                        {
                            foreach (var sst in oldscreenshot)
                            {
                                sst.IsSynchronized = true;
                                result            += await sqliteService.Update(sst);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    result = -1;
                    var err = ex.Message;
                    throw ex;
                }
            }
            return(result);
        }
Exemple #4
0
        public async Task <IEnumerable <PowerPC> > GetSQLPowerTime(DateTime from, DateTime to)
        {
            List <PowerPC> listPowerPCs = null;

            try
            {
                if (sqliteService == null)
                {
                    sqliteService = new SQLiteService <PowerPCSQL>(sqlitePlatform, await fileSystemService.GetPath(configuration.SqlDatabaseName));
                }
            }
            catch (Exception exp)
            {
                sqliteService = null;
            }
            if (sqliteService != null)
            {
                try
                {
                    long f = ConverterHelper.ConvertDateWithoutTimeToMillisec(from);
                    long t = ConverterHelper.ConvertDateWithoutTimeToMillisec(to);
                    //List<PowerPCSQL> listPowerPCSql = await sqliteService.GetWhere<PowerPCSQL>(x => x.Date >= f && x.Date <= t);
                    List <PowerPCSQL> listPowerPCSql = await sqliteService.GetWhere(predicate : x => x.Date >= f && x.Date <= t && x.IsActive, orderBy : x => x.Date);

                    if (listPowerPCSql != null && listPowerPCSql.Count != 0)
                    {
                        listPowerPCs = new List <PowerPC>();
                        foreach (var powerPCSql in listPowerPCSql)
                        {
                            listPowerPCs.Add(converter.ConvertToPowerPC(powerPCSql));
                        }
                    }
                }
                catch (Exception ex)
                {
                    var err = ex.Message;
                    throw ex;
                }
            }
            return(listPowerPCs);
        }
        public async Task <IEnumerable <ScreenShot> > GetSQLScreenShot(DateTime date)
        {
            List <ScreenShot> listScreenShots = null;

            try
            {
                if (sqliteService == null)
                {
                    sqliteService = new SQLiteService <ScreenShotSQL>(sqlitePlatform, await fileSystemService.GetPath(configuration.SqlDatabaseName));
                }
            }
            catch (Exception exp)
            {
                sqliteService = null;
            }
            if (sqliteService != null)
            {
                try
                {
                    long d = ConverterHelper.ConvertDateWithoutTimeToMillisec(date);
                    //List<PowerPCSQL> listPowerPCSql = await sqliteService.GetWhere<PowerPCSQL>(x => x.Date.Equals(d));
                    List <ScreenShotSQL> listScreenShotSql = await sqliteService.GetWhere(predicate : x => x.Date.Equals(d) && x.IsActive, orderBy : x => x.Date);

                    if (listScreenShotSql != null && listScreenShotSql.Count != 0)
                    {
                        listScreenShots = new List <ScreenShot>();
                        foreach (var powerPCSql in listScreenShotSql)
                        {
                            listScreenShots.Add(converter.ConvertToScreenShot(powerPCSql));
                        }
                    }
                }
                catch (Exception ex)
                {
                    var err = ex.Message;
                    throw ex;
                }
            }
            return(await TaskHelper.Complete(listScreenShots));
        }