Example #1
0
 public CloneExclusion(ExclusionMode mode, string propertyName = null, RawPtr pointer = null, AssetsObject pointerTarget = null, Type type = null)
 {
     Mode          = mode;
     PropertyName  = propertyName;
     Pointer       = pointer;
     Type          = type;
     PointerTarget = pointerTarget;
 }
Example #2
0
 private void OverwriteExclusive(object key)
 {
     if (key != Key)
     {
         Key = key;
         this.Children.Clear();
         mode = ExclusionMode.Empty;
     }
 }
Example #3
0
        ///// <summary>
        ///// Store an exclusive child inside this node.
        ///// </summary>
        ///// <param name="v">Bound variable holding the key for the child</param>
        ///// <param name="overwrite">If true, this will overwrite any existing child with a different value.</param>
        ///// <returns>The child node</returns>
        ///// <exception cref="KBExclusionException">If a non-exclusive child has already been written.</exception>
        //public ELNode StoreExclusive(Variable v, bool overwrite)
        //{
        //    return StoreExclusive(v.Value, overwrite);
        //}

        /// <summary>
        /// Store an exclusive child inside this node.
        /// </summary>
        /// <param name="key">Key for the child</param>
        /// <param name="overwrite">If true, this will overwrite any existing child with a different value.</param>
        /// <returns>The child node</returns>
        /// <exception cref="ELNodeExclusionException">If a non-exclusive child has already been written.</exception>
        public ELNode StoreExclusive(object key, bool overwrite)
        {
            switch (mode)
            {
            case ExclusionMode.Empty:
            {
                mode = ExclusionMode.Exclusive;
                var result = new ELNode(this, key);
                if (this.Children.Count == 0)
                {
                    this.Children = new List <ELNode> {
                        result
                    }
                }
                ;
                else
                {
                    this.Children.Add(result);
                }

                return(result);
            }

            case ExclusionMode.NonExclusive:
                throw new ELNodeExclusionException("Exclusive store on non-exclusive node.", this, key);


            case ExclusionMode.Exclusive:
                if (overwrite)
                {
                    if (this.Children.Count > 0)
                    {
                        this.Children[0].OverwriteExclusive(key);
                    }
                    else
                    {
                        this.Children.Add(new ELNode(this, key));
                    }
                }
                else if (key != this.Children[0].Key)
                {
                    throw new ELNodeExclusionException("Exclusive store doesn't match previous store.", this, key);
                }
                return(this.Children[0]);

            default:
                throw new InvalidOperationException("Invalid exclusion mode");
            }
        }
Example #4
0
 public RandomExhaust(List <Type> list, ExclusionMode exclusionMode, int exclusionNumber = 1, string persistencyKey = "", int maxSizeSaved = 30, bool useFirstToPick = false, Type firstToPick = default(Type))
 {
     this.list            = list;
     this.exclusionMode   = exclusionMode;
     this.persistencyKey  = persistencyKey;
     this.maxSizeSaved    = maxSizeSaved;
     this.exclusionNumber = exclusionNumber;
     this.useFirstToPick  = useFirstToPick;
     this.firstToPick     = firstToPick;
     if (persistent)
     {
         LoadExcludingList();
         UpdateExcludingList();
     }
 }
Example #5
0
        /// <summary>
        /// Store an exclusive child inside this node.
        /// </summary>
        /// <param name="key">Key for the child</param>
        /// <param name="overwrite">If true, this will overwrite any existing child with a different value.</param>
        /// <returns>The child node</returns>
        /// <exception cref="KBExclusionException">If a non-exclusive child has already been written.</exception>
        public KnowledgeBaseEntry StoreExclusive(object key, bool overwrite)
        {
            switch (mode)
            {
            case ExclusionMode.Empty:
            {
                mode = ExclusionMode.Exclusive;
                var result = new KnowledgeBaseEntry(this, key);
                if (this.Children == EmptyChildren)
                {
                    this.Children = new List <KnowledgeBaseEntry> {
                        result
                    }
                }
                ;
                else
                {
                    this.Children.Add(result);
                }

                return(result);
            }

            case ExclusionMode.NonExclusive:
                throw new KBExclusionException("Exclusive store on non-exclusive node.");


            case ExclusionMode.Exclusive:
                if (overwrite)
                {
                    this.Children[0].OverwriteExclusive(key);
                }
                else if (key != this.Children[0].Key)
                {
                    throw new KBExclusionException("Exclusive store doesn't match previous store.");
                }
                return(this.Children[0]);

            default:
                throw new InvalidOperationException("Invalid exclusion mode");
            }
        }
Example #6
0
        public static ExclusionMode GetExclusionMode(this IEnumerable <CloneExclusion> exclus, object targetObject, PropertyInfo propInfo)
        {
            if (exclus == null)
            {
                return(ExclusionMode.None);
            }

            ExclusionMode mode = ExclusionMode.None;

            foreach (var e in exclus)
            {
                if (e.Matches(targetObject, propInfo))
                {
                    if (e.Mode > mode)
                    {
                        mode = e.Mode;
                    }
                }
            }
            return(mode);
        }
Example #7
0
        ///// <summary>
        ///// Store a non-exclusive child inside this node.
        ///// </summary>
        ///// <param name="v">Bound variable holding the key for the child</param>
        ///// <returns>The child node</returns>
        ///// <exception cref="KBExclusionException">If an exclusive child has already been written.</exception>
        //public ELNode StoreNonExclusive(Variable v)
        //{
        //    return StoreNonExclusive(v.Value);
        //}

        /// <summary>
        /// Store a non-exclusive child inside this node.
        /// </summary>
        /// <param name="key">Key for the new child</param>
        /// <returns>The child node</returns>
        /// <exception cref="ELNodeExclusionException">If an exclusive child has already been written.</exception>
        public ELNode StoreNonExclusive(object key)
        {
            ELNode result = null;

            switch (mode)
            {
            case ExclusionMode.Empty:
            {
                mode   = ExclusionMode.NonExclusive;
                result = new ELNode(this, key);
                if (this.Children == EmptyChildren)
                {
                    this.Children = new List <ELNode> {
                        result
                    }
                }
                ;
                else
                {
                    this.Children.Add(result);
                }
            }
            break;

            case ExclusionMode.Exclusive:
                throw new ELNodeExclusionException("Non-exclusive store on exclusive node.", this, key);

            case ExclusionMode.NonExclusive:
                foreach (var c in this.Children)
                {
                    if (c.Key == key)
                    {
                        return(c);
                    }
                }
                this.Children.Add(result = new ELNode(this, key));
                break;
            }
            return(result);
        }
Example #8
0
        /// <summary>
        /// Store a non-exclusive child inside this node.
        /// </summary>
        /// <param name="key">Key for the new child</param>
        /// <returns>The child node</returns>
        /// <exception cref="KBExclusionException">If an exclusive child has already been written.</exception>
        public KnowledgeBaseEntry StoreNonExclusive(object key)
        {
            KnowledgeBaseEntry result = null;

            switch (mode)
            {
            case ExclusionMode.Empty:
            {
                mode   = ExclusionMode.NonExclusive;
                result = new KnowledgeBaseEntry(this, key);
                if (this.Children == EmptyChildren)
                {
                    this.Children = new List <KnowledgeBaseEntry> {
                        result
                    }
                }
                ;
                else
                {
                    this.Children.Add(result);
                }
            }
            break;

            case ExclusionMode.Exclusive:
                throw new KBExclusionException("Non-exclusive store on exclusive node.");

            case ExclusionMode.NonExclusive:
                foreach (var c in this.Children)
                {
                    if (c.Key == key)
                    {
                        return(c);
                    }
                }
                this.Children.Add(result = new KnowledgeBaseEntry(this, key));
                break;
            }
            return(result);
        }
Example #9
0
 public RandomExhaustAudioClip(List <AudioClip> list, ExclusionMode exclusionMode, int exclusionNumber = 1, string persistencyKey = "", int maxSizeSaved = 30)
     : base(list, exclusionMode, exclusionNumber, persistencyKey, maxSizeSaved)
 {
 }
Example #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RandomExhaustInt"/> class with a list of numbers ranging from rangeStart to rangeEnd (included).
 /// </summary>
 public RandomExhaustInt(int rangeStart, int rangeEnd, ExclusionMode exclusionMode, int exclusionNumber = 1, string persistencyKey = "", int maxSizeSaved = 30)
     : base(Enumerable.Range(rangeStart, rangeEnd - rangeStart + 1).ToList(), exclusionMode, exclusionNumber, persistencyKey, maxSizeSaved)
 {
 }
Example #11
0
 public CloneExclusion(ExclusionMode mode)
 {
     Mode = mode;
 }
Example #12
0
 private void OverwriteExclusive(object key)
 {
     Key = key;
     this.Children.Clear();
     mode = ExclusionMode.Empty;
 }
Example #13
0
        /// <summary>
        /// Store a non-exclusive child inside this node.
        /// </summary>
        /// <param name="key">Key for the new child</param>
        /// <returns>The child node</returns>
        /// <exception cref="KBExclusionException">If an exclusive child has already been written.</exception>
        public KnowledgeBaseEntry StoreNonExclusive(object key)
        {
            KnowledgeBaseEntry result =null;
            switch (mode)
            {
                case ExclusionMode.Empty:
                    {
                        mode = ExclusionMode.NonExclusive;
                        result = new KnowledgeBaseEntry(this, key);
                        if (this.Children == EmptyChildren)
                            this.Children = new List<KnowledgeBaseEntry> { result };
                        else
                            this.Children.Add(result);
                    }
                    break;

                case ExclusionMode.Exclusive:
                    throw new KBExclusionException("Non-exclusive store on exclusive node.");

                case ExclusionMode.NonExclusive:
                    foreach (var c in this.Children)
                    {
                        if (c.Key == key)
                            return c;
                    }
                    this.Children.Add(result = new KnowledgeBaseEntry(this, key));
                    break;
            }
            return result;
        }
Example #14
0
        /// <summary>
        /// Store an exclusive child inside this node.
        /// </summary>
        /// <param name="key">Key for the child</param>
        /// <param name="overwrite">If true, this will overwrite any existing child with a different value.</param>
        /// <returns>The child node</returns>
        /// <exception cref="KBExclusionException">If a non-exclusive child has already been written.</exception>
        public KnowledgeBaseEntry StoreExclusive(object key, bool overwrite)
        {
            switch (mode)
            {
                case ExclusionMode.Empty:
                    {
                        mode = ExclusionMode.Exclusive;
                        var result = new KnowledgeBaseEntry(this, key);
                        if (this.Children == EmptyChildren)
                            this.Children = new List<KnowledgeBaseEntry> { result };
                        else
                            this.Children.Add(result);

                        return result;
                    }

                case ExclusionMode.NonExclusive:
                    throw new KBExclusionException("Exclusive store on non-exclusive node.");

                case ExclusionMode.Exclusive:
                    if (overwrite)
                        this.Children[0].OverwriteExclusive(key);
                    else if (key != this.Children[0].Key)
                        throw new KBExclusionException("Exclusive store doesn't match previous store.");
                    return this.Children[0];

                default:
                    throw new InvalidOperationException("Invalid exclusion mode");
            }
        }