Ejemplo n.º 1
0
		public async void TestSQLiteService(){
			
			SQLiteService sqliteService = new SQLiteService (new SQLitePlatformWin32(), await GetPath("VTSTest"));

			VacationInfoDTO person = new VacationInfoDTO {
				Date="",
				ImageSRC="test",
				Id=12,
				Status="qwe",
				VacationType = "asd"
			};

			await sqliteService.Insert<VacationInfoDTO> (person);
			var personTest =await sqliteService.Get<VacationInfoDTO>(person.Id.ToString());
			Assert.AreNotEqual (person, personTest,"Message Insert or Get error");

			person.ImageSRC="https://ru.wikipedia.org/wiki";
			await sqliteService.Update<VacationInfoDTO> (person);
			personTest =await sqliteService.Get<VacationInfoDTO>(person.Id.ToString());
			Assert.IsTrue(person.ImageSRC == personTest.ImageSRC,"Message Update or Get error");

			await sqliteService.Delete<VacationInfoDTO>(person.Id.ToString());
			personTest =await sqliteService.Get<VacationInfoDTO>(person.Id.ToString());
			Assert.IsNull (personTest,"Message Delete error");
		}
Ejemplo n.º 2
0
        public async Task ClearPreference()
        {
            try
            {
                if (sqliteService == null)
                {
                    sqliteService = new SQLiteService <PrefSql>(sqlitePlatform, await fileSystemService.GetPath(configuration.SqlDatabaseName));
                }
            }
            catch (Exception exp)
            {
                var err = exp.Message;
                sqliteService = null;
            }
            if (sqliteService != null)
            {
                try
                {
                    List <PrefSql> list = await sqliteService.Get();

                    if (list != null && list.Count != 0)
                    {
                        foreach (var item in list)
                        {
                            await sqliteService.Delete(item.Id.ToString());
                        }
                    }
                }
                catch (Exception ex)
                {
                    var err = ex.Message;
                    throw ex;
                }
            }
        }
Ejemplo n.º 3
0
        public async Task <VacationInfoModel> GetVacationByIdFromSql(int id)
        {
            string            result   = String.Empty;
            VacationInfoModel vacation = null;

            try
            {
                if (sqliteService == null)
                {
                    sqliteService = new SQLiteService(_sqlitePlatform, await _fileSystemService.GetPath(_configuration.SqlDatabaseName));
                }
                if (sqliteService != null)
                {
                    var vacationInfoModelDTO = await sqliteService.Get <VacationInfoModelDTO>(id.ToString());

                    if (vacationInfoModelDTO != null)
                    {
                        vacation = _converter.ConvertToVacationInfoModel(vacationInfoModelDTO);
                    }
                }
            }
            catch (AggregateException e)
            {
                result   = e.InnerExceptions[0].Data["message"].ToString();
                vacation = null;
            }
            catch (Exception e)
            {
                result   = e.Message;
                vacation = null;
            }
            return(await Helper.Complete(vacation));
        }
Ejemplo n.º 4
0
        public async Task <string> GetPrefValue(PrefEnums key)
        {
            try
            {
                if (sqliteService == null)
                {
                    sqliteService = new SQLiteService <PrefSql>(sqlitePlatform, await fileSystemService.GetPath(configuration.SqlDatabaseName));
                }
            }
            catch (Exception exp)
            {
                sqliteService = null;
            }
            if (sqliteService != null)
            {
                try
                {
                    var oldprefSql = await sqliteService.Get(((int)key).ToString());

                    if (oldprefSql != null)
                    {
                        return(oldprefSql.Value);
                    }
                }
                catch (Exception ex)
                {
                    var err = ex.Message;
                    throw ex;
                }
            }
            return(null);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Clear all data in SQLite local DB
        /// </summary>
        /// <returns></returns>

        public async Task ClearMasterPair()
        {
            try
            {
                if (sqliteService == null)
                {
                    sqliteService = new SQLiteService <MasterSQL>(sqlitePlatform, await fileSystemService.GetPath(configuration.SqlDatabaseName));
                }
            }
            catch (Exception exp)
            {
                sqliteService = null;
            }
            if (sqliteService != null)
            {
                try
                {
                    List <MasterSQL> oldmasters = await sqliteService.Get();

                    if (oldmasters != null && oldmasters.Count != 0)
                    {
                        foreach (var master in oldmasters)
                        {
                            await sqliteService.Delete(master.Id.ToString());
                        }
                    }
                }
                catch (Exception ex)
                {
                    var err = ex.Message;
                    throw ex;
                }
            }
        }
Ejemplo n.º 6
0
        public async Task <LoginResponce> LogInOffline(string name, string password)
        {
            string result  = String.Empty;
            bool   success = false;

            try
            {
                if (sqliteService == null)
                {
                    sqliteService = new SQLiteService(_sqlitePlatform, await _fileSystemService.GetPath(_configuration.SqlDatabaseName));
                }
            }
            catch (Exception exp)
            {
                sqliteService = null;
            }
            try {
                if (sqliteService != null)
                {
                    LoginInfoDTO currentLoginInfo = new LoginInfoDTO();
                    currentLoginInfo.UserName = name;
                    currentLoginInfo.Password = SecurytyHash.CalculateSha1Hash(password);
                    result = _localizservice.Localize("NotSavedDataOffline");
                    List <LoginInfoDTO> listlogins = await sqliteService.Get <LoginInfoDTO>();

                    if (listlogins != null && listlogins.Count != 0)
                    {
                        foreach (LoginInfoDTO login in listlogins)
                        {
                            if (login.UserName == currentLoginInfo.UserName)
                            {
                                result = string.Empty;
                                if (login.Password == currentLoginInfo.Password)
                                {
                                    success = true;
                                    result  = string.Empty;
                                }
                                else
                                {
                                    result = _localizservice.Localize("IncorrectLoginOrPassword");
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                result  = String.Format("Error = " + e.Message);
                success = false;
            }
            return(await Helper.Complete(new LoginResponce(success, result)));
        }
Ejemplo n.º 7
0
        //Get saved to local sql code A
        public async Task <Pair> GetPair()
        {
            Pair pair = null;

            try
            {
                if (sqliteService == null)
                {
                    sqliteService = new SQLiteService <CodeResponceSQL>(sqlitePlatform, await fileSystemService.GetPath(configuration.SqlDatabaseName));
                }
            }
            catch (Exception exp)
            {
                sqliteService = null;
            }
            if (sqliteService != null)
            {
                try
                {
                    CodeResponceSQL codeResponcesSQL = await sqliteService.Get("1");

                    if (codeResponcesSQL != null)
                    {
                        //DateTime saved = ConverterHelper.ConvertMillisecToDateTime(Convert.ToInt64(codeResponcesSQL.Date));
                        //DateTime expiredtime = saved.AddSeconds(configuration.TimeOutValidCodeASecond);
                        //DateTime now = DateTime.Now;
                        //bool exp = now > expiredtime;
                        pair = new Pair
                        {
                            CodeA             = codeResponcesSQL.Code,
                            CodeB             = 0,
                            ErrorMessage      = string.Empty,
                            isCodeAExpired    = (DateTime.Now > (ConverterHelper.ConvertMillisecToDateTime(Convert.ToInt64(codeResponcesSQL.Date)).AddSeconds(configuration.TimeOutValidCodeASecond))),
                            TimeOutValidCodeA = configuration.TimeOutValidCodeASecond
                        };
                    }
                }
                catch (Exception ex)
                {
                    pair = new Pair
                    {
                        CodeA             = 0,
                        CodeB             = 0,
                        ErrorMessage      = ex.Message,
                        isCodeAExpired    = true,
                        TimeOutValidCodeA = configuration.TimeOutValidCodeASecond
                    };
                }
            }

            return(pair);// await Helper.Complete(pair);
        }
Ejemplo n.º 8
0
		public async Task<List<VTSModel>> GetVTSList ()
		{
			ModelConverter converter = new ModelConverter ();
			List<VacationInfoModel> listVacationInfoModel;

			try {
				RestService restService = new RestService ("/api/Vacations", Server);
				listVacationInfoModel = await restService.Get<VacationInfoModel> ();
			} catch (AggregateException e) {
				//ErrorMessage = e.InnerExceptions [0].Data ["message"].ToString ();
				listVacationInfoModel = null;
			}

			SQLiteService sqliteService;
			try {
				sqliteService = new SQLiteService (_sqlitePlatform, await _fileSystem.GetPath ("VTS"));
			} catch {
				sqliteService = null;
			}

			List<VTSModel> VTSViewModelList = new List<VTSModel> ();
			VTSModel newItem;

			listVacationInfoModel = new VacationInfoMockModel ().Vacations;


			if (listVacationInfoModel != null) {
				foreach (VacationInfoModel info in listVacationInfoModel) {
					newItem = converter.ConvertToVTSModel (info);
					VTSViewModelList.Add (newItem);
					if (sqliteService != null) {
						await sqliteService.Insert<VacationInfoDTO> (converter.ConvertToVacationInfoDTO (newItem));
					}
				}
			} else if(sqliteService != null) {
				List<VacationInfoDTO> vacationInfoList = await sqliteService.Get<VacationInfoDTO> ();
				if (vacationInfoList != null) {
					foreach (VacationInfoDTO info in vacationInfoList) {
						VTSViewModelList.Add (converter.ConvertToVTSModel (info));
					}
				}
			}
		
			return VTSViewModelList;
		}
Ejemplo n.º 9
0
        /// <summary>
        /// Save Masters to local SQLite for buffer for slow rest internet connections
        /// </summary>
        /// <param name="responce"></param>
        /// <returns></returns>

        public async Task SaveMastersToSql(IEnumerable <Master> responce)
        {
            if (responce == null)
            {
                await ClearMasterPair();

                return;
            }
            try
            {
                if (sqliteService == null)
                {
                    sqliteService = new SQLiteService <MasterSQL>(sqlitePlatform, await fileSystemService.GetPath(configuration.SqlDatabaseName));
                }
            }
            catch (Exception exp)
            {
                sqliteService = null;
            }
            if (sqliteService != null)
            {
                try
                {
                    List <MasterSQL> oldmasters = await sqliteService.Get();

                    if (oldmasters != null && oldmasters.Count != 0)
                    {
                        foreach (var master in oldmasters)
                        {
                            await sqliteService.Delete(master.Id.ToString());
                        }
                    }
                    foreach (var master in responce)
                    {
                        await sqliteService.Insert(converter.ConvertToMasterSQL(master));
                    }
                }
                catch (Exception ex)
                {
                    var err = ex.Message;
                    throw ex;
                }
            }
        }
Ejemplo n.º 10
0
        public async Task UpdateOrCreateCodeAToSql(CodeResponce codeResponce)
        {
            if (codeResponce == null)
            {
                return;
            }
            try
            {
                if (sqliteService == null)
                {
                    sqliteService = new SQLiteService <CodeResponceSQL>(sqlitePlatform, await fileSystemService.GetPath(configuration.SqlDatabaseName));
                }
            }
            catch (Exception exp)
            {
                sqliteService = null;
            }
            if (sqliteService != null)
            {
                try
                {
                    CodeResponceSQL currentCodeAResponce = new CodeResponceSQL {
                        Id = 1, Code = codeResponce.Code, Hash = codeResponce.Hash, ResultCode = codeResponce.ResultCode, Date = ConverterHelper.ConvertDateTimeToMillisec(DateTime.Now).ToString()
                    };
                    var codeResponcesOld = await sqliteService.Get("1");

                    if (codeResponcesOld != null)
                    {
                        await sqliteService.Update(currentCodeAResponce);
                    }
                    else
                    {
                        await sqliteService.Insert(currentCodeAResponce);
                    }
                }
                catch (Exception ex)
                {
                    var err = ex.Message;
                    throw ex;
                }
            }
        }
Ejemplo n.º 11
0
        public async Task SaveLoginModelToSQLite(string name, string password)
        {
            try
            {
                if (sqliteService == null)
                {
                    sqliteService = new SQLiteService(_sqlitePlatform, await _fileSystemService.GetPath(_configuration.SqlDatabaseName));
                }
            }
            catch (Exception exp)
            {
                sqliteService = null;
            }
            if (sqliteService != null)
            {
                try
                {
                    LoginInfoDTO currentLoginInfo = new LoginInfoDTO();
                    currentLoginInfo.UserName = name;
                    currentLoginInfo.Password = SecurytyHash.CalculateSha1Hash(password);

                    List <LoginInfoDTO> listlogins = await sqliteService.Get <LoginInfoDTO>();

                    if (listlogins != null && listlogins.Count != 0)
                    {
                        foreach (LoginInfoDTO login in listlogins)
                        {
                            if (login.UserName == currentLoginInfo.UserName)
                            {
                                await sqliteService.Delete <LoginInfoDTO>(login.Id.ToString());
                            }
                        }
                    }

                    await sqliteService.Insert <LoginInfoDTO>(currentLoginInfo);
                }
                catch (Exception ex)
                {
                }
            }
        }
Ejemplo n.º 12
0
        public async Task DeleteMasterPairSql(long masterId)
        {
            try
            {
                if (sqliteService == null)
                {
                    sqliteService = new SQLiteService <MasterSQL>(sqlitePlatform, await fileSystemService.GetPath(configuration.SqlDatabaseName));
                }
            }
            catch (Exception exp)
            {
                sqliteService = null;
            }
            if (sqliteService != null)
            {
                try
                {
                    List <MasterSQL> listMasterSql = await sqliteService.Get();

                    if (listMasterSql != null && listMasterSql.Count != 0)
                    {
                        foreach (var masterSql in listMasterSql)
                        {
                            if (masterSql.MasterId.Equals(masterId))
                            {
                                await sqliteService.Delete(masterSql.Id.ToString());

                                break;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    var err = ex.Message;
                    throw ex;
                }
            }
        }
Ejemplo n.º 13
0
        public async Task UpdateOrCreateVacationsSql(VacationInfoModel vacation)
        {
            if (vacation == null)
            {
                return;
            }
            try
            {
                if (sqliteService == null)
                {
                    sqliteService = new SQLiteService(_sqlitePlatform, await _fileSystemService.GetPath(_configuration.SqlDatabaseName));
                }
            }
            catch (Exception exp)
            {
                sqliteService = null;
            }
            if (sqliteService != null)
            {
                try
                {
                    var oldvacation = await sqliteService.Get <VacationInfoModelDTO>(vacation.Id.ToString());

                    if (oldvacation != null)
                    {
                        await sqliteService.Update(_converter.ConvertToVacationInfoModelDTO(vacation));
                    }
                    else
                    {
                        await sqliteService.Insert(_converter.ConvertToVacationInfoModelDTO(vacation));
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Ejemplo n.º 14
0
        public async Task <bool> SavePrefValue(PrefEnums key, string value)
        {
            try
            {
                if (sqliteService == null)
                {
                    sqliteService = new SQLiteService <PrefSql>(sqlitePlatform, await fileSystemService.GetPath(configuration.SqlDatabaseName));
                }
            }
            catch (Exception exp)
            {
                sqliteService = null;
            }
            if (sqliteService != null)
            {
                try
                {
                    var oldprefSql = await sqliteService.Get(((int)key).ToString());

                    if (oldprefSql != null)
                    {
                        oldprefSql.Value = value;
                        await sqliteService.Update(oldprefSql);
                    }
                    else
                    {
                        await sqliteService.Insert(new PrefSql { Id = (int)key, Value = value });
                    }
                    return(true);
                }
                catch (Exception ex)
                {
                    var err = ex.Message;
                    throw ex;
                }
            }
            return(false);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Read maters from local SQLite where been saved after read from REST
        /// </summary>
        /// <returns></returns>

        public async Task <IEnumerable <Master> > GetSQLPairedMasters()
        {
            List <Master> listMasters = null;

            try
            {
                if (sqliteService == null)
                {
                    sqliteService = new SQLiteService <MasterSQL> (sqlitePlatform, await fileSystemService.GetPath(configuration.SqlDatabaseName));
                }
            }
            catch (Exception exp)
            {
                sqliteService = null;
            }
            if (sqliteService != null)
            {
                try
                {
                    List <MasterSQL> listMasterSql = await sqliteService.Get();

                    if (listMasterSql != null && listMasterSql.Count != 0)
                    {
                        listMasters = new List <Master>();
                        foreach (var masterSql in listMasterSql)
                        {
                            listMasters.Add(converter.ConvertToMaster(masterSql));
                        }
                    }
                }
                catch (Exception ex)
                {
                    var err = ex.Message;
                    throw ex;
                }
            }
            return(listMasters);
        }
Ejemplo n.º 16
0
        public async Task SaveVacationsToSql(List <VTSModel> listVTSModel)
        {
            try
            {
                if (sqliteService == null)
                {
                    sqliteService = new SQLiteService(_sqlitePlatform, await _fileSystemService.GetPath(_configuration.SqlDatabaseName));
                }
            }
            catch (Exception exp)
            {
                sqliteService = null;
            }
            if (sqliteService != null)
            {
                try
                {
                    var vacationInfoList = await sqliteService.Get <VacationInfoDTO>();

                    if (vacationInfoList != null)
                    {
                        foreach (VacationInfoDTO old in vacationInfoList)
                        {
                            await sqliteService.Delete <VacationInfoDTO>(old.Id.ToString());
                        }
                    }
                    foreach (VTSModel info in listVTSModel)
                    {
                        await sqliteService.Insert(_converter.ConvertToVacationInfoDTO((info)));
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Ejemplo n.º 17
0
        public async Task <List <VTSModel> > GetVacationListFromSQL()
        {
            var vacationsViewModelList = new List <VTSModel>();

            try
            {
                if (sqliteService == null)
                {
                    sqliteService = new SQLiteService(_sqlitePlatform, await _fileSystemService.GetPath(_configuration.SqlDatabaseName));
                }
            }
            catch (Exception exp)
            {
                sqliteService = null;
            }
            try
            {
                if (sqliteService != null)
                {
                    List <VacationInfoDTO> vacationInfoList = await sqliteService.Get <VacationInfoDTO>();

                    if (vacationInfoList != null)
                    {
                        foreach (VacationInfoDTO info in vacationInfoList)
                        {
                            vacationsViewModelList.Add(_converter.ConvertToVTSModel(info));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var error = ex.Message;
            }
            return(await Helper.Complete(vacationsViewModelList));
        }
Ejemplo n.º 18
0
		public async Task<VTSModel> GetVacationInfo (string id)
		{
			ModelConverter converter = new ModelConverter ();

			SQLiteService sqliteService;
			try {
				sqliteService = new SQLiteService (_sqlitePlatform, await _fileSystem.GetPath ("VTS"));
			} catch {
				sqliteService = null;
			}
			VacationInfoDTO info =await sqliteService.Get<VacationInfoDTO> (id);
			return  converter.ConvertToVTSModel(info);
		}