public async Task <CanvasProject> LoadCanvasProjectAsync(int canvasId)
        {
            CanvasProject returnValue = null;

            try
            {
                var objStorageHelper = new WinRtUtility.ObjectStorageHelper <CanvasProject>(WinRtUtility.StorageType.Local);
                returnValue = await objStorageHelper.LoadAsync(canvasId.ToString());
            }
            catch (Exception ex)
            {
                returnValue = null;
            }
            return(returnValue);
        }
 public async Task<bool> SaveCanvasProjectAsync(CanvasProject canvas)
 {
     bool returnValue = false;
     try
     {
         var objStorageHelper = new WinRtUtility.ObjectStorageHelper<CanvasProject>(WinRtUtility.StorageType.Local);
         await objStorageHelper.SaveAsync(canvas, canvas.Id.ToString());
         returnValue = true;
     }
     catch (Exception ex)
     {
         returnValue = false;
     }
     return returnValue;
 }
        public async Task <bool> SaveCanvasProjectAsync(CanvasProject canvas)
        {
            bool returnValue = false;

            try
            {
                var objStorageHelper = new WinRtUtility.ObjectStorageHelper <CanvasProject>(WinRtUtility.StorageType.Local);
                await objStorageHelper.SaveAsync(canvas, canvas.Id.ToString());

                returnValue = true;
            }
            catch (Exception ex)
            {
                returnValue = false;
            }
            return(returnValue);
        }
        private async Task GetDefaultDataAsync()
        {
            if (this._groups.Count != 0)
            {
                return;
            }

            Uri dataUri = new Uri("ms-appx:///DataModel/DefaultData.json");

            StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(dataUri);

            string jsonText = await FileIO.ReadTextAsync(file);

            JsonObject jsonObject = JsonObject.Parse(jsonText);
            JsonArray  jsonArray  = jsonObject["CanvasProjectsMRU"].GetArray();

            foreach (JsonValue groupValue in jsonArray)
            {
                JsonObject    groupObject = groupValue.GetObject();
                CanvasProject group       = new CanvasProject {
                    Id        = Convert.ToInt32(groupObject["Id"].GetString()),
                    Name      = groupObject["Name"].GetString(),
                    ImagePath = groupObject["ImagePath"].GetString(),
                    FilePath  = groupObject["FilePath"].GetString()
                };
                group.Pictures = new List <CanvasPicture>();

                foreach (JsonValue itemValue in groupObject["Pictures"].GetArray())
                {
                    JsonObject itemObject = itemValue.GetObject();
                    group.Pictures.Add(new CanvasPicture
                    {
                        Id              = Convert.ToInt32(itemObject["Id"].GetString()),
                        ImagePath       = itemObject["ImagePath"].GetString(),
                        Left            = itemObject["Left"].GetNumber(),
                        Top             = itemObject["Top"].GetNumber(),
                        Rotation        = itemObject["Rotation"].GetNumber(),
                        CanvasProjectId = group.Id
                    });
                }
                this.Groups.Add(group);
            }
        }
        private async Task GetDefaultDataAsync()
        {
            if (this._groups.Count != 0)
                return;

            Uri dataUri = new Uri("ms-appx:///DataModel/DefaultData.json");

            StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(dataUri);
            string jsonText = await FileIO.ReadTextAsync(file);
            JsonObject jsonObject = JsonObject.Parse(jsonText);
            JsonArray jsonArray = jsonObject["CanvasProjectsMRU"].GetArray();

            foreach (JsonValue groupValue in jsonArray)
            {
                JsonObject groupObject = groupValue.GetObject();
                CanvasProject group = new CanvasProject{ 
                    Id= Convert.ToInt32(groupObject["Id"].GetString()),
                    Name = groupObject["Name"].GetString(),
                    ImagePath = groupObject["ImagePath"].GetString(),
                    FilePath = groupObject["FilePath"].GetString()
                };
                group.Pictures = new List<CanvasPicture>();

                foreach (JsonValue itemValue in groupObject["Pictures"].GetArray())
                {
                    JsonObject itemObject = itemValue.GetObject();
                    group.Pictures.Add(new CanvasPicture
                    {
                        Id = Convert.ToInt32(itemObject["Id"].GetString()),
                        ImagePath = itemObject["ImagePath"].GetString(),
                        Left = itemObject["Left"].GetNumber(),
                        Top = itemObject["Top"].GetNumber(),
                        Rotation = itemObject["Rotation"].GetNumber(),
                        CanvasProjectId = group.Id
                    });
                }
                this.Groups.Add(group);
            }
        }
 /// <summary>
 /// Invoked when an item is clicked.
 /// </summary>
 /// <param name="sender">The GridView (or ListView when the application is snapped)
 /// displaying the item clicked.</param>
 /// <param name="e">Event data that describes the item clicked.</param>
 async void ItemView_ItemClick(object sender, ItemClickEventArgs e)
 {
     var project = ((CanvasProject)e.ClickedItem);
     if (project.Id == -1)
     {
         FileOpenPicker filePicker = new FileOpenPicker();
         filePicker.FileTypeFilter.Add(".png");
         filePicker.FileTypeFilter.Add(".jpg");
         filePicker.FileTypeFilter.Add(".jpeg");
         filePicker.ViewMode = PickerViewMode.Thumbnail;
         filePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
         filePicker.SettingsIdentifier = "imagePicker";
         filePicker.CommitButtonText = "Select Files for Collage";
         IReadOnlyCollection<StorageFile> files = await filePicker.PickMultipleFilesAsync();
         
         if(files.Count > 0)
         {
             project.ImagePath = files.First().Path;
             project = new CanvasProject
             {
                 Name = "NewCanvas.canvas",
                 FilePath = files.First().Path,
                 ImagePath = files.First().Path + ".canvasimage",
                 Id = -1
             };
             int count = 1;
             project.Pictures = new List<CanvasPicture>();
             foreach (var item in files)
             {
                 CanvasPicture pict = new CanvasPicture
                 {
                     Id = count++,
                     ImagePath = item.Path,
                     SourceFile = item
                 };
                 project.Pictures.Add(pict);
             }
         }                
     }
     
     this.Frame.Navigate(typeof(SplitPage), project);
 }
 private async Task BindImages(CanvasProject project)
 {
     collageCanvas.AllowDrop = true;
     Random degrees = new Random(5);
     int maxWidth = (int)Window.Current.Bounds.Width;
     int maxCols = (int)maxWidth / 300;
     int row = 0, col = 0;
     for (int i = 0; i < project.Pictures.Count; i++)
     {
         var canvasPicture = project.Pictures[i];
         Image image = new Image();
         using (var fileStream = await canvasPicture.SourceFile.OpenAsync(FileAccessMode.Read))
         {
             var sourceImage = new BitmapImage();
             sourceImage.SetSource(fileStream);
             image.Source = sourceImage;
             image.Tag = canvasPicture;
             image.Height = 300;
             image.Height = 200;
             image.Stretch = Stretch.Uniform;
             image.IsHitTestVisible = true;
             image.IsTapEnabled = true;
             TransformableContainer container = new TransformableContainer();
             container.Content = image;
             container.Transform.Rotation = degrees.Next(-15, 15);
             col = (col + 1 > maxCols) ? 0 : col + 1;
             row = (col + 1 > maxCols) && (i != 0) ? row + 1 : row;
             container.Transform.TranslateX = col * 300;
             container.Transform.TranslateY = row * 200;
             container.Transform.CenterX = 150;
             container.Transform.CenterY = 100;
             container.CanvasPicture = canvasPicture;
             collageCanvas.Children.Add(container);    
         }
     }
 }
        /// The methods provided in this section are simply used to allow
        /// NavigationHelper to respond to the page's navigation methods.
        /// 
        /// Page specific logic should be placed in event handlers for the  
        /// <see cref="GridCS.Common.NavigationHelper.LoadState"/>
        /// and <see cref="GridCS.Common.NavigationHelper.SaveState"/>.
        /// The navigation parameter is available in the LoadState method 
        /// in addition to page state preserved during an earlier session.

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            _project = (CanvasProject)e.Parameter;
            _navigationHelper.OnNavigatedTo(e);
            Task returnTask = BindImages(_project);
            returnTask.ContinueWith(_ => { });

            DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
            dataTransferManager.DataRequested += DataTransferManager_DataRequested;
        }