Ejemplo n.º 1
0
        public static IChannel Create(ChannelSettings channelSettings, DirectoryInfo workingDirectory)
        {
            if (channelSettings == null)
            {
                throw new ArgumentNullException(nameof(channelSettings));
            }

            if (workingDirectory == null)
            {
                throw new ArgumentNullException(nameof(workingDirectory));
            }

            ChannelDirection channelDirection = channelSettings.GetType() == typeof(FromSettings) ? ChannelDirection.Inbound : ChannelDirection.Outbound;

            switch (channelSettings.Type)
            {
            case ConfigChannelType.Local:
            {
                return(new LocalChannel(workingDirectory, channelSettings));
            }

            case ConfigChannelType.Sftp:
            {
                return(new SftpChannel(workingDirectory, channelSettings));
            }

            default:
            {
                throw new InvalidOperationException($"There is no corresponding channel type for '{channelSettings.Type}'.");
            }
            }
        }
        /// <summary>
        /// This is the base constructor.
        /// </summary>
        /// <param name="context">This is the api context.</param>
        /// <param name="direction">The event direction.</param>
        /// <param name="level">This enumeration determines which part of the data should be logged.</param>
        public ApiBoundaryEvent(HttpActionExecutedContext context, ChannelDirection direction, ApiBoundaryLoggingFilterLevel level)
        {
            Level     = level;
            mContext  = context;
            Direction = direction;
            Type      = BoundaryEventType.Boundary;
            Id        = Guid.NewGuid();

            if ((level & ApiBoundaryLoggingFilterLevel.Exception) > 0)
            {
                Ex = context.Exception;
            }

            if ((level & ApiBoundaryLoggingFilterLevel.Request) > 0)
            {
                Request = new HttpRequestWrapper(context);
            }

            if ((level & ApiBoundaryLoggingFilterLevel.Response) > 0)
            {
                Response = new HttpResponseWrapper(context);
            }

            if ((level & ApiBoundaryLoggingFilterLevel.RequestContent) > 0)
            {
                RequestBody = new ApiMimeContent(context.Request.Content);
            }

            if ((level & ApiBoundaryLoggingFilterLevel.ResponseContent) > 0)
            {
                ResponseBody = new ApiMimeContent(context.Response.Content);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This method attempts to retrieve and existing channel.
        /// </summary>
        /// <param name="channelId">The channel Id.</param>
        /// <param name="direction">The direction.</param>
        /// <param name="channel">Returns the channel object.</param>
        /// <returns></returns>
        public bool TryGet(string channelId, ChannelDirection direction, out Channel channel)
        {
            channel = null;

            if ((direction & ChannelDirection.Incoming) > 0
                & mContainerIncoming.TryGetValue(channelId, out channel))
            {
                return(true);
            }

            if ((direction & ChannelDirection.Outgoing) > 0
                & mContainerOutgoing.TryGetValue(channelId, out channel))
            {
                return(true);
            }

            if (mPolicy.AutoCreateChannels)
            {
                channel = new Channel(channelId, direction, isAutocreated: true);
                Add(channel);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This helper resolves a channel from the direction specified.
        /// </summary>
        /// <param name="cpipe">The pipeline.</param>
        /// <param name="direction"></param>
        /// <param name="throwIfChannelIsNull"></param>
        /// <returns>The resolved channel or null if not resolved and throwIfChannelIsNull is false. Otherwise an exception will be raised.</returns>
        public static Channel ToChannel(this IPipelineChannel cpipe, ChannelDirection direction, bool throwIfChannelIsNull = true)
        {
            Channel channel = null;

            if (cpipe is IPipelineChannelBroadcast)
            {
                switch (direction)
                {
                case ChannelDirection.Incoming:
                    channel = ((IPipelineChannelBroadcast)cpipe).ChannelListener;
                    break;

                case ChannelDirection.Outgoing:
                    channel = ((IPipelineChannelBroadcast)cpipe).ChannelSender;
                    break;

                default:
                    throw new NotSupportedException($"ChannelDirection {direction} not supported in {nameof(CorePipelineExtensions)}/{nameof(ToChannel)}");
                }
            }
            else
            {
                channel = cpipe.Channel;
            }

            if (channel == null && throwIfChannelIsNull)
            {
                throw new ArgumentNullException($"The pipe channel is null -> {direction}");
            }

            return(channel);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// The default constructor.
        /// </summary>
        /// <param name="id">The channel Id.</param>
        /// <param name="direction">The direction of the channel - Incoming or outgoing</param>
        /// <param name="description">The optional description</param>
        /// <param name="bLoggerActive">This is the boundary logger active status for the channel.</param>
        /// <param name="internalOnly">This property specifies that the channel should only be used for internal messaging.</param>
        /// <param name="rewriteRules">A selection of rewrite rules for the channel.</param>
        /// <param name="isAutocreated">A boolean property that specifies whether the channel was created automatically by the communications container.</param>
        public Channel(string id
                       , ChannelDirection direction
                       , string description = null
                       , bool?bLoggerActive = null
                       , bool internalOnly  = false
                       , IEnumerable <MessageRedirectRule> rewriteRules = null
                       , bool isAutocreated = false)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id cannot be null or empty.");
            }

            Id                    = id;
            Direction             = direction;
            Description           = description;
            InternalOnly          = internalOnly;
            BoundaryLoggingActive = bLoggerActive;
            IsAutoCreated         = isAutocreated;

            if (rewriteRules != null)
            {
                mRedirectRules = new ConcurrentDictionary <Guid, MessageRedirectRule>(
                    rewriteRules.Select((r) => new KeyValuePair <Guid, MessageRedirectRule>(r.Id, r)));
            }
        }
Ejemplo n.º 6
0
 public Csound6ChannelEventArgs(string _name, ChannelType _type, ChannelDirection _direction, IntPtr pObject)
 {
     Name      = _name;
     Type      = _type;
     Direction = _direction;
     m_pObject = pObject;
 }
Ejemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="csound"></param>
        /// <param name="name"></param>
        /// <param name="pValue"></param>
        /// <param name="pChannelType"></param>
        private void RawOutputChannelEventCallback(IntPtr csound, string name, IntPtr pValue, IntPtr pChannelType)
        {
            var cstype = (CS_TYPE)Marshal.PtrToStructure(pChannelType, typeof(CS_TYPE));
            Csound6ChannelEventArgs args = null;
            ChannelDirection        dir  = (ChannelDirection)((cstype.argtype != 0) ? cstype.argtype : 3);

            switch (cstype.varTypeName[0])
            {
            case 'k':
                args       = new Csound6ChannelEventArgs(name, ChannelType.Control, dir);
                args.Value = (double)Marshal.PtrToStructure(pValue, typeof(double));
                break;

            case 'S':
                args       = new Csound6ChannelEventArgs(name, ChannelType.String, dir);
                args.Value = Marshal.PtrToStringAnsi(pValue);
                break;

            case 'a':     //audio ksmps buffer: not supported by csound output callbacks
            case 'p':     //pvs: not supported by csound output callbacks
            case 'v':     //var??? no csound code supports this yet
            default:
                //only S and k should be sending output channel callbacks.  Ignore: someday csound might be supporting some of these
                break;
            }
            Csound6ChannelEventHandler handler = m_callbackHandlers[_outputChannelEventKey] as Csound6ChannelEventHandler;

            if ((args != null) && (handler != null))
            {
                handler(this, args);
            }
        }
Ejemplo n.º 8
0
 public NidaQmxChannel(NidaQmxDevice2 device, string channel, ChannelDirection direction, IIDGenerator idgen)
 {
     _status    = DevicePortStatus.Idle;
     Id         = idgen.GetID();
     Channel    = channel;
     Device     = device;
     _direction = direction;
 }
Ejemplo n.º 9
0
        /// <summary>
        /// This method checks whether a channel has been adeed.
        /// </summary>
        /// <param name="channelId">The channel Id.</param>
        /// <param name="direction">The direction.</param>
        /// <returns></returns>
        public bool Exists(string channelId, ChannelDirection direction)
        {
            var success = Wrapper(direction,
                                  (r) => mContainerIncoming.ContainsKey(channelId) ? true : default(bool?)
                                  , (r) => mContainerOutgoing.ContainsKey(channelId) ? true : r
                                  );

            return(success ?? false);
        }
Ejemplo n.º 10
0
        public static ChannelDirection GetChannelDirection(string direction)
        {
            ChannelDirection direct = ChannelDirection.CHANNEL_DIRECTION_UNKOWN;

            if (DictDirection.ContainsKey(direction))
            {
                direct = DictDirection[direction];
            }
            return(direct);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Adds an audio channel object to the bus but doesn't define it to csound
 /// </summary>
 /// <param name="name"></param>
 /// <param name="direction"></param>
 public Csound6AudioChannel AddAudioChannel(string name, ChannelDirection direction)
 {
     if (HasChannel(name) && (m_channels[name].Type != ChannelType.Audio))
     {
         RemoveChannel(name);
     }
     m_channels.Add(name, new Csound6AudioChannel(name, direction, m_csound));
     m_channels[name].Direction = direction;
     return(m_channels[name] as Csound6AudioChannel);
 }
Ejemplo n.º 12
0
        public LocalChannel(DirectoryInfo workingDirectory, ChannelSettings channelSettings)
        {
            _channelSettings = channelSettings ?? throw new ArgumentNullException(nameof(channelSettings));

            _workingDirectory = workingDirectory ?? throw new ArgumentNullException(nameof(channelSettings));

            _channelDirection = ChannelDirectionFactory.Get(channelSettings);

            _source = ChannelHelper.GetSourceOrTarget(_channelSettings, workingDirectory).Item1;

            _target = ChannelHelper.GetSourceOrTarget(_channelSettings, workingDirectory).Item2;
        }
Ejemplo n.º 13
0
 public ChannelEventArgs(
     ChannelEvent @event,
     ChannelDirection direction,
     string uuid,
     string from,
     string to)
 {
     Event     = @event;
     Direction = direction;
     UUID      = uuid;
     From      = from;
     To        = to;
 }
Ejemplo n.º 14
0
        /// <summary>
        /// The default constructor.
        /// </summary>
        /// <param name="id">The channel Id.</param>
        /// <param name="direction">The direction of the channel - Incoming or outgoing</param>
        /// <param name="description">The optional description</param>
        /// <param name="internalOnly">This property specifies that the channel should only be used for internal messaging.</param>
        public Channel(string id, ChannelDirection direction, string description = null, IBoundaryLogger boundaryLogger = null, bool internalOnly = false)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id cannot be null or empty.");
            }

            Id             = id;
            Direction      = direction;
            Description    = description;
            InternalOnly   = internalOnly;
            BoundaryLogger = boundaryLogger;
        }
Ejemplo n.º 15
0
        public SftpChannel(DirectoryInfo workingDirectory, ChannelSettings channelSettings)
        {
            _channelSettings = channelSettings ?? throw new ArgumentNullException(nameof(channelSettings));

            _workingDirectory = workingDirectory ?? throw new ArgumentNullException(nameof(channelSettings));

            _channelDirection = ChannelDirectionFactory.Get(channelSettings);

            _source = string.IsNullOrEmpty(channelSettings.Path) ? throw new ArgumentException(nameof(channelSettings.Path))  :  channelSettings.Path;

            _target = _workingDirectory;

            _connectionInfo = channelSettings.AsConnectionInfo();
        }
Ejemplo n.º 16
0
        /// <summary>
        /// This method is used to ensure either of both collections are invoked for channel based methods.
        /// </summary>
        /// <param name="direction">The channel direction.</param>
        /// <param name="incoming">The incoming function.</param>
        /// <param name="outgoing">The outgoing funtion.</param>
        /// <returns></returns>
        private bool?Wrapper(ChannelDirection direction, Func <bool?, bool?> incoming, Func <bool?, bool?> outgoing)
        {
            bool?result = null;

            if ((direction & ChannelDirection.Incoming) > 0)
            {
                result = incoming?.Invoke(result);
            }

            if ((direction & ChannelDirection.Outgoing) > 0)
            {
                result = outgoing?.Invoke(result);
            }

            return(result);
        }
Ejemplo n.º 17
0
 /// <summary>
 /// This interface is used to log payload data when a message is either incoming or outgoing from the system.
 /// </summary>
 /// <param name="collector">The data collector.</param>
 /// <param name="direction">The direction of the message.</param>
 /// <param name="payload">The payload.</param>
 /// <param name="ex">Any exception generated by the attempt. If this is not null then you can assume that the incoming or outgoing action was not successful.</param>
 /// <param name="batchId">The batch id.</param>
 public static void BoundaryLog(this IDataCollection collector, ChannelDirection direction
                                , TransmissionPayload payload, string channelId, int channelPriority, Exception ex = null, Guid?batchId = null)
 {
     collector.Write(
         new BoundaryEvent()
     {
         Direction         = direction
         , ChannelId       = payload?.Message?.ChannelId
         , Id              = payload?.Id
         , Payload         = payload
         , Ex              = ex
         , BatchId         = batchId
         , Type            = BoundaryEventType.Boundary
         , ChannelPriority = channelPriority
     });
 }
Ejemplo n.º 18
0
        private void TestChannelAutocreateFail(ChannelDirection direction)
        {
            CommunicationContainer mContainer
                = new CommunicationContainer(new CommunicationPolicy()
            {
                AutoCreateChannels = false
            });

            Channel channel = null;

            Assert.IsFalse(mContainer.TryGet("Freddy", direction, out channel));

            Assert.IsTrue(channel == null);

            Assert.IsFalse(mContainer.Exists("Freddy", direction));

            Assert.IsTrue(mContainer.Channels.Count() == 0);
        }
Ejemplo n.º 19
0
        private void TestChannelAutocreateSuccess(ChannelDirection direction)
        {
            CommunicationContainer mContainer
                = new CommunicationContainer(new CommunicationPolicy()
            {
                AutoCreateChannels = true
            });

            Channel channel;

            Assert.IsTrue(mContainer.TryGet("Freddy", direction, out channel));

            Assert.IsTrue(mContainer.Exists("Freddy", direction));

            Assert.IsTrue(channel.IsAutoCreated);

            Assert.IsTrue(mContainer.Channels.Count() == 1);
        }
 public ChannelInternalOnlyException(string channelId, ChannelDirection direction) : base(channelId)
 {
     Direction = direction;
 }
Ejemplo n.º 21
0
        public bool Parse(string name, string value)
        {
            switch (name)
            {
            case "username":
                UserName = value;
                break;

            case "dialplan":
                DialplanType = value;
                break;

            case "caller-id-name":
                _callerIdName = value;
                CreateCallerId();
                break;

            case "caller-id-number":
                _callerIdNumber = value;
                CreateCallerId();
                break;

            case "callee-id-name":
                _calleeIdName = value;
                CreateCalleeId();
                break;

            case "callee-id-number":
                _calleeIdNumber = value;
                CreateCalleeId();
                break;

            case "network-addr":
                IpAddress = value;
                break;

            case "ani":
                ANI = value;
                break;

            case "destination-number":
                DestinationNumber = value;
                break;

            case "unique-id":
                Id = new UniqueId(value);
                break;

            case "context":
                Context = value;
                break;

            case "channel-name":
                ChannelInfo = new ChannelName();
                ChannelInfo.Parse(value);
                break;

            case "profile-created-time":
                ProfileCreatedAt = value.FromUnixTime();
                break;

            case "channel-created-time":
                CreatedAt = value.FromUnixTime();
                break;

            case "channel-answered-time":
                AnsweredAt = value.FromUnixTime();
                break;

            case "channel-hangup-time":
                HangupAt = value.FromUnixTime();
                break;

            case "channel-transfer-time":
                TransferredAt = value.FromUnixTime();
                break;

            case "screen-bit":
                ScreenBit = value == "yes";
                break;

            case "privacy-hide-name":
                PrivacyHideName = value == "yes";
                break;

            case "privacy-hide-number":
                PrivacyHideNumber = value == "yes";
                break;

            case "direction":
                Direction = Enumm.Parse <ChannelDirection>(value);
                break;

            case "source":
                EndpointSource = value;
                break;

            case "profile-index":
                ProfileIndex = int.Parse(value);
                break;

            case "channel-progress-time":
                ChannelProgressTime = long.Parse(value);
                break;

            case "channel-progress-media-time":
                ChannelProgressMediaTime = long.Parse(value);
                break;

            default:
                return(false);
            }
            return(true);
        }
 public ChannelIdMismatchException(string channelId, ChannelDirection direction, string mismatchId) : base(channelId)
 {
     MismatchChannelId = mismatchId;
     Direction         = direction;
 }
Ejemplo n.º 23
0
 public ChannelInfo(string _name, ChannelType _type, ChannelDirection _direction)
 {
     Name      = _name;
     Type      = _type;
     Direction = _direction;
 }
Ejemplo n.º 24
0
        public bool Parse(string name, string value)
        {
            switch (name)
            {
                case "username":
                    UserName = value;
                    break;
                case "dialplan":
                    DialplanType = value;
                    break;
                case "caller-id-name":
                    _callerIdName = value;
                    CreateCallerId();
                    break;
                case "caller-id-number":
                    _callerIdNumber = value;
                    CreateCallerId();
                    break;
                case "callee-id-name":
                    _calleeIdName = value;
                    CreateCalleeId();
                    break;
                case "callee-id-number":
                    _calleeIdNumber = value;
                    CreateCalleeId();
                    break;
                case "network-addr":
                    IpAddress = value;
                    break;
                case "ani":
                    ANI = value;
                    break;
                case "destination-number":
                    DestinationNumber = value;
                    break;
                case "unique-id":
                    Id = new UniqueId(value);
                    break;
                case "context":
                    Context = value;
                    break;
                case "channel-name":
                    ChannelInfo = new ChannelName();
                    ChannelInfo.Parse(value);
                    break;
                case "profile-created-time":
                    ProfileCreatedAt = value.FromUnixTime();
                    break;
                case "channel-created-time":
                    CreatedAt = value.FromUnixTime();
                    break;
                case "channel-answered-time":
                    AnsweredAt = value.FromUnixTime();
                    break;
                case "channel-hangup-time":
                    HangupAt = value.FromUnixTime();
                    break;
                case "channel-transfer-time":
                    TransferredAt = value.FromUnixTime();
                    break;
                case "screen-bit":
                    ScreenBit = value == "yes";
                    break;
                case "privacy-hide-name":
                    PrivacyHideName = value == "yes";
                    break;
                case "privacy-hide-number":
                    PrivacyHideNumber = value == "yes";
                    break;

                case "direction":
                    Direction = Enumm.Parse<ChannelDirection>(value);
                    break;

                case "source":
                    EndpointSource = value;
                    break;

                case "profile-index":
                    ProfileIndex = int.Parse(value);
                    break;

                case "channel-progress-time":
                    ChannelProgressTime = long.Parse(value);
                    break;
                case "channel-progress-media-time":
                    ChannelProgressMediaTime = long.Parse(value);
                    break;

                default:
                    return false;
            }
            return true;
        }
Ejemplo n.º 25
0
 /// <summary>
 /// Creates a control channel object using the provided name, direction, channel hints and csound instance
 /// </summary>
 /// <param name="name"></param>
 /// <param name="direction"></param>
 /// <param name="hints"></param>
 /// <param name="csound"></param>
 public Csound6ControlChannel(string name, ChannelDirection direction, ChannelHints hints, Csound6Net csound)
     : base(name, direction, csound)
 {
     m_hint = hints;
     SetControlChannelHints(hints);
 }
Ejemplo n.º 26
0
 public Csound6AudioChannel(string name, ChannelDirection direction, Csound6Net csound)
     : base(name, direction, csound)
 {
     m_bufsiz = csound.Ksmps;
     m_buffer = Marshal.AllocHGlobal(sizeof(double) * m_bufsiz);
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Creates a string channel object to represent a string value in csound shared with a host program
 /// </summary>
 /// <param name="name"></param>
 /// <param name="direction"></param>
 /// <param name="csound"></param>
 public Csound6StringChannel(string name, ChannelDirection direction, Csound6Net csound)
     : base(name, direction, csound)
 {
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Populates abstract superclass values supplied as from concrete channel subclasses.
 /// </summary>
 /// <param name="_name">Name the channel is known by to csound</param>
 /// <param name="_direction">one or both members (Ored to gether) of the ChannelDirection enumeration</param>
 /// <param name="csound">A reference to the Csound6NetRealtime used that contains this channel</param>
 public Csound6Channel(string _name, ChannelDirection _direction, Csound6Net csound)
 {
     m_csound  = csound;
     Name      = _name;
     Direction = _direction;
 }
Ejemplo n.º 29
0
 public void Log(ChannelDirection direction, TransmissionPayload payload, Exception ex = null, Guid?batchId = default(Guid?))
 {
 }
Ejemplo n.º 30
0
 public EmptyDevicePort(ChannelDirection direction)
 {
     Direction = direction;
 }
Ejemplo n.º 31
0
 /// <summary>
 /// This method returns true if the channel is registered for that specific direction.
 /// </summary>
 /// <param name="channelId">The channel id.</param>
 /// <param name="direction">The channel direction.</param>
 /// <returns>Returns true if the channel exists.</returns>
 public bool HasChannel(string channelId, ChannelDirection direction)
 {
     return(mCommunication.Exists(channelId, direction));
 }