We need you! We're working hard on the next version of Developer Fusion -
Let us know what you think we should be up to!
- namespace System.Runtime.Remoting.Contexts
- {
- using System.Runtime.Remoting;
- using System.Runtime.Remoting.Messaging;
- using System;
- using System.Collections;
- using System.Globalization;
- internal class DynamicPropertyHolder
- {
- private const int GROW_BY = 8;
-
- private IDynamicProperty[] _props;
- private int _numProps;
- private IDynamicMessageSink[] _sinks;
-
- internal virtual bool AddDynamicProperty(IDynamicProperty prop)
- {
- lock (this) {
-
- CheckPropertyNameClash(prop.Name, _props, _numProps);
-
-
- bool bGrow = false;
- if (_props == null || _numProps == _props.Length) {
- _props = GrowPropertiesArray(_props);
- bGrow = true;
- }
-
- _props[_numProps++] = prop;
-
-
-
- if (bGrow) {
- _sinks = GrowDynamicSinksArray(_sinks);
- }
-
- if (_sinks == null) {
-
-
- _sinks = new IDynamicMessageSink[_props.Length];
- for (int i = 0; i < _numProps; i++) {
- _sinks[i] = ((IContributeDynamicSink)_props[i]).GetDynamicSink();
- }
- }
- else {
-
- _sinks[_numProps - 1] = ((IContributeDynamicSink)prop).GetDynamicSink();
- }
-
- return true;
-
- }
- }
-
- internal virtual bool RemoveDynamicProperty(string name)
- {
- lock (this) {
-
- for (int i = 0; i < _numProps; i++) {
- if (_props[i].Name.Equals(name)) {
- _props[i] = _props[_numProps - 1];
- _numProps--;
-
- _sinks = null;
- return true;
- }
- }
- throw new RemotingException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Contexts_NoProperty"), name));
- }
- }
-
- internal virtual IDynamicProperty[] DynamicProperties {
- get {
- if (_props == null) {
- return null;
- }
- lock (this) {
- IDynamicProperty[] retProps = new IDynamicProperty[_numProps];
- Array.Copy(_props, retProps, _numProps);
- return retProps;
- }
- }
- }
-
-
-
-
-
-
- internal virtual ArrayWithSize DynamicSinks {
- get {
- if (_numProps == 0) {
- return null;
- }
- lock (this) {
- if (_sinks == null) {
-
-
- _sinks = new IDynamicMessageSink[_numProps + GROW_BY];
- for (int i = 0; i < _numProps; i++) {
- _sinks[i] = ((IContributeDynamicSink)_props[i]).GetDynamicSink();
- }
- }
- }
- return new ArrayWithSize(_sinks, _numProps);
- }
- }
-
- private static IDynamicMessageSink[] GrowDynamicSinksArray(IDynamicMessageSink[] sinks)
- {
-
- int newSize = (sinks != null ? sinks.Length : 0) + GROW_BY;
- IDynamicMessageSink[] newSinks = new IDynamicMessageSink[newSize];
- if (sinks != null) {
-
-
- Array.Copy(sinks, newSinks, sinks.Length);
- }
- return newSinks;
- }
-
- static internal void NotifyDynamicSinks(IMessage msg, ArrayWithSize dynSinks, bool bCliSide, bool bStart, bool bAsync)
- {
- for (int i = 0; i < dynSinks.Count; i++) {
- if (bStart == true) {
- dynSinks.Sinks[i].ProcessMessageStart(msg, bCliSide, bAsync);
- }
- else {
- dynSinks.Sinks[i].ProcessMessageFinish(msg, bCliSide, bAsync);
- }
- }
- }
-
- static internal void CheckPropertyNameClash(string name, IDynamicProperty[] props, int count)
- {
- for (int i = 0; i < count; i++) {
- if (props[i].Name.Equals(name)) {
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_DuplicatePropertyName"));
- }
- }
- }
-
- static internal IDynamicProperty[] GrowPropertiesArray(IDynamicProperty[] props)
- {
-
- int newSize = (props != null ? props.Length : 0) + GROW_BY;
- IDynamicProperty[] newProps = new IDynamicProperty[newSize];
- if (props != null) {
-
- Array.Copy(props, newProps, props.Length);
- }
- return newProps;
- }
-
- }
-
-
-
-
- internal class ArrayWithSize
- {
- internal IDynamicMessageSink[] Sinks;
- internal int Count;
- internal ArrayWithSize(IDynamicMessageSink[] sinks, int count)
- {
- Sinks = sinks;
- Count = count;
- }
- }
-
- }