Exemple #1
0
 public AssetKey(AssetType assetType, params string[] tags)
 {
     AssetType = assetType;
     Tags = tags.Select(x => x.ToUpperInvariant()).OrderBy(x => x).ToArray();
     var objects = Tags.Concat(new string[] { AssetType.ToString() }).ToArray();
     compoundKey = new CompoundKey(objects);
 }
Exemple #2
0
        public object PackCompoundKey(string kind, IEnumerable<object> components)
        {
            var result = new CompoundKey();
            foreach(var tuple in Enumerable.Zip(GetKeyNames(kind), components, Tuple.Create))
                result[tuple.Item1] = tuple.Item2;

            return result;
        }
Exemple #3
0
        protected override T GetQuery(TKey key, TKey2 key2, TKey3 key3)
        {
            var compoundKey = new CompoundKey {
                Key1 = key, Key2 = key2, Key3 = key3
            };

            _items.TryGetValue(compoundKey, out T result);

            return(result);
        }
Exemple #4
0
        protected override void AddItem(T entity)
        {
            GetPrimaryKey(entity, out TKey key, out TKey2 key2);

            var compoundKey = new CompoundKey {
                Key1 = key, Key2 = key2
            };

            Items[compoundKey] = entity;
        }
Exemple #5
0
        protected override void UpdateItem(T entity)
        {
            GetPrimaryKey(entity, out TKey key, out TKey2 key2, out TKey3 key3);

            var compoundKey = new CompoundKey {
                Key1 = key, Key2 = key2, Key3 = key3
            };

            _items[compoundKey] = entity;
        }
Exemple #6
0
        protected override void DeleteItem(T entity)
        {
            GetPrimaryKey(entity, out TKey key, out TKey2 key2, out TKey3 key3);

            var compoundKey = new CompoundKey {
                Key1 = key, Key2 = key2, Key3 = key3
            };

            _items.TryRemove(compoundKey, out T tmp);
        }
Exemple #7
0
        /// <summary>
        /// Removes listeners that are mapped to keys which have been garbage collected.
        /// </summary>
        protected virtual void ProcessDeadKeys()
        {
            IEnumerator i = listenersMap.Keys.GetEnumerator();

            while (i.MoveNext())
            {
                CompoundKey key = (CompoundKey)i.Current;
                if (!key.IsAlive)
                {
                    listenersMap.Remove(key);
                }
            }
        }
Exemple #8
0
        public object GetKey(string kind, IDictionary<string, object> data)
        {
            var keyNames = GetKeyNames(kind);

            if(keyNames.Count  > 1) {
                var key = new CompoundKey();
                foreach(var name in keyNames)
                    key[name] = data.GetSafe(name);
                return key;
            }

            return data.GetSafe(keyNames.First());
        }
Exemple #9
0
        protected override void AddItem(T entity)
        {
            TKey  key;
            TKey2 key2;
            TKey3 key3;

            GetPrimaryKey(entity, out key, out key2, out key3);

            var compoundKey = new CompoundKey {
                Key1 = key, Key2 = key2, Key3 = key3
            };

            _items[compoundKey] = entity;
        }
Exemple #10
0
            public int CompareTo(object o)
            {
                CompoundKey c = (CompoundKey)o;
                int         n = keys.Length < c.keys.Length?keys.Length:c.keys.Length;

                for (int i = 0; i < n; i++)
                {
                    int diff = ((IComparable)keys[i]).CompareTo(c.keys[i]);
                    if (diff != 0)
                    {
                        return(diff);
                    }
                }
                return(0); // allow to compare part of the compound key
            }
Exemple #11
0
 internal override Key checkKey(Key key)
 {
     if (key != null)
     {
         CompoundKey ck = (CompoundKey)key.oval;
         for (int i = 0; i < ck.keys.Length; i++)
         {
             string s = ck.keys[i] as string;
             if (s != null)
             {
                 ck.keys[i] = s.ToLower();
             }
         }
     }
     return(base.checkKey(key));
 }
Exemple #12
0
        //****************************************************************
        // Implementation - Classes and methods used internally by the
        // notification center.
        //****************************************************************

        /// <summary>
        /// Gets all keys that match the name/object pair.
        /// </summary>
        /// <remarks>
        /// Either or both the name and the object can be null.
        /// <para>
        /// If both the name and the object are specified, only keys that match both of these
        /// values will be returned.  If the name is <c>null</c>, all keys that match the
        /// object will be returned.  If the object is null, all keys that match the name will
        /// be returned.  And, If both the name and the object are <c>null</c>, all of the keys
        /// in the listeners map will be returned.
        /// </para>
        /// </remarks>
        /// <param name="name">The name for which to find matching keys.</param>
        /// <param name="obj">The object for which to find matching keys.</param>
        /// <returns>All keys that match the name/object pair.</returns>
        protected virtual IList MatchingKeys(String name, Object obj)
        {
            IList result = new ArrayList();

            IEnumerator it = listenersMap.Keys.GetEnumerator();

            while (it.MoveNext())
            {
                CompoundKey key = (CompoundKey)it.Current;
                if ((name == null) || (name.Equals(key.Name)))
                {
                    if ((obj == null) || (obj == key.Target))
                    {
                        result.Add(key);
                    }
                }
            }

            return(result);
        }
Exemple #13
0
            /// <summary>
            /// Overridden.  See <see cref="Object.Equals(object)">Object.Equals</see>.
            /// </summary>
            public override bool Equals(object obj)
            {
                if (this == obj)
                {
                    return(true);
                }
                CompoundKey key = (CompoundKey)obj;

                if (name == key.name || (name != null && name.Equals(key.name)))
                {
                    Object thisObj = Target;
                    if (thisObj != null)
                    {
                        if (thisObj == (key.Target))
                        {
                            return(true);
                        }
                    }
                }
                return(false);
            }
        //****************************************************************
        // Add Listener - Methods for registering listeners with this
        // notification center.
        //****************************************************************

        /// <summary>
        /// Registers the listener to receive notifications with the specified
        /// notification name and/or containing the given object.
        /// </summary>
        /// <param name="listener">The listener to register.</param>
        /// <param name="callbackMethodName">
        /// The name of the method to invoke on the listener.
        /// </param>
        /// <param name="notificationName">
        /// The name of notifications the listener would like to receive.
        /// </param>
        /// <param name="obj">
        /// The object for which the listener would like to recieve associated notifications.
        /// </param>
        /// <remarks>
        /// When a matching notification is posted, the 'callBackMethodName' message will be
        /// sent to the listener with a single PNotification argument.  If the notification
        /// name is null, the listener will receive all notifications with an object matching
        /// the given object. If the object is null, the listener will receive all
        /// notifications with the notification name.
        /// </remarks>
        public virtual void AddListener(Object listener, String callbackMethodName, String notificationName, Object obj)
        {
            ProcessDeadKeys();

            Object     name       = notificationName;
            MethodInfo methodInfo = null;

            try {
                methodInfo = listener.GetType().GetMethod(callbackMethodName, new Type[] { typeof(PNotification) });
            } catch (ArgumentNullException e) {
                //System.Console.WriteLine(e.StackTrace);
                System.Console.WriteLine(e.Message);
                return;
            }

            if (name == null)
            {
                name = NULL_MARKER;
            }
            if (obj == null)
            {
                obj = NULL_MARKER;
            }

            Object key = new CompoundKey(name, obj);
            Object val = new CompoundValue(listener, methodInfo);

            IList list = (IList)listenersMap[key];

            if (list == null)
            {
                list = new ArrayList();
                listenersMap.Add(new CompoundKey(name, obj), list);
            }

            if (!list.Contains(val))
            {
                list.Add(val);
            }
        }
Exemple #15
0
        protected string Updates(Type type, ISqlDialect dialect)
        {
            var key = new CompoundKey(dialect.Name, type.FullName, _store.Configuration.TablePrefix, Collection);

            if (!UpdatesList.TryGetValue(key, out var result))
            {
                var allProperties = TypePropertiesCache(type);
                var values        = new StringBuilder(null);

                for (var i = 0; i < allProperties.Length; i++)
                {
                    var property = allProperties[i];
                    values.Append(dialect.QuoteForColumnName(property.Name) + " = @" + property.Name + ParameterSuffix);
                    if (i < allProperties.Length - 1)
                    {
                        values.Append(", ");
                    }
                }

                UpdatesList[key] = result = $"update {dialect.QuoteForTableName(_store.Configuration.TablePrefix + _store.Configuration.TableNameConvention.GetIndexTable(type, Collection))} set {values} where {dialect.QuoteForColumnName("Id")} = @Id{ParameterSuffix};";
            }

            return(result);
        }
Exemple #16
0
        protected string Inserts(Type type, ISqlDialect dialect)
        {
            var key = new CompoundKey(dialect.Name, type.FullName, _store.Configuration.TablePrefix, Collection);

            if (!InsertsList.TryGetValue(key, out var result))
            {
                string values;

                var allProperties = TypePropertiesCache(type);

                if (allProperties.Any())
                {
                    var sbColumnList = new StringBuilder(null);

                    for (var i = 0; i < allProperties.Count(); i++)
                    {
                        var property = allProperties.ElementAt(i);
                        sbColumnList.Append(dialect.QuoteForColumnName(property.Name));
                        if (i < allProperties.Count() - 1)
                        {
                            sbColumnList.Append(", ");
                        }
                    }

                    var sbParameterList = new StringBuilder(null);
                    for (var i = 0; i < allProperties.Count(); i++)
                    {
                        var property = allProperties.ElementAt(i);
                        sbParameterList.Append("@").Append(property.Name).Append(ParameterSuffix);
                        if (i < allProperties.Count() - 1)
                        {
                            sbParameterList.Append(", ");
                        }
                    }

                    if (typeof(MapIndex).IsAssignableFrom(type))
                    {
                        // We can set the document id
                        sbColumnList.Append(", ").Append(dialect.QuoteForColumnName("DocumentId"));
                        sbParameterList.Append(", @DocumentId").Append(ParameterSuffix);
                    }

                    values = $"({sbColumnList}) values ({sbParameterList})";
                }
                else
                {
                    if (typeof(MapIndex).IsAssignableFrom(type))
                    {
                        values = $"({dialect.QuoteForColumnName("DocumentId")}) values (@DocumentId{ParameterSuffix})";
                    }
                    else
                    {
                        values = dialect.DefaultValuesInsert;
                    }
                }

                InsertsList[key] = result = $"insert into {dialect.QuoteForTableName(_store.Configuration.TablePrefix + _store.Configuration.TableNameConvention.GetIndexTable(type, Collection))} {values} {dialect.IdentitySelectString} {dialect.QuoteForColumnName("Id")};";
            }

            return(result);
        }
		//****************************************************************
		// Add Listener - Methods for registering listeners with this
		// notification center.
		//****************************************************************

		/// <summary>
		/// Registers the listener to receive notifications with the specified
		/// notification name and/or containing the given object.
		/// </summary>
		/// <param name="listener">The listener to register.</param>
		/// <param name="callbackMethodName">
		/// The name of the method to invoke on the listener.
		/// </param>
		/// <param name="notificationName">
		/// The name of notifications the listener would like to receive.
		/// </param>
		/// <param name="obj">
		/// The object for which the listener would like to recieve associated notifications.
		/// </param>
		/// <remarks>
		/// When a matching notification is posted, the 'callBackMethodName' message will be
		/// sent to the listener with a single PNotification argument.  If the notification
		/// name is null, the listener will receive all notifications with an object matching
		/// the given object. If the object is null, the listener will receive all
		/// notifications with the notification name.
		/// </remarks>
		public virtual void AddListener(Object listener, String callbackMethodName, String notificationName, Object obj) {
			ProcessDeadKeys();

			Object name = notificationName;
			MethodInfo methodInfo = null;

			try {
				methodInfo = listener.GetType().GetMethod(callbackMethodName, new Type[] { typeof(PNotification) });
			} catch (ArgumentNullException e) {
				System.Console.WriteLine(e.StackTrace);
				return;
			}
		
			if (name == null) name = NULL_MARKER;
			if (obj == null) obj = NULL_MARKER;

			Object key = new CompoundKey(name, obj);
			Object val = new CompoundValue(listener, methodInfo);

			IList list = (IList) listenersMap[key];
			if (list == null) {
				list = new ArrayList();
				listenersMap.Add(new CompoundKey(name, obj), list);
			}

			if (!list.Contains(val)) {
				list.Add(val);
			}
		}
Exemple #18
0
        /// <summary>
        /// Post the notification to this notification center.
        /// </summary>
        /// <remarks>
        /// Instead of calling this method directly, it is usually easier to use one of the
        /// convenience <c>PostNotifcation</c> methods, which create the notification
        /// internally.
        /// </remarks>
        /// <param name="aNotification">The notification to post.</param>
        public virtual void PostNotification(PNotification aNotification)
        {
            ArrayList mergedListeners = new ArrayList();
            IList     listenersList;

            Object name = aNotification.Name;
            Object obj  = aNotification.Object;

            if (name != null)
            {
                if (obj != null)                   // both are specified
                {
                    listenersList = (IList)listenersMap[new CompoundKey(name, obj)];
                    if (listenersList != null)
                    {
                        mergedListeners.AddRange(listenersList);
                    }
                    listenersList = (IList)listenersMap[new CompoundKey(name, NULL_MARKER)];
                    if (listenersList != null)
                    {
                        mergedListeners.AddRange(listenersList);
                    }
                    listenersList = (IList)listenersMap[new CompoundKey(NULL_MARKER, obj)];
                    if (listenersList != null)
                    {
                        mergedListeners.AddRange(listenersList);
                    }
                }
                else                     // object is null
                {
                    listenersList = (IList)listenersMap[new CompoundKey(name, NULL_MARKER)];
                    if (listenersList != null)
                    {
                        mergedListeners.AddRange(listenersList);
                    }
                }
            }
            else if (obj != null)                 // name is null
            {
                listenersList = (IList)listenersMap[new CompoundKey(NULL_MARKER, obj)];
                if (listenersList != null)
                {
                    mergedListeners.AddRange(listenersList);
                }
            }

            Object key = new CompoundKey(NULL_MARKER, NULL_MARKER);

            listenersList = (IList)listenersMap[key];
            if (listenersList != null)
            {
                mergedListeners.AddRange(listenersList);
            }

            CompoundValue val;

            TEMP_LIST.Clear();
            TEMP_LIST.AddRange(mergedListeners);
            IEnumerator i = TEMP_LIST.GetEnumerator();

            while (i.MoveNext())
            {
                val = (CompoundValue)i.Current;
                if (val.Target == null)
                {
                    mergedListeners.Remove(val);
                }
                else
                {
                    try {
                        val.MethodInfo.Invoke(val.Target, new Object[] { aNotification });
                    } catch (MethodAccessException e) {
                        System.Console.WriteLine(e.StackTrace);
                    } catch (TargetInvocationException e) {
                        System.Console.WriteLine(e.StackTrace);
                    }
                }
            }
        }
		/// <summary>
		/// Post the notification to this notification center.
		/// </summary>
		/// <remarks>
		/// Instead of calling this method directly, it is usually easier to use one of the
		/// convenience <c>PostNotifcation</c> methods, which create the notification
		/// internally.
		/// </remarks>
		/// <param name="aNotification">The notification to post.</param>
		public virtual void PostNotification(PNotification aNotification) {
			ArrayList mergedListeners = new ArrayList();
			IList listenersList;
		
			Object name = aNotification.Name;
			Object obj = aNotification.Object;

			if (name != null) {
				if (obj != null) { // both are specified
					listenersList = (IList) listenersMap[new CompoundKey(name, obj)];
					if (listenersList != null) {
						mergedListeners.AddRange(listenersList);
					}
					listenersList = (IList) listenersMap[new CompoundKey(name, NULL_MARKER)];
					if (listenersList != null) {
						mergedListeners.AddRange(listenersList);
					}
					listenersList = (IList) listenersMap[new CompoundKey(NULL_MARKER, obj)];
					if (listenersList != null) {
						mergedListeners.AddRange(listenersList);
					}
				} else { // object is null
					listenersList = (IList) listenersMap[new CompoundKey(name, NULL_MARKER)];
					if (listenersList != null) {
						mergedListeners.AddRange(listenersList);
					}
				}
			} else if (obj != null) { // name is null
				listenersList = (IList) listenersMap[new CompoundKey(NULL_MARKER, obj)];
				if (listenersList != null) {
					mergedListeners.AddRange(listenersList);
				}
			}

			Object key = new CompoundKey(NULL_MARKER, NULL_MARKER);
			listenersList = (IList) listenersMap[key];
			if (listenersList != null) {
				mergedListeners.AddRange(listenersList);
			}

			CompoundValue val;
			TEMP_LIST.Clear();
			TEMP_LIST.AddRange(mergedListeners);
			IEnumerator i = TEMP_LIST.GetEnumerator();

			while (i.MoveNext()) {
				val = (CompoundValue) i.Current;
				if (val.Target == null) {
					mergedListeners.Remove(val);
				} else {
					try {
						val.MethodInfo.Invoke(val.Target, new Object[] { aNotification });
					} catch (MethodAccessException e) {
						System.Console.WriteLine(e.StackTrace);
					} catch (TargetInvocationException e) {
						System.Console.WriteLine(e.StackTrace);
					}
				}
			}
		}