Esempio n. 1
0
        public IActionResult ChangeVersion(Dictionary <string, string[]> version, string url)
        {
            ItemVersion unaddressableMask = new ItemVersion(VersionManager.Instance.UnaddressableVersionKeys.ToDictionary(k => k, k => (object)null));
            ItemVersion iv = new ItemVersion(version
                                             .ToDictionary(kvp => kvp.Key, kvp => JsonConvert.DeserializeObject(kvp.Value[0])));

            sys.Versions.ClientVersionOverride = iv.Mask(unaddressableMask);
            string newUrl = VersionManager.Instance.GetVersionUrl(url, iv);

            return(Content(newUrl));
        }
Esempio n. 2
0
        public IActionResult RefQuery(string query, string listId, string allowedVsn)
        {
            var         types         = listId.Split('_').Select(cn => ContentTypeHierarchy.GetContentType(cn)).ToList();
            bool        showType      = types.Count > 1;
            var         qWords        = query.ToLower().Split(new char [] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            ItemVersion maskVsn       = null;
            ItemVersion currMaskedVsn = null;
            bool        versioned     = false;

            if (!string.IsNullOrEmpty(allowedVsn))
            {
                maskVsn = new ItemVersion(allowedVsn);
                ItemVersion curr = sys.Versions.CurrentVersion;
                ItemVersion vsn  = curr.Superimpose(maskVsn);
                currMaskedVsn = curr.Mask(maskVsn);
                sys.Versions.PushState(VersioningMode.Specific, vsn);
                versioned = true;
            }

            try
            {
                var cachedTypes   = types.Where(t => Cache.IsTotalCached(LyniconModuleManager.Instance, t, true)).ToList();
                var uncachedTypes = types.Except(cachedTypes).ToList();
                var items         = Enumerable.Range(0, 1).Select(n => new { label = "", value = "" }).ToList();
                items.Clear();
                if (uncachedTypes.Count > 0)
                {
                    // TO DO add attribute for containers specifying which field or fields to scan for title, add code to create query to scan here
                }
                if (cachedTypes.Count > 0)
                {
                    items.AddRange(Collator.Instance.Get <Summary, Summary>(cachedTypes,
                                                                            iq => iq.Where(s => qWords.All(w => ((s.Title ?? "").ToLower() + " " + s.Type.Name.ToLower()).Contains(w))).Take(30))
                                   .Select(summ => new
                    {
                        label = summ.Title + (showType ? " (" + LyniconUi.ContentClassDisplayName(summ.Type) + ")" : "")
                                + (versioned && !currMaskedVsn.ContainedBy(summ.Version.Mask(maskVsn)) ? " [" + sys.Versions.DisplayVersion(summ.Version.Mask(maskVsn)).Select(dv => dv.Text).Join(" ") + "]" : ""),
                        value = versioned ? summ.ItemVersionedId.Mask(maskVsn).ToString() : summ.ItemId.ToString()
                    })
                                   .OrderBy(s => s.label));
                }

                return(Json(new { items }));
            }
            finally
            {
                if (versioned)
                {
                    sys.Versions.PopState();
                }
            }
        }
Esempio n. 3
0
        public void ItemVersionOperations()
        {
            // means published English vsn
            var iv1 = new ItemVersion(new Dictionary <string, object> {
                { "Published", true }, { "Locale", "en-GB" }
            });
            // means unpublished vsn used for all locales
            var iv2 = new ItemVersion(new Dictionary <string, object> {
                { "Published", false }, { "Locale", null }
            });
            // means Spanish vsn of type which is not versionable for publishing
            var iv3 = new ItemVersion(new Dictionary <string, object> {
                { "Locale", "es-ES" }
            });

            var iv4 = iv1.GetAddressablePart(sys.LyniconSystem.Versions);

            Assert.Equal(new ItemVersion(new Dictionary <string, object> {
                { "Locale", "en-GB" }
            }), iv4);

            var iv5 = iv1.GetUnaddressablePart(sys.LyniconSystem.Versions);

            Assert.Equal(new ItemVersion(new Dictionary <string, object> {
                { "Published", true }
            }), iv5);

            var iv6 = iv1.GetApplicablePart(sys.LyniconSystem.Versions, typeof(TestContent));

            Assert.Equal(new ItemVersion(new Dictionary <string, object> {
                { "Locale", "en-GB" }
            }), iv6);

            var iv7 = iv1.Superimpose(new ItemVersion(new Dictionary <string, object> {
                { "Published", false }, { "A", "x" }
            }));

            Assert.Equal(true, iv1["Published"]); // does not mutate iv1
            Assert.Equal(new ItemVersion(new Dictionary <string, object> {
                { "Published", false }, { "Locale", "en-GB" }, { "A", "x" }
            }), iv7);

            var d9 = new Dictionary <string, object>(iv1);

            d9.Add("X", null);
            var iv9 = new ItemVersion(d9);

            var iv8 = iv9.Overlay(new ItemVersion(new Dictionary <string, object> {
                { "Published", false }, { "Locale", null }
            }));

            Assert.Equal(new ItemVersion(new Dictionary <string, object> {
                { "Published", false }, { "Locale", null }, { "X", null }
            }), iv8);
            Assert.Equal("en-GB", iv9["Locale"]); // does not mutate iv1

            var iv10 = iv9.Mask(new ItemVersion(new Dictionary <string, object> {
                { "Published", null }, { "Locale", "es-ES" }
            }));

            Assert.Equal(new ItemVersion(new Dictionary <string, object> {
                { "Published", true }, { "Locale", "es-ES" }
            }), iv10);
            Assert.Equal("es-ES", iv10["Locale"]);
        }