internal CAChannelMonitor(CARecord record, string property, CAServerChannel channel,
                                    EpicsType type, int dataCount, MonitorMask monitorMask, int subscriptionId)
        {
            Record = record;
            Property = property;
            Channel = channel;
            Type = type;
            DataCount = dataCount;
            MonitorMask = monitorMask;
            SubscriptionId = subscriptionId;

            try
            {
                object val = Record[Property.ToString()];
                if (val == null)
                    val = 0;
                byte[] realData = val.ToByteArray(Type, Record);
                Channel.TcpConnection.Send(Channel.Server.Filter.MonitorChangeMessage(SubscriptionId, Channel.ClientId, Type, DataCount, val.ToByteArray(Type, Record)));
                lastValue = Record[Property];
                Record.RecordProcessed += new EventHandler(Record_RecordProcessed);
            }
            catch (Exception e)
            {
                Channel.TcpConnection.Send(Channel.Server.Filter.MonitorChangeMessage(SubscriptionId, Channel.ClientId, Type, DataCount, new byte[0]));
            }
        }
        internal ChannelMonitor(CARecord record, string property, CAServerChannel channel,
                                    EpicsType type, int dataCount, MonitorMask monitorMask, int subscriptionId)
        {
            Record = record;
            Property = property;
            Channel = channel;
            Type = type;
            DataCount = dataCount;
            MonitorMask = monitorMask;
            SubscriptionId = subscriptionId;

            try
            {
                object val = Record[Property.ToString()];
                if (val == null)
                    val = 0;
                byte[] realData = val.ToByteArray(Type, Record);
                Channel.sendMonitorChange(SubscriptionId, Type, DataCount, EpicsTransitionStatus.ECA_NORMAL, realData);
                lastValue = Record[Property];
                Record.RecordProcessed += new EventHandler(Record_RecordProcessed);
            }
            catch (Exception e)
            {
                Channel.sendMonitorChange(SubscriptionId, Type, DataCount, EpicsTransitionStatus.ECA_ADDFAIL, new byte[0]);
            }
        }
		internal EpicsServerMonitor(
			EpicsRecord record, 
			RecordProperty property, 
			EpicsServerChannel channel, 
			EpicsType type, 
			int dataCount, 
			MonitorMask monitorMask, 
			int subscriptionId)
		{
			this.record = record;
			this.property = property;
			this.channel = channel;
			this.type = type;
			this.dataCount = dataCount;
			this.monitorMask = monitorMask;
			this.subscriptionId = subscriptionId;

			try
			{
				var val = this.record[this.property.ToString()];
				if (val == null)
				{
					val = 0;
				}

				var realData = NetworkByteConverter.objectToByte(val, this.type, this.record);
				this.channel.sendMonitorChange(
					this.subscriptionId, this.type, this.dataCount, EpicsTransitionStatus.ECA_NORMAL, realData);

				this.StartMonitor();
			}
			catch (Exception e)
			{
				this.channel.sendMonitorChange(
					this.subscriptionId, this.type, this.dataCount, EpicsTransitionStatus.ECA_ADDFAIL, new byte[0]);
			}
		}
		/// <summary>
		/// The add monitor.
		/// </summary>
		/// <param name="type">
		/// The type.
		/// </param>
		/// <param name="dataCount">
		/// The data count.
		/// </param>
		/// <param name="subscriptionId">
		/// The subscription id.
		/// </param>
		/// <param name="mask">
		/// The mask.
		/// </param>
		internal void addMonitor(EpicsType type, int dataCount, int subscriptionId, MonitorMask mask)
		{
			// does he request to add a subscriptionId at the same Id as it already exist?
			if (this.monitors.ContainsKey(subscriptionId))
			{
				return;
			}

			lock (this.monitors)
			{
				this.monitors.Add(
					subscriptionId, new EpicsServerMonitor(this.Record, this.Property, this, type, dataCount, mask, subscriptionId));
			}
		}
        internal void AddMonitor(EpicsType type, int dataCount, int subscriptionId, MonitorMask mask)
        {
            //does he request to add a subscriptionId at the same Id as it already exist?
            lock (monitors)
            {
                if (monitors.ContainsKey(subscriptionId))
                    return;

                monitors.Add(subscriptionId, new CAChannelMonitor(Record, Property, this, type, dataCount, mask, subscriptionId));
            }
        }