Beispiel #1
0
        public static void WriteHttpHeaderSettingFile(SharedHttpHeaderSettingEntity settingObj, HostEntity host)
        {
            if (!System.IO.Directory.Exists(HTTP_BASIC_SETTING_DIRECTORY))
            {
                System.IO.Directory.CreateDirectory(HTTP_BASIC_SETTING_DIRECTORY);
            }

            if (host == null) return;

            if (settingObj == null) return;

            string fileName = String.Format("{0}\\{1}_{2}", HTTP_BASIC_SETTING_DIRECTORY, host.Name, "httpHeadingSetting.txt").ToLower();

            //{content-Type}|||{appId}|||{appSecret}|||{GettingTokenRequestUrl}|||{GetttingTokenRequestBody}|||{AccessToken}|||{agency}|||{environment}|||{accesskey}
            string pattern = "{0}|||{1}|||{2}|||{3}|||{4}|||{5}|||{6}|||{7}|||{8}";
            string content = String.Format(pattern, settingObj.ContentType,
                settingObj.AppId, settingObj.AppSecret,
                settingObj.GetTokenRequestUrl, settingObj.GetTokenRequestBody, settingObj.AccessToken,
                settingObj.Agency,settingObj.Environment,settingObj.AccessKey);
            Stream stream = File.Open(fileName, FileMode.Create);
            StreamWriter sw = new StreamWriter(stream);

            try
            {
                sw.WriteLine(content);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                sw.Close();
            }
        }
Beispiel #2
0
        public static SharedHttpHeaderSettingEntity ReadHttpHeaderSettingFile(HostEntity host)
        {
            if (!System.IO.Directory.Exists(HTTP_BASIC_SETTING_DIRECTORY))
            {
                return null;
            }
            if (host == null) return null;

            string fileName =String.Format("{0}\\{1}_{2}", HTTP_BASIC_SETTING_DIRECTORY,host.Name,"httpHeadingSetting.txt");
            if (!File.Exists(fileName))
            {
                return null;
            }
            try
            {
                StreamReader sr = new StreamReader(fileName);
                string content = sr.ReadToEnd();
                sr.Close();

                if(String.IsNullOrWhiteSpace(content))
                {
                    return null;
                }

                content = content.Replace("\r\n", "");

                var segments = content.Split(new string[]{"|||"},StringSplitOptions.None);
                //if(segments.Length != 9)
                //{
                //    return null;
                //}
                //{content-Type}|||{appId}|||{appSecret}|||{GettingTokenRequestUrl}|||{GetttingTokenRequestBody}|||{AccessToken}|||{agency}|||{environment}|||{accesskey}
                //string pattern = "{0}|||{1}|||{2}|||{3}|||{4}|||{5}|||{6}|||{7}|||{8}";
                SharedHttpHeaderSettingEntity settingEntity = new SharedHttpHeaderSettingEntity();

                if (segments.Length == 0) return null;

                settingEntity.ContentType = segments[0];

                if(segments.Length > 1)
                settingEntity.AppId = segments[1];

                if (segments.Length > 2)
                settingEntity.AppSecret = segments[2];

                if (segments.Length > 3)
                settingEntity.GetTokenRequestUrl = segments[3];

                if (segments.Length > 4)
                settingEntity.GetTokenRequestBody = segments[4];

                if (segments.Length > 5)
                settingEntity.AccessToken = segments[5];

                if (segments.Length > 6)
                settingEntity.Agency = segments[6];

                if (segments.Length > 7)
                settingEntity.Environment = segments[7];

                if (segments.Length > 8)
                settingEntity.AccessKey = segments[8];

                return settingEntity;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #3
0
        public static void WriteHttpHeaderSettingFile(SharedHttpHeaderSettingEntity settingObj, HostEntity host)
        {
            if (!System.IO.Directory.Exists(HTTP_BASIC_SETTING_DIRECTORY))
            {
                System.IO.Directory.CreateDirectory(HTTP_BASIC_SETTING_DIRECTORY);
            }

            if (host == null)
            {
                return;
            }

            if (settingObj == null)
            {
                return;
            }

            string fileName = String.Format("{0}\\{1}_{2}", HTTP_BASIC_SETTING_DIRECTORY, host.Name, "httpHeadingSetting.txt").ToLower();

            //{content-Type}|||{appId}|||{appSecret}|||{GettingTokenRequestUrl}|||{GetttingTokenRequestBody}|||{AccessToken}|||{agency}|||{environment}|||{accesskey}
            string pattern = "{0}|||{1}|||{2}|||{3}|||{4}|||{5}|||{6}|||{7}|||{8}";
            string content = String.Format(pattern, settingObj.ContentType,
                                           settingObj.AppId, settingObj.AppSecret,
                                           settingObj.GetTokenRequestUrl, settingObj.GetTokenRequestBody, settingObj.AccessToken,
                                           settingObj.Agency, settingObj.Environment, settingObj.AccessKey);
            Stream       stream = File.Open(fileName, FileMode.Create);
            StreamWriter sw     = new StreamWriter(stream);

            try
            {
                sw.WriteLine(content);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                sw.Close();
            }
        }
Beispiel #4
0
        private void LoadSharedHttpHeaderSetting(HostEntity host)
        {
            try
            {
                if (host == null) return;
                // open application, init a token
                //btnGenerateToken_Click(null, null);
                SHARED_HTTP_HEADER_SETTING = FileUtility.ReadHttpHeaderSettingFile(host);

                FillSharedHttpHeaderSettings(SHARED_HTTP_HEADER_SETTING);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
        }
Beispiel #5
0
        public static SharedHttpHeaderSettingEntity ReadHttpHeaderSettingFile(HostEntity host)
        {
            if (!System.IO.Directory.Exists(HTTP_BASIC_SETTING_DIRECTORY))
            {
                return(null);
            }
            if (host == null)
            {
                return(null);
            }

            string fileName = String.Format("{0}\\{1}_{2}", HTTP_BASIC_SETTING_DIRECTORY, host.Name, "httpHeadingSetting.txt");

            if (!File.Exists(fileName))
            {
                return(null);
            }
            try
            {
                StreamReader sr      = new StreamReader(fileName);
                string       content = sr.ReadToEnd();
                sr.Close();

                if (String.IsNullOrWhiteSpace(content))
                {
                    return(null);
                }

                content = content.Replace("\r\n", "");

                var segments = content.Split(new string[] { "|||" }, StringSplitOptions.None);
                //if(segments.Length != 9)
                //{
                //    return null;
                //}
                //{content-Type}|||{appId}|||{appSecret}|||{GettingTokenRequestUrl}|||{GetttingTokenRequestBody}|||{AccessToken}|||{agency}|||{environment}|||{accesskey}
                //string pattern = "{0}|||{1}|||{2}|||{3}|||{4}|||{5}|||{6}|||{7}|||{8}";
                SharedHttpHeaderSettingEntity settingEntity = new SharedHttpHeaderSettingEntity();

                if (segments.Length == 0)
                {
                    return(null);
                }

                settingEntity.ContentType = segments[0];

                if (segments.Length > 1)
                {
                    settingEntity.AppId = segments[1];
                }

                if (segments.Length > 2)
                {
                    settingEntity.AppSecret = segments[2];
                }

                if (segments.Length > 3)
                {
                    settingEntity.GetTokenRequestUrl = segments[3];
                }

                if (segments.Length > 4)
                {
                    settingEntity.GetTokenRequestBody = segments[4];
                }

                if (segments.Length > 5)
                {
                    settingEntity.AccessToken = segments[5];
                }

                if (segments.Length > 6)
                {
                    settingEntity.Agency = segments[6];
                }

                if (segments.Length > 7)
                {
                    settingEntity.Environment = segments[7];
                }

                if (segments.Length > 8)
                {
                    settingEntity.AccessKey = segments[8];
                }

                return(settingEntity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }