Ejemplo n.º 1
0
        /// <summary>모델 객체로부터 AZData를 생성</summary>
        /// <param name="source">AZData로 변경할 모델 객체</param>
        public static AZData From <T>(T source)
        {
            AZData rtnValue = new AZData();

#if NET_STD || NET_CORE || NET_STORE
            Type type = typeof(T);
            IEnumerable <PropertyInfo> properties = type.GetRuntimeProperties();
            foreach (PropertyInfo property in properties)
            {
                if (!property.CanRead)
                {
                    continue;
                }
                rtnValue.Add(property.Name, property.Name.Equals("SyncRoot") ? property.GetValue(source, null).ToString() : property.GetValue(source, null));
            }
#endif
#if NET_FX
            Type type = typeof(T);
            System.Reflection.PropertyInfo[] properties = type.GetProperties();
            for (int cnti = 0; cnti < properties.Length; cnti++)
            {
                System.Reflection.PropertyInfo property = properties[cnti];
                if (!property.CanRead)
                {
                    continue;
                }
                // ICollection 구현체에 대한 재귀 오류 수정처리, 2016-05-19,, leeyonghun
                rtnValue.Add(property.Name, property.Name.Equals("SyncRoot") ? property.GetValue(source, null).ToString() : property.GetValue(source, null));
            }
#endif
            return(rtnValue);
        }
Ejemplo n.º 2
0
 /// <summary>현재의 자료에 입력받은 자료를 추가</summary>
 /// <param name="value">AZData, 추가할 AZData 자료</param>
 public AZData Add(AZData value)
 {
     for (int cnti = 0; cnti < value.Size(); cnti++)
     {
         Add(value.GetKey(cnti), value.Get(cnti));
     }
     return(this);
 }
Ejemplo n.º 3
0
        /// <summary>json 형식의 문자열을 AZData로 변경, 이 자료를 현재의 자료에 추가</summary>
        /// <param name="json">string, json형식의 문자열</param>
        public AZData Add(string json)
        {
            AZData data_json = AZString.JSON.Init(json).ToAZData();

            for (int cnti = 0; cnti < data_json.Size(); cnti++)
            {
                Add(data_json.GetKey(cnti), data_json.Get(cnti));
            }
            return(this);
        }
Ejemplo n.º 4
0
 /// <summary>모든 자료를 개별 AZData자료릐 배열로 변환하여 반환</summary>
 public AZData[] ToArray()
 {
     AZData[] rtnValue = new AZData[Size()];
     for (int cnti = 0; cnti < Size(); cnti++)
     {
         AZData dmyData = new AZData();
         dmyData.Add(GetKey(cnti), GetString(cnti));
         rtnValue[cnti] = dmyData;
     }
     return(rtnValue);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 현재에 자료와 통합, 동일 key값이 존재할 때, overwrite가 true이면 새로운 값으로 교체, 아닌경우 기존값 유지
 /// </summary>
 /// <param name="value"></param>
 /// <param name="overwrite"></param>
 /// <returns></returns>
 public AZData Merge(AZData value, bool overwrite = false)
 {
     for (int cnti = 0; cnti < value.Size(); cnti++)
     {
         if (HasKey(value.GetKey(cnti)))
         {
             if (overwrite)
             {
                 Set(value.GetKey(cnti), value.Get(cnti));
             }
         }
         else
         {
             Add(value.GetKey(cnti), value.Get(cnti));
         }
     }
     return(this);
 }
Ejemplo n.º 6
0
        /// <summary></summary>
        public T Get <T>(string p_key, Encrypt?p_encrypt, string p_encrypt_key)
        {
            Type   type  = typeof(T);
            object model = Activator.CreateInstance(type);

            T       rtn_value = default(T);
            string  key, value;
            Encrypt encrypt = Encrypt.BASE64;

            //
            //HttpContext context = System.Web.HttpContext.Current;

            // 쿠키 최상위 이름값이 없으면 모델의 이름으로 지정
            key = p_key != null ? p_key : model.GetType().Name;

            if (p_encrypt.HasValue)
            {
                encrypt = p_encrypt.Value;
            }

            // T -> AZData 형식으로 변환
            AZData data = AZString.JSON.Init(AZString.JSON.Convert <T>((T)model)).ToAZData();

            model = null;

            //
            value = Get(key, encrypt, p_encrypt_key);
            if (value != null)
            {
                for (int cnti = 0; cnti < data.Size(); cnti++)
                {
                    string sub_value = GetSubValue(data.GetKey(cnti), value);
                    if (sub_value != null)
                    {
                        data.Set(cnti, sub_value);
                    }
                }
                rtn_value = data.Convert <T>();
            }

            return(rtn_value);
        }
Ejemplo n.º 7
0
        /// <summary></summary>
        public void Set <T>(string p_key, T p_model, string p_domain, int?p_remain_days, Encrypt?p_encrypt, string p_encrypt_key)
        {
            string  key, value = "";
            Encrypt encrypt     = Encrypt.BASE64;
            int     remain_days = 0;

            //
            //HttpContext context = System.Web.HttpContext.Current;

            // 쿠키 최상위 이름값이 없으면 모델의 이름으로 지정
            key = p_key != null ? p_key : p_model.GetType().Name;
            key = UrlEncoder.Default.Encode(key);//context.Server.UrlEncode(key);

            // T -> AZData 형식으로 변환
            AZData data = AZString.JSON.Init(AZString.JSON.Convert <T>(p_model)).ToAZData();

            for (int cnti = 0; cnti < data.Size(); cnti++)
            {
                value += (cnti > 0 ? "&" : "") + data.GetKey(cnti) + "=" + UrlEncoder.Default.Encode(data.GetString(cnti));//context.Server.UrlEncode(data.GetString(cnti));
            }

            //
            if (p_encrypt.HasValue)
            {
                encrypt = p_encrypt.Value;
            }

            //
            switch (encrypt)
            {
            case Encrypt.PLAIN:
                break;

            case Encrypt.BASE64: // BASE64 인코딩된 자료에 대한 반환 처리
                value = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(UrlEncoder.Default.Encode(value)));
                break;

            case Encrypt.AES256:                                          // AES256 인코딩된 자료에 대한 반환 처리
                //net.imcore.AES256Cipher aes = new net.imcore.AES256Cipher();
                value = new AZEncrypt.AES256().Enc(value, p_encrypt_key); //aes.Encode(value, p_encrypt_key);
                //aes = null;
                break;
            }

            //
            //HttpCookie cookies = new HttpCookie(key);
            //cookies.Value = value;

            //

            /*if (p_domain != null) {
             *  cookies.Domain = p_domain;
             * }*/

            //
            if (p_remain_days.HasValue)
            {
                remain_days = p_remain_days.Value;
            }

            Microsoft.AspNetCore.Http.CookieOptions options = new Microsoft.AspNetCore.Http.CookieOptions();
            options.Expires = DateTime.Today.AddDays(remain_days);
            if (p_domain != null)
            {
                options.Domain = p_domain;
            }
            context.Response.Cookies.Delete(p_key);
            context.Response.Cookies.Append(p_key, value, options);
        }