示例#1
0
        /// <summary>
        /// Mask returns a new ItemVersion made by taking all the key value pairs from the argument ItemVersion
        /// and where the value is null, and this ItemVersion has the corresponding key, taking the value from
        /// this ItemVersion.  The null values in the argument can be viewed as holes in the mask.
        /// </summary>
        /// <param name="other">ItemVersion with which to mask this one to get the result</param>
        /// <returns>Resulting ItemVersion</returns>
        public ItemVersion Mask(ItemVersion other)
        {
            var masked = new ItemVersion();

            other.Do(kvp =>
            {
                if (kvp.Value == null && this.ContainsKey(kvp.Key))
                {
                    masked.Add(kvp.Key, this[kvp.Key]);
                }
                else if (kvp.Value != null)
                {
                    masked.Add(kvp.Key, kvp.Value);
                }
            });
            return(masked);
        }
示例#2
0
        /// <summary>
        /// With some versionings, the different versions are all accessible on different urls (e.g. different language versions).
        /// These are 'addressable'.  Other versionings only have one version which is accessible (e.g. published/unpublished).  These
        /// are 'unaddressable'.  This returns the version key/values in this version which are unaddressable.
        /// </summary>
        /// <returns>Version with unaddressable key/values only</returns>
        public ItemVersion GetUnaddressablePart()
        {
            var unaddressablePart = new ItemVersion();

            this.Where(kvp => VersionManager.Instance.UnaddressableVersionKeys.Contains(kvp.Key))
            .Do(kvp => unaddressablePart.Add(kvp.Key, kvp.Value));
            return(unaddressablePart);
        }
示例#3
0
        /// <summary>
        /// Find the most specific ItemVersion which contains both this ItemVersion and the argument
        /// </summary>
        /// <param name="other">Other ItemVersion</param>
        /// <returns>Most specific ItemVersion containing this and the other</returns>
        public ItemVersion LeastAbstractCommonVersion(ItemVersion other)
        {
            var extended = new ItemVersion();

            other.Do(kvp =>
            {
                if (this.ContainsKey(kvp.Key) && this[kvp.Key] == kvp.Value)
                {
                    extended.Add(kvp.Key, kvp.Value);
                }
            });
            return(extended);
        }
示例#4
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);
        }
示例#5
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());
        }
示例#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>
        /// Find all specific ItemVersions which are applicable to a type
        /// </summary>
        /// <param name="t">The type</param>
        /// <returns>All applicable ItemVersion</returns>
        public List <ItemVersion> MatchingVersions(Type t)
        {
            var vsn   = new ItemVersion(this);
            var other = VersionManager.Instance.VersionForType(t);

            foreach (var key in this.Keys)
            {
                if (!other.ContainsKey(key))
                {
                    vsn.Remove(key);
                }
            }
            foreach (var key in other.Keys)
            {
                if (!vsn.ContainsKey(key))
                {
                    vsn.Add(key, null);
                }
            }
            return(vsn.Expand());
        }