Ejemplo n.º 1
0
        private GetStatus IsFree(ChannelEvent latestEvent)
        {
            if (latestEvent == null)
            {
                return(new GetStatus
                {
                    IsFree = true
                });
            }

            var difference = DateTime.UtcNow - latestEvent.DateTime;

            var isFreeStatus = new GetStatus
            {
                DateTime   = DateTime.SpecifyKind(latestEvent.DateTime, DateTimeKind.Utc),
                Difference = difference
            };

            var differentTimeSpan = (new TimeSpan(0, 2, 0)); // 2 minutes

            if (difference >= differentTimeSpan)
            {
                isFreeStatus.IsFree = true;
            }

            return(isFreeStatus);
        }
Ejemplo n.º 2
0
        public ChannelEvent GetEvent(string channelId)
        {
            ChannelEvent channelsEvent = new ChannelEvent();
            DateTime     utcTimeNow    = DateTime.UtcNow;

            utcTimeNow = utcTimeNow.AddHours(8);
            var    start = utcTimeNow.AddHours(-1);
            var    end   = utcTimeNow.AddHours(1);
            string getChannelEventUrl = url + "/ams/v3/getEvents?channelId=" + channelId + "&periodStart=" + start.ToString("yyyy-MM-dd HH:mm") + "&periodEnd=" + end.ToString("yyyy-MM-dd HH:mm");
            var    response           = InitiateWebRequest(getChannelEventUrl);

            if (response.IsSuccessStatusCode)
            {
                channelsEvent = response.Content.ReadAsAsync <ChannelEvent>().Result;
            }
            response.Dispose();

            foreach (var channelEvent in channelsEvent.getevent ?? new List <Events>())
            {
                var      startTime = channelEvent.displayDateTime;
                TimeSpan duration;

                if (TimeSpan.TryParse(channelEvent.displayDuration, out duration))
                {
                    var endTime = startTime.Add(duration);
                    if (endTime > utcTimeNow)
                    {
                        channelEvent.currentlyAired = true;
                    }
                }
            }

            return(channelsEvent);
        }
Ejemplo n.º 3
0
        public async Task Calling_Connect_on_a_new_OutboundSocket_should_populate_the_ChannelData()
        {
            using (var listener = new OutboundListener(0))
            {
                listener.Start();
                ChannelEvent channelData = null;

                listener.Connections.Subscribe(
                    async(socket) =>
                {
                    channelData = await socket.Connect();
                });

                using (var freeSwitch = new FakeFreeSwitchSocket(listener.Port))
                {
                    freeSwitch.MessagesReceived.FirstAsync(m => m.StartsWith("connect"))
                    .Subscribe(async _ => await freeSwitch.SendChannelDataEvent());

                    await Wait.Until(() => channelData != null);

                    Assert.NotNull(channelData);
                    Assert.Equal(ChannelState.Execute, channelData.ChannelState);
                    Assert.Equal("RINGING", channelData.Headers["Channel-Call-State"]);
                }
            }
        }
Ejemplo n.º 4
0
        static void AddChannelTest()
        {
            var @event = "addChannel";

            Console.WriteLine($"{nameof(AddChannelTest)} Start");
            using (var ws = new WebSocket(URL))
            {
                if (URL.StartsWith("wss", StringComparison.OrdinalIgnoreCase))
                {
                    ws.SslConfiguration.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                }
                ws.OnMessage += (sender, e) => {
                    Console.WriteLine(e.Data);
                    BaseOutput baseOutput = JsonConvert.DeserializeObject <BaseOutput>(e.Data);
                    if (baseOutput.Event == @event)
                    {
                        Console.WriteLine($"Result:{baseOutput.Result} Code:{baseOutput.ErrorCode}");
                    }
                };
                ChannelEvent baseEvent = new ChannelEvent
                {
                    Event   = @event,
                    Channel = "ICEEX_sub_spot_BTC-VHKD_deals"
                };
                var data = JsonConvert.SerializeObject(baseEvent);
                ws.Connect();
                Login(ws);
                ws.Send(data);
                Console.ReadLine();
            }
            Console.WriteLine($"{nameof(AddChannelTest)}  End");
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 根据uuid,更新列表中对应Dialog的DialogState。如果为Hangup、Destroy,则从列表中移除
        /// </summary>
        private void UpdateDialog(string uuid, ChannelEvent state)
        {
            DialogInfo info = GetDialogByUuid(uuid);

            if (info == null)
            {
                Log.Error(string.Format("UpdateDialog__info == null. uuid: {0}, state: {1}", uuid, state));
                return;
            }

            info.DialogState = state;

            if (info.IsDialogHanguped)
            {
                Log.Debug(string.Format("UpdateDialog__info.IsDialogHanguped, goona remove. uuid: {0}", uuid));
                try
                {
                    RemoveDialog(uuid);
                }
                catch (Exception e)
                {
                    Log.Warn(string.Format("UpdateDialog__info.IsDialogHanguped, failed to remove. uuid: {0}", uuid));
                }
            }
            else
            {
                Log.Debug(string.Format("UpdateDialog__!info.IsDialogHanguped. uuid: {0}", uuid));
            }
        }
Ejemplo n.º 6
0
        private void PublishChannel(string channelName, Package data)
        {
            var channelEvent = new ChannelEvent {
                Channel = channelName, Package = data
            };

            Publish(channelEvent);
        }
Ejemplo n.º 7
0
        public async void UpdateIsFreeSocket(ChannelEvent model)
        {
            var newStatusContent = _updateStatusContent.IsFree(model.ChannelUserId);
            await _dataHubContext.Clients.Group(model.ChannelUserId).SendAsync("Update", newStatusContent);

            var result = _updateStatusContent.EventsRecent(model.ChannelUser.NameUrlSafe);
            await _dataHubContext.Clients.Group(model.ChannelUserId).SendAsync("EventsRecent", result);
        }
Ejemplo n.º 8
0
 public ChannelStateChange(ChannelEvent e, ChannelState state, ChannelState previous, ErrorInfo error = null, bool resumed = false)
 {
     Event    = e;
     Previous = previous;
     Current  = state;
     Error    = error;
     Resumed  = resumed;
 }
Ejemplo n.º 9
0
        internal PlayGetDigitsResult(ChannelEvent eventMessage, string channelVariable) : base(eventMessage)
        {
            Digits = eventMessage.GetVariable(channelVariable);

            TerminatorUsed = eventMessage.GetVariable("read_terminator_used");

            Success = !string.IsNullOrEmpty(Digits);
        }
Ejemplo n.º 10
0
        private void OnEvent(EventBase receivedEvent)
        {
            if (!receivedEvent.IsChannelEvent)
            {
                return;
            }

            ChannelEvent channelEvent = (ChannelEvent)receivedEvent;

            if (channelEvent.UniqueId != _uuid)
            {
                return;
            }

            if (receivedEvent is EventChannelAnswer)
            {
                _answered = true;
            }
            else if (receivedEvent is EventDtmf)
            {
                EventDtmf evt = (EventDtmf)receivedEvent;
                Console.WriteLine("DTMF Event: " + evt.Digit);
                if (_queue.GotDtmf(evt.Digit))
                {
                    lock (_dtmf)
                        _dtmf += evt.Digit;

                    if (_dtmfWaitCount != 0 && _dtmf.Length >= _dtmfWaitCount)
                    {
                        Console.WriteLine("Got all DTMF: " + _dtmfWaitCount + "/" + _dtmf.Length);
                        _dtmfTimeout.Set();
                    }

                    if (DtmfReceived != null)
                    {
                        DtmfReceived(this, new DtmfEventArgs(_dtmf));
                    }
                }
            }
            else if (receivedEvent is EventChannelDestroy || receivedEvent is EventChannelHangup)
            {
                if (_mgr != null)
                {
                    _mgr.EventReceived -= OnEvent;
                    _mgr = null;
                }
            }
            else if (receivedEvent is EventChannelExecute)
            {
                EventChannelExecute exec = (EventChannelExecute)receivedEvent;
                _queue.Execute(exec);
            }
            else if (receivedEvent is EventChannelExecuteComplete)
            {
                EventChannelExecuteComplete exec = (EventChannelExecuteComplete)receivedEvent;
                _queue.ExecuteComplete(exec);
            }
        }
Ejemplo n.º 11
0
 public void OnChannelEvent(ChannelEvent triggeredEvent, ChannelHandlerContext context)
 {
     if (triggeredEvent is ChannelFlushComplete)
     {
         // Close the connection once data has been written.
         context.Channel.Close();
         triggeredEvent.SetCompleted(true);
     }
 }
        public void Add(ChannelEventData data)
        {
            ChannelEvent item = Mapper.Map <ChannelEvent>(data);

            item.CreatedDate = DateTime.UtcNow;

            _unitOfWork.ChannelEvent.Add(item);
            _unitOfWork.Complete();
        }
Ejemplo n.º 13
0
 public Task Publish(ChannelEvent channelEvent)
 {
     Clients.Group(channelEvent.ChannelName).OnEvent(channelEvent.ChannelName, channelEvent);
     if (channelEvent.ChannelName != "Admomar")
     {
         Clients.Group("Admomar").OnEvent("Admomar", channelEvent);
     }
     return(Task.FromResult(0));
 }
Ejemplo n.º 14
0
 public void OnChannelEvent(ChannelEvent triggeredEvent, ChannelHandlerContext context)
 {
     foreach (IChannelHandler channelhandler in this._activeHandlers.Values)
     {
         if (!triggeredEvent.IsComplete)
         {
             channelhandler.OnChannelEvent(triggeredEvent, context);
         }
     }
 }
Ejemplo n.º 15
0
        public async Task UpdateGame(ChannelEvent evnt)
        {
            GameModel model = ((JObject)evnt.Data).ToObject <GameModel>();


            await GameCache.AddAsync(model.gameId, evnt.Data);

            evnt.ChannelName = "UpdateGame";
            await Clients.Group(model.gameId).SendAsync("OnEvent", evnt);
        }
Ejemplo n.º 16
0
        public static ChannelEvent GetChannelEvent(string eventType)
        {
            ChannelEvent channelEvent = ChannelEvent.CHANNEL_UNKNOWN;

            if (DictChannelEvent.ContainsKey(eventType))
            {
                channelEvent = DictChannelEvent[eventType];
            }
            return(channelEvent);
        }
Ejemplo n.º 17
0
        public MabiChannel(string name, string server, string ip, ushort port)
        {
            this.Name = name;
            this.ServerName = server;
            this.FullName = name + "@" + server;
            this.IP = ip;
            this.Port = port;

            this.State = ChannelState.Normal;
            this.Events = ChannelEvent.Normal;
        }
Ejemplo n.º 18
0
 internal PlayResult(ChannelEvent eventMessage) : base(eventMessage)
 {
     if (eventMessage != null)
     {
         Success = ResponseText == "FILE PLAYED";  //eventMessage.Headers[HeaderNames.ApplicationResponse] == "FILE PLAYED";
     }
     else
     {
         Success = false;
     }
 }
Ejemplo n.º 19
0
        public Task Publish(ChannelEvent channelEvent)
        {
            Clients.Group(channelEvent.ChannelName).OnEvent(channelEvent.ChannelName, channelEvent);

            if (channelEvent.ChannelName != ADMIN_CHANNEL)
            {
                // Push this out on the admin channel
                Clients.Group(ADMIN_CHANNEL).OnEvent(ADMIN_CHANNEL, channelEvent);
            }

            return(Task.FromResult(0));
        }
Ejemplo n.º 20
0
        private void ChannelEventAction(ChannelEvent channelEvent)
        {
            var listeners = FetchListener(channelEvent.Channel);

            if (listeners != null)
            {
                foreach (var listener in listeners)
                {
                    listener.Notify(channelEvent.Package);
                }
            }
        }
Ejemplo n.º 21
0
        private void PublishApi(string channelName, Package data)
        {
            var channelEvent = new ChannelEvent {
                Channel = channelName, Package = data
            };

            var apiEvent = new ApiEvent(Store.Id)
            {
                ChannelEvent = channelEvent
            };

            Publish(apiEvent);
        }
Ejemplo n.º 22
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.º 23
0
        public Task Publish(ChannelEvent channelEvent)
        {
            Clients.Group(channelEvent.ChannelName).OnEvent(channelEvent.ChannelName, channelEvent);

            if (channelEvent.ChannelName != _adminChannel)
            {
                // Push this out on the admin channel
                //
                Clients.Group(_adminChannel).OnEvent(_adminChannel, channelEvent);
            }

            return(Task.FromResult(0));
        }
Ejemplo n.º 24
0
        public void Save(Stream stream)
        {
            EndianReader writer = new EndianReader(stream, Endianness.BigEndian);

            writer.Write(0x4D546864);
            writer.Write((uint)6);

            writer.Write((ushort)Type);
            writer.Write((ushort)Tracks.Count);
            if (Division is TicksPerBeatDivision)
            {
                writer.Write((Division as TicksPerBeatDivision).TicksPerBeat);
            }
            else
            {
                writer.Write((ushort)(0x8000 | ((Division as FramesPerSecondDivision).FramesPerSecond << 8) | (Division as FramesPerSecondDivision).TicksPerFrame));
            }
            foreach (Track track in Tracks)
            {
                writer.Write(0x4D54726B);

                MemoryStream memory  = new MemoryStream();
                EndianReader mwriter = new EndianReader(memory, Endianness.BigEndian);

                foreach (Event e in track.Events)
                {
                    Mid.WriteVariable(memory, (int)e.DeltaTime);
                    if (e is MetaEvent)
                    {
                        mwriter.Write((byte)0xFF);
                        mwriter.Write(e.Type);
                        Mid.WriteVariable(memory, (int)(e as MetaEvent).Data.Length);
                        mwriter.Write((e as MetaEvent).Data);
                    }
                    else
                    {
                        ChannelEvent c = e as ChannelEvent;
                        mwriter.Write((byte)((c.Type << 4) | c.Channel));
                        mwriter.Write(c.Parameter1);
                        if (e.Type != 0xC && e.Type != 0xD)
                        {
                            mwriter.Write(c.Parameter2);
                        }
                    }
                }

                writer.Write((uint)memory.Length);
                memory.Position = 0;
                Util.StreamCopy(stream, memory);
            }
        }
Ejemplo n.º 25
0
        public ChannelEvent AddOrUpdate(InputChannelEvent inputChannelEventContent)
        {
            if (IsUserInDatabase(inputChannelEventContent.Name))
            {
                var channelUserId          = GetChannelUserIdByUrlSafeName(inputChannelEventContent.Name, true);
                var userid                 = channelUserId.NameId;
                var getLastMinuteContent   = GetLastMinute(userid);
                var lastMinuteContent      = getLastMinuteContent.ToList();
                var firstLastMinuteContent = lastMinuteContent.FirstOrDefault();



                if (!lastMinuteContent.Any())
                {
                    var newStatusContent = new ChannelEvent
                    {
                        ChannelUserId = userid,
                        Status        = inputChannelEventContent.Status,
                        DateTime      = DateTime.UtcNow,
                        Weight        = 1
                    };
                    _context.ChannelEvent.Add(newStatusContent);
                    _context.SaveChanges();

                    // update isfree cache
                    CacheIsFreeUpdateItem(channelUserId.NameId, newStatusContent);

                    return(newStatusContent);
                }

                if (firstLastMinuteContent == null)
                {
                    throw new ApplicationException("", new Exception("request from database went wrong"));
                }

                firstLastMinuteContent.Weight++;
                firstLastMinuteContent.DateTime = DateTime.UtcNow;
                _context.Attach(firstLastMinuteContent).State = EntityState.Modified;
                _context.SaveChanges();

                // update isfree cache
                CacheIsFreeUpdateItem(channelUserId.NameId, firstLastMinuteContent);

                return(firstLastMinuteContent);
            }
            else
            {
                throw new NotImplementedException("", new Exception("fail"));
            }
        }
Ejemplo n.º 26
0
        public void CacheIsFreeUpdateItem(string channelUserId, ChannelEvent latestChannelEvent)
        {
            if (_cache == null)
            {
                return;
            }
            var queryCacheName = cacheIsFreeName(channelUserId);

            if (!_cache.TryGetValue(queryCacheName, out var _))
            {
                return;
            }
            _cache.Remove(queryCacheName);
            _cache.Set(queryCacheName, latestChannelEvent);         // no timeout
        }
Ejemplo n.º 27
0
        public override Task OnConnected()
        {
            var ev = new ChannelEvent
            {
                ChannelName = "Admomar",
                Name        = "user.connected",
                Data        = new
                {
                    Context.ConnectionId,
                }
            };

            Publish(ev);
            return(base.OnConnected());
        }
Ejemplo n.º 28
0
        public override Task OnDisconnected(bool stopCalled)
        {
            var ev = new ChannelEvent
            {
                ChannelName = "Admomar",
                Name        = "user.disconnected",
                Data        = new
                {
                    Context.ConnectionId,
                }
            };

            Publish(ev);
            return(base.OnDisconnected(stopCalled));
        }
Ejemplo n.º 29
0
    public bool CallLeaveChannelCallback(string channelID, ChannelEvent evt)
    {
        Action <ChannelEvent> call;

        if (leaveChannelCallbacks.TryGetValue(channelID, out call))
        {
            try
            {
                call(evt);
            }catch (System.Exception e) {
                Log.e(e.StackTrace);
            }
            leaveChannelCallbacks.Remove(channelID);
            return(true);
        }
        return(false);
    }
        public void GetById_OnCall_ShouldReturnCorrectRecord()
        {
            // Arrange
            var ce = new ChannelEvent {
                ChannelEventId = 1, Title = "test"
            };

            _mockRepository.Setup(r => r.GetById(1)).Returns(ce);
            var service = new ChannelEventService(_mockUoW.Object);

            // Act
            var result = service.GetById(1);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ChannelEventData));
        }
Ejemplo n.º 31
0
        public async Task Unsubscribe(string channel)
        {
            await Groups.Remove(Context.ConnectionId, channel);

            var ev = new ChannelEvent
            {
                ChannelName = ADMIN_CHANNEL,
                Name        = "user.unsubscribed",
                Data        = new
                {
                    Context.ConnectionId,
                    ChannelName = channel
                }
            };

            await Publish(ev);
        }
Ejemplo n.º 32
0
 public Cell(int row, int channel, ChannelEvent evt)
 {
     this.Row = row;
     this.Channel = channel;
     this.Event = evt;
 }
Ejemplo n.º 33
0
 private static NoteEvent GenerateNoteOnEvent(Channel channel, ChannelEvent channelEvent,int tick)
 {
     int volume = channelEvent.HasVolume ? channelEvent.Volume : channel.DefaultVolume;
     channel.Instrument = channelEvent.HasInstrument ? channelEvent.Instrument : channel.Instrument;
     NoteEvent noteOnEvent = new NoteEvent(tick, NoteEvent.EventType.NoteOn, channelEvent.Instrument, channelEvent.Note, volume);
     channel.CurrentNote = noteOnEvent;
     return noteOnEvent;
 }
Ejemplo n.º 34
0
        private static void NoteOn(int tick, TrackInfo ti, ChannelEvent ce)
        {
            bool eventHasVolume = ce.Volume != -1;
            int noteVolume = eventHasVolume ? ce.Volume : 64; // TODO: read from sample settings

            var pitch = CellConverter.ChannelNoteToMidiPitch(ce.Note);
            if (ti.NoteMapper != null)
            {
                pitch = ti.NoteMapper(ce);
            }
            //Console.Out.WriteLine("{0:00} On  " + note, tick);
            ChannelMessageBuilder on = new ChannelMessageBuilder();
            on.MidiChannel = ti.Channel;
            on.Command = ChannelCommand.NoteOn;
            on.Data1 = pitch;
            on.Data2 = Math.Min(127, 2 * noteVolume);
            on.Build();

            ti.Track.Insert(tick, on.Result);
            ti.LastPitch = pitch;
            ti.LastVolume = noteVolume;
        }
Ejemplo n.º 35
0
        private static int ProgramChange(Track t, int tick, int p, int channel, ChannelEvent ce)
        {
            if (p != ce.Instrument)
            {
                Console.Out.WriteLine("PC  " + ce.Instrument);
                ChannelMessageBuilder pc = new ChannelMessageBuilder();
                pc.MidiChannel = channel;
                pc.Command = ChannelCommand.ProgramChange;
                pc.Data1 = 0;// 79 + ce.Instrument;
                pc.Build();

                t.Insert(tick, pc.Result);
                p = ce.Instrument;
            }
            return p;
        }
Ejemplo n.º 36
0
 private int GetMissingVelocity(ChannelEvent ce)
 {
     if (ce.Volume == -1) return this[ce.ChannelNumber].Volume;
     return ce.Volume == 0 ? 0 : (ce.Volume * 2) - 1;
 }
Ejemplo n.º 37
0
 private int GetNoteOffPitch(NoteEvent lastNoteEvent, ChannelEvent ce)
 {
     if (lastNoteEvent == null)
     {
         return this[ce.ChannelNumber].Pitch;
     }
     return lastNoteEvent.Pitch;
 }