private void UpdateFolderFromDisk(MyPluginControl plugin)
        {
            if (string.IsNullOrEmpty(plugin.contextFolderNode.FolderPath))
            {
                var result = MessageBox.Show(plugin,
                                             @"This folder node is not synced with a local folder. Would you like to choose one?", @"Question",
                                             MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (result == DialogResult.Yes)
                {
                    var fbd = new CustomFolderBrowserDialog(tv.OrganizationMajorVersion, true, false)
                    {
                        Text = @"Local folder"
                    };
                    if (fbd.ShowDialog(plugin) == DialogResult.OK)
                    {
                        plugin.contextFolderNode.FolderPath = fbd.FolderPath;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
            }

            var invalidFileNames = new List <string>();

            plugin.tv.RefreshFolderNodeContent(plugin.contextFolderNode, invalidFileNames, null);
            plugin.ShowInvalidFiles(invalidFileNames);
        }
        private void SaveToDisk(IEnumerable <Webresource> resources, bool withRoot = false)
        {
            var fbd = new CustomFolderBrowserDialog(true, false);

            if (!string.IsNullOrEmpty(Settings.Instance.LastFolderUsed))
            {
                fbd.FolderPath = Settings.Instance.LastFolderUsed;
            }

            if (fbd.ShowDialog() == DialogResult.OK)
            {
                Settings.Instance.LastFolderUsed = fbd.FolderPath;
                Settings.Instance.Save();

                foreach (var resource in resources)
                {
                    string[] partPath = resource.Name.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                    string   path     = fbd.FolderPath;

                    if (withRoot)
                    {
                        for (int i = 0; i < partPath.Length - 1; i++)
                        {
                            path = Path.Combine(path, partPath[i]);

                            if (!Directory.Exists(path))
                            {
                                Directory.CreateDirectory(path);
                            }
                        }
                    }

                    if (resource.Node.Parent is FolderNode fldNode)
                    {
                        fldNode.FolderPath = path;
                        fldNode.Synced     = true;
                    }

                    path = Path.Combine(path, partPath[partPath.Length - 1]);

                    if (resource.Content?.Length > 0)
                    {
                        byte[] bytes = Convert.FromBase64String(resource.Content);
                        File.WriteAllBytes(path, bytes);
                    }
                    else
                    {
                        if (File.Exists(path))
                        {
                            File.Delete(path);
                        }
                        File.Create(path).Dispose();
                    }

                    resource.FilePath = path;
                }
            }
        }
 private void importChartsFromFolderToolStripMenuItem_Click(object sender, EventArgs e)
 {
     var cfbDialog = new CustomFolderBrowserDialog(true) { FolderPath = currentFolder };
     if (cfbDialog.ShowDialog(ParentForm) == DialogResult.OK)
     {
         currentFolder = cfbDialog.FolderPath;
         ExecuteMethod(ProcessFiles, new DirectoryInfo(currentFolder).GetFiles("*.xml").Select(f => f.FullName).ToList());
     }
 }
        private void LoadFromDisk()
        {
            try
            {
                // Let the user decides where to find files
                var fbd = new CustomFolderBrowserDialog(true);

                if (!string.IsNullOrWhiteSpace(Settings.Instance.LastFolderUsed) && Directory.Exists(Settings.Instance.LastFolderUsed))
                {
                    fbd.FolderPath = Settings.Instance.LastFolderUsed;
                }

                if (fbd.ShowDialog() == DialogResult.OK)
                {
                    Settings.Instance.LastFolderUsed = fbd.FolderPath;
                    Settings.Instance.Save();

                    if (fbd.FolderPath.EndsWith("\\"))
                    {
                        fbd.FolderPath = fbd.FolderPath.Substring(0, fbd.FolderPath.Length - 1);
                    }

                    CloseOpenedContents();

                    var invalidFilenames = new List <string>();
                    WebresourcesCache.Clear();
                    tv.DisplayWaitingForUpdatePanel();
                    var resources = Webresource.RetrieveFromDirectory(this, fbd.FolderPath, fbd.ExtensionsToLoad, invalidFilenames, ConnectionDetail?.OrganizationMajorVersion ?? -1);

                    tv.DisplayNodes(resources, null, Settings.Instance.ExpandAllOnLoadingResources);

                    if (invalidFilenames.Count > 0)
                    {
                        if (ifnd == null || ifnd.IsDisposed)
                        {
                            ifnd = new InvalidFilenamesDialog();
                        }

                        ifnd.InvalidFiles = invalidFilenames;
                        ifnd.Show(dpMain, DockState.DockBottom);
                    }
                    else if (ifnd != null && !ifnd.IsDisposed)
                    {
                        ifnd.InvalidFiles = invalidFilenames;
                    }
                }
            }
            catch (Exception error)
            {
                MessageBox.Show(this, $@"An error occured while loading webresources from disk: {error.Message}", @"Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 5
0
        private void tsbExportCharts_Click(object sender, EventArgs e)
        {
            var chartsToExport = lvCharts.CheckedItems.Cast <ListViewItem>().Select(c => (Entity)c.Tag).ToList();

            if (chartsToExport.Count > 0)
            {
                try
                {
                    var cfbDialog = new CustomFolderBrowserDialog(false)
                    {
                        FolderPath = currentFolder
                    };
                    if (cfbDialog.ShowDialog(ParentForm) == DialogResult.OK)
                    {
                        currentFolder = cfbDialog.FolderPath;

                        foreach (var chart in chartsToExport)
                        {
                            var doc = new XDocument(
                                new XElement("visualization",
                                             new XElement("visualizationid", chart.Id.ToString("B")),
                                             new XElement("name", chart.GetAttributeValue <string>("name")),
                                             new XElement("description", chart.GetAttributeValue <string>("description")),
                                             new XElement("primaryentitytypecode", chart.GetAttributeValue <string>("primaryentitytypecode")),
                                             new XElement("datadescription", XElement.Parse(chart.GetAttributeValue <string>("datadescription"))),
                                             new XElement("presentationdescription", XElement.Parse(chart.GetAttributeValue <string>("presentationdescription"))),
                                             new XElement("isdefault", chart.GetAttributeValue <bool>("isdefault"))
                                             ));

                            var filename = string.Format("{0}{1}.xml",
                                                         chart.GetAttributeValue <string>("name"),
                                                         chart.LogicalName == "savedqueryvisualization" ? "" : "_personal");

                            doc.Save(Path.Combine(cfbDialog.FolderPath, filename));
                        }

                        if (MessageBox.Show(ParentForm, "Would you like to open destination folder?", "Question",
                                            MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            Process.Start(cfbDialog.FolderPath);
                        }
                    }
                }
                catch (Exception error)
                {
                    MessageBox.Show(ParentForm, error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 6
0
        internal static string UpdateNodesContentWithLocalFiles(TreeNodeCollection nodes)
        {
            var fbDialog = new CustomFolderBrowserDialog(true, false);

            if (fbDialog.ShowDialog() == DialogResult.OK)
            {
                var sBuilder = new StringBuilder();

                UpdateNodesContentWithLocalFiles(nodes, fbDialog.FolderPath, new DirectoryInfo(fbDialog.FolderPath).Name, sBuilder);

                if (sBuilder.Length == 0)
                {
                    sBuilder.AppendLine("No files were updated!");
                }

                return(string.Format("The following web resources have been updated with local files content:\r\n{0}", sBuilder.ToString()));
            }

            return(string.Empty);
        }