Example #1
0
        private async void appBarIconBtnPreview_Click(object sender, EventArgs e)
        {
            await Task.Delay(10);

            ApplicationBar.IsVisible      = false;
            LoadingProgressBar.Visibility = System.Windows.Visibility.Visible;
            LoadingText.Text = AppResources.MsgCreatingPreview;

            LockscreenData data = new LockscreenData(false)
            {
                BackgroundBitmap = GetCropImage(),
                DayList          = VsCalendar.GetCalendarOfMonth(DateTime.Now, DateTime.Now, true, true),
                LiveWeather      = SettingHelper.Get(Constants.WEATHER_LIVE_RESULT) as LiveWeather,
                Forecasts        = SettingHelper.Get(Constants.WEATHER_FORECAST_RESULT) as Forecasts
            };

            if ((bool)SettingHelper.Get(Constants.CALENDAR_SHOW_APPOINTMENT))
            {
                Appointments appointments = new Appointments();
                appointments.SearchCompleted += (s, se) =>
                {
                    VsCalendar.MergeCalendar(data.DayList, se.Results);
                    LockscreenHelper.RenderLayoutToBitmap(data);
                    DisplayPreview(data.BackgroundBitmap);
                };
                appointments.SearchAsync(data.DayList[7].DateTime, data.DayList[data.DayList.Count - 1].DateTime, null);
            }
            else
            {
                LockscreenHelper.RenderLayoutToBitmap(data);
                DisplayPreview(data.BackgroundBitmap);
            }
        }
Example #2
0
        /// <summary>
        /// Invoked when application execution is being suspended.  Application state is saved
        /// without knowing whether the application will be terminated or resumed with the contents
        /// of memory still intact.
        /// </summary>
        /// <param name="sender">The source of the suspend request.</param>
        /// <param name="e">Details about the suspend request.</param>
        private async void OnSuspending(object sender, SuspendingEventArgs e)
        {
            var deferral = e.SuspendingOperation.GetDeferral();
            await LockscreenHelper.ResetLockscreenImage();

            _sessionWatch?.Stop();
            BLogger.Logger?.Info("App suspended and session terminated. Session length: " + _sessionWatch.Elapsed.TotalMinutes);
            CoreWindowLogic.SaveSettings();
            //CoreWindowLogic.DisposeObjects();
            await Task.Delay(500);

            deferral.Complete();
        }
Example #3
0
        private async void OnCheckedLockscreen(object sender, RoutedEventArgs e)
        {
            if (ignoreCheckBoxEvents)
            {
                return;
            }

            if (MessageBoxResult.OK == MessageBox.Show(AppResources.MsgConfirmLockscreenUpdate, AppResources.Confirm, MessageBoxButton.OKCancel))
            {
                if (LockscreenSelector.ItemsSource != null && LockscreenSelector.ItemsSource.Count > 0)
                {
                    //락스크린 프로바이더가 아닌경우 설정 창 띄움.
                    var op = await LockscreenHelper.SetLockscreenProvider();

                    if (op == LockScreenRequestResult.Granted)
                    {
                        var exists = (LockscreenSelector.ItemsSource as ChameleonAlbum).Any(p =>
                        {
                            return((p as PhonePicture).CurrentLockscreen != null);
                        });

                        if (!exists)
                        {
                            await SelectLockscreen(LockscreenSelector.ItemsSource[0] as PhonePicture);
                        }

                        if (ScheduledActionService.Find(Constants.PERIODIC_TASK_NAME) == null)
                        {
                            StartPeriodicAgent();
                        }
                        SettingHelper.Set(Constants.LOCKSCREEN_USE_ROTATOR, true, true);
                    }
                    else
                    {
                        UseLockscreen.IsChecked = false;
                    }
                }
            }
            else
            {
                UseLockscreen.IsChecked = false;
                //이미지가 없고 활성화된 라이브타일이 없으면 스케쥴러 정저
                if (!ExistsActiveTile)
                {
                    RemoveAgent(Constants.PERIODIC_TASK_NAME);
                }
            }
        }
Example #4
0
        private void CreateEpisodeTile(TraktCalendarEpisode nextEpisode)
        {
            ShellTile appTile = ShellTile.ActiveTiles.First();

            if (appTile != null)
            {
                if (doesFileExist(nextEpisode.Show.tvdb_id + "background.jpg"))
                {
                    FlipTileData newTileData = new FlipTileData();
                    newTileData.BackContent = nextEpisode.Show.Title + ", " + nextEpisode.Episode.Season + "x" + nextEpisode.Episode.Number;
                    newTileData.BackTitle   = ((nextEpisode.Date.DayOfYear == DateTime.UtcNow.DayOfYear) ? ("Today, " + nextEpisode.Episode.FirstAiredAsDate.ToShortTimeString()) : (nextEpisode.Episode.FirstAiredAsDate.ToShortDateString()));


                    System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        copyImageToShellContent(nextEpisode.Show.tvdb_id + "background.jpg", nextEpisode.Show.tvdb_id);
                        LockscreenHelper.UpdateLockScreen("ms-appdata:///Local/" + nextEpisode.Show.tvdb_id + "background.jpg");
                        newTileData.BackgroundImage =
                            new Uri("isostore:/Shared/ShellContent/wptraktbg" + nextEpisode.Show.tvdb_id + ".jpg", UriKind.Absolute);
                        newTileData.WideBackgroundImage =
                            new Uri("isostore:/Shared/ShellContent/wptraktbg" + nextEpisode.Show.tvdb_id + ".jpg", UriKind.Absolute);
                        newTileData.SmallBackgroundImage = new Uri("isostore:/Shared/ShellContent/wptraktbg" + nextEpisode.Show.tvdb_id + ".jpg", UriKind.Absolute);
                        newTileData.WideBackContent      = nextEpisode.Show.Title + ", " + nextEpisode.Episode.Season + "x" + nextEpisode.Episode.Number + "\r\n" + nextEpisode.Episode.Title + "\r\n" + ((nextEpisode.Date.DayOfYear == DateTime.UtcNow.DayOfYear) ? ("Today, " + nextEpisode.Episode.FirstAiredAsDate.ToShortTimeString()) : (nextEpisode.Episode.FirstAiredAsDate.ToShortDateString())) + " ( " + nextEpisode.Show.Network + " )";
                        appTile.Update(newTileData);

                        NotifyComplete();
                    });
                }
                else
                {
                    FlipTileData newTileData = new FlipTileData();
                    newTileData.BackContent = nextEpisode.Show.Title + ", " + nextEpisode.Episode.Season + "x" + nextEpisode.Episode.Number;
                    newTileData.BackTitle   = ((nextEpisode.Date.DayOfYear == DateTime.UtcNow.DayOfYear) ? ("Today, " + nextEpisode.Episode.FirstAiredAsDate.ToShortTimeString()) : (nextEpisode.Episode.FirstAiredAsDate.ToShortDateString()));


                    newTileData.BackgroundImage      = new Uri("appdata:background.png");
                    newTileData.WideBackgroundImage  = new Uri("appdata:WideBackground.png");
                    newTileData.SmallBackgroundImage = new Uri("appdata:background.png");
                    newTileData.WideBackContent      = nextEpisode.Show.Title + ", " + nextEpisode.Episode.Season + "x" + nextEpisode.Episode.Number + "\r\n" + nextEpisode.Episode.Title + "\r\n" + ((nextEpisode.Date.DayOfYear == DateTime.UtcNow.DayOfYear) ? ("Today, " + nextEpisode.Episode.FirstAiredAsDate.ToShortTimeString()) : (nextEpisode.Episode.FirstAiredAsDate.ToShortDateString())) + " ( " + nextEpisode.Show.Network + " )";
                    appTile.Update(newTileData);


                    NotifyComplete();
                }
            }
        }
Example #5
0
        public LockscreenData(bool isWVGA)
        {
            Canvas     = new Canvas();
            IsWVGA     = isWVGA;
            FontRatio  = LockscreenHelper.GetFontSizeRatio(IsWVGA);
            FontWeight = (FontWeight)typeof(FontWeights).GetProperty(SettingHelper.GetString(Constants.LOCKSCREEN_FONT_WEIGHT)).GetValue(null);

            if (!UseBackgroundSeparation && Items.Length > 0)
            {
                BackgroundPanel = new Canvas()
                {
                    Opacity    = BackgroundOpacity,
                    Background = BackgroundBrush
                };
                Canvas.Children.Add(BackgroundPanel);
                //Canvas.Opacity = BackgroundOpacity;
                //Canvas.Background = BackgroundBrush;
            }
        }
Example #6
0
        private void OnLoadedLsIBTemplate(object sender, RoutedEventArgs e)
        {
            Grid grid = sender as Grid;
            LockscreenTemplateItem item = (grid.Parent as FrameworkElement).DataContext as LockscreenTemplateItem;

            //이미지를 폰의 비율에 맞게 변경
            Image  bgImg = grid.Children[0] as Image;
            double ratio = bgImg.RenderSize.Width / ResolutionHelper.CurrentResolution.Width;

            bgImg.Height = ratio * ResolutionHelper.CurrentResolution.Height;
            ((grid.Parent as Grid).Children[0] as TextBlock).Width = bgImg.Width;

            if (item.Id < (LockscreenBackgroundTemplatePicker.ItemsSource as List <LockscreenTemplateItem>).Count - 1)
            {
                Thickness margin = LockscreenHelper.GetDisplayAreaMargin(bgImg.RenderSize);
                Size      size   = LockscreenHelper.GetDisplayAreaSize(bgImg.RenderSize);
                margin.Right = margin.Left;

                Grid panel = grid.Children[1] as Grid;
                panel.VerticalAlignment   = System.Windows.VerticalAlignment.Top;
                panel.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                panel.Margin = margin;
                panel.Width  = size.Width;
                panel.Height = (panel.Width - panel.Margin.Left) / 2;

                //추가할 이미지의 가로 폭
                double imageWidth         = panel.Height;
                LockscreenItemInfo[] lsii = item.LockscreenItemInfos;
                bool useSeparation        = (bool)SettingHelper.Get(Constants.LOCKSCREEN_BACKGROUND_USE_SEPARATION);

                if (lsii.Length > 1 && !useSeparation)
                {
                    Canvas backPanel = new Canvas()
                    {
                        Background = new SolidColorBrush((SettingHelper.Get(Constants.LOCKSCREEN_BACKGROUND_COLOR) as ColorItem).Color),
                        Opacity    = (double)(int)SettingHelper.Get(Constants.LOCKSCREEN_BACKGROUND_OPACITY) / 100,
                        Width      = panel.Width,
                        Height     = panel.Height
                    };
                    panel.Children.Add(backPanel);
                }

                for (int i = 0; i < lsii.Length; i++)
                {
                    Thickness innerMargin = new Thickness(5);

                    if (lsii[i].RowSpan == 1)
                    {
                        switch (lsii[i].Row)
                        {
                        case 0: innerMargin.Bottom = 2.5; break;

                        case 1: innerMargin.Bottom = 2.5; break;

                        case 2: innerMargin.Top = 0; break;
                        }
                    }
                    if (lsii[i].RowSpan == 2)
                    {
                        if (lsii[i].Row == 1)
                        {
                            innerMargin.Top    = 2.5;
                            innerMargin.Bottom = 5;
                        }
                    }

                    if (lsii[i].ColSpan == 2)
                    {
                        panel.Width = imageWidth;
                    }
                    //템플렛 이미지를 생성하여 추가
                    Grid imgGrid = new Grid()
                    {
                        Margin = innerMargin
                    };

                    Border imgBorder = new Border()
                    {
                        Child = new Image()
                        {
                            Source = new BitmapImage(new Uri(string.Format("/Images/lockscreen/template.{0}.png", lsii[i].LockscreenItem.ToString().ToLower()), UriKind.Relative)),
                            Width  = imageWidth - innerMargin.Left - innerMargin.Right
                        }
                    };

                    Grid.SetRowSpan(imgGrid, lsii[i].RowSpan);
                    Grid.SetColumnSpan(imgGrid, lsii[i].ColSpan);
                    Grid.SetRow(imgGrid, lsii[i].Row);
                    Grid.SetColumn(imgGrid, lsii[i].Column);

                    imgGrid.Children.Add(imgBorder);
                    panel.Children.Add(imgGrid);

                    //분리선 사용인 경우 각각의 아이템에 배경을 입힌다.
                    if (lsii.Length == 1 || useSeparation)
                    {
                        if (lsii.Length == 1)
                        {
                            imgGrid.Margin = new Thickness(0);
                        }
                        imgGrid.Children.Insert(0, new Canvas()
                        {
                            Background = new SolidColorBrush((SettingHelper.Get(Constants.LOCKSCREEN_BACKGROUND_COLOR) as ColorItem).Color),
                            Opacity    = (double)(int)SettingHelper.Get(Constants.LOCKSCREEN_BACKGROUND_OPACITY) / 100,
                            Width      = imgGrid.Width,
                            Height     = imgGrid.Height
                        });
                    }
                }
            }

            DateTime now = DateTime.Now;
            string   dt  = now.ToShortTimeString();

            (grid.Children[2] as TextBlock).Text = now.ToString("h:mm");
            (grid.Children[3] as TextBlock).Text = now.ToString("dddd");
            (grid.Children[4] as TextBlock).Text = now.ToString("m").Replace(" ", "");
        }
Example #7
0
        private void SetLockscreenImage(ScheduledTask task, LockscreenData data)
        {
            try
            {
                bool isProvider = LockScreenManager.IsProvidedByCurrentApplication;

                if (isProvider)
                {
                    int itemCount = data.Items == null ? 0 : data.Items.Length;

                    //1. 이번에 변경할 파일을 알아야 한다. 그러기 위해서 먼저 현재 락스크린 파일명을 구한다.
                    Uri    lockscreenFileUri  = null;
                    string lockscreenFileName = null;

                    try
                    {
                        lockscreenFileUri = LockScreen.GetImageUri();
                    }
                    catch (Exception)
                    {
                        ShellToast toast = new ShellToast();
                        toast.Title   = AppResources.ApplicationTitle;
                        toast.Content = AppResources.MsgFailShortGetLockscreen;
                        toast.Show();
                        return;
                    }

                    if (lockscreenFileUri != null)
                    {
                        lockscreenFileName = lockscreenFileUri.ToString()
                                             .Replace(Constants.PREFIX_APP_DATA_FOLDER, string.Empty)
                                             .Replace(Constants.LOCKSCREEN_IMAGE_A_POSTFIX, Constants.LOCKSCREEN_IMAGE_POSTFIX)
                                             .Replace(Constants.LOCKSCREEN_IMAGE_B_POSTFIX, Constants.LOCKSCREEN_IMAGE_POSTFIX);
                    }

                    //2. 이번에 변경할 파일명을 구한다.
                    using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
                    {
                        if (!string.IsNullOrEmpty(lockscreenFileName))
                        {
                            lockscreenFileName = lockscreenFileName.Replace(Constants.LOCKSCREEN_IMAGE_POSTFIX, Constants.LOCKSCREEN_IMAGE_READY_POSTFIX);
                        }

                        var imgNames = from element in isoStore.GetFileNames()
                                       where element.Contains(Constants.LOCKSCREEN_IMAGE_READY_POSTFIX) &&
                                       element.CompareTo(lockscreenFileName) > 0
                                       orderby element ascending
                                       select element;

                        //이번에 업데이트 할 이미지 이름을 임시 저장
                        lockscreenFileName = imgNames.Any() ? imgNames.First() :
                                             isoStore.GetFileNames(string.Format("*{0}", Constants.LOCKSCREEN_IMAGE_READY_POSTFIX))[0];

                        using (IsolatedStorageFileStream sourceStream = isoStore.OpenFile(lockscreenFileName, FileMode.Open, FileAccess.Read))
                        {
                            data.BackgroundBitmap = BitmapFactory.New(0, 0).FromStream(sourceStream);
                        }

                        //3. 표시할 아이템들과 이미지를 합성한다. (이미지 리사이징 포함)
                        LockscreenHelper.RenderLayoutToBitmap(data);

                        GC.Collect();
                        System.Threading.Thread.Sleep(1500);
                        System.Diagnostics.Debug.WriteLine("이미지 생성 직후" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage);

                        //4. 새로운 이름으로 저장하기 위해 전환 논리를 이용하여 새로운 이름을 구한다.
                        if (lockscreenFileUri != null && lockscreenFileUri.ToString().EndsWith(Constants.LOCKSCREEN_IMAGE_A_POSTFIX))
                        {
                            lockscreenFileName = lockscreenFileName.Replace(Constants.LOCKSCREEN_IMAGE_READY_POSTFIX, Constants.LOCKSCREEN_IMAGE_B_POSTFIX);
                        }
                        else
                        {
                            lockscreenFileName = lockscreenFileName.Replace(Constants.LOCKSCREEN_IMAGE_READY_POSTFIX, Constants.LOCKSCREEN_IMAGE_A_POSTFIX);
                        }

                        //5. 새로운 이름으로 이미지를 저장
                        using (IsolatedStorageFileStream targetStream = isoStore.OpenFile(lockscreenFileName, FileMode.Create, FileAccess.Write))
                        {
                            data.BackgroundBitmap.SaveJpeg(targetStream, data.BackgroundBitmap.PixelWidth, data.BackgroundBitmap.PixelHeight, 0, 100);
                            //using (MemoryStream ms = new MemoryStream())
                            //{
                            //    data.BackgroundBitmap.SaveJpeg(ms, data.BackgroundBitmap.PixelWidth, data.BackgroundBitmap.PixelHeight, 0, 100);
                            //    System.Diagnostics.Debug.WriteLine("{0}x{1}", data.BackgroundBitmap.PixelWidth, data.BackgroundBitmap.PixelHeight);
                            //    byte[] readBuffer = new byte[4096];
                            //    int bytesRead = -1;
                            //    ms.Position = 0;
                            //    targetStream.Position = 0;

                            //    while ((bytesRead = ms.Read(readBuffer, 0, readBuffer.Length)) > 0)
                            //    {
                            //        targetStream.Write(readBuffer, 0, bytesRead);
                            //    }
                            //}
                        }

                        //6. 새로운 이미지로 락스크린 업데이트
                        LockScreen.SetImageUri(new Uri(string.Format("{0}{1}", Constants.PREFIX_APP_DATA_FOLDER, lockscreenFileName), UriKind.Absolute));
                        Uri newLockscreenFileUri = LockScreen.GetImageUri();

                        //7.변경이 정상적으로 이루어진 경우 기존 파일 삭제
                        if (newLockscreenFileUri.ToString() != lockscreenFileUri.ToString())
                        {
                            if (lockscreenFileUri.ToString().Contains(Constants.PREFIX_APP_DATA_FOLDER))
                            {
                                lockscreenFileName = lockscreenFileUri.ToString().Replace(Constants.PREFIX_APP_DATA_FOLDER, string.Empty);
                                if (isoStore.FileExists(lockscreenFileName))
                                {
                                    isoStore.DeleteFile(lockscreenFileName);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LoggingError("error case 3 : \n" + e.StackTrace);
            }

            // If debugging is enabled, launch the agent again in one minute.
#if DEBUG_AGENT
            ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(30));
            System.Diagnostics.Debug.WriteLine(Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage);

            /*
             * ShellToast toast = new ShellToast();
             * toast.Title = AppResources.ApplicationTitle;
             * toast.Content = AppResources.MsgSuccessChangeLockscreen;
             * toast.Show();
             */
#else
            IsolatedStorageSettings.ApplicationSettings[Constants.LAST_RUN_LOCKSCREEN] = DateTime.Now;
            IsolatedStorageSettings.ApplicationSettings.Save();
#endif
        }
Example #8
0
        private void SetLockscreen(PhonePicture picture, WriteableBitmap wb, Stream beforeImageStream)
        {
            string fileName     = picture.Name.Replace(Constants.LOCKSCREEN_IMAGE_POSTFIX, Constants.LOCKSCREEN_IMAGE_A_POSTFIX);
            Uri    currentImage = null;

            try
            {
                currentImage = LockScreen.GetImageUri();
            }
            catch (Exception)
            {
                MessageBox.Show(AppResources.MsgFailGetLockscreen);
                HideLoadingPanel();
                return;
            }

            if (currentImage != null && currentImage.ToString().EndsWith(Constants.LOCKSCREEN_IMAGE_A_POSTFIX))
            {
                fileName = picture.Name.Replace(Constants.LOCKSCREEN_IMAGE_POSTFIX, Constants.LOCKSCREEN_IMAGE_B_POSTFIX);
            }

            using (MemoryStream ms = new MemoryStream())
            {
                //축소/확대 가능한 이미지라면 축소/확대
                JpegHelper.Resize(wb, ms, ResolutionHelper.CurrentResolution, true);
                FileHelper.SaveImage(fileName, ms);

                LockscreenHelper.SetLockscreen(fileName, false, (result) =>
                {
                    if (result.AsyncState is string)
                    {
                        MessageBox.Show(AppResources.MsgFailChangeLockscreen);
                    }
                    else if (result.AsyncState is bool && (bool)result.AsyncState == true)
                    {
                        if (currentImage != null && currentImage.ToString().StartsWith(Constants.PREFIX_APP_DATA_FOLDER))
                        {
                            fileName = currentImage.ToString().Replace(Constants.PREFIX_APP_DATA_FOLDER, string.Empty);
                            FileHelper.RemoveImage(fileName);
                        }

                        for (int i = 0; i < LockscreenSelector.ItemsSource.Count; i++)
                        {
                            PhonePicture pic = (LockscreenSelector.ItemsSource as ChameleonAlbum)[i] as PhonePicture;
                            if (pic.CurrentLockscreen != null)
                            {
                                pic.CurrentLockscreen = null;
                                pic.Margin            = new Thickness();
                            }
                            //자기자신으로 변경한 경우 및 새롭게 변경된 아이템
                            if (pic.Guid.CompareTo(picture.Guid) == 0)
                            {
                                pic.CurrentLockscreen = currentLockscreenUri;
                                pic.Margin            = currentLockscreenMargin;
                            }
                        }

                        //표시항목들이 적용되지 않은 잘라내기가 수행된 이미지 데이터
                        if (picture.Warnning != null && beforeImageStream != null)
                        {
                            if (MessageBox.Show(AppResources.MsgEditedAutomatically, AppResources.Confirm, MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                            {
                                //ready 파일 저장
                                //락스크린용 이미지로 축소
                                WriteableBitmap rwb = JpegHelper.Resize(beforeImageStream, LockscreenHelper.Size, true);
                                using (MemoryStream rms = new MemoryStream())
                                {
                                    rwb.SaveJpeg(rms, rwb.PixelWidth, rwb.PixelHeight, 0, 100);
                                    FileHelper.SaveImage(picture.Name.Replace(Constants.LOCKSCREEN_IMAGE_POSTFIX, Constants.LOCKSCREEN_IMAGE_READY_POSTFIX), rms);
                                }

                                //상태 변경
                                picture.Warnning = null;
                                //경고 메세지 제어
                                bool isShowWarn = false;
                                foreach (PhonePicture pic in LockscreenSelector.ItemsSource as ChameleonAlbum)
                                {
                                    if (pic.Warnning != null)
                                    {
                                        isShowWarn = true;
                                        break;
                                    }
                                }
                                LockscreenEditWarnning = isShowWarn;

                                SetSchedulerChagendTime(false);
                                //MessageBox.Show(AppResources.MsgSuccessChangeLockscreen);
                            }
                        }
                        else
                        {
                            SetSchedulerChagendTime(false);
                            //MessageBox.Show(AppResources.MsgSuccessChangeLockscreen);
                        }

                        if (beforeImageStream != null)
                        {
                            //스트림 종료
                            beforeImageStream.Close();
                        }
                    }
                    HideLoadingPanel();
                });
            }
        }
Example #9
0
        private async Task SelectLockscreen(PhonePicture picture)
        {
            await Task.Run(async() =>
            {
                if (picture != null)
                {
                    try
                    {
                        var isProvider = LockScreenManager.IsProvidedByCurrentApplication;
                        var op         = isProvider ? LockScreenRequestResult.Granted : LockScreenRequestResult.Denied;

                        if (!isProvider)
                        {
                            // If you're not the provider, this call will prompt the user for permission.
                            // Calling RequestAccessAsync from a background agent is not allowed.
                            op = await LockScreenManager.RequestAccessAsync();
                        }

                        if (op == LockScreenRequestResult.Granted)
                        {
                            Dispatcher.BeginInvoke(() =>
                            {
                                //로딩 패널 띄움
                                ShowLoadingPanel(AppResources.MsgApplyingLockscreen);

                                using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
                                {
                                    using (IsolatedStorageFileStream sourceStream = isoStore.OpenFile(picture.Name, FileMode.Open, FileAccess.Read))
                                    {
                                        WriteableBitmap wb = BitmapFactory.New(0, 0).FromStream(sourceStream);
                                        Size rSize         = ResolutionHelper.CurrentResolution;
                                        MemoryStream ms    = null;

                                        LockscreenData data = new LockscreenData(false)
                                        {
                                            DayList          = VsCalendar.GetCalendarOfMonth(DateTime.Now, DateTime.Now, true, true),
                                            LiveWeather      = SettingHelper.Get(Constants.WEATHER_LIVE_RESULT) as LiveWeather,
                                            Forecasts        = SettingHelper.Get(Constants.WEATHER_FORECAST_RESULT) as Forecasts,
                                            BackgroundBitmap = wb.Crop(new Rect((wb.PixelWidth - rSize.Width) / 2, (wb.PixelHeight - rSize.Height) / 2, rSize.Width, rSize.Height))
                                        };

                                        //편집이 필요한 이미지라면 스트림 생성 및 이미지 복사
                                        if (picture.Warnning != null)
                                        {
                                            //메모리 스트림 생성 (close 처리는 SetLockscreen에서 한다.)
                                            ms = new MemoryStream();
                                            //잘라내기가 된 이미지를 스트림에 저장
                                            data.BackgroundBitmap.SaveJpeg(ms, data.BackgroundBitmap.PixelWidth, data.BackgroundBitmap.PixelHeight, 0, 100);
                                        }

                                        if ((bool)SettingHelper.Get(Constants.CALENDAR_SHOW_APPOINTMENT))
                                        {
                                            Appointments appointments     = new Appointments();
                                            appointments.SearchCompleted += (s, se) =>
                                            {
                                                VsCalendar.MergeCalendar(data.DayList, se.Results);
                                                LockscreenHelper.RenderLayoutToBitmap(data);
                                                SetLockscreen(picture, data.BackgroundBitmap, ms);
                                            };
                                            appointments.SearchAsync(data.DayList[7].DateTime, data.DayList[data.DayList.Count - 1].DateTime, null);
                                        }
                                        else
                                        {
                                            LockscreenHelper.RenderLayoutToBitmap(data);
                                            SetLockscreen(picture, data.BackgroundBitmap, ms);
                                        }
                                    }
                                }
                            });
                        }
                    }
                    catch (System.Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.ToString());
                    }
                }
            });
        }