Exemple #1
0
 private void StepQuery(ThreadQueue.TaskControl control, object state)
 {
     try
     {
         if (db != null)
         {
             StepState stState = state as StepState;
             if (stState.Callback != null)
             {
                 while (stState.Callback(stState.Query, stState.Query.Step(), stState.State))
                 {
                 }
             }
             else
             {
                 stState.Step = stState.Query.Step();
             }
         }
         else
         {
             throw new Exception("Database not ready!");
         }
     }
     catch (Exception ex)
     {
         Debug.LogError("SQLiteAsync : Exception : " + ex.Message);
     }
 }
		public override void Reset()
		{
			if( taskCtrl != null ){
				taskCtrl.Cancel();
				taskCtrl = null;
			}
		}
Exemple #3
0
    //
    // functions
    //
    private void OpenDatabase(ThreadQueue.TaskControl control, object state)
    {
        //Debug.Log( "OpenDatabase");
        OpenState opState = state as OpenState;

        try
        {
            db = new SQLiteDB();
            db.Open(opState.Filename);
            opState.Succeed = true;
        }
        catch (Exception ex)
        {
            opState.Succeed = false;
            Debug.LogError("SQLiteAsync : OpenDatabase : Exception : " + ex.Message);
        }

        if (db != null)
        {
            //Debug.Log( "db dekitayo");
        }
        else
        {
            //Debug.Log( "db dekinakattayo");
        }
    }
 public override void Reset()
 {
     if (taskCtrl != null)
     {
         taskCtrl.Cancel();
         taskCtrl = null;
     }
 }
Exemple #5
0
 public ThreadQueue.TaskControl Open(string filename, string _strDirectory, object state, string _strKey)
 {
     m_strKey = _strKey;
     //Debug.Log("called Open");
     //ThreadQueue.TaskControl ret = m_sqlAsync.Query( sql , SelectQueryCreated , this );
     ThreadQueue.TaskControl ret = m_sqlAsync.AutoOpen(filename, _strDirectory, AutoOpenCallback, this);
     m_tLastTaskControl = ret;
     return(ret);
 }
Exemple #6
0
    // とりあえず簡単に呼び出したい人向け(時間ができた時にちゃんと理解してね!)
    // このあたりはデフォルト引数禁止してます!勝手な変更はNG!!
    public ThreadQueue.TaskControl Select(string _strTableName, string _strOption)
    {
        // とりあえずあんまり指定しないで読みたいとき
        string sql = "select * from " + _strTableName + _strOption;

        // この簡単関数を利用する場合はもれなくasyncの設定がされるので安心!
        ThreadQueue.TaskControl ret = m_sqlAsync.Query(sql, SelectQueryCreated, this);
        m_tLastTaskControl = ret;
        return(ret);
    }
Exemple #7
0
    public ThreadQueue.TaskControl Update(string _strTableName, string _strParams, string _strWhere)
    {
        // とりあえずあんまり指定しないで上書きしたいとき
        string sql = "update " + _strTableName + " set " + _strParams + " " + _strWhere;

        // この簡単関数を利用する場合はもれなくasyncの設定がされるので安心!
        ThreadQueue.TaskControl ret = m_sqlAsync.Query(sql, UpdateQueryCreated, this);
        m_tLastTaskControl = ret;
        return(ret);
    }
		public override void OnEnter()
		{
			if(query==null)
			{
				taskCtrl = SQLiteManager.Instance.GetSQLiteAsync(shortcutName.Value).Query(sqlQuery.Value, QueryComplete,null);
			}
			else
			{
				taskCtrl = SQLiteManager.Instance.GetSQLiteAsync(shortcutName.Value).Step(query,StepComplete,null);
			}
		}
		public void OpenCallback(bool succeed, object state)
		{
			taskCtrl = null;
			
			if(succeed)
				Fsm.Event(onSuccess);
			else 
				Fsm.Event(onFail);
			
			Finish();
		}
 public override void OnEnter()
 {
     if (query == null)
     {
         taskCtrl = SQLiteManager.Instance.GetSQLiteAsync(shortcutName.Value).Query(sqlQuery.Value, QueryComplete, null);
     }
     else
     {
         taskCtrl = SQLiteManager.Instance.GetSQLiteAsync(shortcutName.Value).Step(query, StepComplete, null);
     }
 }
Exemple #11
0
    //
    // functions
    //
    private void OpenDatabase(ThreadQueue.TaskControl control, object obj)
    {
        string filename = obj as string;

        try
        {
            db = new SQLiteDB();
            db.Open(filename);
        }
        catch (Exception ex)
        {
            Debug.LogError("SQLiteAsync : OpenDatabase : Exception : " + ex.Message);
        }
    }
Exemple #12
0
        public void OpenCallback(bool succeed, object state)
        {
            taskCtrl = null;

            if (succeed)
            {
                Fsm.Event(onSuccess);
            }
            else
            {
                Fsm.Event(onFail);
            }

            Finish();
        }
Exemple #13
0
    //
    // functions
    //
    private void OpenDatabase(ThreadQueue.TaskControl control, object state)
    {
        OpenState opState = state as OpenState;

        try
        {
            db = new SQLiteDB();
            db.Open(opState.Filename);
            opState.Succeed = true;
        }
        catch (Exception ex)
        {
            opState.Succeed = false;
            Debug.LogError("SQLiteAsync : OpenDatabase : Exception : " + ex.Message);
        }
    }
Exemple #14
0
 private void CreateQuery(ThreadQueue.TaskControl control, object state)
 {
     try
     {
         if (db != null)
         {
             QueryState qrState = state as QueryState;
             qrState.Query = new SQLiteQuery(db, qrState.Sql);
         }
         else
         {
             throw new Exception("Database not ready!");
         }/**/
     }
     catch (Exception ex)
     {
         Debug.LogError("SQLiteAsync : CreateQuery : Exception : " + ex.Message);
     }
 }
Exemple #15
0
 private void CloseDatabase(ThreadQueue.TaskControl control, object state)
 {
     try
     {
         if (db != null)
         {
             db.Close();
             db = null;
         }
         else
         {
             throw new Exception("Database not ready!");
         }
     }
     catch (Exception ex)
     {
         Debug.LogError("SQLiteAsync : Exception : " + ex.Message);
     }
 }
 private void StepQuery(ThreadQueue.TaskControl control, object state)
 {
     try
     {
         if (db != null)
         {
             StepState stState = state as StepState;
             stState.Step = stState.Query.Step();
         }
         else
         {
             throw new Exception("Database not ready!");
         }
     }
     catch (Exception)
     {
         //Debug.LogError("SQLiteAsync : Exception : " + ex.Message);
     }
 }
Exemple #17
0
 private void ReleaseQuery(ThreadQueue.TaskControl control, object state)
 {
     try
     {
         if (db != null)
         {
             ReleaseState rlState = state as ReleaseState;
             rlState.Query.Release();
         }
         else
         {
             throw new Exception("Database not ready!");
         }
     }
     catch (Exception ex)
     {
         Debug.LogError("SQLiteAsync : Exception : " + ex.Message);
     }
 }
        void QueryComplete(SQLiteQuery qr, object state)
        {
            query = qr;
            if (qr == null)
            {
                Fsm.Event(onFail);
            }
            else
            {
                foreach (FsmStateAction action in State.Actions)
                {
                    SQLiteBindInteger bindInt = action as SQLiteBindInteger;
                    if (bindInt != null)
                    {
                        query.Bind(bindInt.integerValue.Value);
                    }

                    SQLiteBindBool bindBool = action as SQLiteBindBool;
                    if (bindBool != null)
                    {
                        query.Bind(bindBool.boolValue.Value ? 1:0);
                    }

                    SQLiteBindFloat bindFloat = action as SQLiteBindFloat;
                    if (bindFloat != null)
                    {
                        query.Bind((double)bindFloat.floatValue.Value);
                    }

                    SQLiteBindString bindStr = action as SQLiteBindString;
                    if (bindStr != null)
                    {
                        query.Bind(bindStr.stringValue.Value);
                    }
                }

                taskCtrl = SQLiteManager.Instance.GetSQLiteAsync(shortcutName.Value).Step(query, StepComplete, null);
            }
        }
		void QueryComplete(SQLiteQuery qr, object state)
		{
			query = qr;
			if(qr == null)
			{
				Fsm.Event(onFail);
			}
			else
			{
				foreach( FsmStateAction action in State.Actions )
				{
					SQLiteBindInteger bindInt = action as SQLiteBindInteger;
					if(bindInt != null)
					{
						query.Bind(bindInt.integerValue.Value);
					}
					
					SQLiteBindBool bindBool = action as SQLiteBindBool;
					if(bindBool != null)
					{
						query.Bind(bindBool.boolValue.Value ? 1:0);
					}
					
					SQLiteBindFloat bindFloat = action as SQLiteBindFloat;
					if(bindFloat != null)
					{
						query.Bind((double)bindFloat.floatValue.Value);
					}
					
					SQLiteBindString bindStr = action as SQLiteBindString;
					if(bindStr != null)
					{
						query.Bind(bindStr.stringValue.Value);
					}
				}
				
				taskCtrl = SQLiteManager.Instance.GetSQLiteAsync(shortcutName.Value).Step(query,StepComplete,null);
			}
		}
        void StepComplete(SQLiteQuery qr, bool rv, object state)
        {
            taskCtrl = null;
            if (rv)
            {
                foreach (FsmStateAction action in State.Actions)
                {
                    SQLiteOutputString outString = action as SQLiteOutputString;
                    if (outString != null)
                    {
                        outString.stringValue.Value = query.GetString(outString.fieldName.Value);
                    }
                    SQLiteOutputBool outBool = action as SQLiteOutputBool;
                    if (outBool != null)
                    {
                        outBool.boolValue.Value = query.GetInteger(outBool.fieldName.Value) > 0 ? true : false;
                    }
                    SQLiteOutputInteger outInt = action as SQLiteOutputInteger;
                    if (outInt != null)
                    {
                        outInt.integerValue.Value = query.GetInteger(outInt.fieldName.Value);
                    }
                    SQLiteOutputFloat outFloat = action as SQLiteOutputFloat;
                    if (outFloat != null)
                    {
                        outFloat.floatValue.Value = (float)query.GetDouble(outFloat.fieldName.Value);
                    }
                }

                Fsm.Event(onStep);
            }
            else
            {
                query = null;
                Finish();
            }
        }
Exemple #21
0
		public override void OnEnter()
		{
			string dbfilename = Application.persistentDataPath + "/" + filename.Value;
			taskCtrl = SQLiteManager.Instance.GetSQLiteAsync(shortcutName.Value).Open(dbfilename, OpenCallback, null);
		}
 public override void OnEnter()
 {
     taskCtrl = SQLiteManager.Instance.GetSQLiteAsync(shortcutName.Value).Close(CloseCallback, null);
 }
Exemple #23
0
 public ThreadQueue.TaskControl Close()
 {
     ThreadQueue.TaskControl ret = m_sqlAsync.Close(CloseCallback, this);
     return(ret);
 }
 public void CloseCallback(object state)
 {
     taskCtrl = null;
     Finish();
 }
Exemple #25
0
    // Update is called once per frame
    void Update()
    {
        bool bInit = false;

        if (m_eStepPre != m_eStep)
        {
            m_eStepPre = m_eStep;
            bInit      = true;
        }

        switch (m_eStep)
        {
        case STEP.DB_SETUP:
            if (bInit)
            {
                m_dbItem          = new DBItem(Define.DB_TABLE_ASYNC_ITEM);
                m_dbItemMaster    = new DBItemMaster(Define.DB_TABLE_ASYNC_ITEM_MASTER);
                m_dbWork          = new DBWork(Define.DB_TABLE_ASYNC_WORK);
                m_dbMonster       = new DBMonster(Define.DB_TABLE_ASYNC_MONSTER);
                m_dbMonsterMaster = new DBMonsterMaster(Define.DB_TABLE_ASYNC_MONSTER_MASTER);
                m_dbStaff         = new DBStaff(Define.DB_TABLE_ASYNC_STAFF);
                if (m_dbKvs == null)
                {
                    m_dbKvs = new DBKvs(Define.DB_TABLE_ASYNC_KVS);
                }

                /*
                 * m_dbItem.Open (Define.DB_NAME_DOUBTSUEN, Define.DB_FILE_DIRECTORY, "");
                 * m_dbItemMaster.Open (Define.DB_NAME_DOUBTSUEN, Define.DB_FILE_DIRECTORY, "");
                 * m_dbWork.Open (Define.DB_NAME_DOUBTSUEN, Define.DB_FILE_DIRECTORY, "");
                 * m_dbMonster.Open (Define.DB_NAME_DOUBTSUEN, Define.DB_FILE_DIRECTORY, "");
                 * m_dbMonsterMaster.Open (Define.DB_NAME_DOUBTSUEN, Define.DB_FILE_DIRECTORY, "");
                 * m_dbStaff.Open (Define.DB_NAME_DOUBTSUEN, Define.DB_FILE_DIRECTORY, "");
                 * m_tkKvsOpen = m_dbKvs.Open (Define.DB_NAME_DOUBTSUEN, Define.DB_FILE_DIRECTORY, ""); // DEFINE.DB_PASSWORD
                 */
            }
            //if (m_tkKvsOpen.Completed) {
            if (true)
            {
                DataManager.itemMaster = m_dbItemMaster.SelectAll();

                m_header.Initialize();
                m_header.RefleshNum();
                m_collectGold.Initialize();
                m_fukidashiWork.Initialize();


                m_eStep = STEP.IDLE;
            }
            break;

        case STEP.IDLE:
            if (bInit)
            {
                m_fBackupInterval      = 10.0f;
                m_fBackupIntervalTimer = 0.0f;
            }

            /*
             * m_fBackupIntervalTimer += Time.deltaTime;
             * if (m_fBackupInterval < m_fBackupIntervalTimer) {
             *      m_fBackupIntervalTimer -= m_fBackupInterval;
             *
             *      m_eStep = STEP.BACKUP_CHECK;
             * }
             */
            if (TutorialManager.Instance.IsTutorial() == false && ReviewManager.Instance.IsReadyReview())
            {
                m_eStep = STEP.REVIEW;
            }
            break;

        case STEP.REVIEW:
            if (bInit)
            {
                GameObject obj = PrefabManager.Instance.MakeObject("prefab/CtrlReviewWindow", m_goPanelFront);
                m_reviewWindow = obj.GetComponent <CtrlReviewWindow> ();
                m_reviewWindow.Initialize();
            }
            if (m_reviewWindow.IsEnd())
            {
                Destroy(m_reviewWindow.gameObject);;
                m_eStep = STEP.IDLE;
            }
            break;

        case STEP.BACKUP_CHECK:
            if (bInit)
            {
                string sourceDB  = System.IO.Path.Combine(Application.persistentDataPath, Define.DB_NAME_DOUBTSUEN);
                string backup2DB = System.IO.Path.Combine(Application.persistentDataPath, Define.DB_NAME_DOUBTSUEN_BK2);
                System.IO.File.Copy(sourceDB, backup2DB, true);

                m_dbItemBackup  = new DBItem(Define.DB_NAME_DOUBTSUEN_BK2);
                m_tkBackupCheck = new ThreadQueue.TaskControl();
                m_tkBackupCheck = m_dbItemBackup.Open(Define.DB_NAME_DOUBTSUEN_BK2, Define.DB_FILE_DIRECTORY, "");
                //Debug.Log ("STEP.BACKUP_CHECK");
            }
            //Debug.Log ("frame");
            if (m_tkBackupCheck.Completed)
            {
                m_eStep = STEP.IDLE;
                try
                {
                    // DBおかしくなってたらここでThrowされる
                    List <DataItem> check = m_dbItemBackup.SelectAll();

                    //Debug.Log( "Copy" );
                    //string sourcePath = System.IO.Path.Combine (Application.streamingAssetsPath, Define.DB_FILE_DIRECTORY + Define.DB_NAME_DOUBTSUEN );
                    string backupDB  = System.IO.Path.Combine(Application.persistentDataPath, Define.DB_NAME_DOUBTSUEN_BK);
                    string backup2DB = System.IO.Path.Combine(Application.persistentDataPath, Define.DB_NAME_DOUBTSUEN_BK2);
                    if (System.IO.File.Exists(backup2DB))
                    {
                        System.IO.File.Copy(backup2DB, backupDB, true);
                    }
                }catch {
                    //Debug.LogError ("まずー");
                }
            }
            break;

        default:
            break;
        }
    }
Exemple #26
0
        public override void OnEnter()
        {
            string dbfilename = Application.persistentDataPath + "/" + filename.Value;

            taskCtrl = SQLiteManager.Instance.GetSQLiteAsync(shortcutName.Value).Open(dbfilename, OpenCallback, null);
        }
		void StepComplete(SQLiteQuery qr, bool rv, object state)
		{
			taskCtrl = null;
			if(rv){
				foreach( FsmStateAction action in State.Actions )
				{
					SQLiteOutputString outString = action as SQLiteOutputString;
					if(outString != null)
					{
						outString.stringValue.Value = query.GetString(outString.fieldName.Value);
					}
					SQLiteOutputBool outBool = action as SQLiteOutputBool;
					if(outBool != null)
					{
						outBool.boolValue.Value = query.GetInteger(outBool.fieldName.Value) > 0 ? true : false;
					}
					SQLiteOutputInteger outInt = action as SQLiteOutputInteger;
					if(outInt != null)
					{
						outInt.integerValue.Value = query.GetInteger(outInt.fieldName.Value);
					}
					SQLiteOutputFloat outFloat = action as SQLiteOutputFloat;
					if(outFloat != null)
					{
						outFloat.floatValue.Value = (float)query.GetDouble(outFloat.fieldName.Value);
					}
				}
				
				Fsm.Event(onStep);
			}
			else
			{
				query = null;
				Finish();
			}
		}
Exemple #28
0
    // 基本的にはオープンとやることは同じなんですけど、
    // StreamingAssetにファイルがあるかどうかの確認を行う
    public ThreadQueue.TaskControl AutoOpen(string filename, string _strDirectory, OpenCallback callback, object state)
    {
        string pathDB = System.IO.Path.Combine(Application.persistentDataPath, filename);
        //Debug.Log( pathDB );
        bool bFileCtrlError = false;

        if (!System.IO.File.Exists(pathDB))
        {
            //Debug.Log ("DB not Exists in documents folder");
            //original path
            string sourcePath = System.IO.Path.Combine(Application.streamingAssetsPath, _strDirectory + filename);
            //Debug.Log( sourcePath );
            if (sourcePath.Contains("://"))
            {
                // Android
                WWW www = new WWW(sourcePath);
                // Wait for download to complete - not pretty at all but easy hack for now
                // and it would not take long since the data is on the local device.
                while (!www.isDone)
                {
                    ;
                }
                if (String.IsNullOrEmpty(www.error))
                {
                    System.IO.File.WriteAllBytes(pathDB, www.bytes);
                }
                else
                {
                    bFileCtrlError = true;
                    //CanExQuery = false;
                    // エラーで返す
                }
            }
            else
            {
                // Mac, Windows, Iphone
                //validate the existens of the DB in the original folder (folder "streamingAssets")
                if (System.IO.File.Exists(sourcePath))
                {
                    //copy file - alle systems except Android
                    System.IO.File.Copy(sourcePath, pathDB, true);
                }
                else
                {
                    bFileCtrlError = true;
                    //CanExQuery = false;
                    // エラーで返す
                    Debug.Log("ERROR: the file DB named " + filename + " doesn't exist in the StreamingAssets Folder, please copy it there.");
                }
            }
        }
        if (bFileCtrlError)
        {
            //Debug.Log( "open error");
            ThreadQueue.TaskControl retError = new ThreadQueue.TaskControl();
            retError.Cancel();
            return(retError);
        }

        //Debug.Log( "open:"+pathDB );
        return(Open(pathDB, callback, state));
    }
		public override void OnEnter()
		{
			taskCtrl = SQLiteManager.Instance.GetSQLiteAsync(shortcutName.Value).Close(CloseCallback, null);
		}
		public void CloseCallback(object state)
		{
			taskCtrl = null;
			Finish();
		}