블로그 이미지
SQL Server VS. 석이 minsouk@hotmail.com MSSQL 쿼리성능 관련해 궁금한 사항이 있다면 언제나 누구나 TeamViewer + Line (네이버 japan 메신저) 에 minsouk1 추가 후 연락주세요~ 010-9967-0955 보미아빠

카테고리

보미아빠, 석이 (461)
밥벌이 (16)
싸이클 (1)
일상 (1)
Total235,928
Today0
Yesterday38

달력

« » 2019.9
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          

공지사항


create FUNCTION [dbo].[fnString2Base64Unicode]
(
    @STRING nVARCHAR(MAX)
)
RETURNS VARCHAR(MAX)
AS
BEGIN
    RETURN (
        SELECT
            CAST(N'' AS XML).value(
                  'xs:base64Binary(xs:hexBinary(sql:column("bin")))'
                , 'VARCHAR(MAX)'
            )   Base64Encoding
        FROM (
            SELECT CAST(@STRING AS VARBINARY(MAX)) AS bin
        ) AS bin_sql_server_temp
    )
END
GO

create FUNCTION [dbo].[fnBase64Unicode2String]
(
    @BASE64_STRING NVARCHAR(MAX)
)
RETURNS NVARCHAR(MAX)
AS
BEGIN

    RETURN (
        SELECT 
            CAST(
                CAST(N'' AS XML).value('xs:base64Binary(sql:variable("@BASE64_STRING"))', 'VARBINARY(MAX)') 
            AS NVARCHAR(MAX)
            )   UTF8Encoding
    )
END
go

select [dbo].[fnString2Base64Unicode](N'명령어')
select [dbo].[fnBase64Unicode2String]('hbo5uLTF')

Posted by 보미아빠

sortedset

분류없음 / 2019.07.22 20:48

sortedset.txt
0.01MB

 

 

 

 

 

 

http://www.utilities-online.info/xmltojson/#.XTZFDOgzaUk

 

XML to JSON and JSON to XML converter online

 

www.utilities-online.info

https://jsonformatter.org/

 

Best JSON Formatter and JSON Validator: Online JSON Formatter

JSON Formatter is very unique tool for formatting JSON, converting to XML, CSV and YAML. It can be used as json validator, json editor and json viewer.

jsonformatter.org

 

Posted by 보미아빠

using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Serialization;


namespace CRUD
{
    class Program
    {
        static void Main(string[] args)
        {
            ServerDataTest();
            //LoadBalancerDataTest();
        }

        public static void LoadBalancerDataTest()
        {

            DataManager<ServerKey, LoadBalancerValue> dataManager = new DataManager<ServerKey, LoadBalancerValue>();

            dataManager.Insert(
                new ServerKey { ServerName = "ServerA" }, 
                new LoadBalancerValue { LoadBalancerPrivateIp = "pri1", LoadBalancerPublicIp = "pub1" });
            dataManager.Insert(                                                   
                new ServerKey { ServerName = "ServerB" }, 
                new LoadBalancerValue { LoadBalancerPrivateIp = "pri2", LoadBalancerPublicIp = "pub2" });
            dataManager.Update(                                                   
                new ServerKey { ServerName = "ServerB" }, 
                new LoadBalancerValue { LoadBalancerPrivateIp = "pri3" });
            dataManager.Insert(                                                   
                new ServerKey { ServerName = "ServerC" }, 
                new LoadBalancerValue { LoadBalancerPrivateIp = "pri3", LoadBalancerPublicIp = "pub3" });
            dataManager.Delete(
                new ServerKey { ServerName = "ServerA" });

            // SerializeObject
            string json = dataManager.GetJson();
            Console.WriteLine(json);

            // DeserializeObject
            var tempobject = JsonConvert.DeserializeObject<List<KeyValuePair<ServerKey, LoadBalancerValue>>>(json);
            dataManager.Data.Clear();

            foreach (var a in tempobject)
            {
                dataManager.Insert( 
                    new ServerKey { ServerName = a.Key.ServerName },
                    new LoadBalancerValue {
                        LoadBalancerPrivateIp = a.Value.LoadBalancerPrivateIp,
                        LoadBalancerPublicIp = a.Value.LoadBalancerPublicIp });
            }

            // data confirm 
            foreach (var a in dataManager.Data)
            {
                Console.WriteLine($"{a.Key.ServerName}, {a.Value.LoadBalancerPrivateIp}, {a.Value.LoadBalancerPublicIp}");
            }

            Console.ReadKey();
        }


        public static void ServerDataTest()
        {

            DataManager<ServerKey, ServerValue> dataManager = new DataManager<ServerKey, ServerValue>();

            dataManager.Insert(
                new ServerKey { ServerName = "ServerA" },
                new ServerValue { ServerPrivateIp = "pri1", ServerPublicIp = "pub1" });
            dataManager.Insert(
                new ServerKey { ServerName = "ServerB" },
                new ServerValue { ServerPrivateIp = "pri2", ServerPublicIp = "pub2" });
            dataManager.Insert(
                new ServerKey { ServerName = "ServerB" },
                new ServerValue { ServerPrivateIp = "pri3", ServerPublicIp = "pub5" });
            dataManager.Update(
                new ServerKey { ServerName = "ServerB" }, 
                new ServerValue { ServerPrivateIp = "pri3" });
            dataManager.Insert(
                new ServerKey { ServerName = "ServerC" },
                new ServerValue { ServerPrivateIp = "pri3", ServerPublicIp = "pub3" });
            dataManager.Delete(
                new ServerKey { ServerName = "ServerA" });

            // SerializeObject
            string json = dataManager.GetJson();
            Console.WriteLine(json);

            // DeserializeObject
            var tempobject = JsonConvert.DeserializeObject<List<KeyValuePair<ServerKey, ServerValue>>>(json);
            dataManager.Data.Clear();

            foreach (var a in tempobject)
            {
                dataManager.Insert(
                    new ServerKey { ServerName = a.Key.ServerName },
                    new ServerValue { ServerPrivateIp = a.Value.ServerPrivateIp, ServerPublicIp = a.Value.ServerPublicIp });
            }

            // data confirm 
            foreach (var a in dataManager.Data)
            {
                Console.WriteLine($"{a.Key.ServerName}, {a.Value.ServerPrivateIp}, {a.Value.ServerPublicIp}");
            }

            ServerValue sv = dataManager.Data[new ServerKey { ServerName = "ServerB" }];
            Console.WriteLine($"{sv.ServerPrivateIp}, {sv.ServerPublicIp}");
            Console.ReadKey();
        }
    }
    

    class ServerKey : IEquatable <ServerKey>
    {
        
        public string ServerName
        {
            get; set;
        }

        public bool Equals(ServerKey other)
        {
            if (ServerName.Equals(other.ServerName))
                return true;
            else
                return false;
        }

        public override int GetHashCode()
        {
            return ServerName.GetHashCode();
            // return _X.GetHashCode() ^ _Y.GetHashCode();

        }
    }
    
    class ServerValue
    {
        public string ServerPrivateIp { get; set; } = "";
        public string ServerPublicIp { get; set; } = "";
    }

    class LoadBalancerValue
    {
        public string LoadBalancerPrivateIp { get; set; } = "";
        public string LoadBalancerPublicIp { get; set; } = "";
    }

    class DataManager <K, V> 
    {
        private object lockobj = new object(); 

        public Dictionary<K, V> Data { get; set; } = new Dictionary<K, V>();

        public DataManager() { }

        public void Insert(K key, V value)
        {
            lock (lockobj)
            {
                if (!Data.ContainsKey(key))
                    Data.Add(key, value);
                else
                    Update(key, value);
            }
        }

        public void Update(K key, V value)
        {
            lock (lockobj)
            {
                V oldValue;
                if (Data.TryGetValue(key, out oldValue))
                {
                    var newProperies = value.GetType().GetProperties();
                    foreach (var n in newProperies)
                    {
                        var oldProperties = oldValue.GetType().GetProperties();
                        foreach (var o in oldProperties)
                        {
                            if (o.Name == n.Name)
                            {
                                string oldPropertyValue = oldValue.GetType().GetProperty(o.Name).GetValue(oldValue, null).ToString();
                                if (value.GetType().GetProperty(n.Name).GetValue(value, null).Equals(""))
                                {
                                    value.GetType().GetProperty(n.Name).SetValue(value, oldPropertyValue, null);
                                }
                            }
                        }
                    }
                }
                Data[key] = value;
            }
        }

        public void Delete(K key)
        {
            lock (lockobj)
            {
                if (Data.ContainsKey(key))
                {
                    Data.Remove(key);
                }
            }
        }

        public string GetJson()
        {
            JsonSerializerSettings settings = new JsonSerializerSettings();
            settings.Formatting = Formatting.Indented;
            settings.ContractResolver = new DictionaryAsArrayResolver();
            return JsonConvert.SerializeObject(Data, settings);
        }
    }

    class DictionaryAsArrayResolver : DefaultContractResolver
    {
        protected override JsonContract CreateContract(Type objectType)
        {
            if (objectType.GetInterfaces().Any(i => i == typeof(IDictionary) ||
               (i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IDictionary<,>))))
            {
                return base.CreateArrayContract(objectType);
            }
            return base.CreateContract(objectType);
        }
    }
}

Posted by 보미아빠

최근에 달린 댓글

최근에 받은 트랙백

글 보관함