151127 uwp study

Edit

151127 uwp study

황현동 노트북 uwp study
오늘의 uwp 스터디.
윈도우 스토어에 올려볼만한 좋은 유틸리티 아이디어가 생각났다.
그 준비과정…

File I/O

http://www.kunal-chowdhury.com/2012/11/win8dev-tutorial-windows-store-files-folders.html
샌드박스 내부의 디렉토리 즉 설치디렉토리 (Package.Current.InstalledLocation) 에서만 경로로 직접접근이 가능하고 그 외부라면 FilePicker를 사용해야 하는 것 같다. (아직 깊게 조사는 안해봤음.)
StorageFolder folder = Package.Current.InstalledLocation;

// ways to create new folder
folder.CreateFolderAsync("Demo Folder", CreationCollisionOption.FailIfExists);
folder.CreateFolderAsync("Demo Folder", CreationCollisionOption.GenerateUniqueName);
folder.CreateFolderAsync("Demo Folder", CreationCollisionOption.OpenIfExists);
folder.CreateFolderAsync("Demo Folder", CreationCollisionOption.ReplaceExisting);

// ways to get folder
folder.GetFolderAsync("Demo Folder");

// ways to create new file
folder.CreateFileAsync("Demo File.txt", CreationCollisionOption.OpenIfExists);
folder.CreateFileAsync("Demo File.txt", CreationCollisionOption.GenerateUniqueName);
folder.CreateFileAsync("Demo File.txt", CreationCollisionOption.OpenIfExists);
folder.CreateFileAsync("Demo File.txt", CreationCollisionOption.ReplaceExisting);

// ways to get file
folder.GetFileAsync("Demo File.txt");

// ways to get all files by search queries
folder.GetFilesAsync(CommonFileQuery.DefaultQuery);
folder.GetFilesAsync(CommonFileQuery.OrderByDate);
folder.GetFilesAsync(CommonFileQuery.OrderByMusicProperties);
folder.GetFilesAsync(CommonFileQuery.OrderByName);
folder.GetFilesAsync(CommonFileQuery.OrderBySearchRank);
folder.GetFilesAsync(CommonFileQuery.OrderByTitle);

// ways to delete a folder instance
folder.DeleteAsync(StorageDeleteOption.Default);
folder.DeleteAsync(StorageDeleteOption.PermanentDelete);

앱 수명주기

함수 시점 할일
OnLaunched 앱시작 초기 데이타 로딩
OnSuspending 앱종료, 앱비활성화 데이타 저장
OnLaunched 에서 초기데이타 로딩은 하던대로 하고,
OnSuspending 에서 데이타 저장하는 앞뒤로 앱 종료를 지연시키면서 저장시간을 벌어주는 녀석이 있는데 이 규칙을 잘 지켜야 한다. deferral.Complete();을 빼먹으면 저장하다말고 앱종료 될수도 있다.
private async void OnSuspending(object sender, SuspendingEventArgs e){
    var deferral = e.SuspendingOperation.GetDeferral();
    Debug.WriteLine("1");
    //TODO: 응용 프로그램 상태를 저장하고 백그라운드 작업을 모두 중지합니다.
    await Task.Delay(10 * 1000);
    Debug.WriteLine("2");
    deferral.Complete();
    Debug.WriteLine("3");
}
%23151127%20uwp%20study%0A%0A@%28%uD669%uD604%uB3D9%20%uB178%uD2B8%uBD81%29%5Buwp%7Cstudy%5D%0A%0A%5Btoc%5D%0A%0A%uC624%uB298%uC758%20uwp%20%uC2A4%uD130%uB514.%0A%uC708%uB3C4%uC6B0%20%uC2A4%uD1A0%uC5B4%uC5D0%20%uC62C%uB824%uBCFC%uB9CC%uD55C%20%uC88B%uC740%20%uC720%uD2F8%uB9AC%uD2F0%20%uC544%uC774%uB514%uC5B4%uAC00%20%uC0DD%uAC01%uB0AC%uB2E4.%20%0A%uADF8%20%uC900%uBE44%uACFC%uC815...%0A%0A%23%23File%20I/O%0Ahttp%3A//www.kunal-chowdhury.com/2012/11/win8dev-tutorial-windows-store-files-folders.html%0A%uC0CC%uB4DC%uBC15%uC2A4%20%uB0B4%uBD80%uC758%20%uB514%uB809%uD1A0%uB9AC%20%uC989%20%uC124%uCE58%uB514%uB809%uD1A0%uB9AC%20%28%60Package.Current.InstalledLocation%60%29%20%uC5D0%uC11C%uB9CC%20%uACBD%uB85C%uB85C%20%uC9C1%uC811%uC811%uADFC%uC774%20%uAC00%uB2A5%uD558%uACE0%20%uADF8%20%uC678%uBD80%uB77C%uBA74%20FilePicker%uB97C%20%uC0AC%uC6A9%uD574%uC57C%20%uD558%uB294%20%uAC83%20%uAC19%uB2E4.%20%28%uC544%uC9C1%20%uAE4A%uAC8C%20%uC870%uC0AC%uB294%20%uC548%uD574%uBD24%uC74C.%29%0A%0A%60%60%60csharp%0AStorageFolder%20folder%20%3D%20Package.Current.InstalledLocation%3B%0A%0A//%20ways%20to%20create%20new%20folder%0Afolder.CreateFolderAsync%28%22Demo%20Folder%22%2C%20CreationCollisionOption.FailIfExists%29%3B%0Afolder.CreateFolderAsync%28%22Demo%20Folder%22%2C%20CreationCollisionOption.GenerateUniqueName%29%3B%0Afolder.CreateFolderAsync%28%22Demo%20Folder%22%2C%20CreationCollisionOption.OpenIfExists%29%3B%0Afolder.CreateFolderAsync%28%22Demo%20Folder%22%2C%20CreationCollisionOption.ReplaceExisting%29%3B%0A%20%0A//%20ways%20to%20get%20folder%0Afolder.GetFolderAsync%28%22Demo%20Folder%22%29%3B%0A%20%0A//%20ways%20to%20create%20new%20file%0Afolder.CreateFileAsync%28%22Demo%20File.txt%22%2C%20CreationCollisionOption.OpenIfExists%29%3B%0Afolder.CreateFileAsync%28%22Demo%20File.txt%22%2C%20CreationCollisionOption.GenerateUniqueName%29%3B%0Afolder.CreateFileAsync%28%22Demo%20File.txt%22%2C%20CreationCollisionOption.OpenIfExists%29%3B%0Afolder.CreateFileAsync%28%22Demo%20File.txt%22%2C%20CreationCollisionOption.ReplaceExisting%29%3B%0A%20%0A//%20ways%20to%20get%20file%0Afolder.GetFileAsync%28%22Demo%20File.txt%22%29%3B%0A%20%0A//%20ways%20to%20get%20all%20files%20by%20search%20queries%0Afolder.GetFilesAsync%28CommonFileQuery.DefaultQuery%29%3B%0Afolder.GetFilesAsync%28CommonFileQuery.OrderByDate%29%3B%0Afolder.GetFilesAsync%28CommonFileQuery.OrderByMusicProperties%29%3B%0Afolder.GetFilesAsync%28CommonFileQuery.OrderByName%29%3B%0Afolder.GetFilesAsync%28CommonFileQuery.OrderBySearchRank%29%3B%0Afolder.GetFilesAsync%28CommonFileQuery.OrderByTitle%29%3B%0A%0A//%20ways%20to%20delete%20a%20folder%20instance%0Afolder.DeleteAsync%28StorageDeleteOption.Default%29%3B%0Afolder.DeleteAsync%28StorageDeleteOption.PermanentDelete%29%3B%0A%60%60%60%0A%0A%23%23%20%uC571%20%uC218%uBA85%uC8FC%uAE30%0Ahttps%3A//msdn.microsoft.com/ko-kr/library/windows/apps/mt243287%0A%uC544%uC8FC%20%uAC04%uB2E8%uD788%20%uC815%uB9AC%uD558%uBA74...%0A%0A%7C%20%uD568%uC218%20%7C%20%uC2DC%uC810%20%7C%20%uD560%uC77C%20%7C%0A%7C%20--------%20%7C%20--------%7C%20------%20%7C%0A%7C%20OnLaunched%20%7C%20%uC571%uC2DC%uC791%20%7C%20%uCD08%uAE30%20%uB370%uC774%uD0C0%20%uB85C%uB529%20%7C%0A%7C%20OnSuspending%20%7C%20%uC571%uC885%uB8CC%2C%20%uC571%uBE44%uD65C%uC131%uD654%20%7C%20%uB370%uC774%uD0C0%20%uC800%uC7A5%20%7C%0A%0AOnLaunched%20%uC5D0%uC11C%20%uCD08%uAE30%uB370%uC774%uD0C0%20%uB85C%uB529%uC740%20%uD558%uB358%uB300%uB85C%20%uD558%uACE0%2C%0AOnSuspending%20%uC5D0%uC11C%20%uB370%uC774%uD0C0%20%uC800%uC7A5%uD558%uB294%20%uC55E%uB4A4%uB85C%20%uC571%20%uC885%uB8CC%uB97C%20%uC9C0%uC5F0%uC2DC%uD0A4%uBA74%uC11C%20%uC800%uC7A5%uC2DC%uAC04%uC744%20%uBC8C%uC5B4%uC8FC%uB294%20%uB140%uC11D%uC774%20%uC788%uB294%uB370%20%uC774%20%uADDC%uCE59%uC744%20%uC798%20%uC9C0%uCF1C%uC57C%20%uD55C%uB2E4.%20%60deferral.Complete%28%29%3B%60%uC744%20%uBE7C%uBA39%uC73C%uBA74%20%uC800%uC7A5%uD558%uB2E4%uB9D0%uACE0%20%uC571%uC885%uB8CC%20%uB420%uC218%uB3C4%20%uC788%uB2E4.%0A%0A%60%60%60%0Aprivate%20async%20void%20OnSuspending%28object%20sender%2C%20SuspendingEventArgs%20e%29%0A%7B%0A%20%20%20%20var%20deferral%20%3D%20e.SuspendingOperation.GetDeferral%28%29%3B%0A%20%20%20%20Debug.WriteLine%28%221%22%29%3B%0A%20%20%20%20//TODO%3A%20%uC751%uC6A9%20%uD504%uB85C%uADF8%uB7A8%20%uC0C1%uD0DC%uB97C%20%uC800%uC7A5%uD558%uACE0%20%uBC31%uADF8%uB77C%uC6B4%uB4DC%20%uC791%uC5C5%uC744%20%uBAA8%uB450%20%uC911%uC9C0%uD569%uB2C8%uB2E4.%0A%20%20%20%20await%20Task.Delay%2810%20*%201000%29%3B%0A%20%20%20%20Debug.WriteLine%28%222%22%29%3B%0A%20%20%20%20deferral.Complete%28%29%3B%0A%20%20%20%20Debug.WriteLine%28%223%22%29%3B%0A%7D%0A%60%60%60

이 글은 Evernote에서 작성되었습니다. Evernote는 하나의 업무 공간입니다. Evernote를 다운로드하세요.

댓글