Ejemplo n.º 1
0
 public bool AddChildScope(IBasicScope scope)
 {
     if (this.HasHandler && !this.Handler.AddChildScope(scope))
     {
         if ((log != null) && log.get_IsDebugEnabled())
         {
             log.Debug(string.Concat(new object[] { "Failed to add child scope: ", scope, " to ", this }));
         }
         return(false);
     }
     if ((scope is IScope) && (this.HasHandler && !this.Handler.Start((IScope)scope)))
     {
         if ((log != null) && log.get_IsDebugEnabled())
         {
             log.Debug(string.Concat(new object[] { "Failed to start child scope: ", scope, " in ", this }));
         }
         return(false);
     }
     if ((log != null) && log.get_IsDebugEnabled())
     {
         log.Debug(string.Concat(new object[] { "Add child scope: ", scope, " to ", this }));
     }
     this._children[scope.Type + Separator + scope.Name] = scope;
     return(true);
 }
Ejemplo n.º 2
0
        public IMessageInput GetLiveProviderInput(IScope scope, string name, bool needCreate)
        {
            IBasicScope basicScope = scope.GetBasicScope(Constants.BroadcastScopeType, name);

            if (basicScope == null)
            {
                if (needCreate)
                {
                    lock (scope.SyncRoot)
                    {
                        // Re-check if another thread already created the scope
                        basicScope = scope.GetBasicScope(Constants.BroadcastScopeType, name);
                        if (basicScope == null)
                        {
                            basicScope = new BroadcastScope(scope, name);
                            scope.AddChildScope(basicScope);
                        }
                    }
                }
                else
                {
                    return(null);
                }
            }
            if (!(basicScope is IBroadcastScope))
            {
                return(null);
            }
            return(basicScope as IBroadcastScope);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Free managed resources.
        /// </summary>
        protected override void Free()
        {
            if (HasParent)
            {
                Parent.RemoveChildScope(this);
            }
            if (HasHandler)
            {
                Handler.Stop(this);
            }
            // Kill all child scopes
            foreach (KeyValuePair <string, IBasicScope> entry in _children)
            {
#if !SILVERLIGHT
                if (log.IsDebugEnabled)
                {
                    log.Debug(string.Format("Stopping child scope: {0}", entry.Key));
                }
#endif
                IBasicScope basicScope = entry.Value;
                if (basicScope is Scope)
                {
                    ((Scope)basicScope).Uninit();
                }
            }
        }
Ejemplo n.º 4
0
        public IMessageInput GetLiveProviderInput(IScope scope, string name, bool needCreate)
        {
            IBasicScope basicScope = scope.GetBasicScope("bs", name);

            if (basicScope == null)
            {
                if (!needCreate)
                {
                    return(null);
                }
                lock (scope.SyncRoot)
                {
                    basicScope = scope.GetBasicScope("bs", name);
                    if (basicScope == null)
                    {
                        basicScope = new BroadcastScope(scope, name);
                        scope.AddChildScope(basicScope);
                    }
                }
            }
            if (basicScope is IBroadcastScope)
            {
                return(basicScope as IBroadcastScope);
            }
            return(null);
        }
Ejemplo n.º 5
0
		/// <summary>
		/// Advances the enumerator to the next element of the collection.
		/// </summary>
		/// <returns>
		/// true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.
		/// </returns>
		/// <exception cref="T:System.InvalidOperationException">
		/// The collection was modified after the enumerator was created.
		/// </exception>
		public bool MoveNext() {
			if (_index < _enumerable.Count - 1) {
				_index++;
				_currentElement = _enumerable[_index] as IBasicScope;
				return true;
			}
			_index = _enumerable.Count;
			return false;
		}
Ejemplo n.º 6
0
        /// <summary>
        /// Removes scope from the children scope list.
        /// </summary>
        /// <param name="scope">Removes the specified scope.</param>
        public void RemoveChildScope(IBasicScope scope)
        {
            //Synchronize retrieval of the child scope (with removal)
            Monitor.Enter(SyncRoot);
            try
            {
                // Don't remove if reference if we have another one
                if (HasChildScope(scope.Name) && GetScope(scope.Name) != scope)
                {
#if !SILVERLIGHT
                    log.Warn(string.Format("Being asked to remove wrong scope reference child scope is {0} not {1}", GetScope(scope.Name), scope));
#endif
                    return;
                }
#if !SILVERLIGHT
                if (log != null && log.IsDebugEnabled)
                {
                    log.Debug(string.Format("Remove child scope: {0} path: {1}", scope, scope.Path));
                }
#endif
                if (scope is IScope)
                {
                    if (HasHandler)
                    {
                        Handler.Stop((IScope)scope);
                    }
                    _subscopeStats.Decrement();
                }
                string child = scope.Type + Separator + scope.Name;
                if (_children.ContainsKey(child))
                {
                    _children.Remove(child);
                }
            }
            finally
            {
                Monitor.Exit(SyncRoot);
            }

            if (HasHandler)
            {
#if !SILVERLIGHT
                if (log != null && log.IsDebugEnabled)
                {
                    log.Debug("Remove child scope");
                }
#endif
                Handler.RemoveChildScope(scope);
            }
            if (scope is Scope)
            {
                //Chain service containers
                (scope as Scope).ServiceContainer.Container = null;
            }
        }
Ejemplo n.º 7
0
 public bool MoveNext()
 {
     if (this._index < (this._enumerable.Count - 1))
     {
         this._index++;
         this._currentElement = this._enumerable[this._index] as IBasicScope;
         return(true);
     }
     this._index = this._enumerable.Count;
     return(false);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Advances the enumerator to the next element of the collection.
 /// </summary>
 /// <returns>
 /// true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.
 /// </returns>
 /// <exception cref="T:System.InvalidOperationException">
 /// The collection was modified after the enumerator was created.
 /// </exception>
 public bool MoveNext()
 {
     if (_index < _enumerable.Count - 1)
     {
         _index++;
         _currentElement = _enumerable[_index] as IBasicScope;
         return(true);
     }
     _index = _enumerable.Count;
     return(false);
 }
Ejemplo n.º 9
0
        public bool UnregisterBroadcastStream(IScope scope, string name)
        {
            bool status = false;

            lock (scope.SyncRoot) {
                IBasicScope basicScope = scope.GetBasicScope(Constants.BroadcastScopeType, name);
                if (basicScope is IBroadcastScope)
                {
                    scope.RemoveChildScope(basicScope);
                    status = true;
                }
            }
            return(status);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Adds scope as a child scope.
        /// </summary>
        /// <param name="scope">Add the specified scope.</param>
        /// <returns>
        /// true if child scope was successfully added, false otherwise.
        /// </returns>
        public bool AddChildScope(IBasicScope scope)
        {
            if (HasChildScope(scope.Type, scope.Name))
            {
#if !SILVERLIGHT
                log.Warn(string.Format("Child scope {0} already exists", scope.Name));
#endif
                return(false);
            }

            if (HasHandler && !Handler.AddChildScope(scope))
            {
#if !SILVERLIGHT
                if (log != null && log.IsDebugEnabled)
                {
                    log.Debug("Failed to add child scope: " + scope + " to " + this);
                }
#endif
                return(false);
            }
            if (scope is IScope)
            {
                // Start the scope
                if (HasHandler && !Handler.Start((IScope)scope))
                {
#if !SILVERLIGHT
                    if (log != null && log.IsDebugEnabled)
                    {
                        log.Debug("Failed to start child scope: " + scope + " in " + this);
                    }
#endif
                    return(false);
                }
            }
#if !SILVERLIGHT
            if (scope is Scope)
            {
                //Chain service containers
                (scope as Scope).ServiceContainer.Container = ServiceContainer;
            }
            if (log != null && log.IsDebugEnabled)
            {
                log.Debug("Add child scope: " + scope + " to " + this);
            }
#endif
            _children[scope.Type + Separator + scope.Name] = scope;
            _subscopeStats.Increment();
            return(true);
        }
Ejemplo n.º 11
0
        public bool UnregisterBroadcastStream(IScope scope, string name)
        {
            bool flag = false;

            lock (scope.SyncRoot)
            {
                IBasicScope basicScope = scope.GetBasicScope("bs", name);
                if (basicScope is IBroadcastScope)
                {
                    scope.RemoveChildScope(basicScope);
                    flag = true;
                }
            }
            return(flag);
        }
Ejemplo n.º 12
0
        public bool AddChildScope(IBasicScope scope)
        {
            if (HasHandler && !Handler.AddChildScope(scope))
            {
                return(false);
            }

            if (scope is IScope)
            {
                // Start the scope
                if (HasHandler && !Handler.Start((IScope)scope))
                {
                    return(false);
                }
            }
            _children[scope.Type + Separator + scope.Name] = scope;
            return(true);
        }
Ejemplo n.º 13
0
        public bool RegisterBroadcastStream(IScope scope, string name, IBroadcastStream broadcastStream)
        {
            bool status = false;

            lock (scope.SyncRoot) {
                IBasicScope basicScope = scope.GetBasicScope(Constants.BroadcastScopeType, name);
                if (basicScope == null)
                {
                    basicScope = new BroadcastScope(scope, name);
                    scope.AddChildScope(basicScope);
                }
                if (basicScope is IBroadcastScope)
                {
                    (basicScope as IBroadcastScope).Subscribe(broadcastStream.Provider, null);
                    status = true;
                }
            }
            return(status);
        }
Ejemplo n.º 14
0
        public void RemoveChildScope(IBasicScope scope)
        {
            if (scope is IScope)
            {
                if (HasHandler)
                {
                    this.Handler.Stop((IScope)scope);
                }
            }
            string child = scope.Type + Separator + scope.Name;

            if (_children.ContainsKey(child))
            {
                _children.Remove(child);
            }
            if (HasHandler)
            {
                this.Handler.RemoveChildScope(scope);
            }
        }
Ejemplo n.º 15
0
        public void RemoveChildScope(IBasicScope scope)
        {
            if ((scope is IScope) && this.HasHandler)
            {
                this.Handler.Stop((IScope)scope);
            }
            string key = scope.Type + Separator + scope.Name;

            if (this._children.ContainsKey(key))
            {
                this._children.Remove(key);
            }
            if (this.HasHandler)
            {
                if ((log != null) && log.get_IsDebugEnabled())
                {
                    log.Debug("Remove child scope");
                }
                this.Handler.RemoveChildScope(scope);
            }
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Sets the enumerator to its initial position, which is before the first element in the collection.
 /// </summary>
 /// <exception cref="T:System.InvalidOperationException">
 /// The collection was modified after the enumerator was created.
 /// </exception>
 public void Reset()
 {
     _currentElement = null;
     _index          = -1;
 }
Ejemplo n.º 17
0
		/// <summary>
		/// Check whether scope is a room scope (level 2 leaf in scope tree or lower, e.g. 3, 4, ...) or not
		/// </summary>
		/// <param name="scope"></param>
		/// <returns></returns>
		public static bool IsRoom(IBasicScope scope)
		{
			return scope.Depth >= Room;
		}
Ejemplo n.º 18
0
		//private static string ServiceCachePrefix = "__service_cache:";

		/// <summary>
		/// Check whether scope is an application scope (level 1 leaf in scope tree) or not
		/// </summary>
		/// <param name="scope"></param>
		/// <returns></returns>
		public static bool IsApplication(IBasicScope scope)
		{
			return scope.Depth == Application;
		}
Ejemplo n.º 19
0
        /// <summary>
        /// Sets the enumerator to its initial position, which is before the first element in the collection.
        /// </summary>
        /// <exception cref="T:System.InvalidOperationException">
        /// The collection was modified after the enumerator was created.
        /// </exception>
		public void Reset()
		{
			_currentElement = null;
			_index = -1;
		}
Ejemplo n.º 20
0
 /// <summary>
 /// Registers basic scope.
 /// </summary>
 /// <param name="basicScope">Basic scope to register.</param>
 public void RegisterBasicScope(IBasicScope basicScope)
 {
     _basicScopes.Add(basicScope);
     basicScope.AddEventListener(this);
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Check whether scope is a room scope (level 2 leaf in scope tree or lower, e.g. 3, 4, ...) or not
 /// </summary>
 /// <param name="scope"></param>
 /// <returns></returns>
 public static bool IsRoom(IBasicScope scope)
 {
     return(scope.Depth >= Room);
 }
Ejemplo n.º 22
0
        //private static string ServiceCachePrefix = "__service_cache:";

        /// <summary>
        /// Check whether scope is an application scope (level 1 leaf in scope tree) or not
        /// </summary>
        /// <param name="scope"></param>
        /// <returns></returns>
        public static bool IsApplication(IBasicScope scope)
        {
            return(scope.Depth == Application);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Returns broadcast scope object for given scope and child scope name.
        /// </summary>
        /// <param name="scope">Scope object.</param>
        /// <param name="name">Child scope name.</param>
        /// <returns>Broadcast scope.</returns>
        public IBroadcastScope GetBroadcastScope(IScope scope, string name)
        {
            IBasicScope basicScope = scope.GetBasicScope(Constants.BroadcastScopeType, name);

            return(basicScope as IBroadcastScope);
        }
Ejemplo n.º 24
0
 public bool AddChildScope(IBasicScope scope)
 {
     return(this._canAddChildScope);
 }
Ejemplo n.º 25
0
 public void Reset()
 {
     this._currentElement = null;
     this._index          = -1;
 }
Ejemplo n.º 26
0
        /// <summary>
        /// Called just before a child scope is added.
        /// </summary>
        /// <param name="scope">Scope that will be added.</param>
        /// <returns>true to allow, false to deny.</returns>
		public bool AddChildScope(IBasicScope scope)
		{
			return _canAddChildScope;
		}
Ejemplo n.º 27
0
		public bool AddChildScope(IBasicScope scope)
		{
			return true;
		}
Ejemplo n.º 28
0
 public bool AddChildScope(IBasicScope scope)
 {
     return(true);
 }
Ejemplo n.º 29
0
        /// <summary>
        /// Called just after a child scope has been removed.
        /// </summary>
        /// <param name="scope">Scope that has been removed.</param>
		public void RemoveChildScope(IBasicScope scope)
		{
			// NA
		}
Ejemplo n.º 30
0
 /// <summary>
 /// Unregister basic scope.
 /// </summary>
 /// <param name="basicScope">Unregister basic scope.</param>
 public void UnregisterBasicScope(IBasicScope basicScope)
 {
     _basicScopes.Remove(basicScope);
     basicScope.RemoveEventListener(this);
 }
Ejemplo n.º 31
0
 public void RemoveChildScope(IBasicScope scope)
 {
     //NA
 }