Beispiel #1
0
        /// <summary>
        /// Gets all the sync jobs registered with the sync manager.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <returns>
        /// Returns the list of SyncJobData corresponding to sync requests.
        /// </returns>
        public static IEnumerable <KeyValuePair <int, SyncJobData> > GetAllSyncJobs()
        {
            IDictionary <int, SyncJobData> syncJobs = new Dictionary <int, SyncJobData>();

            Interop.Manager.SyncManagerSyncJobCallback cb = (IntPtr accountHandle, string syncJobName, string syncCapability, int syncJobId, IntPtr syncJobUserData, IntPtr userData) =>
            {
                AccountManager.Account account = new AccountManager.Account(new SafeAccountHandle(accountHandle, true));
                Bundle bundle = new Bundle(new SafeBundleHandle(syncJobUserData, true));

                SyncJobData syncJobData = new SyncJobData();
                syncJobData.Account = account;
                if (syncJobName != null)
                {
                    syncJobData.SyncJobName = syncJobName;
                }
                else
                {
                    syncJobData.SyncJobName = syncCapability;
                }
                syncJobData.UserData = bundle;

                syncJobs.Add(syncJobId, syncJobData);
                return(true);
            };

            int ret = Interop.Manager.ForeachSyncJob(cb, IntPtr.Zero);

            if (ret != (int)SyncManagerErrorCode.None)
            {
                Log.Error(ErrorFactory.LogTag, "Failed to get registered sync job");
                throw ErrorFactory.GetException(ret);
            }
            return(syncJobs);
        }
Beispiel #2
0
        /// <summary>
        /// Sets the client (sync adapter) callback functions.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <param name="startSyncCb"> A callback function to be called by the sync manager for performing the sync operation. </param>
        /// <param name="cancelSyncCb"> A callback function to be called by the sync manager for cancelling the sync operation. </param>
        /// <exception cref="ArgumentNullException"> Thrown when any of the arguments are null. </exception>
        /// <exception cref="InvalidOperationException"> Thrown when the application calling this API cannot be a sync adapter. </exception>
        public void SetSyncEventCallbacks(StartSyncCallback startSyncCb, CancelSyncCallback cancelSyncCb)
        {
            if (startSyncCb == null || cancelSyncCb == null)
            {
                throw new ArgumentNullException();
            }

            _startSyncCallback = (IntPtr accountHandle, string syncJobName, string syncCapability, IntPtr syncJobUserData) =>
            {
                Log.Debug(ErrorFactory.LogTag, "Start sync event received");

                AccountManager.Account account = new AccountManager.Account(new SafeAccountHandle(accountHandle, true));
                Bundle bundle = new Bundle(new SafeBundleHandle(syncJobUserData, true));

                SyncJobData syncJobData = new SyncJobData();
                syncJobData.Account = account;
                if (syncJobName == null)
                {
                    syncJobData.SyncJobName = syncCapability;
                }
                else
                {
                    syncJobData.SyncJobName = syncJobName;
                }
                syncJobData.UserData = bundle;


                return(startSyncCb(syncJobData));
            };

            _cancelSyncCallback = (IntPtr accountHandle, string syncJobName, string syncCapability, IntPtr syncJobUserData) =>
            {
                Log.Debug(ErrorFactory.LogTag, "cancel sync event received");

                AccountManager.Account account = new AccountManager.Account(new SafeAccountHandle(accountHandle, true));
                Bundle bundle = new Bundle(new SafeBundleHandle(syncJobUserData, true));

                SyncJobData syncJobData = new SyncJobData();
                syncJobData.Account = account;
                if (syncJobName == null)
                {
                    syncJobData.SyncJobName = syncCapability;
                }
                else
                {
                    syncJobData.SyncJobName = syncJobName;
                }
                syncJobData.UserData = bundle;

                cancelSyncCb(syncJobData);
            };

            int ret = Interop.Adapter.SetCallbacks(_startSyncCallback, _cancelSyncCallback);

            if (ret != (int)SyncManagerErrorCode.None)
            {
                Log.Error(ErrorFactory.LogTag, "Failed to set callbacks");
                throw ErrorFactory.GetException(ret);
            }
        }
    public IEnumerator RequestCoroutine <T1, T2>(string path, T1 postData, Action <T2> call_back, string get_param = "", string token = "") where T2 : BaseModel, new()
    {
        WWWForm form = new WWWForm();
        string  data = JSONSerializer.Serialize <T1>(postData);

        AccountManager.Account account = MonoBehaviourSingleton <AccountManager> .I.account;
        string key          = (!string.IsNullOrEmpty(account.userHash)) ? account.userHash : "ELqdT/y.pM#8+J##x7|3/tLb7jZhmqJ,";
        string encrypt_data = Cipher.EncryptRJ128(key, "yCNBH$$rCNGvC+#f", data);
        string data_to_send = string.IsNullOrEmpty(encrypt_data) ? string.Empty : encrypt_data;

        form.AddField("data", data_to_send);
        yield return((object)this.StartCoroutine(this.RequestFormCoroutine <T2>(path, form, call_back, get_param, token)));
    }
    private Dictionary <string, string> GetHeader(WWWForm form)
    {
        Dictionary <string, string> dictionary = new Dictionary <string, string>();

        foreach (string key in form.get_headers().Keys)
        {
            dictionary.Add(key, form.get_headers()[key].ToString());
        }
        AccountManager.Account account = MonoBehaviourSingleton <AccountManager> .I.account;
        dictionary["Cookie"] = (account.token ?? string.Empty);
        dictionary["apv"]    = NetworkNative.getNativeVersionName();
        dictionary["amv"]    = string.Empty;
        if (MonoBehaviourSingleton <ResourceManager> .IsValid())
        {
            dictionary["amv"] = MonoBehaviourSingleton <ResourceManager> .I.manifestVersion.ToString();
        }
        dictionary["aidx"] = string.Empty;
        if (MonoBehaviourSingleton <ResourceManager> .IsValid())
        {
            dictionary["aidx"] = MonoBehaviourSingleton <ResourceManager> .I.assetIndex.ToString();
        }
        dictionary["tidx"] = string.Empty;
        if (MonoBehaviourSingleton <ResourceManager> .IsValid())
        {
            dictionary["tidx"] = MonoBehaviourSingleton <ResourceManager> .I.tableIndex.ToString();
        }
        dictionary["tmv"] = string.Empty;
        if (MonoBehaviourSingleton <DataTableManager> .IsValid())
        {
            dictionary["tmv"] = MonoBehaviourSingleton <DataTableManager> .I.manifestVersion.ToString();
        }
        dictionary[ServerConstDefine.CDV_KEY] = string.Empty;
        if (MonoBehaviourSingleton <UserInfoManager> .IsValid() && MonoBehaviourSingleton <UserInfoManager> .I.userInfo != null)
        {
            dictionary[ServerConstDefine.CDV_KEY] = MonoBehaviourSingleton <UserInfoManager> .I.userInfo.constDefine.cdv.ToString();
        }
        dictionary["User-Agent"] = NetworkNative.getDefaultUserAgent();
        return(dictionary);
    }
    private IEnumerator Request_Impl <T>(string path, WWWForm form, Action <T> call_back, Action call_fatal, string get_param = "", string token = "") where T : BaseModel, new()
    {
        SetPreload(false);
        if (form == null)
        {
            form = new WWWForm();
        }
        form.AddField("app", "rob");
        if (!string.IsNullOrEmpty(token))
        {
            form.AddField("rcToken", token);
        }
        string url = GetUrl(path, get_param);

        CrashlyticsReporter.SetAPIRequest(url);
        CrashlyticsReporter.SetAPIRequestStatus(true);
        byte[] data = form.get_data();
        Dictionary <string, string> headers = GetHeader(form);
        string msg = GenerateErrorMsg(Error.Unknown);

        AccountManager.Account account = MonoBehaviourSingleton <AccountManager> .I.account;
        lastRequestTime = Time.get_time();
        WWW www = new WWW(url, data, headers);

        try
        {
            WWWInfo wwwinfo = new WWWInfo(www, false, false);
            wwwInfos.Add(wwwinfo);
            DateTime timeBegin = DateTime.Now;
            while (true)
            {
                yield return((object)new WaitForEndOfFrame());

                if ((DateTime.Now - timeBegin).TotalSeconds > 15.0)
                {
                    msg = GenerateErrorMsg(Error.TimeOut);
                    break;
                }
                if (!string.IsNullOrEmpty(www.get_error()))
                {
                    string txt       = www.get_error();
                    int    httpError = 0;
                    msg = ((!int.TryParse(txt.Substring(0, 3), out httpError)) ? GenerateErrorMsg(Error.DetectHttpError) : GenerateErrorMsg((Error)(200000 + httpError)));
                    break;
                }
                if (www.get_isDone())
                {
                    www.get_text();
                    string signature = null;
                    foreach (KeyValuePair <string, string> responseHeader in www.get_responseHeaders())
                    {
                        string headerName = responseHeader.Key.ToLower();
                        if (string.IsNullOrEmpty(tokenTemp) && headerName == "set-cookie")
                        {
                            List <string> values = new List <string>((IEnumerable <string>)responseHeader.Value.Split(';'));
                            foreach (string item in values)
                            {
                                if (item.Contains("robpt"))
                                {
                                    tokenTemp = item;
                                }
                            }
                        }
                        else if (headerName == "x-compress-encrypt")
                        {
                            if (!(responseHeader.Value.Trim() == "cipher"))
                            {
                                continue;
                            }
                        }
                        else if (headerName == "x-signature")
                        {
                            signature = responseHeader.Value.Trim();
                        }
                    }
                    bool   isDecryptSuccess2 = true;
                    byte[] gzippedResponse   = null;
                    try
                    {
                        string key = (!string.IsNullOrEmpty(account.userHash)) ? account.userHash : "ELqdT/y.pM#8+J##x7|3/tLb7jZhmqJ,";
                        gzippedResponse = Cipher.DecryptRJ128Byte(key, "yCNBH$$rCNGvC+#f", www.get_text());
                    }
                    catch (Exception exc4)
                    {
                        Debug.LogException(exc4);
                        Debug.LogError((object)("Decrypt fail: " + www.get_url() + " data " + www.get_text()));
                        Debug.LogError((object)("Key Decrypt : " + ((!string.IsNullOrEmpty(account.userHash)) ? account.userHash : "ELqdT/y.pM#8+J##x7|3/tLb7jZhmqJ,")));
                        isDecryptSuccess2 = false;
                    }
                    if (!isDecryptSuccess2)
                    {
                        if (string.IsNullOrEmpty(account.userHash))
                        {
                            msg = GenerateErrorMsg(Error.DecryptResponceIsNull);
                            Log.Error(LOG.NETWORK, "Decrypt failed!!!");
                            break;
                        }
                        isDecryptSuccess2 = true;
                        try
                        {
                            gzippedResponse = Cipher.DecryptRJ128Byte("ELqdT/y.pM#8+J##x7|3/tLb7jZhmqJ,", "yCNBH$$rCNGvC+#f", www.get_text());
                        }
                        catch (Exception exc3)
                        {
                            Log.Exception(exc3);
                            isDecryptSuccess2 = false;
                        }
                        if (!isDecryptSuccess2)
                        {
                            msg = GenerateErrorMsg(Error.DecryptFailed);
                            Log.Error(LOG.NETWORK, "Decrypt failed");
                            break;
                        }
                    }
                    if (gzippedResponse == null)
                    {
                        msg = GenerateErrorMsg(Error.DecryptResponceIsNull);
                        Log.Error(LOG.NETWORK, "Decrypt responce is null");
                    }
                    else
                    {
                        bool isUncompressSuccess = true;
                        try
                        {
                            msg = GzUncompress(gzippedResponse);
                        }
                        catch (Exception ex)
                        {
                            Exception exc2 = ex;
                            Log.Exception(exc2);
                            isUncompressSuccess = false;
                        }
                        if (!isUncompressSuccess)
                        {
                            msg = GenerateErrorMsg(Error.UncompressFailed);
                        }
                        else if (signature == null)
                        {
                            msg = GenerateErrorMsg(Error.SignatureIsNull);
                            Log.Error(LOG.NETWORK, "Signature is null");
                        }
                        else
                        {
                            bool isVerifySignatureSuccess = true;
                            bool isValidSignature         = true;
                            try
                            {
                                isValidSignature = Cipher.verify(msg, signature);
                            }
                            catch (Exception ex2)
                            {
                                Exception exc = ex2;
                                Log.Exception(exc);
                                isVerifySignatureSuccess = false;
                            }
                            if (!isVerifySignatureSuccess)
                            {
                                msg = GenerateErrorMsg(Error.VerifySignatureFailed);
                            }
                            else if (!isValidSignature)
                            {
                                msg = GenerateErrorMsg(Error.InvalidSignature);
                            }
                            else
                            {
                                msg = Regex.Unescape(msg);
                                if (msg == "{\"error\":0,\"result\":[]}")
                                {
                                    msg = GenerateErrorMsg(Error.EmptyRecord);
                                }
                                if (msg.Contains("\"result\":[]"))
                                {
                                    msg = msg.Replace("\"result\":[]", "\"dummy\":[]");
                                }
                            }
                        }
                    }
                    break;
                }
            }
            wwwInfos.Remove(wwwinfo);
        }
        finally
        {
            ((IDisposable)www)?.Dispose();
        }
        yield return((object)new WaitForEndOfFrame());

        yield return((object)new WaitForEndOfFrame());

        yield return((object)new WaitForEndOfFrame());

        try
        {
            if (call_back != null)
            {
                new T();
                try
                {
                    JSONSerializer.Deserialize <T>(msg);
                }
                catch (Exception ex3)
                {
                    Exception exp2 = ex3;
                    string    decode_failed_msg = GenerateErrorMsg(Error.DecodeFailed);
                    JSONSerializer.Deserialize <T>(decode_failed_msg);
                    Debug.LogException(exp2);
                }
                finally
                {
                    ((_003CRequest_Impl_003Ec__Iterator1E7 <T>) /*Error near IL_08b6: stateMachine*/)._003C_003E__Finally0();
                }
            }
        }
        catch (Exception exp)
        {
            Debug.LogException(exp);
            CrashlyticsReporter.SetAPIRequestStatus(false);
            call_fatal();
        }
    }