Esempio n. 1
0
    public void Create <T>(T pExample, ReceiveRecordDelegate <JsnReceiver> pReceiveGoesHere)
    {
        try
        {
            bool         isAuto      = false;
            string       tblName     = typeof(T).ToString();
            var          tblType     = typeof(T);
            TableMapping map         = AkeakeState.DB.Connection.GetMapping(tblType);
            var          PrimaryKeys = map.Columns.Where <TableMapping.Column>(
                x =>
            {
                if (x.IsAutoInc)
                {
                    isAuto = true;                  // a bit shonky
                }
                return(x.IsPK);
            }
                ).ToList <TableMapping.Column>();
            string pkName = PrimaryKeys.First <TableMapping.Column>().Name;

            string jsnString = JsonConvert.SerializeObject(pExample);
            jsnString = ReplacePKName(jsnString, pkName, isAuto);
            jsnString = "{\"CREATE\":\"" + tblName + "\",\"EXAMPLE\":" + jsnString + "}";

            Post(jsnString, pReceiveGoesHere);


            // Return is via pReceiveGoesHere
        }
        catch (Exception ex)
        {
            throw (ex);
        }
    }
Esempio n. 2
0
    }//DELETE WHERE

    #endregion
    #region DROP table
    public void Drop <T>(ReceiveRecordDelegate <JsnReceiver> pReceiveGoesHere)
    {
        try
        {
            string tblName   = typeof(T).ToString();
            string jsnString = "{\"DROP\":\"" + tblName + "\"}";
            Post(jsnString, pReceiveGoesHere);
        }
        catch (Exception ex)
        {
            throw (ex);
        }
    }//DROP table
Esempio n. 3
0
    }//SELECT WHERE

    #endregion
    #region DELETE records WHERE
    public void Delete <T>(string pStrWhere, ReceiveRecordDelegate <JsnReceiver> pReceiveGoesHere)
    {
        try
        {
            string tblName   = typeof(T).ToString();
            string jsnString = "{\"DELETE\":\"" + tblName + "\",\"WHERE\":\"" + pStrWhere + "\"}";
            Post(jsnString, pReceiveGoesHere);
        }
        catch (Exception ex)
        {
            throw (ex);
        }
    }//DELETE WHERE
Esempio n. 4
0
    }//Store

    #endregion
    #region retrieve ALL records
    public void All <T, S>(ReceiveRecordDelegateList <T> pReceiveSuccessGoesHere, ReceiveRecordDelegate <S> pReceiveFailGoesHere)
    {
        try
        {
            string tblName   = typeof(T).ToString();
            string jsnString = "{\"ALL\":\"" + tblName + "\"}";
            Post <T, S>(jsnString, pReceiveSuccessGoesHere, pReceiveFailGoesHere);
        }
        catch (Exception ex)
        {
            throw (ex);
        }
    }//Store
Esempio n. 5
0
    private void Post(string pJsn, ReceiveRecordDelegate <JsnReceiver> pReceiveGoesHere)
    {
        UnityWebRequest lcWebReq = jsnWebRequest(pJsn);

        // VERY WEIRD, because Send returns an object that
        // you then add a "completed" event handler to the
        // completed listeners
        var lcAsyncOp = lcWebReq.SendWebRequest();

        lcAsyncOp.completed += (x => {
            Debug.Log("RETURNED FROM JsnDROP:" + lcWebReq.downloadHandler.text);
            pReceiveGoesHere(JsonUtility.FromJson <JsnReceiver>(lcWebReq.downloadHandler.text));
        });
    }
Esempio n. 6
0
 public void Store <T>(List <T> pRecords, ReceiveRecordDelegate <JsnReceiver> pReceiveGoesHere)
 {
     try
     {
         string tblName   = typeof(T).ToString();
         string jsnList   = JsonConvert.SerializeObject(pRecords);//ListToJson<T>(pRecords);
         string jsnString = "{\"STORE\":\"" + tblName + "\",\"VALUE\":" + jsnList + "}";
         Post(jsnString, pReceiveGoesHere);
     }
     catch (Exception ex)
     {
         throw (ex);
     }
 }//Store
Esempio n. 7
0
 public void Store <T>(T pRecord, ReceiveRecordDelegate <JsnReceiver> pReceiveGoesHere)
 {
     try
     {
         string tblName   = typeof(T).ToString();
         string jsnRecord = JsonConvert.SerializeObject(pRecord);
         //string jsnRecord = JsonUtility.ToJson(pRecord);
         string jsnString = "{\"STORE\":\"" + tblName + "\",\"VALUE\":" + jsnRecord + "}";
         Post(jsnString, pReceiveGoesHere);
     }
     catch (Exception ex)
     {
         throw (ex);
     }
 }
Esempio n. 8
0
    public void PutJson <T>(T pRecord, string pStrURI, ReceiveRecordDelegate <T> pDelReceiveRecord)
    {
        string strJSONURI = pStrURI + "?put=" + JsonUtility.ToJson(pRecord);

        System.Uri lcURI = new System.Uri(strJSONURI);

        UnityWebRequest lcWebReq = new UnityWebRequest(lcURI, "GET")
        {
            downloadHandler = new DownloadHandlerBuffer(),
        };

        var lcAsyncOp = lcWebReq.SendWebRequest();

        lcAsyncOp.completed += (x => {
            GameModel.DebugDisplay = "COMPLETED " + lcWebReq.downloadHandler.text;
            pDelReceiveRecord(JsonUtility.FromJson <T>(lcWebReq.downloadHandler.text));
        });
    }
Esempio n. 9
0
    public void GetJson <T>(string pStrURI, ReceiveRecordDelegate <T> pDelReceiveRecord)
    {
        System.Uri lcURI = new System.Uri(pStrURI);

        UnityWebRequest lcWebReq = new UnityWebRequest(lcURI, "GET")
        {
            downloadHandler = new DownloadHandlerBuffer(),
        };

        // VERY WEIRD, because Send returns an object that
        // you then add a "completed" event handler to the
        // completed listeners
        var lcAsyncOp = lcWebReq.SendWebRequest();

        lcAsyncOp.completed += (x => {
            GameModel.DebugDisplay = "COMPLETED " + lcWebReq.downloadHandler.text;
            pDelReceiveRecord(JsonUtility.FromJson <T>(lcWebReq.downloadHandler.text));
        });
    }
Esempio n. 10
0
    private void Post <T, S>(string pJsn, ReceiveRecordDelegateList <T> pReceiveSuccessGoesHere, ReceiveRecordDelegate <S> pReceiveFailGoesHere)
    {
        UnityWebRequest lcWebReq = jsnWebRequest(pJsn);

        // VERY WEIRD, because Send returns an object that
        // you then add a "completed" event handler to the
        // completed listeners
        var lcAsyncOp = lcWebReq.SendWebRequest();

        lcAsyncOp.completed += (x => {
            Debug.Log("RETURNED FROM JsnDROP:" + lcWebReq.downloadHandler.text);
            string lcStrJsnReceived = lcWebReq.downloadHandler.text;
            string lcJsnMsgArray = "";

            // THIS IS LOOKING MESSY!!
            S jsnAsTypeS = JsonUtility.FromJson <S>(lcStrJsnReceived);
            JsnReceiver jsnReceived = jsnAsTypeS as JsnReceiver;
            List <T> receivedList;
            switch (jsnReceived.JsnMsg)
            {
            case "SUCCESS.ALL":
            case "SUCCESS.SELECT":
                lcJsnMsgArray = GetArrayFromMsg(lcStrJsnReceived);

                receivedList = FromJsonArrayToList <T>(lcJsnMsgArray);
                Debug.Log("Post<T,S> LIST length is " + receivedList.Count().ToString());
                pReceiveSuccessGoesHere(receivedList);
                break;

            default:
                pReceiveFailGoesHere(jsnAsTypeS);
                break;
            }
        });
    }
Esempio n. 11
0
    }//Store

    #endregion

    #region SELECT records WHERE
    public void Select <T, S>(string pStrWhere, ReceiveRecordDelegateList <T> pReceiveSuccessGoesHere, ReceiveRecordDelegate <S> pReceiveFailGoesHere)
    {
        try
        {
            string tblName   = typeof(T).ToString();
            string jsnString = "{\"SELECT\":\"" + tblName + "\",\"WHERE\":\"" + pStrWhere + "\"}";
            Post <T, S>(jsnString, pReceiveSuccessGoesHere, pReceiveFailGoesHere);
        }
        catch (Exception ex)
        {
            throw (ex);
        }
    }//SELECT WHERE