Example #1
0
            public static string GetCoCUrlSingle(stCoCAPI.CoCAPI.CoCEnum.CoCFmtReq type, string key, string clanTag, string curlexe, string rootpath, stCore.IMessage iLog = null)
            {
                if (!CoCRequest._CheckArgs(type, key, clanTag, iLog))
                {
                    return(String.Empty);
                }
                string reqUrl = CoCRequest.MakeCoCUrl(type, clanTag);

                if (string.IsNullOrWhiteSpace(reqUrl))
                {
                    stCore.LogException.Error(Properties.Resources.CoCUrlEmpty, iLog);
                    return(String.Empty);
                }
#if DEBUG_CHECKCURL
                stConsole.WriteHeader("Get URL: " + reqUrl);
#endif

                dynamic ccl = null;

                try
                {
                    ccl = CoCRequest._InitCUrlObj(curlexe, key, rootpath, iLog);

                    string jsonOut = ccl.GetJson(reqUrl, ((stRuntime.isRunTime()) ? null : key));
                    if (!CoCRequest._CheckReturnString(jsonOut, type, iLog))
                    {
                        return(String.Empty);
                    }
                    return(jsonOut);
                }
                catch (Exception e)
                {
                    stCore.LogException.Error(e, iLog);
                    return(String.Empty);
                }
                finally
                {
                    if (ccl != null)
                    {
                        ccl.Dispose();
                    }
                }
            }
Example #2
0
            public static string GetCoCUrlMulti(stCoCAPI.CoCAPI.CoCEnum.CoCFmtReq type, string key, string clanTag, dynamic curlobj, stCore.IMessage iLog = null)
            {
                if (curlobj == null)
                {
                    stCore.LogException.Error(Properties.Resources.CurlObjEmpty, iLog);
                    return(String.Empty);
                }
                if (!CoCRequest._CheckArgs(type, key, clanTag, iLog))
                {
                    return(String.Empty);
                }
                string reqUrl = CoCRequest.MakeCoCUrl(type, clanTag);

                if (string.IsNullOrWhiteSpace(reqUrl))
                {
                    stCore.LogException.Error(Properties.Resources.CoCUrlEmpty, iLog);
                    return(String.Empty);
                }
#if DEBUG_CHECKCURL
                stConsole.WriteHeader("Get URL: " + reqUrl);
#endif
                try
                {
                    string jsonOut = curlobj.GetJson(reqUrl, ((stRuntime.isRunTime()) ? null : key));
                    if (!CoCRequest._CheckReturnString(jsonOut, type, iLog))
                    {
                        return(String.Empty);
                    }
                    return(jsonOut);
                }
                catch (Exception e)
                {
                    stCore.LogException.Error(e, iLog);
                    return(String.Empty);
                }
            }
Example #3
0
            private void _StartRequest(string clanTag)
            {
                string jsonOut = String.Empty;

                try
                {
                    if (string.IsNullOrWhiteSpace(clanTag))
                    {
                        throw new ArgumentNullException(Properties.Resources.CoCClanTagEmpty);
                    }
                    if (this._parent._cocNotifier != null)
                    {
                        this._parent._cocNotifier.EventClear();
                    }
                    this._ccl = CoCRequest.InitCUrlObj(this._parent.CurlPath, this._parent.KeyAPI, this._parent.RootPath, this._parent._ilog);
                    this._parent._cocRrd.Create();

                    foreach (var handl in _handleMap)
                    {
                        if ((handl.Value != null) && (handl.Value.Update != null))
                        {
                            try
                            {
                                jsonOut = CoCRequest.GetCoCUrlMulti(handl.Key, this._parent.KeyAPI, clanTag, this._ccl, this._parent._ilog);
                                if (string.IsNullOrWhiteSpace(jsonOut))
                                {
                                    throw new CoCDBExceptionReason(
                                              string.Format(
                                                  Properties.Resources.DataTableEmptyIn,
                                                  handl.Key.ToString()
                                                  )
                                              );
                                }
                            }
                            catch (CoCDBExceptionReason e)
                            {
                                if (handl.Key == stCoCAPI.CoCAPI.CoCEnum.CoCFmtReq.Warlog)
                                {
                                    try
                                    {
                                        this._parent.dbMgr.QueryNoReturn(
                                            string.Format(
                                                Properties.Settings.Default.DBSysUpdateNotPublicWar,
                                                clanTag
                                                )
                                            );
                                    }
                                    catch (Exception ex)
                                    {
                                        throw ex;
                                    }
                                }
                                if (this._parent.isLogEnable)
                                {
                                    this._parent._ilog.LogError(e.Message);
                                }
                                continue;
                            }
                            catch (Exception e)
                            {
                                throw e;
                            }
                            handl.Value.Update(handl.Key, jsonOut);
                            jsonOut = String.Empty;
                        }
                    }
                    this._parent._cocRrd.UpdateRrd();
                }
                catch (Exception e)
                {
#if DEBUG_START
                    stConsole.WriteHeader(e.ToString());
                    throw e;
#else
                    stCore.LogException.Error(e, this._parent._ilog);
                    return;
#endif
                }
                finally
                {
                    this._curlClear();
                }
            }
Example #4
0
 /// <summary>
 /// Initialize cURL instance
 /// </summary>
 /// <param name="curlexe">name and path of curl binary, is null - auto detect</param>
 /// <param name="key">Bearer auth key</param>
 /// <param name="iLog">log instance, <see cref="stCore.IMessage"/></param>
 /// <returns></returns>
 public static dynamic InitCUrlObj(string curlexe, string key, string rootpath, stCore.IMessage iLog = null)
 {
     return(CoCRequest._InitCUrlObj(curlexe, key, rootpath, iLog));
 }
Example #5
0
 /// <summary>
 /// Initialize cURL instance
 /// </summary>
 /// <param name="key">Bearer auth key</param>
 /// <param name="iLog">log instance, <see cref="stCore.IMessage"/></param>
 /// <returns></returns>
 public static dynamic InitCUrlObj(string key, stCore.IMessage iLog = null)
 {
     return(CoCRequest._InitCUrlObj(null, key, null, iLog));
 }