コード例 #1
0
        protected virtual void InitProperties()
        {
            this.WidthInput.Value  = WebUtil.GetQueryString(Constants.PlayerParameters.Width, MediaFrameworkContext.DefaultPlayerSize.Width.ToString(CultureInfo.InvariantCulture));
            this.HeightInput.Value = WebUtil.GetQueryString(Constants.PlayerParameters.Height, MediaFrameworkContext.DefaultPlayerSize.Height.ToString(CultureInfo.InvariantCulture));

            string player = WebUtil.GetQueryString(Constants.PlayerParameters.PlayerId, string.Empty);

            this.PlayerId = ShortID.IsShortID(player) ? new ShortID(player) : ID.Null.ToShortID();

            var mediaItemId = WebUtil.GetQueryString(Constants.PlayerParameters.ItemId);

            if (ID.IsID(mediaItemId))
            {
                Item     item;
                Database db = Context.ContentDatabase ?? Context.Database;

                if (db != null && (item = db.GetItem(new ID(mediaItemId))) != null)
                {
                    this.Filename.Value = item.Paths.MediaPath;
                    this.DataContext.SetFolder(item.Uri);

                    this.SourceItemID = item.ID;
                    this.InitPlayersList(item);

                    string activePage = WebUtil.GetQueryString(Constants.PlayerParameters.ActivePage);
                    if (!string.IsNullOrEmpty(activePage))
                    {
                        this.Active = activePage;
                    }
                }
            }
        }
        /// <summary>
        /// Raises the load event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        /// <remarks>
        /// This method notifies the server control that it should perform actions common to each HTTP
        ///             request for the page it is associated with, such as setting up a database query. At this
        ///             stage in the page lifecycle, server controls in the hierarchy are created and initialized,
        ///             view state is restored, and form controls reflect client-side data. Use the IsPostBack
        ///             property to determine whether the page is being loaded in response to a client postback,
        ///             or if it is being loaded and accessed for the first time.
        /// </remarks>
        protected override void OnLoad(EventArgs e)
        {
            Assert.ArgumentNotNull(e, "e");
            base.OnLoad(e);
            if (Context.ClientPage.IsEvent)
            {
                return;
            }

            Mode = WebUtil.GetQueryString("mo");
            DataContext.GetFromQueryString();
            string queryString = WebUtil.GetQueryString("fo");

            if (ShortID.IsShortID(queryString))
            {
                DataContext.Folder = ShortID.Parse(queryString).ToID().ToString();
            }

            Context.ClientPage.ServerProperties["mode"] = WebUtil.GetQueryString("mo");

            if (!string.IsNullOrEmpty(WebUtil.GetQueryString("databasename")))
            {
                DataContext.Parameters = "databasename=" + WebUtil.GetQueryString("databasename");
            }

            Item folder = DataContext.GetFolder();

            Assert.IsNotNull(folder, "Folder not found");
            SelectItem(folder);

            Upload.Click = "media:upload(edit=" + (Settings.Media.OpenContentEditorAfterUpload ? "1" : "0") +
                           ",load=1)";
            Upload.ToolTip     = Translate.Text("Upload a new media file to the Media Library");
            EditButton.ToolTip = Translate.Text("Edit the media item in the Content Editor.");
        }
コード例 #3
0
        protected override string GetMediaPath(string localPath)
        {
            int    indexA = -1;
            string strB   = string.Empty;

            foreach (string str in MediaManager.Provider.Config.MediaPrefixes)
            {
                indexA = localPath.IndexOf(str, StringComparison.InvariantCultureIgnoreCase);
                if (indexA >= 0)
                {
                    strB = str;
                    break;
                }
            }
            if (indexA < 0 || string.Compare(localPath, indexA, strB, 0, strB.Length, true, CultureInfo.InvariantCulture) != 0)
            {
                return(string.Empty);
            }
            string id = StringUtil.Divide(StringUtil.Mid(localPath, indexA + strB.Length), '.', true)[0];

            if (id.EndsWith("/", StringComparison.InvariantCulture))
            {
                return(string.Empty);
            }
            if (ShortID.IsShortID(id))
            {
                return(ShortID.Decode(id));
            }
            //2014-06-16 - Removed decode call below
            return("/sitecore/media library/" + id.TrimStart(new char[1] {
                '/'
            }));;
        }
コード例 #4
0
        /// <summary>
        /// On Load
        /// </summary>
        /// <param name="e">
        /// The e.
        /// </param>
        protected override void OnLoad(EventArgs e)
        {
            Assert.ArgumentNotNull(e, "e");
            base.OnLoad(e);

            if (!Context.ClientPage.IsEvent)
            {
                this.Mode = WebUtil.GetQueryString("mo");
                try
                {
                    this.InternalLinkDataContext.GetFromQueryString();
                }
                catch
                {
                }

                try
                {
                    this.MediaDataContext.GetFromQueryString();
                }
                catch
                {
                }

                var queryString = WebUtil.GetQueryString("fo");
                if (queryString.Length > 0)
                {
                    if (queryString.EndsWith(".aspx", StringComparison.OrdinalIgnoreCase))
                    {
                        if (!queryString.StartsWith("/sitecore"))
                        {
                            queryString = FileUtil.MakePath("/sitecore/content", queryString, '/');
                        }

                        if (queryString.EndsWith(".aspx"))
                        {
                            queryString = StringUtil.Left(queryString, queryString.Length - 5);
                        }

                        this.InternalLinkDataContext.Folder = queryString;
                    }
                    else if (ShortID.IsShortID(queryString))
                    {
                        queryString = ShortID.Parse(queryString).ToID().ToString();
                        var item = Client.ContentDatabase.GetItem(queryString);
                        if (item != null)
                        {
                            if (!item.Paths.IsMediaItem)
                            {
                                this.InternalLinkDataContext.Folder = queryString;
                            }
                            else
                            {
                                this.MediaDataContext.Folder = queryString;
                            }
                        }
                    }
                }
            }
        }
コード例 #5
0
ファイル: SearchHelper.cs プロジェクト: vrkmajeti/reboot
        public static Expression <Func <T, bool> > GetPredicate <T>(ISearchParameter parameters, ISitecoreContext context) where T : IFacetableContent
        {
            var predicate = PredicateBuilder.True <T>();

            predicate = parameters.FilterOnTemplates.Aggregate(predicate, (current, temp) => current.Or(p => p.TemplateId == temp));
            if (parameters.FilterOnFields == null || !parameters.FilterOnFields.Any())
            {
                return(predicate);
            }
            IEnumerable <Guid> facetOns = parameters.FilterOnFields;
            IEnumerable <Models.Glass.Reboot.Facet> facets =
                facetOns.Select(i => context.GetItem <Models.Glass.Reboot.Facet>(i)).Reverse();

            foreach (var filter in facets)
            {
                string s = HttpContext.Current.Request.QueryString.Get(filter.Name);
                switch (filter.FacetName)
                {
                case "Genres":
                    if (!string.IsNullOrEmpty(s) && ShortID.IsShortID(s))
                    {
                        //w = w.Where(a => a.Genres.Contains(Guid.Parse(s)));
                        predicate = predicate.And(o => o.Genres.Contains(Guid.Parse(s)));
                    }
                    break;

                case "Production Company":
                    if (!string.IsNullOrEmpty(s) && ShortID.IsShortID(s))
                    {
                        //w = w.Where(a => a.ProductionCompanies.Contains(Guid.Parse(s)));
                        predicate = predicate.And(a => a.ProductionCompanies.Contains(Guid.Parse(s)));
                    }
                    break;

                case "Status":
                    if (!string.IsNullOrEmpty(s))
                    {
                        //w = w.Where(a => a.Status.Equals(s));
                        predicate = predicate.And(a => a.Status.Equals(s));
                    }
                    break;

                case "Spoken Language":
                    if (!string.IsNullOrEmpty(s))
                    {
                        //w = w.Where(a => a.Status.Equals(s));
                        predicate = predicate.And(a => a.SpokenLanguages.Contains(Guid.Parse(s)));
                    }
                    break;
                }
            }
            return(predicate);
        }
コード例 #6
0
        /// <summary>
        /// Executes the media file event.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <contract>
        ///   <requires name="file" condition="not null" />
        /// </contract>
        private void DownloadMediaFile(string file)
        {
            Assert.ArgumentNotNull(file, "file");
            string text = null;
            int    num  = -1;

            foreach (string current in MediaManager.Config.MediaPrefixes)
            {
                num = file.IndexOf(current, StringComparison.OrdinalIgnoreCase);
                if (num >= 0)
                {
                    text = current;
                    break;
                }
            }
            Assert.IsNotNull(text, "media prefix not found.");
            file = StringUtil.Mid(file, num + text.Length);
            num  = file.LastIndexOf('?');
            if (num >= 0)
            {
                file = StringUtil.Left(file, num);
            }
            num = file.LastIndexOf('.');
            if (num >= 0)
            {
                file = StringUtil.Left(file, num);
            }
            Item item = null;

            if (ShortID.IsShortID(file))
            {
                item = Sitecore.Context.ContentDatabase.GetItem(new ShortID(file).ToID());
            }
            if (item == null && Sitecore.Data.ID.IsID(file))
            {
                item = Sitecore.Context.ContentDatabase.GetItem(file);
            }
            if (item == null)
            {
                if (!file.StartsWith("/", StringComparison.InvariantCulture))
                {
                    file = "/" + file;
                }
                file = FileUtil.MakePath("/sitecore/media library", file);
                item = Sitecore.Context.ContentDatabase.GetItem(file);
            }
            if (item == null)
            {
                return;
            }
            this.WriteMediaItem(item);
        }
コード例 #7
0
        public static IEnumerable <Item> ResolveDatasourceItems(this Database db, string datasource, Item contextItem = null)
        {
            if (string.IsNullOrWhiteSpace(datasource))
            {
                return(new Item[0]);
            }

            try
            {
                var ids = ID.ParseArray(datasource);
                if (ids.Length > 0)
                {
                    return(ids.Select(db.GetItem).Where(x => x != null));
                }
            }
            catch { }

            var itemId = ShortID.IsShortID(datasource)
                ? ShortID.Parse(datasource).ToID()
                : ID.Null;

            if (!ID.IsNullOrEmpty(itemId))
            {
                var item = db.GetItem(itemId);
                return(item == null
                           ? new Item[0]
                           : new[] { item });
            }

            string query = null;

            if (!string.IsNullOrWhiteSpace(datasource) && datasource.StartsWith("query:"))
            {
                query = datasource.Substring("query:".Length);
            }
            else if (!string.IsNullOrWhiteSpace(datasource) && (datasource.StartsWith("/") || datasource.StartsWith("./") || datasource.StartsWith("../")))
            {
                query = EscapeItemPathForQuery(datasource);
            }

            if (!string.IsNullOrWhiteSpace(query))
            {
                return((contextItem == null
                    ? db.SelectItems(query)
                    : contextItem.Axes.SelectItems(query))
                       ?? new Item[0]);
            }
            return(new Item[0]);
        }
コード例 #8
0
ファイル: BCTreeviewEx.cs プロジェクト: cryptoRebel/sukiyoshi
        private static string GetDragID(string id)
        {
            Assert.ArgumentNotNull(id, "id");
            int num = id.LastIndexOf("_");

            if (num >= 0)
            {
                id = StringUtil.Mid(id, num + 1);
            }
            if (ShortID.IsShortID(id))
            {
                id = ShortID.Decode(id);
            }
            return(id);
        }
コード例 #9
0
 public Guid GetItemId(string value)
 {
     if (string.IsNullOrWhiteSpace(value))
     {
         return(Guid.Empty);
     }
     if (ShortID.IsShortID(value))
     {
         return(ShortID.Parse(value).ToID().Guid);
     }
     if (ID.IsID(value))
     {
         return(ID.Parse(value).Guid);
     }
     return(Guid.Parse(value));
 }
コード例 #10
0
        public static ID OrID(this object s)
        {
            if (s.OrEmpty() != string.Empty)
            {
                if (ShortID.IsShortID(s.ToString()))
                {
                    return((new ShortID(s.ToString())).ToID());
                }

                if (ID.IsID(s.ToString()))
                {
                    return(new ID(s.ToString()));
                }
            }

            return(ID.Null);
        }
コード例 #11
0
        /// <summary>
        /// Gets the target Sitecore Item and spawns a new T object.
        /// </summary>
        /// <typeparam name="T">The generic type to return. Must be of type <see cref="Fortis.Model.IItemWrapper"/></typeparam>
        /// <returns>If the target is not set, returns null, otherwise returns T</returns>
        public virtual T GetTarget <T>() where T : IItemWrapper
        {
            if (string.IsNullOrWhiteSpace(RawValue))
            {
                return(default(T));
            }
            if (ShortID.IsShortID(RawValue))
            {
                return(GetTarget <T>(ShortID.Parse(RawValue).ToID()));
            }
            if (ID.IsID(RawValue))
            {
                return(GetTarget <T>(ID.Parse(RawValue)));
            }

            return(default(T));
        }
コード例 #12
0
ファイル: LinkFieldWrapper.cs プロジェクト: vhil/xWrap
        /// <summary>
        /// Gets the target item.
        /// </summary>
        /// <returns></returns>
        public virtual Item GetTarget()
        {
            if (string.IsNullOrWhiteSpace(this.RawValue))
            {
                return(null);
            }
            if (ShortID.IsShortID(this.RawValue))
            {
                return(this.GetTarget(ShortID.Parse(this.RawValue).ToID()));
            }
            if (ID.IsID(this.RawValue))
            {
                return(this.GetTarget(ID.Parse(this.RawValue)));
            }

            return(null);
        }
コード例 #13
0
        public string Execute([NotNull] string text, [NotNull] string id, [NotNull] string databaseName)
        {
            Assert.ArgumentNotNull(databaseName, nameof(databaseName));
            Assert.ArgumentNotNull(id, nameof(id));
            Assert.ArgumentNotNull(text, nameof(text));

            var database = Factory.GetDatabase(databaseName);

            if (database == null)
            {
                throw new Exception("Database not found");
            }

            if (ShortID.IsShortID(id))
            {
                id = ShortID.Decode(id);
            }

            var start = database.GetItem(id);

            var item = start;

            if (item == null)
            {
                item = database.GetRootItem();
            }

            var result = FindItem(item, ID.Null, text);

            if (result == null && start != null)
            {
                result = FindItem(database.GetRootItem(), start.ID, text);
            }

            if (result != null)
            {
                return(result.ID.ToString());
            }

            return(string.Empty);
        }
コード例 #14
0
        public static IEnumerable <Guid> ToGuidEnumerable(this IEnumerable ids, bool throwOnBadId = true)
        {
            var convertedIds = new List <Guid>();

            foreach (var id in ids)
            {
                if (id is Guid)
                {
                    convertedIds.Add((Guid)id);
                    continue;
                }
                else
                {
                    var  idString = id.ToString();
                    Guid idGuid;

                    if (ID.IsID(idString))
                    {
                        convertedIds.Add(ID.Parse(idString).Guid);
                        continue;
                    }
                    else if (ShortID.IsShortID(idString))
                    {
                        convertedIds.Add(ShortID.Parse(idString).Guid);
                        continue;
                    }
                    else if (Guid.TryParse(idString, out idGuid))
                    {
                        convertedIds.Add(idGuid);
                        continue;
                    }
                }

                if (throwOnBadId)
                {
                    throw new Exception("Fortis: Unable to convert enumerable object to Guid");
                }
            }

            return(convertedIds);
        }
コード例 #15
0
        public static IEnumerable <Item> ResolveDatasourceItems(this Database db, string datasource, Item contextItem = null)
        {
            if (string.IsNullOrWhiteSpace(datasource))
            {
                return(new Item[0]);
            }

            var itemId = ID.IsID(datasource)
                            ? ID.Parse(datasource)
                            : (ShortID.IsShortID(datasource)
                                   ? ShortID.Parse(datasource).ToID()
                                   : ID.Null);

            if (!ID.IsNullOrEmpty(itemId))
            {
                var item = db.GetItem(itemId);
                return(item == null
                           ? new Item[0]
                           : new[] { item });
            }

            string query = null;

            if (!string.IsNullOrWhiteSpace(datasource) && datasource.StartsWith("query:"))
            {
                query = datasource.Substring("query:".Length);
            }
            else if (!string.IsNullOrWhiteSpace(datasource) && (datasource.StartsWith("/") || datasource.StartsWith("./") || datasource.StartsWith("../")))
            {
                query = datasource;
            }

            if (!string.IsNullOrWhiteSpace(query))
            {
                return(contextItem == null
                           ? db.SelectItems(query)
                           : contextItem.Axes.SelectItems(query));
            }
            return(new Item[0]);
        }
コード例 #16
0
ファイル: PathTest.cs プロジェクト: kamsar/Rhino
		public TestResult Execute(DiskItem contextItem, DiskItem[] allItems)
		{
			// translate the full physical path into an item path
			var mappedPath = PathUtils.MakeItemPath(contextItem.FullPath, _rootPath);

			// if more than one item is in the same path with the same name, it will map something like "name_FDA63242325453" (guid)
			// we want to strip the disambiguating GUID from the name, if it exists
			var split = mappedPath.Split('_');
			if (ShortID.IsShortID(split.Last()))
				mappedPath = string.Join("_", split.Take(split.Length - 1));

			if (_databaseName != null)
			{
				string dbPrefix = "/" + _databaseName;

				if (mappedPath.StartsWith(dbPrefix, StringComparison.OrdinalIgnoreCase))
					mappedPath = mappedPath.Substring(dbPrefix.Length);
			}

			// MakeItemPath seems to return paths in the format "//sitecore/foo" sometimes, let's normalize that
			mappedPath = "/" + mappedPath.TrimStart('/');

			// if we have a database name (e.g. we are pointing at a raw serialized root such as "serialization\master" instead of "serialization"), prepend to the mapped path
			if (_databaseName != null)
			{
				mappedPath = "/" + _databaseName + mappedPath;
			}

			// compute the item reference path for the context item SyncItem
			string syncItemReferencePath = new ItemReference(contextItem.Item.DatabaseName, contextItem.Item.ItemPath).ToString();

			// ensure the ref path is prepended with /
			syncItemReferencePath = "/" + syncItemReferencePath.TrimStart('/');

			bool passed = mappedPath.Equals(syncItemReferencePath, StringComparison.OrdinalIgnoreCase);

			if (passed) return new TestResult(this, true);

			return new TestResult(this, false, string.Format("Physical: {0} != Serialized: {1}", mappedPath, syncItemReferencePath));
		}
コード例 #17
0
        protected virtual Item GetItem(Database database, NameValueCollection collection, string key)
        {
            Assert.ArgumentNotNull(database, "database");
            Assert.ArgumentNotNull(collection, "collection");
            Assert.ArgumentNotNull(key, "key");

            string idStr = collection[key];

            if (string.IsNullOrEmpty(idStr) || !ShortID.IsShortID(idStr))
            {
                LogHelper.Warn("Invalid id parameter:" + idStr, this);
                return(null);
            }

            Item item = database.GetItem(new ID(idStr));

            if (item == null)
            {
                LogHelper.Warn("Item could not be found. ItemId:" + new ID(idStr), this);
            }
            return(item);
        }
コード例 #18
0
        protected override void OnLoad(EventArgs e)
        {
            Assert.ArgumentNotNull(e, "e");
            base.OnLoad(e);
            if (!Context.ClientPage.IsEvent)
            {
                this.Mode = WebUtil.GetQueryString(QueryMode);
                this.InitProperties();

                this.DataContext.GetFromQueryString();
                this.UploadFrame.SourceUri += string.Format("?type=embed&database={0}", this.DataContext.GetDatabase());
                string queryString = WebUtil.GetQueryString(SourceFolder);
                if (ShortID.IsShortID(queryString))
                {
                    queryString             = ShortID.Parse(queryString).ToID().ToString();
                    this.DataContext.Folder = queryString;
                }

                var folder = this.DataContext.GetFolder();
                Assert.IsNotNull(folder, "Folder not found");
            }
        }
コード例 #19
0
        private string GetMediaPath(string localPath)
        {
            int    num  = -1;
            string text = string.Empty;

            foreach (string current in MediaManager.Provider.Config.MediaPrefixes)
            {
                num = localPath.IndexOf(current, System.StringComparison.InvariantCultureIgnoreCase);
                if (num >= 0)
                {
                    text = current;
                    break;
                }
            }
            if (num < 0)
            {
                return(string.Empty);
            }
            if (string.Compare(localPath, num, text, 0, text.Length, true, System.Globalization.CultureInfo.InvariantCulture) != 0)
            {
                return(string.Empty);
            }
            string text2 = StringUtil.Divide(StringUtil.Mid(localPath, num + text.Length), '.', true)[0];

            if (text2.EndsWith("/"))
            {
                return(string.Empty);
            }
            if (ShortID.IsShortID(text2))
            {
                return(ShortID.Decode(text2));
            }
            char[] trimChars = new char[]
            {
                '/'
            };
            return("/sitecore/media library/" + text2.TrimStart(trimChars));
        }
コード例 #20
0
        protected override void InitProperties()
        {
            this.WidthInput.Value  = WebUtil.GetQueryString(Constants.PlayerParameters.Width, MediaFrameworkContext.DefaultPlayerSize.Width.ToString(CultureInfo.InvariantCulture));
            this.HeightInput.Value = WebUtil.GetQueryString(Constants.PlayerParameters.Height, MediaFrameworkContext.DefaultPlayerSize.Height.ToString(CultureInfo.InvariantCulture));
            this.InitAspectRatiosList();
            this.JavascriptRadiobutton.Checked = true;
            this.EmbedInput.Value = Brightcove.Constants.EmbedJavascript;
            this.ResponsiveRadiobutton.Checked = true;
            this.SizingInput.Value             = Brightcove.Constants.SizingResponsive;
            string player = WebUtil.GetQueryString(Constants.PlayerParameters.PlayerId, string.Empty);

            this.PlayerId = ShortID.IsShortID(player) ? new ShortID(player) : ID.Null.ToShortID();

            var mediaItemId = WebUtil.GetQueryString(Constants.PlayerParameters.ItemId);

            if (ID.IsID(mediaItemId))
            {
                Item     item;
                Database db = Sitecore.Context.ContentDatabase ?? Sitecore.Context.Database;

                if (db != null && (item = db.GetItem(new ID(mediaItemId))) != null)
                {
                    this.Filename.Value = item.Paths.MediaPath;
                    this.DataContext.SetFolder(item.Uri);

                    this.SourceItemID = item.ID;
                    this.InitPlayersList(item);

                    string activePage = WebUtil.GetQueryString(Constants.PlayerParameters.ActivePage);
                    if (!string.IsNullOrEmpty(activePage))
                    {
                        this.Active = activePage;
                    }
                }
            }
        }
コード例 #21
0
ファイル: BaseSearchCommand.cs プロジェクト: vsegrad/Console
        public Expression <Func <SearchResultItem, bool> > ProcessCriteria(SearchCriteria[] criterias, SearchOperation operation)
        {
            var predicate = operation == SearchOperation.Or
                ? PredicateBuilder.False <SearchResultItem>()
                : PredicateBuilder.True <SearchResultItem>();

            if (criterias != null)
            {
                foreach (var criteria in criterias)
                {
                    if (criteria.Value == null)
                    {
                        continue;
                    }
                    var boost    = criteria.Boost;
                    var comparer = criteria.CaseSensitive.HasValue && criteria.CaseSensitive.Value
                        ? StringComparison.Ordinal
                        : StringComparison.OrdinalIgnoreCase;
                    switch (criteria.Filter)
                    {
                    case FilterType.DescendantOf:
                        var root = ObjectToString(criteria.Value);

                        if (string.IsNullOrEmpty(root) || !ShortID.IsShortID(root))
                        {
                            WriteError(typeof(ArgumentException),
                                       "The value for DescendantOf criteria must be an Item or ID.",
                                       ErrorIds.InvalidOperation, ErrorCategory.InvalidArgument, criteria.Value);
                            return(null);
                        }

                        predicate = criteria.Invert
                                ? predicate.AddPredicate(i => !i["_path"].Contains(root).Boost(boost), operation)
                                : predicate.AddPredicate(i => i["_path"].Contains(root).Boost(boost), operation);
                        break;

                    case FilterType.StartsWith:
                        var startsWith = ObjectToString(criteria.Value);

                        predicate = criteria.Invert
                                ? predicate.AddPredicate(i => !i[criteria.Field].StartsWith(startsWith, comparer).Boost(boost), operation)
                                : predicate.AddPredicate(i => i[criteria.Field].StartsWith(startsWith, comparer).Boost(boost), operation);
                        break;

                    case FilterType.Contains:
                        if (comparer == StringComparison.OrdinalIgnoreCase && criteria.CaseSensitive.HasValue)
                        {
                            WriteWarning("Case insensitiveness is not supported on Contains criteria due to platform limitations.");
                        }

                        var contains = ObjectToString(criteria.Value);

                        predicate = criteria.Invert
                                ? predicate.AddPredicate(i => !i[criteria.Field].Contains(contains).Boost(boost), operation)
                                : predicate.AddPredicate(i => i[criteria.Field].Contains(contains).Boost(boost), operation);
                        break;

                    case FilterType.ContainsAny:
                        if (comparer == StringComparison.OrdinalIgnoreCase && criteria.CaseSensitive.HasValue)
                        {
                            WriteWarning("Case insensitiveness is not supported on Contains criteria due to platform limitations.");
                        }

                        var valuesAny = ObjectToStringArray(criteria.Value);
                        predicate = criteria.Invert
                                ? predicate.AddPredicate(valuesAny.Aggregate(PredicateBuilder.True <SearchResultItem>(), (current, keyword) => current.Or(c => !((string)c[(ObjectIndexerKey)criteria.Field]).Contains(keyword))))
                                : predicate.AddPredicate(valuesAny.Aggregate(PredicateBuilder.True <SearchResultItem>(), (current, keyword) => current.Or(c => ((string)c[(ObjectIndexerKey)criteria.Field]).Contains(keyword))));
                        break;

                    case FilterType.ContainsAll:
                        if (comparer == StringComparison.OrdinalIgnoreCase && criteria.CaseSensitive.HasValue)
                        {
                            WriteWarning("Case insensitiveness is not supported on Contains criteria due to platform limitations.");
                        }

                        var valuesAll = ObjectToStringArray(criteria.Value);
                        predicate = criteria.Invert
                                ? predicate.AddPredicate(valuesAll.Aggregate(PredicateBuilder.True <SearchResultItem>(), (current, keyword) => current.And(c => !((string)c[(ObjectIndexerKey)criteria.Field]).Contains(keyword))))
                                : predicate.AddPredicate(valuesAll.Aggregate(PredicateBuilder.True <SearchResultItem>(), (current, keyword) => current.And(c => ((string)c[(ObjectIndexerKey)criteria.Field]).Contains(keyword))));
                        break;

                    case FilterType.EndsWith:
                        var endsWith = ObjectToString(criteria.Value);

                        predicate = criteria.Invert
                                ? predicate.AddPredicate(i => !i[criteria.Field].EndsWith(endsWith, comparer).Boost(boost), operation)
                                : predicate.AddPredicate(i => i[criteria.Field].EndsWith(endsWith, comparer).Boost(boost), operation);
                        break;

                    case FilterType.Equals:
                        var equals = ObjectToString(criteria.Value);

                        predicate = criteria.Invert
                                ? predicate.AddPredicate(i => !i[criteria.Field].Equals(equals, comparer).Boost(boost), operation)
                                : predicate.AddPredicate(i => i[criteria.Field].Equals(equals, comparer).Boost(boost), operation);
                        break;

                    case FilterType.Fuzzy:
                        var fuzzy = ObjectToString(criteria.Value);

                        predicate = criteria.Invert
                                ? predicate.AddPredicate(i => !i[criteria.Field].Like(fuzzy).Boost(boost), operation)
                                : predicate.AddPredicate(i => i[criteria.Field].Like(fuzzy).Boost(boost), operation);
                        break;

                    case FilterType.InclusiveRange:
                    case FilterType.ExclusiveRange:
                        predicate = GetRangeExpression(predicate, criteria, operation);
                        break;

                    case FilterType.MatchesRegex:
                        var regex = criteria.StringValue;

                        predicate = criteria.Invert
                                ? predicate.AddPredicate(i => !i[criteria.Field].Matches(regex).Boost(boost), operation)
                                : predicate.AddPredicate(i => i[criteria.Field].Matches(regex).Boost(boost), operation);
                        break;

                    case FilterType.MatchesWildcard:
                        var wildcard = criteria.StringValue;

                        predicate = criteria.Invert
                                ? predicate.AddPredicate(i => !i[criteria.Field].MatchWildcard(wildcard).Boost(boost), operation)
                                : predicate.AddPredicate(i => i[criteria.Field].MatchWildcard(wildcard).Boost(boost), operation);
                        break;
                    }
                }
            }

            return(predicate);
        }
コード例 #22
0
 protected static ID GetId(string value)
 {
     return(!string.IsNullOrEmpty(value) && ShortID.IsShortID(value) ? new ID(value) : ID.Null);
 }
コード例 #23
0
        protected void Run(ClientPipelineArgs args)
        {
            Assert.ArgumentNotNull((object)args, "args");
            parentItemID = args.Parameters["itemid"];
            Item itemNotNull = Sitecore.Client.GetItemNotNull(args.Parameters["itemid"], Language.Parse(args.Parameters["language"]));

            if (args.IsPostBack)
            {
                if (!args.HasResult)
                {
                    return;
                }
                string[] strArray    = args.Result.Split(new[] { "||" }, StringSplitOptions.None);
                string   id          = strArray[0];
                string   name        = Uri.UnescapeDataString(strArray[1]);
                string   displayName = Uri.UnescapeDataString(strArray[2]);
                string   metaTitle   = Uri.UnescapeDataString(strArray[3]);
                if (ShortID.IsShortID(id))
                {
                    id = ShortID.Parse(id).ToID().ToString();
                }
                BranchItem branch = Sitecore.Client.ContentDatabase.Branches[id, itemNotNull.Language];
                Assert.IsNotNull((object)branch, typeof(BranchItem));
                this.ExecuteCommand(itemNotNull, branch, name);
                Sitecore.Client.Site.Notifications.Disabled = true;
                Item obj = Context.Workflow.AddItem(name, branch, itemNotNull);
                Sitecore.Client.Site.Notifications.Disabled = false;
                if (obj == null)
                {
                    return;
                }
                this.PolicyBasedUnlock(obj);
                if (!HasPresentationPipeline.Run(obj) || !MainUtil.GetBool(args.Parameters["navigate"], true))
                {
                    WebEditCommand.Reload();
                }
                else
                {
                    UrlOptions  defaultOptions = UrlOptions.DefaultOptions;
                    SiteContext site           = SiteContext.GetSite(string.IsNullOrEmpty(args.Parameters["sc_pagesite"]) ? Sitecore.Web.WebEditUtil.SiteName : args.Parameters["sc_pagesite"]);
                    if (site == null)
                    {
                        return;
                    }
                    string url = string.Empty;
                    using (new SiteContextSwitcher(site))
                    {
                        using (new LanguageSwitcher(obj.Language))
                            url = LinkManager.GetItemUrl(obj, defaultOptions);
                    }
                    WebEditCommand.Reload(new UrlString(url));
                    SheerResponse.Alert("New page item created.");
                }
                HealthIS.Apps.Util.SetDisplayNameAndMetaTitle(obj, displayName, metaTitle);
            }
            else if (!itemNotNull.Access.CanCreate())
            {
                SheerResponse.Alert("You do not have permission to create an item here.");
            }
            else
            {
                UrlString urlString = ResourceUri.Parse("control:CustomAddMasterWebEdit").ToUrlString();
                itemNotNull.Uri.AddToUrlString(urlString);
                SheerResponse.ShowModalDialog(urlString.ToString(), "1200px", "700px", string.Empty, true);
                args.WaitForPostBack();
            }
        }