2017. 5. 16. 10:22

공통

    public static class LangPack

    {

        static LangPack()

        {

            Resources = new Dictionary<Language, Dictionary<string, string>>();


            Dictionary<string, string> kr = new Dictionary<string, string>();

            kr.Add("language", "한국어");


            Dictionary<string, string> en = new Dictionary<string, string>();

            en.Add("language", "영어");


            Dictionary<string, string> ch = new Dictionary<string, string>();

            ch.Add("language", "중국어");


            Resources.Add(Language.Korean, kr);

            Resources.Add(Language.English, en);

            Resources.Add(Language.Chinese, ch);

        }


        private static Dictionary<Language, Dictionary<string, string>> Resources;


        public static string GetString(string key)

        {

            if (Resources.ContainsKey(App.SelectedLanguage))

            {

                if (Resources[App.SelectedLanguage].ContainsKey(key))

                    return Resources[App.SelectedLanguage][key];

            }


            return string.Empty;

        }

    }


컨버터

    public class LanguageConverter : IValueConverter

    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

        {

            if (parameter == null)

                return string.Empty;


            if (parameter is string)

                return LangPack.GetString((string)parameter);

            else

                return string.Empty;

        }


        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

        {

            throw new NotImplementedException();

        }

    }


Application Resource

   <Application.Resources>

        <ResourceDictionary>

            <converter:LanguageConverter x:Key="LangConverter" />

            <ObjectDataProvider x:Key="language"

                ObjectType="{x:Type lang:LangPack}"

                MethodName="GetString" >

                <ObjectDataProvider.MethodParameters>

                    <s:String>language</s:String>

                </ObjectDataProvider.MethodParameters>

            </ObjectDataProvider>

        </ResourceDictionary>

    </Application.Resources>


XAML

<Button Content="{Binding Source={StaticResource language}}" />

<Button Content="{Binding Converter={StaticResource LangConverter},  ConverterParameter=language}" />







Posted by CoolDragon
2017. 4. 18. 10:38

Command Pattern



선언

    public class DelegateCommand : ICommand
    {
        private Action<object> _execute;
        private Predicate<object> _canExecute;

        public DelegateCommand(Action<object> execute)
               : this(execute, null)
        {
        }

        public DelegateCommand(Action<object> execute, Predicate<object> canExecute)
        {
            _execute = execute;
            _canExecute = canExecute;
        }

        public bool CanExecute(object parameter)
        {
            return _canExecute == null ? true : _canExecute(parameter);
        }

        public event EventHandler CanExecuteChanged = delegate { };

        public void Execute(object parameter)
        {
            _execute(parameter);
        }

        public void RaiseCanExecuteChanged()
        {
            CanExecuteChanged(this, EventArgs.Empty);
        }
    }


구현

        private ICommand _addCommand;
        public ICommand AddCommand
        {
            get
            {
                return _addCommand ??
                    (_addCommand = new DelegateCommand(
                        p => { 
                            // Add 로직 
                        },
                        p => { // Command 사용여부 
                                  return true; 
                        }
                    ));
            }
        }




Xaml

<Button Content="Add" Command={Binding AddCommand} />

<Window.InputBidings>
    <KeyBinding Key="A"
                       Modifiers="Control"
                       Command={Binding AddCommand} />
</Window.InputBidings>




Posted by CoolDragon
2017. 4. 17. 16:39

WPF

if (DesignerProperties.GetIsInDesignMode(new System.Windows.DependencyObject()))

{

  // Design Time Code

}

else

{

  // Runtime Code

}


WindowPhone, Silverlight

if (DesignerProperties.IsInDesignTool)

{

  // Design Time Code

}

else

{

  // Runtime Code

}


Windows Store

if (DesignerProperties.DesignModeEnabled)

{

  // Design Time Code

}

else

{

  // Runtime Code

}






Posted by CoolDragon
2017. 4. 17. 14:39
    public class ObservableObject : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged = delegate { };

        protected virtual void RaisePropertyChangedEvent([CallerMemberName] string propertyName = null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        protected virtual void SetProperty<T>(ref T member, T val, [CallerMemberName] string propertyName = null)
        {
            if (object.Equals(member, val)) return;

            member = val;
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }


    
    public class ViewModelBase : ObservableObject
    {
        public virtual bool IsInDesignMode()
        {
#if WINDOWS_PHONE_APP
            if (DesignerProperties.IsInDesignTool)
            {
              return true;
            }
            else
            {
              return false;
            }
#else
            if (DesignerProperties.GetIsInDesignMode(new System.Windows.DependencyObject()))
            {
                return true;
            }
            else
            {
                return false;
            }
#endif
        }
    }


Posted by CoolDragon
2017. 2. 24. 12:39

어떤 현업께서 IIS가 자동으로 설치가 가능하냐고 물었다. (다 되는건 아니니까 난 안된다고 했다. ㅋㅋ)

OS의 지원 여부에 따라서 command line 또는 powershell로 설치가 가능 할 것 같다. 이 기능을 이용하여 OS가 부팅되면 IIS의 설치여부를 비교하여 설치 명령어를 실행시키면 되지 않을까 하는게 본 필자의 생각이다.


1) 필자는 C# 을 주로 다루는 개발자이므로 아래의 코드와 같이 레지스트리를 비교하여 IIS설치여부를 비교한다.

private static bool IsIisInstalled() => Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp", "VersionString", null) != null;

※ HKLM\Software\Microsoft\InetStp\MajorVersion 레지스트리를 통해 설치버전도 비교 가능



2) command에서 사용할 수 있는 설치명령어로 IIS를 설치한다.

pkgmgr은 deprecated 되었다고 해서 DISM을 사용하라고 하는데 내 OS(Windows 10)에서는 설치가 가능했다.

다른 OS버전에서는 사용이 가능한지는 해당 OS에서 적용해봐야지 알 수 있을 것 같다.


일반권한으로 실행해도 가능

c:\> start /w pkgmgr /iu:IIS-WebServerRole;IIS-WebServer;IIS-CommonHttpFeatures;IIS-StaticContent;IIS-DefaultDocument;IIS-DirectoryBrowsing;IIS-HttpErrors;IIS-ApplicationDevelopment;IIS-ISAPIExtensions;IIS-ISAPIFilter;IIS-NetFxExtensibility45;IIS-ASPNET45;NetFx4Extended-ASPNET45;IIS-NetFxExtensibility;IIS-ASPNET;IIS-HealthAndDiagnostics;IIS-HttpLogging;IIS-RequestMonitor;IIS-Security;IIS-RequestFiltering;IIS-HttpCompressionStatic;IIS-WebServerManagementTools;IIS-ManagementConsole;WAS-WindowsActivationService;WAS-ProcessModel;WAS-NetFxEnvironment;WAS-ConfigurationAPI


관리자권한으로 실행

c:\> START /WAIT DISM /Online /Enable-Feature /FeatureName:IIS-ApplicationDevelopment /FeatureName:IIS-ASP /FeatureName:IIS-ASPNET /FeatureName:IIS-ASPNET45 /FeatureName:IIS-BasicAuthentication /FeatureName:IIS-CGI /FeatureName:IIS-ClientCertificateMappingAuthentication /FeatureName:IIS-CommonHttpFeatures /FeatureName:IIS-CustomLogging /FeatureName:IIS-DefaultDocument /FeatureName:IIS-DigestAuthentication /FeatureName:IIS-DirectoryBrowsing /FeatureName:IIS-FTPExtensibility /FeatureName:IIS-FTPServer /FeatureName:IIS-FTPSvc /FeatureName:IIS-HealthAndDiagnostics /FeatureName:IIS-HostableWebCore /FeatureName:IIS-HttpCompressionDynamic /FeatureName:IIS-HttpCompressionStatic /FeatureName:IIS-HttpErrors /FeatureName:IIS-HttpLogging /FeatureName:IIS-HttpRedirect /FeatureName:IIS-HttpTracing /FeatureName:IIS-IIS6ManagementCompatibility /FeatureName:IIS-IISCertificateMappingAuthentication /FeatureName:IIS-IPSecurity /FeatureName:IIS-ISAPIExtensions /FeatureName:IIS-ISAPIFilter /FeatureName:IIS-LegacyScripts /FeatureName:IIS-LegacySnapIn /FeatureName:IIS-LoggingLibraries /FeatureName:IIS-ManagementConsole /FeatureName:IIS-ManagementScriptingTools /FeatureName:IIS-ManagementService /FeatureName:IIS-Metabase /FeatureName:IIS-NetFxExtensibility /FeatureName:IIS-NetFxExtensibility45 /FeatureName:IIS-ODBCLogging /FeatureName:IIS-Performance /FeatureName:IIS-RequestFiltering /FeatureName:IIS-RequestMonitor /FeatureName:IIS-Security /FeatureName:IIS-ServerSideIncludes /FeatureName:IIS-StaticContent /FeatureName:IIS-URLAuthorization /FeatureName:IIS-WebDAV /FeatureName:IIS-WebServer /FeatureName:IIS-WebServerManagementTools /FeatureName:IIS-WebServerRole /FeatureName:IIS-WindowsAuthentication /FeatureName:IIS-WMICompatibility /FeatureName:WAS-ConfigurationAPI /FeatureName:WAS-NetFxEnvironment /FeatureName:WAS-ProcessModel /FeatureName:WAS-WindowsActivationService


※ 이외에 다른방법은 분명히 있을 것이 분명하므로 이것만이 정답은 아님을 말씀드립니다.


참고:

http://stackoverflow.com/questions/37846864/how-to-know-iis-installed-or-not-programmatically

http://stackoverflow.com/questions/32097336/programmatically-enable-install-iis

Posted by CoolDragon
2017. 1. 11. 10:47

로또 번호 수집기

LottNumberoCollector.zip



1. HttpClient를 이용하여 html 다운로딩 후

2. HttpAgilityPack 패키지를 이용한 HTML 파싱


Posted by CoolDragon
2016. 10. 26. 13:28

1.Windows

1) java sdk 설치

 - download: http://java.sun.com

 - 환경변수 설정

   JAVA_HOME 변수 추가: jdk 설치 경로

   Path 설정: ~~~;%JAVA_HOME%\bin; 추가


2) Tomcat

  - download: http://tomcat.apache.org

  - 압축풀면 해당 경로가 사용경로가 된다.


3) 이클립스 설치

 - download: http://www.eclipse.org (Eclipse IDE for Java EE Developers)

 - 이클립스 tomcat 서버 연동

   > Wiindow > Show View > Other... 메뉴 선택 후 화면에서 Server 선택

   > Servers 탭에서 "No servers are available. Click this link to create a new server... 를 클릭 후 설치한 Apache 버전을 선택후 Next > Tomcat installation directory를 선택 tomcat 설치 경로를 설정, JRE는 jre1.8.0_xxx로 변경 한 후 Finish

   > Servers 에서 Tomcat vx.x Server at localhost를 클릭하여 tomcat 설정

     >> Server Locations에서 "Use Tomcat installation (takes control of Tomcat installation)을 선택

     >> Server Options 에서 "Publish module contexts to separate XML files를 체크

     >> Ports 에서 HTTP/1.1를 8080에서 다른포트(8181)를 선택


2. Linux




Posted by CoolDragon
2016. 5. 26. 14:17

c#에서의 정규식

string tmp = System.Text.RegularExpressions.Regex.Replace("abce!@#%123123가나다라", "[^0-9a-zA-Zㄱ-힗]+", "");

Posted by CoolDragon
2016. 5. 25. 12:20

아래 코드를 입력하면 클래스 오브젝트를 XML 또는 JSON 타입으로 리턴시켜준다.

[Global.aspx]

public class Global : HttpApplication
{
    void Application_Start(object sender, EventArgs e)
    {
        // 응용 프로그램 시작 시 실행되는 코드
        AreaRegistration.RegisterAllAreas();
        GlobalConfiguration.Configure(WebApiConfig.Register);
        RouteConfig.RegisterRoutes(RouteTable.Routes);

        // Content-type 전역지정
        GlobalConfiguration.Configuration.Formatters.Clear();
        //GlobalConfiguration.Configuration.Formatters.Add(new System.Net.Http.Formatting.XmlMediaTypeFormatter());
        GlobalConfiguration.Configuration.Formatters.Add(new System.Net.Http.Formatting.JsonMediaTypeFormatter());
    }
}


Posted by CoolDragon
2015. 11. 4. 22:35

CSS part (style.css)

@font-face {
    font-family: 'intro_head_rbase';
    src: url('introheadr-base-webfont.eot');
    src: url('introheadr-base-webfont.eot?#iefix') format('embedded-opentype'),
         url('introheadr-base-webfont.woff2') format('woff2'),
         url('introheadr-base-webfont.woff') format('woff'),
         url('introheadr-base-webfont.ttf') format('truetype'),
         url('introheadr-base-webfont.svg#intro_head_rbase') format('svg');
    font-weight: normal;
    font-style: normal;
}

body{font-family: 'intro_head_rbase';}


HTML part (index.html)

<!DOCTYPE html> <html class="no-js"> <head> <meta charset="utf-8"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="style.css"> </head> <body> <div class="huge">abcde</div> </body> </html>


Posted by CoolDragon