Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        //private void CanvasCreateResources(
        //    CanvasControl sender,
        //    CanvasCreateResourcesEventArgs args)
        //{
        //    Debug.WriteLine("CanvasCreateResources");
        //}

        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GenerateRandomGraphBtn_OnClick(
            Object sender,
            RoutedEventArgs e)
        {
            Debug.WriteLine("Generate button clicked");
            // generate the graph
            this.appCtx.CurrentGraph = GraphUtils.GenerateRandomGraph(this.appCtx);
            // update the appcontext graph state
            this.appCtx.CurrentGraphState = GraphState.New;
            // layout the graph
            //DrawingUtils.LayoutDGraphRandom(this.appCtx, this.MainDrawingCanvas, this.appCtx.DrawableEdges, this.appCtx.DrawableVertices);
            //this.MainDrawingCanvas.Invalidate();
            this.statusTextBlock.Text = "Random graph generated.";
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="file"></param>
        private async void LoadGraphFromFile(Windows.Storage.StorageFile file)
        {
            Windows.Storage.CachedFileManager.DeferUpdates(file);
            String jsonString = await Windows.Storage.FileIO.ReadTextAsync(file);

            Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file);

            if (status == Windows.Storage.Provider.FileUpdateStatus.Complete)
            {
                this.statusTextBlock.Text = string.Format("file {0} read", file.Name);

                UGraph loadedGraph = GraphUtils.JsonToGraph(jsonString);
                //ms.Close();
                this.appCtx.CurrentGraph = loadedGraph;
                // TODO: fire event to update graph;
                //DrawingUtils.LayoutDGraphRandom(this.appCtx, this.MainDrawingCanvas, this.appCtx.DrawableEdges, this.appCtx.DrawableVertices);
            }
            else
            {
                this.statusTextBlock.Text =
                    string.Format("file {0} not read", file.Name);
            }
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void SaveGraphToFileAsync(Object sender, RoutedEventArgs e)
        {
            String jsonString = GraphUtils.GraphToJson(this.appCtx.CurrentGraph);

            var savePicker = new Windows.Storage.Pickers.FileSavePicker
            {
                SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary
            };

            savePicker.FileTypeChoices.Add("JSON", new List <String>()
            {
                ".json"
            });
            savePicker.SuggestedFileName = "New Graph";
            Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync();

            if (file != null)
            {
                Windows.Storage.CachedFileManager.DeferUpdates(file);
                await Windows.Storage.FileIO.WriteTextAsync(file, jsonString);

                Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file);

                if (status == Windows.Storage.Provider.FileUpdateStatus.Complete)
                {
                    this.statusTextBlock.Text = "File" + file.Name + " saved.";
                }
                else
                {
                    this.statusTextBlock.Text = "File" + file.Name + " not saved.";
                }
            }
            else
            {
                this.statusTextBlock.Text = "Operation canceled.";
            }
        }