Example #1
0
        public DNSErrCode Query(string domainName, ProcessQueryResult process, string OId, string SId, string version, string userData)
        {
            QueryValue value2;

            if (this.mInitStatus != DNSErrCode.DNS_NO_ERROR)
            {
                this.DNS_LOG_ERROR("init failed or uninit");
                this.mErrCode   = this.mInitStatus;
                this.mErrString = "init failed or uninit";
                return(this.mInitStatus);
            }
            if ((domainName == null) || (domainName.Length == 0))
            {
                this.DNS_LOG_ERROR("domainName is null");
                this.mErrCode   = DNSErrCode.DNS_INPUT_PARAM_ERROR;
                this.mErrString = "domainName is null";
                return(DNSErrCode.DNS_INPUT_PARAM_ERROR);
            }
            if (process == null)
            {
                this.DNS_LOG_ERROR("delegate function is null");
                this.mErrCode   = DNSErrCode.DNS_INPUT_PARAM_ERROR;
                this.mErrString = "delegate function is null";
                return(DNSErrCode.DNS_INPUT_PARAM_ERROR);
            }
            this.DNS_LOG_INFO(string.Format("domainName is [{0}]", domainName));
            this.mUploadeDomainName = string.Empty;
            if ((((OId != null) || (version != null)) || (userData != null)) && ((SId == null) || (SId.Length == 0)))
            {
                this.DNS_LOG_ERROR("OId, version or userData is not null but the SId is null");
                this.mErrCode   = DNSErrCode.DNS_INPUT_PARAM_ERROR;
                this.mErrString = "OId, version or userData is not null but the SId is null";
                return(DNSErrCode.DNS_INPUT_PARAM_ERROR);
            }
            if ((OId != null) && (OId.Length != 0))
            {
                this.mUploadeUserInfo = this.mUploadeUserInfo + ":" + OId;
            }
            else
            {
                this.mUploadeUserInfo = this.mUploadeUserInfo + ":N";
            }
            if ((SId != null) && (SId.Length != 0))
            {
                this.mUploadeUserInfo = this.mUploadeUserInfo + ":" + SId;
            }
            else
            {
                this.mUploadeUserInfo = this.mUploadeUserInfo + ":N";
            }
            if ((version != null) && (version.Length != 0))
            {
                this.mUploadeUserInfo = this.mUploadeUserInfo + ":" + version;
            }
            else
            {
                this.mUploadeUserInfo = this.mUploadeUserInfo + ":N";
            }
            char[]        separator      = new char[] { '|' };
            string[]      strArray       = domainName.Split(separator);
            List <string> domainNameList = new List <string>();

            foreach (string str in strArray)
            {
                if ((str.Length != 0) && !domainNameList.Contains(str))
                {
                    domainNameList.Add(str);
                }
            }
            if (domainNameList.Count == 0)
            {
                this.DNS_LOG_ERROR("all domainNames is empty");
                this.mErrCode   = DNSErrCode.DNS_INPUT_PARAM_ERROR;
                this.mErrString = "all domainNames is empty";
                return(DNSErrCode.DNS_INPUT_PARAM_ERROR);
            }
            if (10 < domainNameList.Count)
            {
                this.DNS_LOG_ERROR("more then ten domainNames in the list");
                this.mErrCode   = DNSErrCode.DNS_TOOMANY_DOMAINNAMES;
                this.mErrString = "more then ten domainNames in the list";
                return(DNSErrCode.DNS_TOOMANY_DOMAINNAMES);
            }
            this.DNS_LOG_INFO("all param is legal");
            value2.errCode   = 0L;
            value2.errString = "no error";
            value2.value     = new ListView <DnValue>();
            List <string> subDomainNames = new List <string>();

            if ((this.mFileSys != null) && this.isCacheEnable)
            {
                this.DNS_LOG_INFO("search domainName in cache");
                this.SearchDomainNameInCache(domainNameList, ref value2, ref subDomainNames);
            }
            else
            {
                this.DNS_LOG_INFO("search all domainNames in DNS server");
                foreach (string str2 in domainNameList)
                {
                    subDomainNames.Add(str2);
                }
            }
            if (subDomainNames.Count == 0)
            {
                this.DNS_LOG_INFO("all domainName's IP exist in cache");
                this.UploadStatisticData();
                process(value2);
                return(DNSErrCode.DNS_NO_ERROR);
            }
            string str3 = string.Empty;

            for (int i = 0; i < (subDomainNames.Count - 1); i++)
            {
                str3 = str3 + subDomainNames[i] + "|";
            }
            str3 = str3 + subDomainNames[subDomainNames.Count - 1];
            this.DNS_LOG_INFO(string.Format("send to DNS server's domainNames are [{0}]", str3));
            DNSErrCode code = dns_Query(base.ObjectId, str3, OId, SId, version, userData);

            this.mErrCode = dns_GetErrorCode(base.ObjectId);
            IntPtr ptr = dns_GetErrorString(base.ObjectId);

            this.mErrString = Marshal.PtrToStringAnsi(ptr);
            if (code != DNSErrCode.DNS_NO_ERROR)
            {
                this.DNS_LOG_ERROR(string.Format("send request failed, error code is [{0}]", Convert.ToString(code)));
                foreach (string str4 in subDomainNames)
                {
                    DnValue value3;
                    value3.errCode    = 0x455L;
                    value3.errString  = "send request error";
                    value3.domainName = str4;
                    value3.IPList     = new List <string>();
                    value2.value.Add(value3);
                    if (0 < this.mUploadeDomainName.Length)
                    {
                        this.mUploadeDomainName = this.mUploadeDomainName + ":" + str4 + "_0";
                    }
                    else
                    {
                        this.mUploadeDomainName = this.mUploadeDomainName + str4 + "_0";
                    }
                }
                if (subDomainNames.Count == domainNameList.Count)
                {
                    value2.errCode   = 0x455L;
                    value2.errString = "send request error";
                }
                this.UploadStatisticData();
                process(value2);
                return(code);
            }
            if (this.callbackObjectDic.ContainsKey(str3))
            {
                this.callbackObjectDic[str3].Add(process);
            }
            else
            {
                ListView <ProcessQueryResult> view = new ListView <ProcessQueryResult>();
                view.Add(process);
                this.callbackObjectDic.Add(str3, view);
            }
            if (this.isCallbackMode)
            {
                process(value2);
                value2.value.Clear();
            }
            this.mInitDomainNameMap.Add(str3, value2);
            return(DNSErrCode.DNS_NO_ERROR);
        }
Example #2
0
        private void ParseRecvData(DnResult result)
        {
            QueryValue value2;

            this.DNS_LOG_INFO("ParseRecvData begin");
            value2.errCode   = 0L;
            value2.errString = "no error";
            value2.value     = new ListView <DnValue>();
            foreach (KeyValuePair <string, QueryValue> pair in this.mInitDomainNameMap)
            {
                if (pair.Key == result.domainName)
                {
                    QueryValue value3 = pair.Value;
                    if (value3.value.Count != 0)
                    {
                        foreach (DnValue value4 in value3.value)
                        {
                            value2.value.Add(value4);
                        }
                    }
                }
            }
            if (result.errCode == 0)
            {
                this.DNS_LOG_INFO("result is success");
                if (this.ParseJsonValue(ref result.value, ref value2) == DNSErrCode.DNS_NO_ERROR)
                {
                    this.DNS_LOG_INFO("json parse success");
                }
                else
                {
                    this.DNS_LOG_ERROR("parse json date return from DNS server error");
                    this.mErrCode   = DNSErrCode.DNS_JSON_PARSE_ERROR;
                    this.mErrString = "parse json date return from DNS server error";
                    if (value2.value.Count == 0)
                    {
                        value2.errCode   = 0x452L;
                        value2.errString = "json parse error";
                    }
                }
            }
            else
            {
                this.DNS_LOG_ERROR("result is failed");
                this.mErrCode = dns_GetErrorCode(base.ObjectId);
                IntPtr ptr = dns_GetErrorString(base.ObjectId);
                this.mErrString = Marshal.PtrToStringAnsi(ptr);
                if (value2.value.Count == 0)
                {
                    value2.errCode   = result.errCode;
                    value2.errString = result.errString;
                }
                char[] separator = new char[] { '|' };
                foreach (string str in result.domainName.Split(separator))
                {
                    DnValue value5;
                    value5.errCode    = result.errCode;
                    value5.errString  = result.errString;
                    value5.domainName = str;
                    value5.IPList     = new List <string>();
                    value2.value.Add(value5);
                    if (0 < this.mUploadeDomainName.Length)
                    {
                        this.mUploadeDomainName = this.mUploadeDomainName + ":" + str + "_0";
                    }
                    else
                    {
                        this.mUploadeDomainName = this.mUploadeDomainName + str + "_0";
                    }
                }
            }
            foreach (KeyValuePair <string, ListView <ProcessQueryResult> > pair2 in this.callbackObjectDic)
            {
                if (pair2.Key == result.domainName)
                {
                    ListView <ProcessQueryResult> view = pair2.Value;
                    if (view.Count != 0)
                    {
                        this.DNS_LOG_INFO(string.Format("process delegate function for domainNames[{0}]", result.domainName));
                        ProcessQueryResult result2 = view[0];
                        this.UploadStatisticData();
                        result2(value2);
                        view.RemoveAt(0);
                        if (view.Count == 0)
                        {
                            this.mInitDomainNameMap.Remove(result.domainName);
                            this.callbackObjectDic.Remove(result.domainName);
                        }
                    }
                    else
                    {
                        this.DNS_LOG_INFO(string.Format("no delegate function for domainName[{0}]", result.domainName));
                        this.mErrCode   = DNSErrCode.DNS_HANDLE_FAILED;
                        this.mErrString = "no delegate function for domainName";
                    }
                    return;
                }
            }
            this.DNS_LOG_INFO(string.Format("no such domainName[{0}] in dictionary", result.domainName));
            this.mErrCode   = DNSErrCode.DNS_HANDLE_FAILED;
            this.mErrString = "no such domainName in dictionary";
        }