예제 #1
0
        public void Create_From_DirectoryInfo_Relative_Parent()
        {
            var sut = new SmartFolder(new DirectoryInfo(".."));

            sut.ToString("O").Should().Be("..");
            sut.ToString("G").Should().Be(new DirectoryInfo(Environment.CurrentDirectory).Parent.FullName + @"\");
        }
예제 #2
0
        public void Absolute_Returns_The_Folder_With_An_Absolute_Path_And_Expands_Variables()
        {
            var lhs = SmartFolder.FromEnvironmentVariable("temp");
            var rhs = lhs.ToAbsolute();

            rhs.ToString("O").Should().NotContain("%", "environment variables must be expanded");
        }
예제 #3
0
        public void A_Folder_With_And_Without_Trailing_Separator_Are_The_Same()
        {
            var lhs = new SmartFolder(@"C:\Windows\");
            var rhs = new SmartFolder(@"C:\Windows");

            lhs.Equals(rhs).Should().BeTrue();
        }
예제 #4
0
        public void Operator_MinMin_Moves_One_Directory_Up()
        {
            var sut = new SmartFolder(@"C:\Windows\Temp\");

            sut--;
            sut.ToString().Should().Be(@"C:\Windows\");
        }
예제 #5
0
        public void Equality_For_Relative_And_Absolute_Paths()
        {
            var lhs = new SmartFolder(".");
            var rhs = new SmartFolder(Environment.CurrentDirectory);

            lhs.Equals(rhs).Should().BeTrue();
        }
예제 #6
0
        public void ToString_With_R_Format_Returns_The_Relative_Path()
        {
            var sut = new SmartFolder("..");

            sut.ToString("R").Should().Be(@"..\");
            sut.ToString("G").Should().NotBe("..");
        }
예제 #7
0
        public void Create_Using_Environment_Variable()
        {
            var sut = SmartFolder.FromEnvironmentVariable("TEMP");

            sut.ToString("O").Should().Be("%TEMP%");
            sut.ToString("G").Should().Be(ExpandEnvironmentVariables("%TEMP%") + @"\");
        }
예제 #8
0
        public GenericContent FetchContent()
        {
            if (_fetchContent == null && !_fetchError)
            {
                if (!string.IsNullOrEmpty(Query))
                {
                    var sf = SmartFolder.GetRuntimeQueryFolder();
                    sf.Query = this.Query;

                    var c = Content.Create(sf);

                    c.ChildrenDefinition.EnableAutofilters    = this.EnableAutofilters;
                    c.ChildrenDefinition.EnableLifespanFilter = this.EnableLifespanFilter;
                    c.ChildrenDefinition.Skip = 0;
                    //c.ChildrenDefinition.Sort = this.ChildrenDefinition.Sort;
                    c.ChildrenDefinition.Top = 1;

                    try
                    {
                        if (c.Children != null && c.Children.Any())
                        {
                            _fetchContent = c.Children?.ToList()?.FirstOrDefault()?.ContentHandler as GenericContent;
                        }
                    }
                    catch (Exception ex)
                    {
                        _fetchError = true;
                    }
                }
            }
            return(_fetchContent);
        }
        protected override object GetModel()
        {
            SmartFolder sf = null;

            sf = Node.Load <SmartFolder>("/Root/System/RuntimeQuery");
            if (sf == null)
            {
                using (new SystemAccount())
                {
                    var systemFolder = Node.LoadNode("/root/system");
                    sf = new SmartFolder(systemFolder)
                    {
                        Name = "RuntimeQuery"
                    };
                    sf.Save();
                }
            }

            var c = ContentRepository.Content.Create(sf);

            sf.Query = ReplaceTemplates(this.QueryString);

            var oldc = base.GetModel() as ContentRepository.Content;

            if (oldc != null)
            {
                c.ChildrenQueryFilter   = oldc.ChildrenQueryFilter;
                c.ChildrenQuerySettings = oldc.ChildrenQuerySettings;
            }

            return(c);
        }
예제 #10
0
        public void Add_Sub_Path_By_Using_Add_Operator_With_String()
        {
            var sut = new SmartFolder(@"C:\");

            sut += "temp";
            sut.ToString().Should().Be(@"C:\temp\");
        }
예제 #11
0
        public void An_Environment_Variable_Is_Equal_To_The_Path_It_Resolves_To()
        {
            var lhs = SmartFolder.FromEnvironmentVariable("TEMP");
            var rhs = new SmartFolder(ExpandEnvironmentVariables("%TEMP%"));

            lhs.Equals(rhs).Should().BeTrue();
        }
예제 #12
0
        public void Add_Returns_The_Original_Path_When_The_Addition_Is_Empty()
        {
            var temp = new SmartFolder(@"C:\Temp\");
            var sut  = temp + string.Empty;

            sut.Should().Be(temp);
        }
예제 #13
0
        //====================================================================== Model

        protected override object GetModel()
        {
            var contextNode = GetContextNode();

            if (contextNode == null)
            {
                return(null);
            }

            var smartFolder = SmartFolder.GetRuntimeQueryFolder();

            smartFolder.Query = string.Format("+InTree:\"{0}\" +TypeIs:Workspace -TypeIs:(Blog Wiki)", contextNode.Path);

            var content = Content.Create(smartFolder);

            //Get base model as Content and use some of its children definition properties.
            //Do not override the whole ChildrenDefinition object here because SmartFolder
            //has its own special children definition override.
            var oldc = base.GetModel() as Content;

            if (oldc != null)
            {
                content.ChildrenDefinition.EnableAutofilters    = oldc.ChildrenDefinition.EnableAutofilters;
                content.ChildrenDefinition.EnableLifespanFilter = oldc.ChildrenDefinition.EnableLifespanFilter;
                content.ChildrenDefinition.Skip = oldc.ChildrenDefinition.Skip;
                content.ChildrenDefinition.Sort = oldc.ChildrenDefinition.Sort;
                content.ChildrenDefinition.Top  = oldc.ChildrenDefinition.Top;
            }

            return(content);
        }
예제 #14
0
        public void Add_Throws_Exception_When_The_Addition_Is_Null()
        {
            var    temp   = new SmartFolder(@"C:\Temp\");
            Action action = () => { var _ = temp + (string)null; };

            action.Should().Throw <ArgumentNullException>();
        }
예제 #15
0
        public void Add_Throws_Exception_When_The_Addition_Is_Absolute()
        {
            var    temp   = new SmartFolder(@"C:\Temp\");
            Action action = () => { var _ = temp + "C:"; };

            action.Should().Throw <ArgumentOutOfRangeException>();
        }
예제 #16
0
        public void Equality_Case_Sensitive_Or_Not_Can_Be_Influenced()
        {
            var lhs = new SmartFolder(@"C:\Windows\");
            var rhs = new SmartFolder(@"c:\windows");

            lhs.Equals(rhs, StringComparison.CurrentCultureIgnoreCase).Should().BeTrue();
            lhs.Equals(rhs, StringComparison.CurrentCulture).Should().BeFalse();
        }
예제 #17
0
        public void Ignore_Leading_Directory_Separator_Char()
        {
            var windows = new SmartFolder(@"C:\Windows\");
            var one     = windows + @"\Temp\";
            var other   = windows + "Temp";

            one.Should().Be(other);
        }
예제 #18
0
        public void Equality_For_String()
        {
            var sut = new SmartFolder(@"C:\temp\");

            sut.Equals((object)@"C:\temp").Should().BeTrue();
            sut.Should().Be(@"C:\temp");
            sut.Should().Be(@"C:\temp\");
        }
예제 #19
0
        public void Operator_Minus_Throws_An_Exception_When_The_Path_To_Subtract_Do_Not_Match()
        {
            var lhs = new SmartFolder(@"C:\Windows\Temp\");
            var rhs = new SmartFolder(@"Program Files\Temp\");

            Action action = () => { var x = lhs - rhs; };

            action.Should().Throw <ArgumentOutOfRangeException>();
        }
예제 #20
0
        public void Operator_Minus_Throws_An_Exception_When_The_Paths_Are_The_Same()
        {
            var lhs = new SmartFolder(@"C:\Windows\Temp\");
            var rhs = new SmartFolder(@"C:\Windows\Temp\");

            Action action = () => { var x = lhs - rhs; };

            action.Should().Throw <ArgumentOutOfRangeException>();
        }
예제 #21
0
        public void Operator_Minus_Subtracts_Absolute_Paths_And_Gives_Partial_Path()
        {
            var lhs = new SmartFolder(@"C:\Windows\Temp");
            var rhs = new SmartFolder(@"C:\Windows");

            var sut = lhs - rhs;

            sut.ToString("R").Should().Be(@"Temp\");
        }
예제 #22
0
        public void Operator_Minus_Subtracts_Partial_Paths_From_Path()
        {
            var lhs = new SmartFolder(@"C:\Windows\Temp\");
            var rhs = new SmartFolder(@"Windows\Temp");

            var sut = lhs - rhs;

            sut.ToString().Should().Be(@"C:\");
        }
예제 #23
0
        public void Operator_Minus_Subtracts_Absolute_Paths_Not_Allowed_When_The_Paths_Do_Not_Match()
        {
            var lhs = new SmartFolder(@"C:\Windows\Temp");
            var rhs = new SmartFolder(@"D:\Windows");

            Action action = () => { var sut = lhs - rhs; };

            action.Should().Throw <ArgumentOutOfRangeException>();
        }
예제 #24
0
        protected override object GetModel()
        {
            var sf = Node.Load <SmartFolder>("/Root/System/RuntimeQuery");

            if (sf == null)
            {
                using (new SystemAccount())
                {
                    var systemFolder = Node.LoadNode("/root/system");
                    sf = new SmartFolder(systemFolder)
                    {
                        Name = "RuntimeQuery"
                    };
                    sf.Save();
                }
            }

            var model = Content.Create(sf);

            if (!this.AllowEmptySearch && SearchTextIsTooGeneric(this.QueryString))
            {
                this.ErrorMessage = "Please give a more specific search text";
                return(model);
            }

            sf.Query = ReplaceTemplates(this.QueryString);

            var baseModel = base.GetModel() as Content;

            if (baseModel != null)
            {
                model.ChildrenQueryFilter   = baseModel.ChildrenQueryFilter;
                model.ChildrenQuerySettings = baseModel.ChildrenQuerySettings;

                if (FilterByContext)
                {
                    var ctx = GetContextNode();
                    if (ctx != null)
                    {
                        //add filter: we search only under the current context
                        var excapedPath = ctx.Path.Replace("(", "\\(").Replace(")", "\\)");

                        sf.Query = ContentQuery.AddClause(sf.Query, string.Format("InTree:\"{0}\"", excapedPath), ChainOperator.And);
                    }
                }
            }

            ResultModel = model;

            return(model);
        }
예제 #25
0
        /// <summary>
        /// All crawlers is configed as text file and put in crawlerFolder
        /// CrawlerName|rule for fetch url
        /// Name of Url | Url | Output | Dept| Keywords split by ";"
        /// Example for Crawler config
        /// VMFCrawler|http://diendantoanhoc.net/|VMF.txt|topic;
        /// </summary>
        /// <param name="crawlerFolder"></param>
        public void LoadCrawlers(string crawlerFolder)
        {
            SmartFolder _folder     = new SmartFolder(crawlerFolder, false);
            var         _smartFiles = _folder.GeSmartFiles(false);

            if (_smartFiles != null && _smartFiles.Count() > 0)
            {
                foreach (var smartFile in _smartFiles)
                {
                    var _crawler = LoadCrawler(smartFile.FullPath);
                    Crawlers.Add(_crawler);
                }
            }
        }
예제 #26
0
        protected override object GetModel()
        {
            var sf = SmartFolder.GetRuntimeQueryFolder();

            var model = Content.Create(sf);

            if (!this.AllowEmptySearch && SearchTextIsTooGeneric(this.QueryString))
            {
                if (HttpContext.Current.Request.Params.AllKeys.Contains(QueryParameterName))
                {
                    this.ErrorMessage = SNSR.GetString(ContextSearchClass, "Error_GenericSearchExpression");
                }
                return(model);
            }

            sf.Query = ReplaceTemplates(this.QueryString);

            var baseModel = base.GetModel() as Content;

            if (baseModel != null)
            {
                model.ChildrenDefinition           = baseModel.ChildrenDefinition;
                model.ChildrenDefinition.PathUsage = PathUsageMode.NotUsed;
                if (FilterByContext)
                {
                    var ctx = GetContextNode();
                    if (ctx != null)
                    {
                        //add filter: we search only under the current context
                        var escapedPath = ctx.Path.Replace("(", "\\(").Replace(")", "\\)");
                        model.ChildrenDefinition.ContentQuery =
                            ContentQuery.AddClause(model.ChildrenDefinition.ContentQuery,
                                                   ContentQuery.AddClause(sf.Query, string.Format("InTree:\"{0}\"", escapedPath), ChainOperator.And), ChainOperator.And);
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(sf.Query))
                    {
                        model.ChildrenDefinition.ContentQuery = ContentQuery.AddClause(model.ChildrenDefinition.ContentQuery, sf.Query, ChainOperator.And);
                    }
                }
            }

            ResultModel = model;

            return(model);
        }
예제 #27
0
        //====================================================================== Model

        protected override object GetModel()
        {
            var contextNode = GetContextNode();

            if (contextNode == null)
            {
                return(null);
            }

            var smartFolder = Node.Load <SmartFolder>("/Root/System/RuntimeQuery");

            if (smartFolder == null)
            {
                using (new SystemAccount())
                {
                    var systemFolder = Node.LoadNode("/Root/System");
                    smartFolder = new SmartFolder(systemFolder)
                    {
                        Name = "RuntimeQuery"
                    };
                    smartFolder.Save();
                }
            }

            var content = Content.Create(smartFolder);

            smartFolder.Query = string.Format("+InTree:\"{0}\" +TypeIs:Workspace -TypeIs:(Blog Wiki)", contextNode.Path);

            var baseModel = base.GetModel() as Content;

            if (baseModel != null)
            {
                content.ChildrenQueryFilter   = baseModel.ChildrenQueryFilter;
                content.ChildrenQuerySettings = baseModel.ChildrenQuerySettings;
            }

            return(content);
        }
예제 #28
0
        protected override object GetModel()
        {
            var sf = SmartFolder.GetRuntimeQueryFolder();

            sf.Query = ReplaceTemplates(this.QueryString);

            var c = ContentRepository.Content.Create(sf);

            // Get base model as Content and use some of its children definition properties.
            // Do not override the whole ChildrenDefinition object here because SmartFolder
            // has its own special children definition override.
            var oldc = base.GetModel() as ContentRepository.Content;

            if (oldc != null)
            {
                c.ChildrenDefinition.EnableAutofilters    = oldc.ChildrenDefinition.EnableAutofilters;
                c.ChildrenDefinition.EnableLifespanFilter = oldc.ChildrenDefinition.EnableLifespanFilter;
                c.ChildrenDefinition.Skip = oldc.ChildrenDefinition.Skip;
                c.ChildrenDefinition.Sort = oldc.ChildrenDefinition.Sort;
                c.ChildrenDefinition.Top  = oldc.ChildrenDefinition.Top;
            }

            return(c);
        }
예제 #29
0
        private Content[] GetFeed2Private(string feedPath, bool onlyFiles, bool onlyFolders, int start, int limit)
        {
            Node container = GetNodeById(feedPath);

            if (container == null)
            {
                throw new NodeLoadException("Error loading path");
            }
            IFolder folder = container as IFolder;

            if (folder == null)
            {
                return new Content[] { }
            }
            ;

            IEnumerable <Node> nodeList;
            NodeQuery          query;

            if (onlyFiles || onlyFolders)
            {
                nodeList = onlyFiles ?
                           from child in folder.Children where child is IFile select child :
                           from child in folder.Children where child is IFolder select child;
            }
            else
            {
                //nodeList = folder.Children;
                if (start == 0 && limit == 0)
                {
                    nodeList = folder.Children;
                }
                else
                {
                    SmartFolder smartFolder = folder as SmartFolder;
                    if (folder is SmartFolder)
                    {
                        query = new NodeQuery();
                        string queryString = ((SmartFolder)folder).Query;

                        ExpressionList orExp = new ExpressionList(ChainOperator.Or);

                        if (!string.IsNullOrEmpty(queryString))
                        {
                            orExp.Add(NodeQuery.Parse(queryString));
                        }

                        orExp.Add(new IntExpression(IntAttribute.ParentId, ValueOperator.Equal, container.Id));
                        query.Add(orExp);
                    }
                    else
                    {
                        query = new NodeQuery();
                        query.Add(new IntExpression(IntAttribute.ParentId, ValueOperator.Equal, container.Id));
                    }
                    query.PageSize   = limit;
                    query.StartIndex = start == 0 ? 1 : start;
                    nodeList         = query.Execute().Nodes;
                }
            }

            return(nodeList.Select(node => new Content(node, false, false, false, false, start, limit)).ToArray());
        }
예제 #30
0
        public void Expand_EnvironmentVariable()
        {
            var sut = new SmartFolder("%Temp%");

            sut.ToString().Should().Be(ExpandEnvironmentVariables("%Temp%") + @"\");
        }