public void Test_01_Construction()
		{
			FileFilters filter1 = new FileFilters("Word Documents (*.doc)|*.doc");
			Assert.IsTrue(filter1.Count == 1);
			Assert.IsTrue(filter1.GetDescription(0) == "Word Documents (*.doc)");
			Assert.IsTrue(filter1.GetFilter(0) == "*.doc");
			Assert.IsTrue(filter1[0] != null, "Failed to create the regular expression for the filter");
			Assert.IsTrue(((Regex)filter1[0]).ToString() == @".+\.doc$");

			FileFilters filter2 = new FileFilters("Excel Document (*.xls)|*.xls|Word Documents (*.doc)|*.doc|All Files(*.*)|*.*");
			Assert.IsTrue(filter2.Count == 3);

			Assert.IsTrue(filter2.GetDescription(0) == "Excel Document (*.xls)");
			Assert.IsTrue(filter2.GetFilter(0) == "*.xls");
			Assert.IsTrue(filter2[0] != null, "Failed to create the regular expression for the filter");
			Assert.IsTrue(((Regex)filter2[0]).ToString() == @".+\.xls$");

			Assert.IsTrue(filter2.GetDescription(1) == "Word Documents (*.doc)");
			Assert.IsTrue(filter2.GetFilter(1) == "*.doc");
			Assert.IsTrue(filter2[1] != null, "Failed to create the regular expression for the filter");
			Assert.IsTrue(((Regex)filter2[1]).ToString() == @".+\.doc$");

			Assert.IsTrue(filter2.GetDescription(2) == "All Files(*.*)");
			Assert.IsTrue(filter2.GetFilter(2) == "*.*");
			Assert.IsTrue(filter2[2] != null, "Failed to create the regular expression for the filter");
			Assert.IsTrue(((Regex)filter2[2]).ToString() == @".+");
		}
        protected void DeleteFile_Click(object sender, EventArgs e)
        {
            FileInfo file = GetFile();

            if (FileFilters.IsDeletable(file.Name))
            {
                try
                {
                    file.Delete();
                    ActionMessage.Text = "The file " + file.Name + " was deleted";
                    ActionMessage.Type = StatusType.Success;

                    DownloadButton.Visible = false;
                    EditButton.Visible     = false;
                    DeleteButton.Visible   = false;
                }
                catch (Exception ex)
                {
                    Log.Error("FileBrowser", "The file {0} could not be deleted\n\nReason: {1}", file.FullName, ex.Message);

                    ActionMessage.Text = "The file " + file.Name + " could not be deleted";
                    ActionMessage.Type = StatusType.Error;
                }
            }
        }
Exemple #3
0
            public async Task RequestsCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new FilesClient(connection);

                var filters = new FileFilters
                {
                    PageSize  = 1,
                    PageCount = 1,
                    StartPage = 0,
                };

                await client.GetAll(filters);

                Received.InOrder(async() =>
                {
                    await connection.GetAll <File>(
                        Arg.Is <Uri>(u => u.ToString() == "files"),
                        Arg.Is <Dictionary <string, string> >(d => d.Count == 0),
                        Arg.Is <ApiOptions>(o => o.PageSize == 1 &&
                                            o.PageCount == 1 &&
                                            o.StartPage == 0)
                        );
                });
            }
        public bool IsMatch(string name, string path, ItemType type)
        {
            if (PathFilters.Any(reg => reg.IsMatch(path)))
            {
                return(true);
            }

            if (CommonFilters.Any(reg => reg.IsMatch(name)))
            {
                return(true);
            }

            if (type == ItemType.File)
            {
                return(FileFilters.Any(reg => reg.IsMatch(name)));
            }
            else if (type == ItemType.Directory)
            {
                return(DirectoryFilters.Any(reg => reg.IsMatch(name)));
            }
            else
            {
                return(false);
            }
        }
 public void DeleteFileFilterEvent(object sender, SelectionChangedEventArgs e)
 {
     if (e.AddedItems.Count > 0)
     {
         FileFilters.Remove(( FilterItem )e.AddedItems[0]);
     }
 }
        public bool IsMatch(FileSystemInfo itemInfo)
        {
            string path = itemInfo.FullName;

            if (PathFilters.Any(reg => reg.IsMatch(path)))
            {
                return(true);
            }

            string name = itemInfo.Name;

            if (CommonFilters.Any(reg => reg.IsMatch(name)))
            {
                return(true);
            }

            if (itemInfo is FileInfo fileInfo)
            {
                return(FileFilters.Any(reg => reg.IsMatch(name)));
            }
            else if (itemInfo is DirectoryInfo directoryInfo)
            {
                return(DirectoryFilters.Any(reg => reg.IsMatch(name)));
            }
            else
            {
                return(false);
            }
        }
Exemple #7
0
        public IEnumerable <FileInfo> GetFilesFromDirectory(string directoryPath, FileFilters filters = null)
        {
            if (string.IsNullOrWhiteSpace(directoryPath) || !Directory.Exists(directoryPath))
            {
                throw new Exception("Invalid directory path");
            }

            var filesQuery = Directory.GetFiles(directoryPath, filters.SearchPattern, filters.SearchOption)
                             .Select(f => new FileInfo(f));

            if (filters.DateFilterType != DateFilterType.None)
            {
                filesQuery = filters.DateFilterType == DateFilterType.Older
                    ? filesQuery.Where(f => f.CreationTime < filters.DateFilter)
                    : filters.DateFilterType == DateFilterType.Newer
                        ? filesQuery.Where(f => f.CreationTime > filters.DateFilter)
                        : filesQuery.Where(f => f.CreationTime == filters.DateFilter);
            }


            if (filters.NamesToIgnore != null)
            {
                filesQuery = filesQuery.Where(f => !filters.NamesToIgnore.Contains(f.Name));
            }

            return(filesQuery.ToList());
        }
        public void Test_04_FileNameMatching_FilterFromDeltaView( )
        {
            string filterString = "Documents (*.docx;*.doc;*.pdf;*.rtf;*.txt)|*.docx; *.doc; *.pdf; *.rtf; *.txt|All files (*.*)|*.*||";
            FileFilters filter = new FileFilters( filterString );
            filter.SelectedIndex = 0;

            Assert.IsTrue( filter.Match( "test.doc" ), "Filter failed to recognize test.doc" );
            Assert.IsTrue( filter.Match( "c:\test.doc" ), "Filter failed to recognize c:\test.doc" );
            Assert.IsTrue( filter.Match( "c:\folder\test.doc" ), "Filter failed to recognize c:\folder\test.doc" );
            Assert.IsTrue( filter.Match( "test.DoC" ), "Filter failed to recognize test.DoC" );
            Assert.IsTrue( filter.Match( "http://somewhere/test.doc" ), "Filter failed to recognize http://somewhere/test.doc" );
            Assert.IsTrue( filter.Match( "http://somewhere/deeper/test.doc" ), "Filter failed to recognize http://somewhere/deeper/test.doc" );
            Assert.IsTrue( filter.Match( "test.doc.doc.doc" ), "Filter failed to recognize test.doc.doc.doc" );
            Assert.IsTrue( filter.Match( "test.xls.doc.doc" ), "Filter failed to recognize test.xls.doc.doc" );
            Assert.IsTrue( filter.Match( "test.doc.xls.doc" ), "Filter failed to recognize test.doc.xls.doc" );
            Assert.IsTrue(filter.Match( TestServerInfo.CombineUrlWithSPServer("/sites/dev/TestDocs/172172v1.doc")), string.Format("Filter failed to recognize {0}/sites/dev/TestDocs/172172v1.doc", TestServerInfo.SPTestServerAddr));

            Assert.IsFalse( filter.Match( "test.xls" ), "Incorrecly matched test.xls on a .doc filter" );
            Assert.IsFalse( filter.Match( "test.doc.xls" ), "Incorrecly matched test.doc.xls on a .doc filter" );
            Assert.IsFalse( filter.Match( "test" ), "Incorrecly matched 'test' on a .doc filter" );
            Assert.IsFalse( filter.Match( "http://test.xls" ), "Incorrecly matched http://test.xls on a .doc filter" );
            Assert.IsFalse( filter.Match( "http://test.doc.xls" ), "Incorrecly matched http://test.doc.xls on a .doc filter" );
            Assert.IsFalse( filter.Match( "" ), "Incorrecly matched a blank string on a .doc filter" );
            Assert.IsFalse( filter.Match( null ), "Incorrecly matched a null to a .doc filter" );
        }
        public void ImportTexSrtAnim()
        {
            OpenFileDialog ofd = new OpenFileDialog();

            if (IsWiiU)
            {
                ofd.Filter = FileFilters.GetFilter(typeof(FSHU), MaterialAnimation.AnimationType.TextureSrt);
            }
            else
            {
                ofd.Filter = FileFilters.FMAA;
            }
            ofd.Multiselect = true;

            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            BFRESGroupNode group = null;

            if (IsWiiU)
            {
                group = GetOrCreateFolder <FSHU>(MaterialAnimation.AnimationType.TextureSrt);
            }
            else
            {
                group = GetOrCreateFolder <FMAA>(MaterialAnimation.AnimationType.TextureSrt);
            }

            group.Import(ofd.FileNames, GetResFile(), GetResFileU());
            AddFolder(group);
        }
Exemple #10
0
        /// <summary>
        /// Return the file filter depending of the given value
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        private static string GetFileFilter(FileFilters filter)
        {
            switch (filter)
            {
            case FileFilters.Bmp:
                return(FilterBmp);

            case FileFilters.Images:
                return(FilterImage);

            case FileFilters.Jpeg:
                return(FilterJpeg);

            case FileFilters.Mtl:
                return(FilterMtl);

            case FileFilters.Obj:
                return(FilterObj);

            case FileFilters.Png:
                return(FilterPng);

            case FileFilters.Smd:
                return(FilterSmd);

            case FileFilters.Wrl:
                return(FilterWrl);

            case FileFilters.None:
            default:
                break;
            }
            return(string.Empty);
        }
Exemple #11
0
        private static IReadOnlyDictionary <string, IReadOnlyList <string> > GetSaveFileDialogFilters()
        {
            IReadOnlyList <FileFilterModel> fileFilters =
                FileFilters.GetFileFiltersByFilterTypes(new[] { FileFilterType.Text });

            return(fileFilters.ToDictionary(x => x.FilterName, y => y.Filters));
        }
Exemple #12
0
        static FileFilters makeDefaultFileFilters()
        {
            var ret = new FileFilters();

            ret.Add(makeFileFilter("*.sln"));
            return(ret);
        }
Exemple #13
0
        private string GetSubfileExtensions(bool IsExporting)
        {
            switch (Type)
            {
            case BRESGroupType.Models: return(FileFilters.GetFilter(typeof(FMDL), null, IsExporting));

            case BRESGroupType.Textures: return(FileFilters.GetFilter(typeof(FTEX), null, IsExporting));

            case BRESGroupType.SkeletalAnim: return(FileFilters.GetFilter(typeof(FSKA), null, IsExporting));

            case BRESGroupType.MaterialAnim: return(FileFilters.GetFilter(typeof(FMAA), null, IsExporting));

            case BRESGroupType.ShaderParamAnim: return(FileFilters.GetFilter(typeof(FSHU), null, IsExporting));

            case BRESGroupType.ColorAnim: return(FileFilters.GetFilter(typeof(FSHU), MaterialAnimation.AnimationType.Color, IsExporting));

            case BRESGroupType.TexSrtAnim: return(FileFilters.GetFilter(typeof(FSHU), MaterialAnimation.AnimationType.TextureSrt, IsExporting));

            case BRESGroupType.TexPatAnim: return(FileFilters.GetFilter(typeof(FTXP), MaterialAnimation.AnimationType.ShaderParam, IsExporting));

            case BRESGroupType.BoneVisAnim: return(FileFilters.GetFilter(typeof(FVIS), null, IsExporting));

            case BRESGroupType.MatVisAnim: return(FileFilters.GetFilter(typeof(FVIS), null, IsExporting));

            case BRESGroupType.ShapeAnim: return(FileFilters.GetFilter(typeof(FSHA), null, IsExporting));

            case BRESGroupType.SceneAnim: return(FileFilters.GetFilter(typeof(FSCN), null, IsExporting));

            case BRESGroupType.Embedded: return(FileFilters.GetFilter(typeof(ExternalFileData), null, IsExporting));

            default: return("All files(*.*)|*.*");
            }
        }
Exemple #14
0
        public virtual UploadBoxBuilder Filters(Action <FileFilters> action)
        {
            FileFilters fileFilters = new FileFilters();

            action(fileFilters);
            base.Component.filters = fileFilters;
            return(this);
        }
Exemple #15
0
        protected virtual void createFilesList()
        {
            IEnumerable <FileInfo> files =
                Destinations[SOURCE_DIRECTORY_TYPE_NAME].GetFiles();

            Files = files.Where(file =>
                                FileFilters.Any(filter => filter.isMatch(file)));
        }
Exemple #16
0
		public void Test_02_WithMultipleMasks()
		{
			FileFilters filter1 = new FileFilters("Word & Excel (*.doc,*.xls)|*.doc,*.xls");
			Assert.IsTrue(filter1.Count == 1);
			Assert.IsTrue(filter1.GetDescription(0) == "Word & Excel (*.doc,*.xls)");
			Assert.IsTrue(filter1.GetFilter(0) == "*.doc,*.xls");
			Assert.IsTrue(filter1[0] != null, "Failed to create the regular expression for the filter");
			Assert.IsTrue(((Regex)filter1[0]).ToString() == @"(.+\.doc$)|(.+\.xls$)");
		}
        protected void DownloadFile_Click(object sender, EventArgs e)
        {
            FileInfo fi = GetFile();

            if (FileFilters.IsDownloadable(fi.Name))
            {
                Context.Response.AppendHeader("content-disposition", "attachment; filename=" + fi.Name);

                Context.Response.ContentType = Util.GetMapping(fi.Name);
                Context.Response.WriteFile(fi.FullName);
                Context.Response.End();
            }
        }
Exemple #18
0
            public async Task ReturnsCorrectCountWithoutStart()
            {
                var pipedrive = Helper.GetAuthenticatedClient();

                var filters = new FileFilters
                {
                    PageSize  = 3,
                    PageCount = 1
                };

                var files = await pipedrive.File.GetAll(filters);

                Assert.Equal(3, files.Count);
            }
Exemple #19
0
        public void ExportToFolder(string outFolder, string imageExtension, string modelExtension)
        {
            if (!Directory.Exists(outFolder))
            {
                Directory.CreateDirectory(outFolder);
            }

            List <string> directChildrenExportedPaths = new List <string>();

            foreach (ResourceNode entry in Children)
            {
                if (entry is ARCNode)
                {
                    ((ARCNode)entry).ExtractToFolder(Path.Combine(outFolder, (entry.Name == null || entry.Name.Contains("<Null>", StringComparison.InvariantCultureIgnoreCase)) ? "Null" : entry.Name), imageExtension, modelExtension);
                }
                else if (entry is BRRESNode)
                {
                    ((BRRESNode)entry).ExportToFolder(Path.Combine(outFolder, (entry.Name == null || entry.Name.Contains("<Null>", StringComparison.InvariantCultureIgnoreCase)) ? "Null" : entry.Name), imageExtension, modelExtension);
                }
                else if (entry is U8Node)
                {
                    ((U8Node)entry).ExtractToFolder(Path.Combine(outFolder, (entry.Name == null || entry.Name.Contains("<Null>", StringComparison.InvariantCultureIgnoreCase)) ? "Null" : entry.Name), imageExtension, modelExtension);
                }
                else if (entry is U8FolderNode)
                {
                    ((U8FolderNode)entry).ExportToFolder(Path.Combine(outFolder, (entry.Name == null || entry.Name.Contains("<Null>", StringComparison.InvariantCultureIgnoreCase)) ? "Null" : entry.Name), imageExtension, modelExtension);
                }
                else
                {
                    if (entry.WorkingSource.Length == 0)
                    {
                        continue;
                    }

                    string ext  = FileFilters.GetDefaultExportAllExtension(entry.GetType());
                    string path = Path.Combine(outFolder, entry.Name + ext);

                    if (directChildrenExportedPaths.Contains(path))
                    {
                        throw new Exception($"There is more than one node underneath {this.Name} with the name {entry.Name}.");
                    }
                    else
                    {
                        directChildrenExportedPaths.Add(path);
                        entry.Export(path);
                    }
                }
            }
        }
Exemple #20
0
 /* Private methods */
 private void OpenFile(EventHandler <TextChangedEventArgs> textChanged)
 {
     using (var ofd = new OpenFileDialog {
         Title = @"Select a file to open"
     })
     {
         ofd.Filter = FileFilters.GetFilters();
         if (ofd.ShowDialog(_tabStrip.Parent) == DialogResult.Cancel)
         {
             return;
         }
         var info = new FileInfo(ofd.FileName);
         CreateTab(textChanged, info);
     }
 }
Exemple #21
0
        /// <summary>
        /// Open the Save File Browser Dialog with the given settings
        /// </summary>
        /// <param name="filter">Type of files to filter</param>
        /// <param name="defaultFileName">Default filename</param>
        /// <param name="defaultExt">Default extension</param>
        /// <param name="initialDirectory">Intitial directory</param>
        /// <returns>Return the path of the file to save, null if none</returns>
        public static string SaveFileDialog(FileFilters filter, string defaultFileName, string defaultExt, string initialDirectory = "")
        {
            switch (filter)
            {
            case FileFilters.Bsp:
                return(SaveFileDialog(filterBsp, defaultFileName, defaultExt, titleBspOutput, initialDirectory));

            case FileFilters.Zip:
                return(SaveFileDialog(filterZip, defaultFileName, defaultExt, titleBspOutput, initialDirectory));

            case FileFilters.None:
            default:
                break;
            }
            return(SaveFileDialog(string.Empty, defaultFileName, defaultExt, string.Empty, initialDirectory));
        }
        private void SetFileList(DirectoryInfo di)
        {
            var files     = di.GetFiles();
            var the_Files = new List <FileInfo>();

            foreach (FileInfo fi in files)
            {
                if (FileFilters.IsValidFile(fi.Name))
                {
                    the_Files.Add(fi);
                }
            }

            if (the_Files.Count > 0)
            {
                the_Files.Sort(delegate(FileInfo f1, FileInfo f2) { return(Comparer <string> .Default.Compare(f1.Name, f2.Name)); });
                int half = the_Files.Count / 2 + the_Files.Count % 2;

                var left  = new List <AFile>();
                var right = new List <AFile>();

                for (int i = 0; i < the_Files.Count; i++)
                {
                    AFile af = new AFile();
                    af.Name    = the_Files[i].Name;
                    af.Path    = Request.QueryString["path"] ?? "";
                    af.OnClick = string.IsNullOrEmpty(OnClientFileClickedFunction)
                                                             ? ""
                                                             : "return select('" + GetJavaScriptUrl(the_Files[i].FullName) + "');";

                    if (i + 1 <= half)
                    {
                        left.Add(af);
                    }
                    else
                    {
                        right.Add(af);
                    }
                }

                LeftFiles.DataSource = left;
                LeftFiles.DataBind();

                RightFiles.DataSource = right;
                RightFiles.DataBind();
            }
        }
Exemple #23
0
        public void ReplaceFromFolder(string inFolder)
        {
            DirectoryInfo dir = new DirectoryInfo(inFolder);

            FileInfo[]      files = dir.GetFiles();
            DirectoryInfo[] dirs;
            foreach (ARCEntryNode entry in Children)
            {
                if (entry is ARCNode)
                {
                    dirs = dir.GetDirectories(entry.Name);
                    if (dirs.Length > 0)
                    {
                        ((ARCNode)entry).ReplaceFromFolder(dirs[0].FullName);
                        continue;
                    }
                }
                else if (entry is BRRESNode)
                {
                    dirs = dir.GetDirectories(entry.Name);
                    if (dirs.Length > 0)
                    {
                        ((BRRESNode)entry).ReplaceFromFolder(dirs[0].FullName);
                        continue;
                    }
                    else
                    {
                        ((BRRESNode)entry).ReplaceFromFolder(inFolder);
                        continue;
                    }
                }
                else
                {
                    string ext = FileFilters.GetDefaultExportAllExtension(entry.GetType());
                    foreach (FileInfo info in files)
                    {
                        if (info.Extension.Equals(ext, StringComparison.OrdinalIgnoreCase) && info.Name.Equals(entry.Name + ext, StringComparison.OrdinalIgnoreCase))
                        {
                            entry.Replace(info.FullName);
                            break;
                        }
                    }
                }
            }
        }
Exemple #24
0
 private string SaveFileAs(FaTabStripItem f)
 {
     using (var sfd = new SaveFileDialog {
         Title = string.Format(@"Select the filename to save {0} as...", f.Title)
     })
     {
         sfd.Filter      = FileFilters.GetFilters();
         sfd.FileName    = Path.GetFileNameWithoutExtension(f.Title);
         sfd.FilterIndex = FileFilters.GetExtensionIndex(string.Format("*{0}", Path.GetExtension(f.Title)));
         if (sfd.ShowDialog(_tabStrip.Parent) == DialogResult.Cancel)
         {
             return(string.Empty);
         }
         var fileName = sfd.FileName;
         f.Tag = fileName;
         System.Diagnostics.Debug.Print(fileName);
         return(fileName);
     }
 }
        private void SetFileDetails(FileInfo fi)
        {
            FileViews.SetActiveView(FileDetails);

            FileDetailsLastModified.Text = fi.LastWriteTime.ToLongDateString() + " " +
                                           fi.LastWriteTime.ToShortTimeString();
            if (FileFilters.IsLinkable(fi.Name))
            {
                FileDetailsName.Text        = fi.Name;
                FileDetailsName.NavigateUrl = "~/" + (Request.QueryString["path"] ?? "") + "/" + fi.Name;
            }
            else
            {
                FileDetailsName.Visible = false;
                FileDetailsText.Text    = fi.Name;
            }

            DownloadButton.Visible = FileFilters.IsDownloadable(fi.Name);
            EditButton.Visible     = FileFilters.IsEditable(fi.Name);
            DeleteButton.Visible   = FileFilters.IsDeletable(fi.Name);

            if (fi.Extension == ".dll")
            {
                Assembly assembly = Assembly.LoadFile(fi.FullName);
                FileDetailsAssemblyVersion.Text = assembly.GetName().Version.ToString();
            }
            else
            {
                assemblyLI.Visible = false;
            }

            if (FileFilters.IsVersionable(fi.Name))
            {
                FileDetailsRevision.Text = (VersionStore.CurrentVersion(fi) == 0 ? 1 : VersionStore.CurrentVersion(fi)).ToString();
            }
            else
            {
                FileDetailsRevision.Text = "n.a.";
                revsionLI.Visible        = false;
            }

            FileDetailsSize.Text = fi.Length.ToString("0,0") + " kB";
        }
Exemple #26
0
        /// <summary>
        /// Open the File Browser Dialog and return the path of the selected file, null if none
        /// </summary>
        /// <param name="filter">Filter for the file selection</param>
        /// <returns></returns>
        public static string OpenFileDialog(FileFilters filter)
        {
            switch (filter)
            {
            case FileFilters.Bsp:
                return(OpenFileDialog(filterBsp, titleBspInput));

            case FileFilters.BspZipExe:
                return(OpenFileDialog(filterBspZipExe, titleBspZipExe));

            case FileFilters.GameinfoTxt:
                return(OpenFileDialog(filterGameinfoTxt, titleGameinfoTxt));

            case FileFilters.None:
            default:
                break;
            }
            return(OpenFileDialog(string.Empty, string.Empty));
        }
Exemple #27
0
        void ReadFilters(out DirFilters dirFilters, out FileFilters fileFilters)
        {
            dirFilters  = makeDefaultDirFilters();
            fileFilters = makeDefaultFileFilters();
            try
            {
                var fname = Path.Combine(_rootPath, FiltersFilename);
                if (!File.Exists(fname))
                {
                    return;
                }

                var text = File.ReadAllText(fname);
                using (var json = JsonDocument.Parse(text))
                {
                    var         root = json.RootElement;
                    JsonElement dirs;
                    if (root.TryGetProperty("dirs", out dirs))
                    {
                        var edirs = dirs.EnumerateArray();
                        dirFilters = new DirFilters();
                        foreach (var d in edirs)
                        {
                            dirFilters.Add(d.GetString());
                        }
                    }
                    JsonElement files;
                    if (root.TryGetProperty("files", out files))
                    {
                        var efiles = files.EnumerateArray();
                        fileFilters = new FileFilters();
                        foreach (var f in efiles)
                        {
                            fileFilters.Add(makeFileFilter(f.GetString()));
                        }
                    }
                }
            }
            catch
            {
            }
        }
Exemple #28
0
        public void ExtractToFolder(string outFolder)
        {
            if (!Directory.Exists(outFolder))
            {
                Directory.CreateDirectory(outFolder);
            }

            List <string> directChildrenExportedPaths = new List <string>();

            foreach (ARCEntryNode entry in Children)
            {
                if (entry is ARCNode)
                {
                    ((ARCNode)entry).ExtractToFolder(Path.Combine(outFolder, entry.Name));
                }
                else if (entry is BRRESNode)
                {
                    ((BRRESNode)entry).ExportToFolder(Path.Combine(outFolder, entry.Name));
                }
                else
                {
                    if (entry.WorkingSource.Length == 0)
                    {
                        continue;
                    }

                    string ext  = FileFilters.GetDefaultExportAllExtension(entry.GetType());
                    string path = Path.Combine(outFolder, entry.Name + ext);

                    if (directChildrenExportedPaths.Contains(path))
                    {
                        throw new Exception($"There is more than one node underneath {this.Name} with the name {entry.Name}.");
                    }
                    else
                    {
                        directChildrenExportedPaths.Add(path);
                        entry.Export(path);
                    }
                }
            }
        }
        protected void SaveFile_Click(object sender, EventArgs e)
        {
            FileInfo fi = GetFile();

            if (FileFilters.IsEditable(fi.Name) && FileFilters.IsValidFile(fi.Name))
            {
                try
                {
                    bool isversioned = FileFilters.IsVersionable(fi.Name);

                    if (isversioned && VersionStore.CurrentVersion(fi) == 0)
                    {
                        VersionStore.VersionFile(fi);
                    }

                    using (StreamWriter sw = new StreamWriter(fi.FullName, false))
                    {
                        sw.Write(EditBox.Text);
                        sw.Close();
                    }

                    if (isversioned)
                    {
                        fi = GetFile();
                        VersionStore.VersionFile(fi);

                        version = VersionStore.CurrentVersion(fi).ToString();

                        SetVersioning(fi.FullName);
                    }

                    EditMessage.Text = "<strong>" + fi.Name + "</strong> was successfully updated.";
                    EditMessage.Type = StatusType.Success;
                }
                catch (Exception ex)
                {
                    EditMessage.Text = "Your file could not be updated. \n\n Reason: " + ex.Message;
                    EditMessage.Type = StatusType.Error;
                }
            }
        }
Exemple #30
0
		public void Test_03_FileNameMatching()
		{
			FileFilters filter = new FileFilters("Word (*.doc)|*.doc|Excel (*.xls)|*.xls|All(*.*)|*.*");
			filter.SelectedIndex = 0;
			Assert.IsTrue(filter.Match("test.doc"), "Filter failed to recognize test.doc");
			Assert.IsTrue(filter.Match("c:\test.doc"), "Filter failed to recognize c:\test.doc");
			Assert.IsTrue(filter.Match("c:\folder\test.doc"), "Filter failed to recognize c:\folder\test.doc");
			Assert.IsTrue(filter.Match("test.DoC"), "Filter failed to recognize test.DoC");
			Assert.IsTrue(filter.Match("http://somewhere/test.doc"), "Filter failed to recognize http://somewhere/test.doc");
			Assert.IsTrue(filter.Match("http://somewhere/deeper/test.doc"), "Filter failed to recognize http://somewhere/deeper/test.doc");
			Assert.IsTrue(filter.Match("test.doc.doc.doc"), "Filter failed to recognize test.doc.doc.doc");
			Assert.IsTrue(filter.Match("test.xls.doc.doc"), "Filter failed to recognize test.xls.doc.doc");
			Assert.IsTrue(filter.Match("test.doc.xls.doc"), "Filter failed to recognize test.doc.xls.doc");
            Assert.IsTrue(filter.Match(TestServerInfo.CombineUrlWithSPServer("/sites/dev/TestDocs/172172v1.doc")), string.Format("Filter failed to recognize {0}/sites/dev/TestDocs/172172v1.doc",TestServerInfo.SPTestServerAddr));
			
            Assert.IsFalse(filter.Match("test.xls"), "Incorrecly matched test.xls on a .doc filter");
			Assert.IsFalse(filter.Match("test.doc.xls"), "Incorrecly matched test.doc.xls on a .doc filter");
			Assert.IsFalse(filter.Match("test"), "Incorrecly matched 'test' on a .doc filter");
			Assert.IsFalse(filter.Match("http://test.xls"), "Incorrecly matched http://test.xls on a .doc filter");
			Assert.IsFalse(filter.Match("http://test.doc.xls"), "Incorrecly matched http://test.doc.xls on a .doc filter");
			Assert.IsFalse(filter.Match(""), "Incorrecly matched a blank string on a .doc filter");
			Assert.IsFalse(filter.Match(null), "Incorrecly matched a null to a .doc filter");
		}
Exemple #31
0
            public async Task ReturnsDistinctInfosBasedOnStartPage()
            {
                var pipedrive = Helper.GetAuthenticatedClient();

                var startFilters = new FileFilters
                {
                    PageSize  = 1,
                    PageCount = 1
                };

                var firstPage = await pipedrive.File.GetAll(startFilters);

                var skipStartFilters = new FileFilters
                {
                    PageSize  = 1,
                    PageCount = 1,
                    StartPage = 1
                };

                var secondPage = await pipedrive.File.GetAll(skipStartFilters);

                Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
            }
Exemple #32
0
        /// <summary>
        /// Adds filters below the specified xml element.
        /// </summary>
        /// <param name="root">Filter root element.</param>
        private void AddFiltersFromXml(IFilterChain chain, XElement root)
        {
            if (root == null)
            {
                return;
            }
            foreach (var filterElement in root.Elements().Where(element => element.Name.LocalName == XML_ELEMENT_FILTER))
            {
                var fileFilter = FileFilters.CreateFileFilter(filterElement);
                if (fileFilter != null)
                {
                    // Configure filter mode
                    IInvertibleFileFilter invertibleFileFilter = fileFilter as IInvertibleFileFilter;
                    if (invertibleFileFilter != null)
                    {
                        var modeAttribute = filterElement.Attribute(XML_ATTRIBUTE_MODE);
                        if (modeAttribute != null)
                        {
                            FileFilterMode mode;
                            if (Enum.TryParse <FileFilterMode>(modeAttribute.Value, true, out mode))
                            {
                                invertibleFileFilter.Mode = mode;
                            }
                        }
                    }

                    // Add sub filters, if the filter is a filter chain.
                    IFilterChain filterChain = fileFilter as IFilterChain;
                    if (filterChain != null)
                    {
                        AddFiltersFromXml(filterChain, filterElement);
                    }

                    chain.Filters.Add(fileFilter);
                }
            }
        }
        private void SetFileEdit(FileInfo fi)
        {
            FileViews.SetActiveView(FileEditor);

            if (!FileFilters.IsEditable(fi.Name))
            {
                Log.Error("FileBrowser", "Invalid attempt to edit the file {0} which is not editable", fi.FullName);
                throw new Exception("File does not exist");
            }

            EditFileName.Text        = fi.Name;
            EditFileName.NavigateUrl = "~/" + (Request.QueryString["path"] ?? "") + "/" + fi.Name;

            if (!IsPostBack)
            {
                using (StreamReader sr = new StreamReader(fi.FullName))
                {
                    EditBox.Text = sr.ReadToEnd();
                    sr.Close();
                }

                SetVersioning(fi.FullName);
            }
        }
Exemple #34
0
 /// <summary>
 /// Open the File Browser Dialog and return the list of selected files, null if none
 /// </summary>
 /// <param name="filter"></param>
 /// <returns></returns>
 public static string[] OpenFilesDialog(FileFilters filter)
 {
     return(OpenFilesDialog(GetFileFilter(filter)));
 }
Exemple #35
0
        public void Test_07_TestGetExtension( )
        {
            FileFilters filter = new FileFilters( );
            string filters = ( "Word (*.doc)|*.doc|WordX (*.docx)|*.docx||" );
            filter.PopulateCollections( filters );

            Assert.AreEqual( ".doc", filter.GetExtension( 0 ) );
            Assert.AreEqual( ".docx", filter.GetExtension( 1 ) );
            Assert.AreEqual( "should throw IndexOutOfRangeExctption", filter.GetExtension( 2 ) );
        }
Exemple #36
0
        public void Test_05_TestGetValue( )
        {
            FileFilters filter = new FileFilters( );
            string filters = ( "Documents (*.docx; *.doc)|*.docx; *.doc||" );

            int pos = 0;
            string description = filter.GetValue( ref pos, filters );
            Assert.AreEqual( "Documents (*.docx; *.doc)", description );

            string value = filter.GetValue( ref pos, filters);
            Assert.AreEqual( "*.docx; *.doc", value );
        }
Exemple #37
0
        public void Test_06_TestCreateRegularExpression( )
        {
            FileFilters filter = new FileFilters( );
            string filters = ( "Documents (*.docx; *.doc)|*.docx; *.doc||" );
            filter.PopulateCollections( filters );

            filter.CreateRegularExpressions( );
            Regex regex = filter[ 0 ];
            Assert.AreEqual( @"(.+\.docx$)|(.+\.doc$)", regex.ToString( ) );
        }