블로그 이미지
보미아빠

카테고리

보미아빠, 석이 (528)
밥벌이 (16)
싸이클 (1)
일상 (1)
Total
Today
Yesterday

달력

« » 2025.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

공지사항

최근에 올라온 글

'보미아빠, 석이'에 해당되는 글 528건

  1. 2019.07.22 sortedset
  2. 2019.04.30 json SerializeObject DeserializeObject
  3. 2019.03.13 console.progressbar
  4. 2019.02.22 dotnet core test
  5. 2019.02.01 sql server 로 .net framework 와 powershell 깔아보기
  6. 2018.11.11 tail
  7. 2018.11.02 task
  8. 2018.09.12 delete
  9. 2018.09.11 helppage
  10. 2018.08.30 ncp c# apicall sample

sortedset

카테고리 없음 / 2019. 7. 22. 20:48
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 보미아빠
, |

https://gist.github.com/DanielSWolf/0ab6a96899cc5377bf54

Posted by 보미아빠
, |

dotnet core test

카테고리 없음 / 2019. 2. 22. 15:22


# Install repository configuration

curl https://packages.microsoft.com/config/rhel/7/prod.repo > ./microsoft-prod.repo

sudo cp ./microsoft-prod.repo /etc/yum.repos.d/


# Install Microsoft's GPG public key

curl https://packages.microsoft.com/keys/microsoft.asc > ./microsoft.asc

sudo rpm --import ./microsoft.asc


# Add the dotnet product feed

sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm


# dotnet install 

# sudo yum -y update 

sudo yum -y install dotnet-sdk-2.2  


dotnet new console

dotnet run



Posted by 보미아빠
, |

sql 은 localhost 나 admin 권한이 있다고 가정.


declare @sql varchar(8000) = 'exec xp_cmdshell ''@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString(''''https://chocolatey.org/install.ps1''''))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"'''

print @sql 

exec (@sql)


declare @sql varchar(8000) = 'exec xp_cmdshell ''choco install dotnet4.7.2 -y'''

print @sql 

exec (@sql)


declare @sql varchar(8000) = 'exec xp_cmdshell ''choco install powershell -y'''

print @sql 

exec (@sql)


끝...

Posted by 보미아빠
, |

tail

카테고리 없음 / 2018. 11. 11. 15:41

PS> Get-Content "C:\Users\rdsadmin\Documents\visual studio 2015\Projects\LazyLogConsoleAuto\LazyLogCon

soleAuto\bin\Debug\log\2018-11-11.log" -Wait -Tail 10

Posted by 보미아빠
, |

task

카테고리 없음 / 2018. 11. 2. 14:35

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading;

using System.Threading.Tasks;

using System.Windows.Forms;


namespace winform

{

    public partial class Form1 : Form

    {

        DataTable table;

        public Form1()

        {

            InitializeComponent();


        }


        private async void button1_Click(object sender, EventArgs e)

        {

            await Task.Run(() => {


                FillData();


                dataGridView1.InvokeIfRequired(s => {

                    s.ColumnCount = 3;

                    s.Columns[0].Name = "Column1";

                    s.Columns[1].Name = "Column2";

                    s.Columns[2].Name = "Column3";

                    s.Columns[0].Width = 100;

                    s.Columns[1].Width = 100;

                    s.Columns[2].Width = 300;

                    s.RowHeadersVisible = false;

                });


                foreach (DataRow row in table.Rows)

                {

                    dataGridView1.InvokeIfRequired(s => {

                        int n = s.Rows.Add();

                        s.Rows[n].Cells[0].Value = row["Column1"].ToString();

                        s.Rows[n].Cells[1].Value = row["Column2"].ToString();

                        s.Rows[n].Cells[2].Value = row["Column3"].ToString();

                    });

                }

            });

        }

        

        private void FillData()

        {

            table = new DataTable();

            table.Columns.Add("Column1", typeof(string));

            table.Columns.Add("Column2", typeof(string));

            table.Columns.Add("Column3", typeof(string));

            for (int i = 0; i < 1000000; i++)

            {

                table.Rows.Add(i.ToString(), "Indocin", "David");

            }

        }

    }


    public static class ControlHelpers

    {

        public static void InvokeIfRequired<T>(this T control, Action<T> action) where T : ISynchronizeInvoke

        {

            if (control.InvokeRequired)

            {

                control.Invoke(new Action(() => action(control)), null);

            }

            else

            {

                action(control);

            }

        }

    }

}



Posted by 보미아빠
, |

delete

카테고리 없음 / 2018. 9. 12. 11:37
set nocount on 



declare @rowcount varchar(100) ;

while (1=1)

begin 

 delete top (1000) t from perfmon t where machinename is null 

 select @rowcount = @@rowcount 

 if @rowcount = 0 break; 

 RAISERROR(@rowcount, 0, 1) WITH NOWAIT

 waitfor delay '00:00:00.200'

end

 

Posted by 보미아빠
, |

helppage

카테고리 없음 / 2018. 9. 11. 15:42

Install-Package Microsoft.AspNet.WebApi.HelpPage

Adding Help Documentation to a Web API REST Service

http://localhost:54212/Help

REST POST Build a REST Service in Visual Studio 2015 Part 1

Posted by 보미아빠
, |

using System;

using System.Collections.Generic;

using System.Threading.Tasks;

using System.Text;

using System.Net.Http;

using System.Threading;

using System.Diagnostics;

using System.Security.Cryptography;


namespace APITest

{

    public class Config

    {

        private static readonly Lazy<Config> lazy =

            new Lazy<Config>(() => new Config(), LazyThreadSafetyMode.ExecutionAndPublication);


        public static Config Instance { get { return lazy.Value; } }

        

        public string apiKey

        {

            get { return "apiGwKey"; }

        }

        public string accessKey

        {

            get { return "accessKey"; }

        }

        public string secureKey

        {

            get { return "secureKey"; }

        }

        public string ncpUrl

        {

            get { return @"https://ncloud.apigw.ntruss.com/clouddb/v1/"; }

        }

    }


    class Program

    {

        static void Main(string[] args)

        {

            Config config = Config.Instance;

            var postParams = new List<KeyValuePair<string, string>>();

            postParams.Add(new KeyValuePair<string, string>("dbKindCode", "MSSQL"));

            postParams.Add(new KeyValuePair<string, string>("responseFormatType", "json"));


            AsyncCall asyncCall = new AsyncCall();

            Task<string> t = asyncCall.NCloudApiCall("getCloudDBConfigGroupList", postParams, config.apiKey, config.accessKey, config.secureKey, config.ncpUrl);

            t.Wait();


            Console.WriteLine(t.Result);

        }

    }

    


    class AsyncCall

    {

        public async Task<string> NCloudApiCall(string action, List<KeyValuePair<string, string>> postParams, string apiKey, string accessKey, string secureKey, string ncpUrl)

        {

            string responseString = string.Empty;

            try

            {


                HttpClient client = Client.Instance.getClient();

                string timestamp = string.Empty;

                string sig = Auth.Instance.makePostSignature(action, ref timestamp, apiKey, accessKey, secureKey);


                string url = ncpUrl + action;

                var content = new FormUrlEncodedContent(postParams);


                client.DefaultRequestHeaders.Add("x-ncp-apigw-timestamp", timestamp);

                client.DefaultRequestHeaders.Add("x-ncp-apigw-api-key", apiKey);

                client.DefaultRequestHeaders.Add("x-ncp-iam-access-key", accessKey);

                client.DefaultRequestHeaders.Add("x-ncp-apigw-signature-v1", sig);


                var response = await client.PostAsync(url, content);

                responseString = await response.Content.ReadAsStringAsync();

            }

            catch (Exception e)

            {

                Console.WriteLine(e.Message);

            }

            return responseString;

        }

    }


    class Auth

    {

        private static readonly Lazy<Auth> lazy =

            new Lazy<Auth>(() => new Auth(), LazyThreadSafetyMode.ExecutionAndPublication);


        public static Auth Instance { get { return lazy.Value; } }


        public string makePostSignature(string action, ref string stringtimestamp, string apiKey, string accessKey, string secureKey)

        {

            if (string.IsNullOrEmpty(action))

                return "parameter error";


            long timestamp = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;

            string space = " ";

            string newLine = "\n";

            string method = "POST";

            string url = @"/clouddb/v1/" + action;

            stringtimestamp = timestamp.ToString();


            string message = new StringBuilder()

                .Append(method)

                .Append(space)

                .Append(url)

                .Append(newLine)

                .Append(stringtimestamp)

                .Append(newLine)

                .Append(apiKey)

                .Append(newLine)

                .Append(accessKey)

                .ToString();


            Debug.WriteLine(message);


            byte[] secretKey = Encoding.UTF8.GetBytes(secureKey);

            HMACSHA256 hmac = new HMACSHA256(secretKey);

            hmac.Initialize();

            byte[] bytes = Encoding.UTF8.GetBytes(message);

            byte[] rawHmac = hmac.ComputeHash(bytes);


            Debug.WriteLine(Convert.ToBase64String(rawHmac));

            return Convert.ToBase64String(rawHmac);

        }

    }


    class Client

    {

        private static readonly Lazy<Client> lazy =

            new Lazy<Client>(() => new Client(), LazyThreadSafetyMode.ExecutionAndPublication);


        public static Client Instance { get { return lazy.Value; } }


        private readonly HttpClient client = new HttpClient();


        public HttpClient getClient()

        {

            return client;

        }

    }

}



Posted by 보미아빠
, |

최근에 달린 댓글

최근에 받은 트랙백

글 보관함