Esempio n. 1
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;
        }
Esempio n. 2
0
        private void SaveWebResourcesToDisk(IEnumerable<TreeNode> nodes, bool withRoot = false)
        {
            var fbd = new CustomFolderBrowserDialog(true, false);

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

            if (fbd.ShowDialog() == DialogResult.OK)
            {
                Properties.Settings.Default.LastFolderUsed = fbd.FolderPath;
                Properties.Settings.Default.Save();
                foreach (var node in nodes)
                {
                    if (node.Tag != null && ((WebResource)node.Tag).WebResourceEntity != null)
                    {
                        var webResource = ((WebResource)node.Tag).WebResourceEntity;

                        if (webResource.Contains("content") && webResource["content"].ToString().Length > 0)
                        {
                            string[] partPath = webResource["name"].ToString().Split('/');
                            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);
                                }
                            }

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

                            byte[] bytes = Convert.FromBase64String(webResource["content"].ToString());
                            File.WriteAllBytes(path, bytes);

                            ((WebResource) node.Tag).FilePath = path;
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        private void LoadWebResourcesToolStripMenuItem1Click(object sender, EventArgs e)
        {
            try
            {
                // Let the user decides where to find files
                // Let the user decides where to find files
                var fbd = new CustomFolderBrowserDialog(true);

                if (!string.IsNullOrEmpty(currentFolderForFiles))
                {
                    fbd.FolderPath = currentFolderForFiles;
                }

                if (fbd.ShowDialog() == DialogResult.OK)
                {
                    var extensionsToLoad = fbd.ExtensionsToLoad;
                    currentFolderForFiles = fbd.FolderPath;
                    tvWebResources.Nodes.Clear();
                    invalidFilenames = new List<string>();

                    var di = new DirectoryInfo(fbd.FolderPath);

                    foreach (DirectoryInfo diChild in di.GetDirectories("*_", SearchOption.TopDirectoryOnly))
                    {
                        if (WebResource.IsInvalidName(diChild.Name))
                        {
                            invalidFilenames.Add(diChild.FullName);
                            continue;
                        }

                        var rootFolderNode = new TreeNode(diChild.Name) { ImageIndex = 0, Tag = diChild.FullName };

                        tvWebResources.Nodes.Add(rootFolderNode);

                        TreeViewHelper.CreateFolderStructure(rootFolderNode, diChild, invalidFilenames, extensionsToLoad);
                    }

                    foreach (FileInfo fiChild in di.GetFiles("*.*", SearchOption.TopDirectoryOnly))
                    {
                        if (fiChild.Extension.Length == 0)
                        {
                            invalidFilenames.Add(fiChild.FullName);
                            continue;
                        }

                        if (WebResource.IsInvalidName(fiChild.Name) || !WebResource.ValidExtensions.Contains(fiChild.Extension.Remove(0, 1).ToLower()))
                        {
                            invalidFilenames.Add(fiChild.FullName);
                            continue;
                        }

                        if (extensionsToLoad.Contains(fiChild.Extension))
                        {
                            TreeViewHelper.CreateWebResourceNode(fiChild, tvWebResources);
                        }
                    }

                    tvWebResources.ExpandAll();
                    tvWebResources.TreeViewNodeSorter = new NodeSorter();
                    tvWebResources.Sort();

                    tsbClear.Visible = true;

                    if (invalidFilenames.Count > 0)
                    {
                        var errorDialog = new InvalidFileListDialog(invalidFilenames)
                        {
                            StartPosition =
                                FormStartPosition.CenterParent
                        };
                        errorDialog.ShowDialog(this);
                    }
                }
            }
            catch (Exception error)
            {
                MessageBox.Show(this, "Error while loading web resources: " + error.Message, "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void SaveWebResourcesToDisk(IEnumerable<WebResource> resources, bool withRoot = false)
        {
            var fbd = new CustomFolderBrowserDialog(true, false);

            if (!string.IsNullOrEmpty(currentFolderForFiles))
            {
                fbd.FolderPath = currentFolderForFiles;
            }

            if (fbd.ShowDialog() == DialogResult.OK)
            {
                currentFolderForFiles = fbd.FolderPath;
                Options.Instance.Save();
                foreach (var resource in resources)
                {
                    if (resource.Entity != null)
                    {
                        var resourceEntity = resource.Entity;

                        if (resourceEntity.GetAttributeValue<string>("content").Length > 0)
                        {
                            string[] partPath = resourceEntity.GetAttributeValue<string>("name").Split('/');
                            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);
                                    }
                                }
                            }

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

                            byte[] bytes = Convert.FromBase64String(resourceEntity["content"].ToString());
                            File.WriteAllBytes(path, bytes);

                            resource.FilePath = path;
                        }
                    }
                }
            }
        }
        private void TsmiLoadWebResourcesFromDiskClick(object sender, EventArgs e)
        {
            try
            {
                // Let the user decides where to find files
                var fbd = new CustomFolderBrowserDialog(true);

                if (!string.IsNullOrEmpty(currentFolderForFiles))
                {
                    fbd.FolderPath = currentFolderForFiles;
                }

                if (fbd.ShowDialog() == DialogResult.OK)
                {
                    currentFolderForFiles = fbd.FolderPath;
                    Options.Instance.Save();

                    var invalidFilenames = webresourceTreeView1.LoadWebResourcesFromDisk(fbd.FolderPath, fbd.ExtensionsToLoad);

                    if (invalidFilenames.Count > 0)
                    {
                        var errorDialog = new InvalidFileListDialog(invalidFilenames)
                        {
                            StartPosition =
                                FormStartPosition.CenterParent
                        };
                        errorDialog.ShowDialog(this);
                    }
                }
            }
            catch (Exception error)
            {
                MessageBox.Show(this, "Error while loading web resources: " + error.Message, Resources.MessageBox_ErrorTitle,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }