Пример #1
0
        public async Task <int> SaveScreenShotToSql(ScreenShot screenShot)
        {
            int result = 0;

            if (screenShot == null)
            {
                return(result);
            }

            try
            {
                if (sqliteService == null)
                {
                    sqliteService = new SQLiteService <ScreenShotSQL>(sqlitePlatform, await fileSystemService.GetPath(configuration.SqlDatabaseName));
                }
            }
            catch (Exception exp)
            {
                sqliteService = null;
            }
            if (sqliteService != null)
            {
                try
                {
                    result = await sqliteService.Insert(converter.ConvertToScreenShotSQL(screenShot));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(await TaskHelper.Complete(result));
        }
Пример #2
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");
		}
Пример #3
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);
        }
        /// <summary>
        /// json转sql
        /// </summary>
        /// <param name="f"></param>
        /// <param name="json"></param>
        static private void Json2Sqlite(string f, string json)
        {
            //
            var table     = Path.GetFileName(f).Replace(Path.GetExtension(f), "");
            var classname = "Game.Data." + table;
            var jsonObj   = JsonMapper.ToObject(json);
            var assPath   = IPath.Combine(BApplication.ProjectRoot,
                                          "Library/ScriptAssemblies/Assembly-CSharp.dll");
            var ass = Assembly.LoadFile(assPath);
            //
            var t = ass.GetType(classname);

            //
            EditorUtility.DisplayProgressBar("Excel2Sqlite", string.Format("生成:{0} 记录条目:{1}", classname, jsonObj.Count),
                                             0);

            if (t == null)
            {
                Debug.LogError(classname + "类不存在,请检查!");
                return;
            }
            else
            {
                Debug.Log("导出:" + classname);
            }

            //数据库创建表
            //sql.DB.Delete<>()
            sql.CreateDB(t);

            EditorUtility.ClearProgressBar();
            //
            for (int i = 0; i < jsonObj.Count; i++)
            {
                var j  = jsonObj[i];
                var jo = JsonMapper.ToObject(t, j.ToJson());
                try
                {
                    sql.Insert(jo);
                }
                catch
                {
                    Debug.LogError("导出数据有错,跳过! 错误位置:" + classname + ":" + i + "-" + jsonObj.Count);
                }
            }

            EditorUtility.DisplayProgressBar("Excel2Sqlite", string.Format("生成:{0} 记录条目:{1}", classname, jsonObj.Count),
                                             1);
        }
Пример #5
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;
		}
Пример #6
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;
                }
            }
        }
Пример #7
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;
                }
            }
        }
Пример #8
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)
                {
                }
            }
        }
Пример #9
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;
                }
            }
        }
Пример #10
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);
        }
Пример #11
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;
                }
            }
        }
Пример #12
0
		public async Task SaveVacationInfo (VTSModel newItem)
		{
			ModelConverter converter = new ModelConverter ();

			SQLiteService sqliteService;
			try {
				sqliteService = new SQLiteService (_sqlitePlatform, await _fileSystem.GetPath ("VTS"));
			} catch {
				sqliteService = null;
			}
			VacationInfoDTO dt = converter.ConvertToVacationInfoDTO (newItem);
			await sqliteService.Insert<VacationInfoDTO> (dt);

			RestService restService = new RestService ("/api/Vacations", Server);
			var req = await restService.Post<VacationInfoModel> (converter.ConvertToVacationInfoModel(newItem));
		}