Пример #1
0
 /// <summary>
 /// Set the current value for this versioning system using supplied mode on supplied ItemVersion
 /// </summary>
 /// <param name="mode">The mode to use</param>
 /// <param name="version">The ItemVersion on which to add the key/value for this versioning system</param>
 public abstract void SetCurrentVersion(VersioningMode mode, ItemVersion version);
Пример #2
0
 /// <summary>
 /// Get display details for displaying the value for this versioning system from the supplied ItemVersion
 /// </summary>
 /// <param name="version">The ItemVersion for which to get display information for this versioning system</param>
 /// <returns>Display information for version from this versioning system</returns>
 public abstract VersionDisplay DisplayItemVersion(ItemVersion version);
Пример #3
0
 /// <summary>
 /// Get a list of VersionSelectionViewModels to create a version selector for a given user and a given current version
 /// </summary>
 /// <param name="u">The user</param>
 /// <param name="currVersion">The current version</param>
 /// <returns>List of VersionSelectionViewModels</returns>
 public List<VersionSelectionViewModel> SelectionViewModel(IUser u, ItemVersion currVersion)
 {
     return SelectionViewModel(u, currVersion, false);
 }
Пример #4
0
        /// <summary>
        /// Whether a given version can be viewed by a given user
        /// </summary>
        /// <param name="u">The user</param>
        /// <param name="version">The ItemVersion</param>
        /// <returns>Whether the ItemVersion can be viewed by the user</returns>
        public bool VersionPermitted(IUser u, ItemVersion version)
        {
            foreach (var versioner in Versioners)
                if (!versioner.GetAllowedVersions(u).Contains(version[versioner.VersionKey]))
                    return false;

            return true;
        }
Пример #5
0
 /// <summary>
 /// Transform a url via processors on GenerateUrl
 /// </summary>
 /// <param name="url">The url to process</param>
 /// <param name="iv">The ItemVersion which is the context in which to process the url</param>
 /// <returns>The processed url</returns>
 public string UrlTransform(string url, ItemVersion iv)
 {
     var tpl = (Tuple<string, ItemVersion>)EventHub.Instance.ProcessEvent("GenerateUrl", this, Tuple.Create(url, iv)).Data;
     return tpl.Item1;
 }
Пример #6
0
 /// <summary>
 /// Make the ItemVersion applicable to a given type by removing any inapplicable keys
 /// </summary>
 /// <param name="version">The original ItemVersion</param>
 /// <param name="t">The type to which to make it applicable</param>
 /// <returns>The modified, applicable ItemVersion</returns>
 public ItemVersion GetApplicableVersion(ItemVersion version, Type t)
 {
     ItemVersion res = new ItemVersion();
     foreach (var versioner in Versioners)
     {
         if (!version.ContainsKey(versioner.VersionKey))
             continue;
         if (versioner.Versionable(t))
             res.Add(versioner.VersionKey, version[versioner.VersionKey]);
     }
     return res;
 }
Пример #7
0
 /// <summary>
 /// Create a VersionedAddress from an Address and an ItemVersion
 /// </summary>
 /// <param name="a">The Address</param>
 /// <param name="version">The ItemVersion</param>
 public VersionedAddress(Address a, ItemVersion version) :
     base(a.Type, a.GetAsContentPath())
 {
     Version = version;
 }
 private void MappingsListView_ContextMenuOpening(object sender, ContextMenuEventArgs e)
 {
     ItemVersion itemVersion = MappingsListView.SelectedItem as ItemVersion;
     SiteSetting siteSetting = ConfigurationManager.GetInstance().GetSiteSetting(itemVersion.SiteSettingID);
     //ContextMenuManager.Instance.FillContextMenuItems(MappingsListView.ContextMenu, siteSetting, itemVersion, null, null);
 }
Пример #9
0
        /// <summary>
        /// Creates a VersionedAddress from an address using the current ItemVersion
        /// </summary>
        /// <param name="a">The Address</param>
        /// <returns>The resulting VersionedAddress</returns>
        public static VersionedAddress CurrentFromAddress(Address a)
        {
            ItemVersion curr = VersionManager.Instance.CurrentVersionForType(a.Type);

            return(new VersionedAddress(a, curr));
        }
Пример #10
0
 /// <summary>
 /// Create the VersionedAddress of a container
 /// </summary>
 /// <param name="container">The container</param>
 public VersionedAddress(object container) :
     base(container)
 {
     Version = new ItemVersion(container);
 }
Пример #11
0
 /// <summary>
 /// Create a VersionedAddress from an Address and an ItemVersion
 /// </summary>
 /// <param name="a">The Address</param>
 /// <param name="version">The ItemVersion</param>
 public VersionedAddress(Address a, ItemVersion version) :
     base(a.Type, a.GetAsContentPath())
 {
     Version = VersionManager.Instance.GetApplicableVersion(version, a.Type);
 }
Пример #12
0
 /// <summary>
 /// Create a CrossVersionReference with an ItemVersion which has an AllowedVersionsOverlay to limit the versions which
 /// can be referred to, and the ItemVersionedId of the referred to item
 /// </summary>
 /// <param name="allowedVersionsOverlay">A version key set to 'null' will allow the reference to be set to any version of that key. A version key set to a value will mean the reference is ALWAYS to that version, irrespective of the current version.</param>
 /// <param name="ivid">ItemVersionedId for the referred to item</param>
 public CrossVersionReference(ItemVersion allowedVersionsOverlay, ItemVersionedId ivid)
     : this(ivid)
 {
     AllowedVersionsOverlay = allowedVersionsOverlay;
 }
Пример #13
0
 /// <summary>
 /// Create a CrossVersionReference with an ItemVersion which has an AllowedVersionsOverlay to limit the versions which
 /// can be referred to
 /// </summary>
 /// <param name="allowedVersionsOverlay">A version key set to 'null' will allow the reference to be set to any version of that key. A version key set to a value will mean the reference is ALWAYS to that version, irrespective of the current version.</param>
 public CrossVersionReference(ItemVersion allowedVersionsOverlay)
     : this()
 {
     AllowedVersionsOverlay = allowedVersionsOverlay;
 }
Пример #14
0
 public List <ItemVersion> RestoreVersion(ISiteSetting siteSetting, ItemVersion itemVersion)
 {
     return(null);
 }
Пример #15
0
 /// <summary>
 /// Create a VersionedAddress from a Type, an address path and an ItemVersion
 /// </summary>
 /// <param name="t">the Type</param>
 /// <param name="path">the address path</param>
 /// <param name="version">the ItemVersion</param>
 public VersionedAddress(Type t, string path, ItemVersion version) :
     this(new Address(t, path), version)
 {
 }
Пример #16
0
 public LatestTableForCutoff(DateTime cutoff, ItemVersion tableVersion)
 {
     TableVersion = tableVersion;
     Cutoff       = cutoff;
 }
Пример #17
0
 /// <summary>
 /// Create the VersionedAddress of a container
 /// </summary>
 /// <param name="container">The container</param>
 public VersionedAddress(LyniconSystem sys, object container) :
     base(container)
 {
     Version = new ItemVersion(sys, container);
 }
Пример #18
0
 /// <summary>
 /// Change the current UI version where this is permitted
 /// </summary>
 /// <param name="version">The new version</param>
 /// <returns>Status of operation</returns>
 public ActionResult ChangeVersion(Dictionary<string, string[]> version)
 {
     ItemVersion iv = new ItemVersion(version.ToDictionary(kvp => kvp.Key, kvp => JsonConvert.DeserializeObject(kvp.Value[0])));
     VersionManager.Instance.ClientVersionOverride = iv;
     return Content("OK");
 }
Пример #19
0
        protected virtual bool AnyFieldMatch(FieldDictionary sourceFields, FieldDictionary targetFields, ISourceItem existingItem, ISerializedItem serializedItem, DeferredLogWriter <ISerializedAsMasterEvaluatorLogger> deferredUpdateLog, ItemVersion version = null)
        {
            if (sourceFields == null)
            {
                return(false);
            }

            return(sourceFields.Any(x =>
            {
                if (!_fieldPredicate.Includes(x.Key).IsIncluded)
                {
                    return false;
                }

                if (!existingItem.IsFieldComparable(x.Key))
                {
                    return false;
                }

                bool isMatch = IsFieldMatch(x.Value, targetFields, x.Key);
                if (isMatch)
                {
                    deferredUpdateLog.AddEntry(logger =>
                    {
                        string sourceFieldValue;
                        targetFields.TryGetValue(x.Key, out sourceFieldValue);

                        if (version == null)
                        {
                            logger.IsSharedFieldMatch(serializedItem, x.Key, x.Value, sourceFieldValue);
                        }
                        else
                        {
                            logger.IsVersionedFieldMatch(serializedItem, version, x.Key, x.Value, sourceFieldValue);
                        }
                    });
                }
                return isMatch;
            }));
        }
Пример #20
0
        /// <summary>
        /// Get the current version with only the keys applicable to a type
        /// </summary>
        /// <param name="type">The type to which the keys must be applicable</param>
        /// <returns>Current Item version with only the keys applicable to a type</returns>
        public ItemVersion CurrentVersionForType(Type type)
        {
            var vsn = new ItemVersion(CurrentVersion);
            foreach (var versioner in Versioners)
                if (!versioner.Versionable(type))
                    vsn.Remove(versioner.VersionKey);

            return vsn;
        }
 public virtual void NewSerializedVersionMatch(ItemVersion newSerializedVersion, ISerializedItem serializedItem, ISourceItem existingItem)
 {
     _logger.Debug("> New version {0}#{1} (serialized)".FormatWith(newSerializedVersion.Language, newSerializedVersion.VersionNumber));
 }
Пример #22
0
 /// <summary>
 /// Get the url to access a specific version of a content item given a base url
 /// </summary>
 /// <param name="currUrl">The base url</param>
 /// <param name="version">The version for which to modify the url to access</param>
 /// <returns>Modified url</returns>
 public string GetVersionUrl(string currUrl, ItemVersion version)
 {
     string url = currUrl;
     foreach (var versioner in Versioners)
     {
         url = versioner.GetVersionUrl(url, version);
     }
     return url;
 }
Пример #23
0
        /// <summary>
        /// Starting from a list of addresses and optionally (or only) the containers at those addresses, fetch
        /// any containers necessary and any other containers required to supply redirected properties for them,
        /// obtain the contained content items and collate their properties, returning the content items at the
        /// addresses.
        /// </summary>
        /// <typeparam name="T">Type of content items to return</typeparam>
        /// <param name="startContainers">Initial list of containers if they are available</param>
        /// <param name="startAddresses">Initial list of addresses, which may be omitted and derived from containers</param>
        /// <returns>List of content items</returns>
        public IEnumerable <T> Collate <T>(IEnumerable <object> startContainers, IEnumerable <Address> startAddresses) where T : class
        {
            // place to store all the containers we have currently
            var containers = new Dictionary <VersionedAddress, object>();

            ItemVersion containerCommonVersion = null;

            // Ensure we have the start addresses
            if (startContainers != null)
            {
                containers             = startContainers.ToDictionary(sc => new VersionedAddress(sc), sc => sc);
                startAddresses         = containers.Keys.Select(va => va.Address).Distinct().ToList();
                containerCommonVersion = ItemVersion.LeastAbstractCommonVersion(containers.Keys.Select(va => va.Version));
            }

            var fetchAddrs = startAddresses
                             .GroupBy(a => a.Type.GetCustomAttributes <RedirectPropertySourceAttribute>())
                             .SelectMany(ag =>
                                         ag.SelectMany(a => ag.Key
                                                       .Select(attr => attr.Redirect(a))
                                                       .Concat(a)))
                             .Distinct()
                             .Except(containers.Keys.Select(va => va.Address))
                             .ToList();

            bool pushVersion = (startContainers != null);

            if (pushVersion) // Get containers in any version that might be relevant to a start container
            {
                VersionManager.Instance.PushState(VersioningMode.Specific, containerCommonVersion);
            }

            try
            {
                // Get all the containers for collation (if current version is not fully specified, may be multiple per address)
                foreach (var cont in Repository.Instance.Get(typeof(object), fetchAddrs))
                {
                    var va = new VersionedAddress(cont);
                    if (containers.ContainsKey(va))
                    {
                        log.Error("Duplicate versioned address in db: " + va.ToString());
                    }
                    else
                    {
                        containers.Add(new VersionedAddress(cont), cont);
                    }
                }
            }
            finally
            {
                if (pushVersion)
                {
                    VersionManager.Instance.PopState();
                }
            }

            var contLookup = containers.ToLookup(kvp => kvp.Key.Address.ToString(), kvp => kvp.Value);

            if (startContainers == null)
            {
                startContainers = startAddresses.SelectMany(a => contLookup[a.ToString()]);
            }

            // We have the data, now collate it into the content from the startContainers
            foreach (var addrTypeG in startAddresses.GroupBy(a => a.Type))
            {
                // Process all the start addresses of a given type

                Type contentType   = addrTypeG.Key;
                var  rpsAttributes = contentType
                                     .GetCustomAttributes(typeof(RedirectPropertySourceAttribute), false)
                                     .Cast <RedirectPropertySourceAttribute>()
                                     .ToList();

                foreach (var addr in addrTypeG)
                {
                    var primaryPath = addr.GetAsContentPath();
                    if (!contLookup.Contains(addr.ToString()))
                    {
                        continue;
                    }

                    foreach (var cont in contLookup[addr.ToString()])
                    {
                        object primaryContent = cont;

                        if (primaryContent is IContentContainer)
                        {
                            primaryContent = ((IContentContainer)primaryContent).GetContent();
                        }

                        foreach (var rpsAttribute in rpsAttributes)
                        {
                            var refAddress = new VersionedAddress(
                                rpsAttribute.ContentType ?? contentType,
                                PathFunctions.Redirect(primaryPath, rpsAttribute.SourceDescriptor),
                                new ItemVersion(cont)
                                );
                            if (refAddress.Address == addr) // redirected to itself, ignore
                            {
                                continue;
                            }
                            object refItem = containers.ContainsKey(refAddress) ? containers[refAddress] : null;
                            if (refItem is IContentContainer)
                            {
                                refItem = ((IContentContainer)refItem).GetContent();
                            }
                            if (refItem != null)
                            {
                                foreach (string propertyPath in rpsAttribute.PropertyPaths)
                                {
                                    var    toFromPaths = GetPaths(propertyPath);
                                    object val         = ReflectionX.GetPropertyValueByPath(refItem, toFromPaths[1]);
                                    var    piSet       = ReflectionX.GetPropertyByPath(primaryContent.GetType(), toFromPaths[0]);
                                    piSet.SetValue(primaryContent, val);
                                }
                            }
                        }

                        yield return(primaryContent as T);
                    }
                }
            }
        }
Пример #24
0
 /// <summary>
 /// Set the container to have the ItemVersion supplied
 /// </summary>
 /// <param name="version">ItemVersion to set on the container</param>
 /// <param name="container">The container to set the ItemVersion for</param>
 public void SetVersion(ItemVersion version, object container)
 {
     foreach (var versioner in Versioners)
         if (version.ContainsKey(versioner.VersionKey) && versioner.Versionable(container))
             versioner.SetItemVersion(version, container);
 }
Пример #25
0
 public PublishingVersioner(LyniconSystem sys) : base(sys)
 {
     PublishedVersion = new ItemVersion(new Dictionary <string, object> {
         { VersionKey, true }
     });
 }
Пример #26
0
 /// <summary>
 /// Create a CrossVersionReference from the name of the data type, the identity of the item and the version of the item,
 /// which has an AllowedVersionsOverlay to limit the versions which can be referred to
 /// </summary>
 /// <param name="allowedVersionsOverlay">A version key set to 'null' will allow the reference to be set to any version of that key. A version key set to a value will mean the reference is ALWAYS to that version, irrespective of the current version.</param>
 /// <param name="dataType">The data type of the referred to item</param>
 /// <param name="id">The identity of the referred to item</param>
 /// <param name="itemVersion">The ItemVersion of the referred to item</param>
 public CrossVersionReference(ItemVersion allowedVersionsOverlay, string dataType, string id, string itemVersion)
     : base(dataType, id)
 {
     AllowedVersionsOverlay = allowedVersionsOverlay;
     Version = Version.Mask(allowedVersionsOverlay);
 }
Пример #27
0
 public PublishingVersioner(LyniconSystem sys, Func <Type, bool> isVersionable) : base(sys, isVersionable)
 {
     PublishedVersion = new ItemVersion(new Dictionary <string, object> {
         { VersionKey, true }
     });
 }
Пример #28
0
 /// <summary>
 /// Set the versioning on a container to have the value from this versioning system from the supplied ItemVersion
 /// </summary>
 /// <param name="version">The ItemVersion from which to get the versioning value</param>
 /// <param name="container">The container on which to set the versioning value</param>
 public abstract void SetItemVersion(ItemVersion version, object container);
Пример #29
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"]);
        }
Пример #30
0
        /// <summary>
        /// Run a filter based on the user inputs from the Filter page including the version key values for the selected version,
        /// the list of allowed content class names, the filters and a paging spec
        /// </summary>
        /// <param name="versionFilter">list of version keys in the order they appear in VersionManager.SelectionViewModel</param>
        /// <param name="classFilter">List of content class names</param>
        /// <param name="filters">List of filters</param>
        /// <param name="pagingSpec">Specification of paging</param>
        /// <returns>A list of container x summary tuples which are the results of filtering</returns>
        public List <Tuple <object, Summary> > RunFilter(List <string> versionFilter, string[] classFilter, List <ListFilter> filters, PagingSpec pagingSpec)
        {
            if (filters == null)
            {
                filters = new List <ListFilter>();
            }

            var u     = SecurityManager.Current.User;
            var v     = VersionManager.Instance.CurrentVersion;
            var vsvms = VersionManager.Instance.SelectionViewModel(u, v);
            int vIdx  = 0;

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

            foreach (var vsvm in vsvms)
            {
                object vVal = JsonConvert.DeserializeObject(versionFilter[vIdx]);
                dict.Add(vsvm.VersionKey, vVal is Int64 ? Convert.ToInt32(vVal) : vVal);
                vIdx++;
            }
            var reqVersion = new ItemVersion(dict);

            VersionManager.Instance.PushState(VersioningMode.Specific, reqVersion);

            List <Tuple <object, Summary> > pagedResult = null;

            try
            {
                var types = (classFilter ?? new string[0]).Select(c => ContentTypeHierarchy.GetAnyType(c)).ToList();

                var vm = new ItemListerViewModel();

                for (var i = 0; i < filters.Count; i++)
                {
                    filters[i].MergeOriginal(vm.Filters[filters[i].Idx]);
                }

                var containerFilters = filters.Where(f => (f.Active || f.Sort != 0) && !typeof(Summary).IsAssignableFrom(f.ApplicableType)).ToList();
                var summaryFilters   = filters.Where(f => (f.Active || f.Sort != 0) && typeof(Summary).IsAssignableFrom(f.ApplicableType)).ToList();

                var filterResult = FilterManager.Instance.GetFilterSummaries(types, containerFilters, summaryFilters);

                pagingSpec.Total = filterResult.Count;

                pagedResult = filterResult.ApplyPaging(pagingSpec).ToList();

                //var resultView = pagedResult.Select(t => new List<string> { t.Item2.Url, t.Item2.Title }).ToList();

                //foreach (var filt in filters.Where(f => f.Show))
                //{
                //    for (int i = 0; i < resultView.Count; i++)
                //        resultView[i].Add(filt.GetShowText(pagedResult[i]));
                //}
            }
            finally
            {
                VersionManager.Instance.PopState();
            }

            return(pagedResult);
        }
Пример #31
0
 public static void OpenVersionHistory(ISiteSetting siteSetting, ItemVersion itemVersion)
 {
     Process.Start("IExplore.exe", itemVersion.URL);
 }
Пример #32
0
 public override SC_MenuItems GetItemVersionMenuItems(ISiteSetting siteSetting, ItemVersion itemVersion)
 {
     return(ItemsManager.GetItemVersionMenuItems(siteSetting, itemVersion));
 }
Пример #33
0
        public static void RollbackVersion(ISiteSetting siteSetting, ItemVersion itemVersion)
        {
            IServiceManager serviceManager = ServiceManagerFactory.GetServiceManager(siteSetting.SiteSettingType);

            serviceManager.RestoreVersion(siteSetting, itemVersion);
        }
Пример #34
0
        public IXTable Build(string tableName, XDatabaseContext outerContext, bool deferred)
        {
            // Validate the source name is recognized
            if (!Sources.Contains(tableName))
            {
                throw new UsageException(tableName, "Table", outerContext.StreamProvider.Tables());
            }

            // If we previously found the latest for this table, just return it again
            LatestTableForCutoff previousLatest;

            if (_currentTableVersions.TryGet(tableName, out previousLatest) &&
                previousLatest.Cutoff >= outerContext.RequestedAsOfDateTime &&
                previousLatest.TableVersion.AsOfDate <= outerContext.RequestedAsOfDateTime)
            {
                outerContext.NewestDependency = previousLatest.TableVersion.AsOfDate;
                return(new BinaryTableReader(outerContext.StreamProvider, previousLatest.TableVersion.Path));
            }

            // Create a context to track what we're building now
            XDatabaseContext innerContext = XDatabaseContext.Push(outerContext);

            innerContext.Runner       = this;
            innerContext.CurrentTable = tableName;

            // If this is a query, there won't be a cached table - just build a pipeline to make it
            StreamAttributes queryAttributes = innerContext.StreamProvider.Attributes(innerContext.StreamProvider.Path(LocationType.Query, tableName, ".xql"));

            if (queryAttributes.Exists)
            {
                IXTable queryPipeline = innerContext.Query(innerContext.StreamProvider.ReadAllText(queryAttributes.Path));
                innerContext.Pop(outerContext);
                return(queryPipeline);
            }

            // Find the latest already built result, and associated query
            ItemVersions tableVersions    = innerContext.StreamProvider.ItemVersions(LocationType.Table, tableName);
            ItemVersion  latestTable      = tableVersions.LatestBeforeCutoff(CrawlType.Full, outerContext.RequestedAsOfDateTime);
            string       latestTableQuery = "";

            if (latestTable != null)
            {
                using (BinaryTableReader reader = new BinaryTableReader(outerContext.StreamProvider, latestTable.Path))
                {
                    latestTableQuery = reader.Query;
                }
            }

            // Set the dependency date to the latest table we've already built (if any)
            innerContext.NewestDependency = (latestTable == null ? DateTime.MinValue : latestTable.AsOfDate);

            // Determine the XQL to build the table and construct a builder which can do so
            string  xql;
            IXTable builder;

            // Find the config to build the table and scan dependency versions to determine whether table is out-of-date
            StreamAttributes configAttributes = innerContext.StreamProvider.Attributes(innerContext.StreamProvider.Path(LocationType.Config, tableName, ".xql"));

            if (!configAttributes.Exists)
            {
                // If this is a simple source, just reading it is how to build it
                xql = $"read {XqlScanner.Escape(tableName, TokenType.Value)}";

                // Build a reader concatenating all needed pieces
                builder = ReadSource(tableName, innerContext);
            }
            else
            {
                // If there is a config, the config is how to build it
                xql = innerContext.StreamProvider.ReadAllText(configAttributes.Path);

                // Build a pipeline for the query, recursively creating dependencies
                builder = innerContext.Query(xql);
            }

            // If we don't have the table or the source, we have to throw
            if (latestTable == null && builder == null)
            {
                throw new UsageException(tableName, "Table", innerContext.StreamProvider.Tables());
            }

            // Get the path we're either reading or building
            string tablePath = innerContext.StreamProvider.Path(LocationType.Table, tableName, CrawlType.Full, innerContext.NewestDependency);

            // If sources rebuilt, the query changed, or the latest output isn't up-to-date, rebuild it
            if (innerContext.RebuiltSomething || (latestTableQuery != null && xql != latestTableQuery) || IsOutOfDate(latestTable.AsOfDate, innerContext.NewestDependency))
            {
                // If we're not running now, just return how to build it
                if (deferred)
                {
                    return(builder);
                }

                // Otherwise, build it now; we'll return the query to read the output
                innerContext.CurrentQuery = xql;
                Trace.WriteLine($"COMPUTE: [{innerContext.NewestDependency.ToString(StreamProviderExtensions.DateTimeFolderFormat)}] {tableName}");
                new BinaryTableWriter(builder, innerContext, tablePath).RunAndDispose();
                innerContext.RebuiltSomething = true;
            }

            // Report the newest dependency in this chain to the components above
            innerContext.Pop(outerContext);

            _currentTableVersions.Add(tableName, new LatestTableForCutoff(outerContext.RequestedAsOfDateTime, new ItemVersion(LocationType.Table, tableName, CrawlType.Full, innerContext.NewestDependency)));
            return(new BinaryTableReader(innerContext.StreamProvider, tablePath));
        }
Пример #35
0
 public List <ItemVersion> RestoreVersion(ISiteSetting siteSetting, ItemVersion itemVersion)
 {
     throw new Exception("Not implemented yet");
 }
Пример #36
0
        private bool VersionPermitted(object content)
        {
            if (VersionMask.Keys.Count == 0)
                return true;

            Type type = null;
            if (content is IList)
                type = content.GetType().GetGenericArguments()[0];
            else if (content != null)
                type = content.GetType().ContentType();

            if (content == null || !ContentTypeHierarchy.AllContentTypes.Contains(type))
                return false;

            ItemVersion vsn = null;
            if (content is IList)
            {
                vsn = VersionManager.Instance.CurrentVersion;
            }
            else
            {
                var container = Collator.Instance.GetContainer(content);
                if (container == null)
                    return false;

                vsn = new ItemVersion(container);
            }

            foreach (var kvp in vsn)
            {
                if (VersionMask.ContainsKey(kvp.Key))
                    if (!VersionMask[kvp.Key].Contains(kvp.Value))
                        return false;
            }
            return true;
        }
Пример #37
0
 /// <summary>
 /// Create an ItemVersionedId from an ItemId and an ItemVersion
 /// </summary>
 /// <param name="id">the ItemId</param>
 /// <param name="version">the ItemVersion</param>
 public ItemVersionedId(ItemId id, ItemVersion version) :
     base(id.Type, id.Id)
 {
     Version = version;
 }
Пример #38
0
        /// <summary>
        /// Get the url(s) of a container or content item with option to process through
        /// processes registered to GenerateUrl event
        /// </summary>
        /// <param name="o">container or content item</param>
        /// <param name="transform">whether to process through GenerateUrl event</param>
        /// <returns>All the possible urls</returns>
        public IEnumerable<string> GetUrls(object o, bool transform)
        {
            Type type = Collator.GetContentType(o);

            ICollator collator = Collator.Instance.Registered(type);
            var address = collator.GetAddress(o);

            var urls = GetUrls(address);

            if (transform)
            {
                var container = Collator.Instance.GetContainer(o);
                ItemVersion iv = new ItemVersion(container);
                urls = urls.Select(url => transform ? UrlTransform(url, iv) : url);
            }

            return urls;
        }
Пример #39
0
 /// <summary>
 /// Create an ItemVersionedId from a type, an id and an ItemVersion
 /// </summary>
 /// <param name="type">the type</param>
 /// <param name="id">the id</param>
 /// <param name="version">the ItemVersion</param>
 public ItemVersionedId(Type type, object id, ItemVersion version) :
     base(type, id)
 {
     Version = version ?? throw new ArgumentException("ItemVersion cannot be null");
 }
Пример #40
0
 /// <summary>
 /// Expand the abstract version to a list of fully-specified versions
 /// with all the keys of all the registered versions
 /// </summary>
 /// <param name="iv">Abstract version to expand</param>
 /// <returns>List of fully-specified versions</returns>
 public List<ItemVersion> ContainingVersions(ItemVersion iv)
 {
     var expIv = new ItemVersion(iv);
     foreach (var versioner in Versioners)
     {
         if (!iv.ContainsKey(versioner.VersionKey))
             expIv.Add(versioner.VersionKey, null);
     }
     return expIv.Expand();
 }
Пример #41
0
 /// <summary>
 /// Creates an ItemVersionedId for a content item specified by its ItemId and an
 /// ItemVersion without removing any version keys inapplicable to the type of the item
 /// </summary>
 /// <param name="id">The ItemId of the content item</param>
 /// <param name="vers">The version required</param>
 /// <returns>The ItemVersionedId made of the given ItemId and ItemVersion</returns>
 public static ItemVersionedId CreateWithoutVersionApplicability(ItemId id, ItemVersion vers)
 {
     return(new ItemVersionedId {
         Id = id, Version = vers
     });
 }
Пример #42
0
 /// <summary>
 /// Get all the displays for all the keys in an ItemVersion
 /// </summary>
 /// <param name="version">The ItemVersion to display</param>
 /// <returns>The VersionDisplays for all the keys of the ItemVersion</returns>
 public List<VersionDisplay> DisplayVersion(ItemVersion version)
 {
     return Versioners
         .OrderBy(v => v.VersionKey)
         .Where(v => version.ContainsKey(v.VersionKey))
         .Select(v => v.DisplayItemVersion(version))
         .Where(vi => vi != null && !string.IsNullOrEmpty(vi.Text))
         .ToList();
 }
Пример #43
0
 /// <summary>
 /// Create the ItemVersionedId of a given container or content item
 /// </summary>
 /// <param name="container">The container or content item</param>
 public ItemVersionedId(LyniconSystem sys, object o) :
     base(sys.Collator, o)
 {
     Version = new ItemVersion(sys, o);
 }
Пример #44
0
        /// <summary>
        /// Get the ItemVersion of a container
        /// </summary>
        /// <param name="container">The container</param>
        /// <returns>The ItemVersion of the container</returns>
        public ItemVersion GetVersion(object container)
        {
            var version = new ItemVersion();
            foreach (var versioner in Versioners)
                if (versioner.Versionable(container))
                    versioner.GetItemVersion(container, version);

            return version;
        }
Пример #45
0
        // Methods
        public ItemAction(byte[] data)
            : base(data)
        {
            this.superiorType = SuperiorItemType.NotApplicable;
            this.charClass = CharacterClass.NotApplicable;
            this.level = -1;
            this.usedSockets = -1;
            this.use = -1;
            this.graphic = -1;
            this.color = -1;
            this.stats = new List<StatBase>();
            this.unknown1 = -1;
            this.runewordID = -1;
            this.runewordParam = -1;
            BitReader br = new BitReader(data, 1);
            this.action = (ItemActionType) br.ReadByte();
            br.SkipBytes(1);
            this.category = (ItemCategory) br.ReadByte();
            this.uid = br.ReadUInt32();
            if (data[0] == 0x9d)
            {
                br.SkipBytes(5);
            }
            this.flags = (ItemFlags) br.ReadUInt32();
            this.version = (ItemVersion) br.ReadByte();
            this.unknown1 = br.ReadByte(2);
            this.destination = (ItemDestination) br.ReadByte(3);
            if (this.destination == ItemDestination.Ground)
            {
                this.x = br.ReadUInt16();
                this.y = br.ReadUInt16();
            }
            else
            {
                this.location = (EquipmentLocation) br.ReadByte(4);
                this.x = br.ReadByte(4);
                this.y = br.ReadByte(3);
                this.container = (ItemContainer) br.ReadByte(4);
            }
            if ((this.action == ItemActionType.AddToShop) || (this.action == ItemActionType.RemoveFromShop))
            {
                int num = ((int) this.container) | 0x80;
                if ((num & 1) == 1)
                {
                    num--;
                    this.y += 8;
                }
                this.container = (ItemContainer) num;
            }
            else if (this.container == ItemContainer.Unspecified)
            {
                if (this.location == EquipmentLocation.NotApplicable)
                {
                    if ((this.Flags & ItemFlags.InSocket) == ItemFlags.InSocket)
                    {
                        this.container = ItemContainer.Item;
                        this.y = -1;
                    }
                    else if ((this.action == ItemActionType.PutInBelt) || (this.action == ItemActionType.RemoveFromBelt))
                    {
                        this.container = ItemContainer.Belt;
                        this.y = this.x / 4;
                        this.x = this.x % 4;
                    }
                }
                else
                {
                    this.x = -1;
                    this.y = -1;
                }
            }
            if ((this.flags & ItemFlags.Ear) == ItemFlags.Ear)
            {
                this.charClass = (CharacterClass) br.ReadByte(3);
                this.level = br.ReadByte(7);
                this.name = br.ReadString(7, '\0', 0x10);
                this.baseItem = BaseItem.Get(ItemType.Ear);
            }
            else
            {
                this.baseItem = BaseItem.GetByID(this.category, br.ReadUInt32());
                if (this.baseItem.Type == ItemType.Gold)
                {
                    this.stats.Add(new SignedStat(BaseStat.Get(StatType.Quantity), br.ReadInt32(br.ReadBoolean(1) ? 0x20 : 12)));
                }
                else
                {
                    this.usedSockets = br.ReadByte(3);
                    if ((this.flags & (ItemFlags.Compact | ItemFlags.Gamble)) == ItemFlags.None)
                    {
                        BaseStat stat;
                        int num2;
                        this.level = br.ReadByte(7);
                        this.quality = (ItemQuality) br.ReadByte(4);
                        if (br.ReadBoolean(1))
                        {
                            this.graphic = br.ReadByte(3);
                        }
                        if (br.ReadBoolean(1))
                        {
                            this.color = br.ReadInt32(11);
                        }
                        if ((this.flags & ItemFlags.Identified) == ItemFlags.Identified)
                        {
                            switch (this.quality)
                            {
                                case ItemQuality.Inferior:
                                    this.prefix = new ItemAffix(ItemAffixType.InferiorPrefix, br.ReadByte(3));
                                    break;

                                case ItemQuality.Superior:
                                    this.prefix = new ItemAffix(ItemAffixType.SuperiorPrefix, 0);
                                    this.superiorType = (SuperiorItemType) br.ReadByte(3);
                                    break;

                                case ItemQuality.Magic:
                                    this.prefix = new ItemAffix(ItemAffixType.MagicPrefix, br.ReadUInt16(11));
                                    this.suffix = new ItemAffix(ItemAffixType.MagicSuffix, br.ReadUInt16(11));
                                    break;

                                case ItemQuality.Set:
                                    this.setItem = BaseSetItem.Get(br.ReadUInt16(12));
                                    break;

                                case ItemQuality.Rare:
                                case ItemQuality.Crafted:
                                    this.prefix = new ItemAffix(ItemAffixType.RarePrefix, br.ReadByte(8));
                                    this.suffix = new ItemAffix(ItemAffixType.RareSuffix, br.ReadByte(8));
                                    break;

                                case ItemQuality.Unique:
                                    if (this.baseItem.Code != "std")
                                    {
                                        try
                                        {
                                            this.uniqueItem = BaseUniqueItem.Get(br.ReadUInt16(12));
                                        }
                                        catch{}
                                    }
                                    break;
                            }
                        }
                        if ((this.quality == ItemQuality.Rare) || (this.quality == ItemQuality.Crafted))
                        {
                            this.magicPrefixes = new List<MagicPrefixType>();
                            this.magicSuffixes = new List<MagicSuffixType>();
                            for (int i = 0; i < 3; i++)
                            {
                                if (br.ReadBoolean(1))
                                {
                                    this.magicPrefixes.Add((MagicPrefixType) br.ReadUInt16(11));
                                }
                                if (br.ReadBoolean(1))
                                {
                                    this.magicSuffixes.Add((MagicSuffixType) br.ReadUInt16(11));
                                }
                            }
                        }
                        if ((this.Flags & ItemFlags.Runeword) == ItemFlags.Runeword)
                        {
                            this.runewordID = br.ReadUInt16(12);
                            this.runewordParam = br.ReadUInt16(4);
                            num2 = -1;
                            if (this.runewordParam == 5)
                            {
                                num2 = this.runewordID - (this.runewordParam * 5);
                                if (num2 < 100)
                                {
                                    num2--;
                                }
                            }
                            else if (this.runewordParam == 2)
                            {
                                num2 = ((this.runewordID & 0x3ff) >> 5) + 2;
                            }
                            br.ByteOffset -= 2;
                            this.runewordParam = br.ReadUInt16();
                            this.runewordID = num2;
                            if (num2 == -1)
                            {
                                throw new Exception("Unknown Runeword: " + this.runewordParam);
                            }
                            this.runeword = BaseRuneword.Get(num2);
                        }
                        if ((this.Flags & ItemFlags.Personalized) == ItemFlags.Personalized)
                        {
                            this.name = br.ReadString(7, '\0', 0x10);
                        }
                        if (this.baseItem is BaseArmor)
                        {
                            stat = BaseStat.Get(StatType.ArmorClass);
                            this.stats.Add(new SignedStat(stat, br.ReadInt32(stat.SaveBits) - stat.SaveAdd));
                        }
                        if ((this.baseItem is BaseArmor) || (this.baseItem is BaseWeapon))
                        {
                            stat = BaseStat.Get(StatType.MaxDurability);
                            num2 = br.ReadInt32(stat.SaveBits);
                            this.stats.Add(new SignedStat(stat, num2));
                            if (num2 > 0)
                            {
                                stat = BaseStat.Get(StatType.Durability);
                                this.stats.Add(new SignedStat(stat, br.ReadInt32(stat.SaveBits)));
                            }
                        }
                        if ((this.Flags & (ItemFlags.None | ItemFlags.Socketed)) == (ItemFlags.None | ItemFlags.Socketed))
                        {
                            stat = BaseStat.Get(StatType.Sockets);
                            this.stats.Add(new SignedStat(stat, br.ReadInt32(stat.SaveBits)));
                        }
                        if (this.baseItem.Stackable)
                        {
                            if (this.baseItem.Useable)
                            {
                                this.use = br.ReadByte(5);
                            }
                            this.stats.Add(new SignedStat(BaseStat.Get(StatType.Quantity), br.ReadInt32(9)));
                        }
                        if ((this.Flags & ItemFlags.Identified) == ItemFlags.Identified)
                        {
                            StatBase base2;
                            int num4 = (this.Quality == ItemQuality.Set) ? br.ReadByte(5) : -1;
                            this.mods = new List<StatBase>();
                            while ((base2 = ReadStat(br)) != null)
                            {
                                this.mods.Add(base2);
                            }
                            if ((this.flags & ItemFlags.Runeword) == ItemFlags.Runeword)
                            {
                                while ((base2 = ReadStat(br)) != null)
                                {
                                    this.mods.Add(base2);
                                }
                            }
                            if (num4 > 0)
                            {
                                this.setBonuses = new List<StatBase>[5];
                                for (int j = 0; j < 5; j++)
                                {
                                    if ((num4 & (((int) 1) << j)) != 0)
                                    {
                                        this.setBonuses[j] = new List<StatBase>();
                                        while ((base2 = ReadStat(br)) != null)
                                        {
                                            this.setBonuses[j].Add(base2);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #46
0
 /// <summary>
 /// Push a versioning state with a VersioningMode and a specific ItemVersion (making it active)
 /// </summary>
 /// <param name="mode">The VersioningMode to push</param>
 /// <param name="specificVersion">The SpecificVersion to push</param>
 public void PushState(VersioningMode mode, ItemVersion specificVersion)
 {
     StateStack.Push(new VersioningState { Mode = this.Mode, SpecificVersion = this.SpecificVersion });
     this.Mode = mode;
     if (specificVersion != null)
         this.SpecificVersion = specificVersion;
 }
Пример #47
0
        public void ItemVersionedIdConstructors()
        {
            ItemVersion iv0 = new ItemVersion(new Dictionary <string, object> {
                { "Locale", "en-GB" }
            });

            // ItemId uses ContentType() of the relevant type
            Guid id1     = Guid.NewGuid();
            Type extType = sys.LyniconSystem.Extender[typeof(TestData)];
            var  ii1     = new ItemVersionedId(extType, id1, iv0);

            Assert.Equal(typeof(TestData), ii1.Type);

            // Serialize/Deserialize
            var ii2 = new ItemVersionedId(ii1.ToString());

            Assert.Equal(ii2.Type, ii1.Type);
            Assert.Equal(ii2.Id, ii1.Id);
            Assert.Equal(ii2, ii1);

            // Construct from basic type
            TestData td = Collator.Instance.GetNew <TestData>(new Address(typeof(TestData), "a"));

            td.Id = 5;
            var ii3 = new ItemVersionedId(sys.LyniconSystem, td);

            Assert.Equal(ii3.Id, td.Id);
            Assert.Equal(ii3.Version, VersionManager.Instance.CurrentVersionForType(typeof(TestData)));

            // Construct from container
            //Guid id = Guid.NewGuid();
            //Guid ident = Guid.NewGuid();
            //ContentItem ci = new ContentItem { Id = id, Identity = ident, DataType = typeof(RestaurantContent).FullName };
            //var ii4 = new ItemVersionedId(ci);
            //Assert.Equal(ii4.Id, ident);
            //Assert.Equal(ii4.Type, typeof(RestaurantContent));
            //Assert.Equal(ii4.Version, VersionManager.Instance.CurrentVersionForType(typeof(RestaurantContent)));

            // Construct from data item
            RestaurantContent rc = Collator.Instance.GetNew <RestaurantContent>(new Address(typeof(RestaurantContent), "x"));
            var ii5 = new ItemVersionedId(sys.LyniconSystem, rc);

            Assert.Equal(ii5.Id, ((ICoreMetadata)rc).Identity);
            Assert.Equal(ii5.Version, VersionManager.Instance.CurrentVersionForType(typeof(RestaurantContent)));

            // Construct from summary
            RestaurantSummary rs = Collator.Instance.GetSummary <RestaurantSummary>(rc);
            var ii6 = new ItemVersionedId(sys.LyniconSystem, rs);

            Assert.Equal(ii6.Id, rs.Id);
            Assert.Equal(ii6.Type, rs.Type);
            Assert.Equal(ii6.Version, VersionManager.Instance.CurrentVersionForType(typeof(RestaurantContent)));

            // No empty value allowed
            ContentItem cc       = null;
            ItemId      iitest   = null;
            object      otest    = null;
            string      stest    = null;
            Summary     summtest = null;

            Assert.Throws <NullReferenceException>(() => new ItemVersionedId(sys.LyniconSystem, cc));
            Assert.Throws <NullReferenceException>(() => new ItemVersionedId(iitest));
            Assert.Throws <NullReferenceException>(() => new ItemVersionedId(sys.LyniconSystem, otest));
            Assert.Throws <ArgumentException>(() => new ItemVersionedId(stest));
            Assert.Throws <NullReferenceException>(() => new ItemVersionedId(sys.LyniconSystem, summtest));
            Assert.Throws <ArgumentException>(() => new ItemVersionedId(typeof(RestaurantContent), null, iv0));
            Assert.Throws <ArgumentException>(() => new ItemVersionedId(null, Guid.NewGuid(), iv0));
            Assert.Throws <ArgumentException>(() => new ItemVersionedId(typeof(RestaurantContent), Guid.NewGuid(), null));
        }
Пример #48
0
        /// <summary>
        /// Get a list of VersionSelectionViewModels to create a version selector for a given user and a given current version
        /// </summary>
        /// <param name="u">The user</param>
        /// <param name="currVersion">The current version</param>
        /// <param name="abbreviated">Whether the display is abbreviated (not implemented)</param>
        /// <returns>List of VersionSelectionViewModels</returns>
        public List<VersionSelectionViewModel> SelectionViewModel(IUser u, ItemVersion currVersion, bool abbreviated)
        {
            var vm = new List<VersionSelectionViewModel>();
            foreach (var v in Versioners.Where(v => currVersion.ContainsKey(v.VersionKey) && currVersion[v.VersionKey] != null).OrderBy(v => v.VersionKey))
            {
                var versions = v.GetAllowedVersions(u);
                var selectList = new List<SelectListItem>();
                string cssClass = null;
                foreach (object o in versions)
                {
                    var iv = new ItemVersion { { v.VersionKey, o } };
                    var dv = v.DisplayItemVersion(iv);
                    cssClass = dv.CssClass;
                    var sli = new SelectListItem();
                    sli.Text = (abbreviated ? dv.Text + "|" : "") + dv.ListItem;
                    sli.Value = JsonConvert.SerializeObject(o);
                    sli.Selected = currVersion[v.VersionKey] != null && currVersion[v.VersionKey].Equals(o);
                    selectList.Add(sli);
                }
                vm.Add(new VersionSelectionViewModel
                    {
                        Title = v.VersionKey,
                        SelectList = selectList,
                        VersionKey = v.VersionKey,
                        CssClass = cssClass
                    });
            }

            return vm;
        }
Пример #49
0
 /// <summary>
 /// Get the versioning system value from a container and set this value on the supplied ItemVersion
 /// </summary>
 /// <param name="container">The container from which to get the version key</param>
 /// <param name="version">The ItemVersion on which to add the key/value for this versioning system</param>
 public abstract void GetItemVersion(object container, ItemVersion version);
Пример #50
0
 /// <summary>
 /// Create an ItemVersion with null values for all the keys applicable to a type
 /// </summary>
 /// <param name="type">The type for which to create the ItemVersion</param>
 /// <returns>ItemVersion with null values for all the keys applicable</returns>
 public ItemVersion VersionForType(Type type)
 {
     var iv = new ItemVersion();
     foreach (var versioner in Versioners)
         if (versioner.Versionable(type))
             iv.Add(versioner.VersionKey, null);
     return iv;
 }
Пример #51
0
 /// <summary>
 /// Taking a url, add to it any switches or changes in this versioning system required for it to refer to a content
 /// item with the versioning value contained in the supplied ItemVersion for this versioning system.  This will
 /// leave the url unchanged for 'unaddressable' version keys
 /// </summary>
 /// <param name="url">The initial url</param>
 /// <param name="version">The version for which we are modifying the url</param>
 /// <returns>The modified url</returns>
 public virtual string GetVersionUrl(string url, ItemVersion version)
 {
     return url;
 }
Пример #52
0
        private bool OverrideVersion(ItemVersion v, ItemVersion over)
        {
            bool changed = false;
            foreach (var versioner in Versioners)
            {
                if (over.ContainsKey(versioner.VersionKey))
                {
                    IUser u = LyniconSecurityManager.Current.User;
                    var legalVals = versioner.GetAllowedVersions(u);
                    var overVal = over[versioner.VersionKey];
                    if (legalVals.Any(lVal => lVal.Equals(overVal)))
                    {
                        if (!v.ContainsKey(versioner.VersionKey)
                            || (v[versioner.VersionKey] == null && overVal != null)
                            || !v[versioner.VersionKey].Equals(overVal))
                        {
                            v[versioner.VersionKey] = overVal;
                            changed = true;
                        }
                    }
                }
            }

            return changed;
        }
Пример #53
0
 /// <summary>
 /// Create a CrossVersionReference from the name of the data type, the identity of the item and the version of the item
 /// </summary>
 /// <param name="dataType">The data type of the referred to item</param>
 /// <param name="id">The identity of the referred to item</param>
 /// <param name="itemVersion">The ItemVersion of the referred to item</param>
 public CrossVersionReference(string dataType, string id, string itemVersion) : base(dataType, id)
 {
     Version = new ItemVersion(itemVersion);
 }