2017. 7. 21. 13:34


### 관리자 모드로 실행해야 함 ###

> Dism /online /Get-Features


### FTP 활성화 ###

> DISM /Online /Enable-Feature /FeatureName:IIS-WebServer /FeatureName:IIS-WebServerRole /FeatureName:IIS-FTPServer /FeatureName:IIS-FTPSvc /FeatureName:IIS-FTPExtensibility

> echo %errorlevel%


참조

https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/enable-or-disable-windows-features-using-dism

Posted by CoolDragon
2017. 7. 14. 16:02

- 지정된 폴더의 파일 변화 모니터링 (생성,삭제, 리네임, 변경)

- 파일이 현재 복사가 되는지 File Lock 여부


using System;

using System.Collections.Generic;

using System.IO;

using System.Linq;

using System.Runtime.InteropServices;

using System.Text;

using System.Threading.Tasks;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Navigation;

using System.Windows.Shapes;


namespace FileWatcher

{

    /// <summary>

    /// MainWindow.xaml에 대한 상호 작용 논리

    /// </summary>

    public partial class MainWindow : Window

    {

        public MainWindow()

        {

            InitializeComponent();


            Start();

        }


        System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer();

        string filePath = null;


        private void Start()

        {

            System.IO.FileSystemWatcher watcher = new System.IO.FileSystemWatcher();

            watcher.Path = @"d:\watch";

            watcher.NotifyFilter = System.IO.NotifyFilters.FileName | System.IO.NotifyFilters.DirectoryName | System.IO.NotifyFilters.Size;


            watcher.Changed += Watcher_Changed;

            watcher.Created += Watcher_Created;

            watcher.Deleted += Watcher_Deleted;

            watcher.Renamed += Watcher_Renamed;

            watcher.EnableRaisingEvents = true;


            timer.Interval = new TimeSpan(0, 0, 1);

            timer.Tick += (s, args) =>

            {

                if (!string.IsNullOrEmpty(filePath))

                {

                    if (IsFileLocked(filePath))

                        Log($"File Locked");

                    else

                    {

                        Log($"File unlocked");

                        timer.Stop();

                    }

                }

            };

        }


        private void Watcher_Renamed(object sender, System.IO.RenamedEventArgs e)

        {

            Log($"{e.ChangeType}, File: {e.FullPath}, Old File: {e.OldFullPath}");

        }


        private void Watcher_Deleted(object sender, System.IO.FileSystemEventArgs e)

        {

            Log($"{e.ChangeType}, File: {e.FullPath}");

        }


        private void Watcher_Created(object sender, System.IO.FileSystemEventArgs e)

        {

            Log($"{e.ChangeType}, File: {e.FullPath}");

            timer.Start();

        }


        private void Watcher_Changed(object sender, System.IO.FileSystemEventArgs e)

        {

            filePath = e.FullPath;

            Log($"{e.ChangeType}, File: {filePath}, Length: {new System.IO.FileInfo(filePath).Length}");

        }


        private void Timer_Tick(object sender, EventArgs e)

        {

            throw new NotImplementedException();

        }


        private void Log(string str)

        {

            this.Dispatcher.Invoke(() =>

            {

                txt.Text += str + "\r\n";

            });

        }


        const int ERROR_SHARING_VIOLATION = 32;

        const int ERROR_LOCK_VIOLATION = 33;

        private bool IsFileLocked(string file)

        {

            //check that problem is not in destination file

            if (File.Exists(file) == true)

            {

                FileStream stream = null;

                try

                {

                    stream = File.Open(file, FileMode.Open, FileAccess.ReadWrite, FileShare.None);

                }

                catch (Exception ex2)

                {

                    //_log.WriteLog(ex2, "Error in checking whether file is locked " + file);

                    int errorCode = Marshal.GetHRForException(ex2) & ((1 << 16) - 1);

                    if ((ex2 is IOException) && (errorCode == ERROR_SHARING_VIOLATION || errorCode == ERROR_LOCK_VIOLATION))

                    {

                        return true;

                    }

                }

                finally

                {

                    if (stream != null)

                        stream.Close();

                }

            }

            return false;

        }

    }

}



Posted by CoolDragon
2017. 6. 21. 16:44

https://developer.xamarin.com/guides/xamarin-forms/user-interface/controls/layouts/


Posted by CoolDragon
2017. 6. 21. 16:43

https://developer.xamarin.com/guides/xamarin-forms/user-interface/controls/pages/



Posted by CoolDragon
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. 4. 15. 13:46

각 Device별로 설정값을 저장하는 위치가 다르다.

이 것을 아래의 플러그인이 손쉽게 해당 설정값에 접근하기 쉽게 도와준다.

Settings Plugin for Xamarin and Windows



CrossSettings.Current.AddOrUpdateValue<string>("Key", "Value");

string value = CrossSettings.Current.GetValueOrDefault<string>("Key", "Unknown");


Posted by CoolDragon
2017. 4. 15. 13:10

1. install Xamarin

  - Download

  - 인스톨 후 Xamarin Studio를 실행 > 메뉴에서 Account를 선택 후 계정 생성


2. Install Emulator

  아래 필요한 에뮬레이터를 설치한다.

  - android-player

  - BlueStacks

  - Genymotion

  - Andy

Posted by CoolDragon