Ejemplo n.º 1
0
        internal static string GenerateFileName(string name)
        {
            string tempFold;

            // Create temp directory
            try
            {
                tempFold = GlobalSettings.CreateTempFolder();
            }
            catch
            {
                MessageBox.Show("Something went wrong creating the temporary folder to store the graph.",
                                "Error");
                return(null);
            }

            // Assemble download path
            return(tempFold + name);
        }
Ejemplo n.º 2
0
        private void TreeViewItem_OnItemSelected(object sender, RoutedEventArgs e)
        {
            var tree = sender as TreeView;

            // ... Determine type of SelectedItem.
            if (tree.SelectedItem is TreeViewItem)
            {
                // Do nothing
            }

            // Else if it's the child element
            else if (tree.SelectedItem is string)
            {
                List <string> keysList = allPaths.Keys.ToList();

                string path = null;

                // get path from name of the file selected by the user
                foreach (string k in keysList)
                {
                    if (k.Contains(tree.SelectedItem.ToString()))
                    {
                        path = k;
                    }
                }

                // Instantiate web client to download file
                WebClient wc = new WebClient();

                // Get file's uri from dictionary using path/key
                string uri = allPaths[path];


                string tempFold;

                // Create temp directory
                try
                {
                    tempFold = GlobalSettings.CreateTempFolder();
                }
                catch
                {
                    MessageBox.Show("Something went wrong creating the temporary folder to store the graph.",
                                    "Error");
                    return;
                }

                // Assemble download path
                string fName = tempFold + tree.SelectedItem.ToString();

                // Download file locally
                try
                {
                    wc.DownloadFile(uri, fName);
                }
                catch (WebException)
                {
                    MessageBox.Show("Sorry, I couldn't find that file.", "Web Exception");
                    return;
                }
                catch
                {
                    MessageBox.Show("Ooops, something went wrong.", "Error");
                    return;
                }
                // Notify user but don't block process in case user doesn't close window
                AutoClosingMessageBox.Show("Downloaded (temporarily)! Opening now...", "Success!", 2000);

                // Pass path to downloaded file to main Dynamo method
                toOpen = fName;
                // And close window
                Close();
            }
        }