Exemple #1
0
        public void RunFSEventFileDeleted()
        {
            var storage = this.GetInitializedStorage();
            var path    = new Mock <IFileInfo>();
            var name    = "a";

            path.Setup(p => p.FullName).Returns(Path.Combine(this.localRoot, name));
            string id = "id";

            var mappedObject = new MappedObject(name, id, MappedObjectType.File, null, "changeToken");

            storage.SaveMappedObject(mappedObject);

            var session = new Mock <ISession>();

            session.SetupSessionDefaultValues();
            session.SetupChangeLogToken("default");
            session.SetupTypeSystem();
            IDocument remote = MockOfIDocumentUtil.CreateRemoteDocumentMock(null, id, name, (string)null, changeToken: "changeToken").Object;

            session.Setup(s => s.GetObject(id, It.IsAny <IOperationContext>())).Returns(remote);
            var myEvent = new FSEvent(WatcherChangeTypes.Deleted, path.Object.FullName, false);
            var queue   = this.CreateQueue(session, storage);

            queue.AddEvent(myEvent);
            queue.Run();

            session.Verify(f => f.Delete(It.Is <IObjectId>(i => i.Id == id), true), Times.Once());
            Assert.That(storage.GetObjectByRemoteId(id), Is.Null);
        }
Exemple #2
0
        public void DoNotFilterValidLocalFSAddedEvents()
        {
            this.SetupMocks();
            var fileEvent = new FSEvent(WatcherChangeTypes.Created, Path.Combine(Path.GetTempPath(), "file.txt"), false);

            Assert.That(this.underTest.Handle(fileEvent), Is.False);
        }
Exemple #3
0
        public void CloseInCallback()
        {
            string directory = TestHelper.CreateTempDirectory();

            this.directoryList.Add(directory);

            string file1 = TestHelper.CreateTempFile(directory);
            string file2 = TestHelper.CreateTempFile(directory);
            string file3 = TestHelper.CreateTempFile(directory);
            string file4 = TestHelper.CreateTempFile(directory);
            string file5 = TestHelper.CreateTempFile(directory);

            FSEvent fsEvent = this.loop.CreateFSEvent();

            fsEvent.Start(directory, this.OnFSeventClose);

            /* Generate a couple of fs events. */
            TestHelper.TouchFile(file1, 10);
            TestHelper.TouchFile(file2, 20);
            TestHelper.TouchFile(file3, 30);
            TestHelper.TouchFile(file4, 40);
            TestHelper.TouchFile(file5, 50);

            this.loop.RunDefault();

            Assert.Equal(1, this.closeCount);
            Assert.Equal(3, this.callbackCount);
        }
Exemple #4
0
        public void RunFSEventFolderDeleted()
        {
            var storage = this.GetInitializedStorage();
            var path    = new Mock <IFileInfo>();
            var name    = "a";

            path.Setup(p => p.FullName).Returns(Path.Combine(this.localRoot, name));
            string id = "id";

            var mappedObject = new MappedObject(name, id, MappedObjectType.Folder, null, null);

            storage.SaveMappedObject(mappedObject);

            var session = new Mock <ISession>();

            session.SetupTypeSystem();
            session.SetupSessionDefaultValues();
            session.SetupChangeLogToken("default");
            IFolder remote = MockOfIFolderUtil.CreateRemoteFolderMock(id, name, (string)null).Object;

            session.Setup(s => s.GetObject(id, It.IsAny <IOperationContext>())).Returns(remote);
            var myEvent = new FSEvent(WatcherChangeTypes.Deleted, path.Object.FullName, true);
            var queue   = this.CreateQueue(session, storage);

            queue.AddEvent(myEvent);
            queue.Run();

            Mock.Get(remote).Verify(d => d.DeleteTree(false, UnfileObject.DeleteSinglefiled, true), Times.Once());
            Assert.That(storage.GetObjectByRemoteId(id), Is.Null);
        }
Exemple #5
0
        public void WatchDirRecursive()
        {
            if (!Platform.IsWindows &&
                !Platform.IsMacOS)
            {
                // Recursive directory watching not supported on this platform.
                return;
            }

            string directory = TestHelper.CreateTempDirectory();

            this.currentFileName = TestHelper.CreateRandomDirectory(directory);
            this.directoryList.Add(this.currentFileName);

            this.fsEventCurrent = this.loop
                                  .CreateFSEvent()
                                  .Start(this.currentFileName, this.OnFSEventDirMultipleFile, FSEventMask.Recursive);

            this.timer = this.loop
                         .CreateTimer()
                         .Start(this.OnTimerCreateFile, 100, 0);

            this.loop.RunDefault();

            Assert.True(this.fileCreated + this.fileRemoved == this.callbackCount);
            Assert.Equal(2, this.closeCount);
        }
Exemple #6
0
        public void ReportFSFileAddedEvent()
        {
            this.localFile.Delete();
            this.localFile = new FileInfo(Path.Combine(this.localFolder.FullName, Path.GetRandomFileName()));
            this.queue.Setup(q => q.AddEvent(It.Is <FSEvent>(e => e.LocalPath == this.localFile.FullName)))
            .Callback((ISyncEvent file) => this.returnedFSEvent = file as FSEvent);
            var watcherData = this.GetWatcherData(this.localFolder.FullName, this.queue.Object);

            watcherData.Watcher.EnableEvents = true;
            var t = Task.Factory.StartNew(() => {
                int count = 0;
                while (this.returnedFSEvent == null && count < RETRIES)
                {
                    WaitWatcherData(watcherData, this.localFile.FullName, WatcherChangeTypes.Created, MILISECONDSWAIT);
                    count++;
                }
            });

            using (this.localFile.Create())
            {
            }

            t.Wait();
            if (this.returnedFSEvent != null)
            {
                Assert.IsFalse(this.returnedFSEvent.IsDirectory);
                Assert.AreEqual(this.localFile.FullName, this.returnedFSEvent.LocalPath);
                Assert.AreEqual(WatcherChangeTypes.Created, this.returnedFSEvent.Type);
            }
            else
            {
                Assert.Inconclusive("Missed file added event");
            }
        }
Exemple #7
0
        public void FilterLocalFSDeletionEvents()
        {
            this.SetupMocks();
            var fileEvent = new FSEvent(WatcherChangeTypes.Deleted, Path.Combine(this.ignoredPath, "file.txt"), false);

            Assert.That(this.underTest.Handle(fileEvent), Is.True);
        }
Exemple #8
0
        public void ReportFSFolderRemovedEvent()
        {
            this.queue.Setup(q => q.AddEvent(It.Is <FSEvent>(e => e.LocalPath == this.localSubFolder.FullName)))
            .Callback((ISyncEvent file) => this.returnedFSEvent = file as FSEvent);
            var watcherData = this.GetWatcherData(this.localFolder.FullName, this.queue.Object);

            watcherData.Watcher.EnableEvents = true;
            var t = Task.Factory.StartNew(() => {
                int count = 0;
                while (this.returnedFSEvent == null && count < RETRIES)
                {
                    WaitWatcherData(watcherData, this.localSubFolder.FullName, WatcherChangeTypes.Deleted, MILISECONDSWAIT);
                    count++;
                }
            });

            this.localSubFolder.Delete();
            t.Wait();
            if (this.returnedFSEvent != null)
            {
                Assert.AreEqual(this.localSubFolder.FullName, this.returnedFSEvent.LocalPath);
                Assert.AreEqual(WatcherChangeTypes.Deleted, this.returnedFSEvent.Type);
                Assert.That(this.returnedFSEvent.IsDirectory, Is.True);
            }
            else
            {
                Assert.Inconclusive("Missed folder removed event");
            }
        }
Exemple #9
0
        protected void SetUp()
        {
            var config = ITUtils.GetConfig();

            this.uuid = Guid.NewGuid();
            string localPath = Path.Combine(config[1].ToString(), Path.GetRandomFileName());

            this.localFolder = new DirectoryInfo(localPath);
            this.localFolder.Create();
            this.localSubFolder = new DirectoryInfo(Path.Combine(this.localFolder.FullName, Path.GetRandomFileName()));
            this.localSubFolder.Create();
            this.localFile = new FileInfo(Path.Combine(this.localFolder.FullName, Path.GetRandomFileName()));
            using (this.localFile.Create())
            {
            }

            if (AreExtendedAttributesAvailable(this.localFile.FullName))
            {
                new FileInfoWrapper(this.localFile).Uuid = this.uuid;
            }

            if (AreExtendedAttributesAvailable(this.localSubFolder.FullName))
            {
                new DirectoryInfoWrapper(this.localSubFolder).Uuid = this.uuid;
            }

            this.queue           = new Mock <ISyncEventQueue>();
            this.returnedFSEvent = null;
        }
Exemple #10
0
    public FSEvent On(string eventName)
    {
        FSEvent newEvent = new FSEvent(eventName, null, this, mOwner, mEnterDelegate, mPushDelegate, mPopDelegate);

        mTranslationEvents.Add(eventName, newEvent);
        return(newEvent);
    }
    public FSState On <T>(string eventName, Action <T> action)
    {
        Debug.Log("on 2" + eventName);
        FSEvent newEvent = new FSEvent(eventName, null, this, mOwner, mEnterDelegate, mPushDelegate, mPopDelegate);

        newEvent.mAction = delegate(object o1, object o2, object o3)
        {
            T param1;
            try{ param1 = (T)o1; }
            catch { param1 = default(T); }
            action(param1);
            if (param1 == null)
            {
                Debug.Log(1);
            }
            else
            {
                Debug.Log(2);
                Debug.Log(param1);
            }
            return(true);
        };
        mTranslationEvents.Add(eventName, newEvent);
        return(this);
    }
Exemple #12
0
        public FSEvent[] GetFSEvents(Client client)
        {
            lock (client.SyncAccess)
            {
                int lastId = 0;
                if (client.FSEvents != null && client.FSEvents.Length != 0)
                {
                    lastId = client.FSEvents[0].EventID;
                }
                else
                {
                    client.FSEvents = new FSEvent[0];
                }

                FSEvent[] newFSEvents = server.GetFSEvents(client, lastId);
                if (newFSEvents == null || newFSEvents.Length == 0)
                {
                    return(client.FSEvents);
                }

                FSEvent[] oldFSEvents   = client.FSEvents;
                int       finalLen      = oldFSEvents.Length + newFSEvents.Length;
                FSEvent[] finalFSEvents = new FSEvent[finalLen];

                Array.Copy(newFSEvents, 0, finalFSEvents, 0, newFSEvents.Length);
                Array.Copy(oldFSEvents, 0, finalFSEvents, newFSEvents.Length, oldFSEvents.Length);

                client.FSEvents = finalFSEvents;
                return(finalFSEvents);
            }
        }
Exemple #13
0
        //public void Trigger(E eventEnum, P param1)
        //{
        //    mFSEventsPool[eventEnum].Execute(param1, param2, null);
        //}
        //public void Trigger(E eventEnum, P param1, object param2, object param3)
        //{
        //    mFSEventsPool[eventEnum].Execute(param1, param2, param3);
        //}


        public FSState OnFunc(E eventEnum, Func <P, bool> action)
        {
            FSEvent newEvent = new FSEvent(eventEnum, null, this, mOwner, mEnterDelegate, mPushDelegate, mPopDelegate);

            newEvent.mAction = action;
            mFSEventsPool.Add(eventEnum, newEvent);
            return(this);
        }
Exemple #14
0
        void OnTimer(Timer handle)
        {
            FSEvent fsEvent = this.loop
                              .CreateFSEvent()
                              .Start(".", this.OnFSEvent);

            fsEvent.CloseHandle(this.OnClose);
            handle.CloseHandle(this.OnClose);
        }
Exemple #15
0
        public void FsEventStoresDirectoryState()
        {
            var path = Path.Combine(Path.GetTempPath(), "newPath");

            Directory.CreateDirectory(path);
            var e = new FSEvent(WatcherChangeTypes.Created, path, true);

            Assert.That(e.IsDirectory, Is.True, "It is a Directory");
        }
Exemple #16
0
        void OnFSeventClose(FSEvent fsEvent, FileSystemEvent fileSystemEvent)
        {
            this.callbackCount++;

            if (this.callbackCount == 3)
            {
                fsEvent.CloseHandle(this.OnClose);
            }
        }
Exemple #17
0
        public void FilterIgnoresNonExistingPaths()
        {
            var storage   = new Mock <IMetaDataStorage>();
            var fsFactory = new Mock <IFileSystemInfoFactory>();
            var filter    = new IgnoreAlreadyHandledFsEventsFilter(storage.Object, fsFactory.Object);
            var fsEvent   = new FSEvent(WatcherChangeTypes.Created, Path.Combine(Path.GetTempPath(), "path"), true);

            Assert.That(filter.Handle(fsEvent), Is.False);
        }
Exemple #18
0
        public void Constructor()
        {
            string name = "test";
            string path = Path.Combine(Path.GetTempPath(), name);
            var    e    = new FSEvent(WatcherChangeTypes.Created, path, false);

            Assert.That(e.Name, Is.EqualTo(name));
            Assert.That(e.LocalPath, Is.EqualTo(path));
        }
Exemple #19
0
        void OnFSEventDirectory(FSEvent fsEvent, FileSystemEvent fileSystemEvent)
        {
            if (fileSystemEvent.EventType == FSEventType.Rename)
            {
                this.callbackCount++;
            }

            fsEvent.Stop();
            fsEvent.CloseHandle(this.OnClose);
        }
Exemple #20
0
        void OnFSEventFile(FSEvent fsEvent, FileSystemEvent fileSystemEvent)
        {
            if (fileSystemEvent.EventType == FSEventType.Change)
            {
                this.callbackCount++;
            }

            fsEvent.Stop();
            fsEvent.CloseHandle(this.OnClose);
        }
Exemple #21
0
        public void FsEventExtractsDirectoryName()
        {
            string name = "newPath";
            var    path = Path.Combine(Path.GetTempPath(), name);

            Directory.CreateDirectory(path);
            var e = new FSEvent(WatcherChangeTypes.Created, path, true);

            Assert.That(e.Name, Is.EqualTo(name));
        }
            public void AddEvent(ISyncEvent newEvent)
            {
                lock (Events) {
                    FSEvent fsEvent = newEvent as FSEvent;
                    if (fsEvent != null)
                    {
                        Events.Add(fsEvent);
                    }

                    Queue.AddEvent(newEvent);
                }
            }
Exemple #23
0
    /// <summary>
    /// 事件注册函数,将事件的名字和事件加入到Dictionary里面
    /// </summary>
    /// <param name="eventName"></param>
    /// <returns></returns>
    public FSEvent On(string eventName)
    {
        if (mTranslationEvents.ContainsKey(eventName))
        {
            return(mTranslationEvents[eventName]);
        }

        FSEvent newEvent = new FSEvent(eventName, null, this, mOwner, mEnterDelegate, mPushDelegate, mPopDelegate);

        mTranslationEvents.Add(eventName, newEvent);
        return(newEvent);
    }
Exemple #24
0
        void OnFSEventFileCurrentDir(FSEvent fsEvent, FileSystemEvent fileSystemEvent)
        {
            if (this.callbackCount == 0 &&
                fileSystemEvent.EventType == FSEventType.Change &&
                !string.IsNullOrEmpty(fileSystemEvent.FileName))
            {
                this.callbackCount++;
            }

            this.loop.CreateTimer()
            .Start(this.OnTimerClose, 250, 0);
        }
Exemple #25
0
        public void FSEvent()
        {
            FSEvent fsEvent = this.loop
                              .CreateFSEvent()
                              .Start(".", this.OnFSEvent);

            fsEvent.RemoveReference();

            this.loop.RunDefault();
            Assert.Equal(0, this.callbackCount);

            this.CloseHandle(fsEvent);
        }
    // Evaluators return self, for chaining of on calls
    public FSState On <T>(string eventName, Func <T, bool> action)
    {
        FSEvent newEvent = new FSEvent(eventName, null, this, mOwner, mEnterDelegate, mPushDelegate, mPopDelegate);

        newEvent.mAction = delegate(object o1, object o2, object o3) {
            T param1;
            try { param1 = (T)o1; } catch { param1 = default(T); }
            action(param1);
            return(true);
        };
        mTranslationEvents.Add(eventName, newEvent);
        return(this);
    }
Exemple #27
0
        public void WatchFileRootDir()
        {
            string  root    = TestHelper.RootSystemDirectory();
            FSEvent fsEvent = this.loop
                              .CreateFSEvent()
                              .Start(root, this.OnFSEvent);

            fsEvent.CloseHandle(this.OnClose);

            this.loop.RunDefault();
            Assert.Equal(0, this.callbackCount);
            Assert.Equal(1, this.closeCount);
        }
Exemple #28
0
        public void HandleFSFolderRemovedEvents()
        {
            this.queue.Setup(q => q.AddEvent(It.IsAny <AbstractFolderEvent>()))
            .Callback((ISyncEvent f) => this.returnedFolderEvent = f as AbstractFolderEvent);
            var watcher = new WatcherConsumer(this.queue.Object);

            var folderRemovedFSEvent = new FSEvent(WatcherChangeTypes.Deleted, this.localFolder.FullName, true);

            Assert.True(watcher.Handle(folderRemovedFSEvent));
            Assert.AreEqual(MetaDataChangeType.DELETED, this.returnedFolderEvent.Local);
            Assert.AreEqual(this.localFolder.FullName, (this.returnedFolderEvent as FolderEvent).LocalFolder.FullName);
            Assert.IsNull((this.returnedFolderEvent as FolderEvent).RemoteFolder);
            Assert.AreEqual(MetaDataChangeType.NONE, (this.returnedFolderEvent as FolderEvent).Remote);
        }
Exemple #29
0
        public void Dispose()
        {
            this.fsEventCurrent?.Dispose();
            this.fsEventCurrent = null;

            this.fsEventCurrent1?.Dispose();
            this.fsEventCurrent1 = null;

            TestHelper.DeleteDirectories(this.directoryList);
            this.directoryList = null;

            this.loop?.Dispose();
            this.loop = null;
        }
Exemple #30
0
 public static void DebugEventDump(FSEvent evt)
 {
     #if DEBUG_LOG_EVENTS
     String event_dump = evt.event_id.ToString();
     if (!String.IsNullOrEmpty(evt.subclass_name))
         event_dump += " " + evt.subclass_name;
     event_dump += ":\n";
     switch_event_header hdr = evt.first_header;
     while (hdr != null) {
         event_dump += "\t" + hdr.name + ": " + hdr.value + "\n";
         hdr = hdr.next;
     }
     DebugWrite(event_dump + "\n");
     #endif
 }
    public FSState On <T1, T2>(string eventName, Action <T1, T2> action)
    {
        FSEvent newEvent = new FSEvent(eventName, null, this, mOwner, mEnterDelegate, mPushDelegate, mPopDelegate);

        newEvent.mAction = delegate(object o1, object o2, object o3) {
            T1 param1;
            T2 param2;
            try { param1 = (T1)o1; } catch { param1 = default(T1); }
            try { param2 = (T2)o2; } catch { param2 = default(T2); }
            action(param1, param2);
            return(true);
        };
        mTranslationEvents.Add(eventName, newEvent);
        return(this);
    }
Exemple #32
0
 private static void HandleDTMFEvent(FSEvent evt, string uuid)
 {
     String digit = evt.get_header("DTMF-Digit");
     var call = (from c in calls where c.leg_a_uuid == uuid || c.leg_b_uuid == uuid select c).SingleOrDefault();
     if (call.state == CALL_STATE.Answered && digit.Length == 1)
         PortAudio.PlayDTMF(digit[0], call.leg_a_uuid);
 }
Exemple #33
0
        public static void HandleHangupCompleteEvent(FSEvent evt, String uuid)
        {
            Utils.DebugEventDump(evt);
            Call call = (from c in calls where c.leg_a_uuid == uuid || c.leg_b_uuid == uuid select c).SingleOrDefault();
            if (call == null || call.call_ended)
                return;

            CALL_STATE new_state = CALL_STATE.None;

            if (call.state != CALL_STATE.Answered && call.state != CALL_STATE.Missed && call.state != CALL_STATE.Hold) {
                if (String.IsNullOrEmpty(call.note))
                    call.note = evt.get_header("variable_sip_hangup_phrase");
                if (!call.is_outgoing && call.state == CALL_STATE.Ringing)
                    new_state = CALL_STATE.Missed;
                else
                    new_state = CALL_STATE.Failed;
            }
            else if (call.state == CALL_STATE.Answered || call.state == CALL_STATE.Hold)
                new_state = CALL_STATE.Ended;

            if (new_state == CALL_STATE.None)
                throw new Exception("Not sure what happened call was at state...: " + call.state);
            Call new_active_call;
            if (Call.active_call != call)
                new_active_call = Call.active_call;
            else
                new_active_call = (from c in calls where c.state == CALL_STATE.Ringing && c.is_outgoing == false && c != call select c).FirstOrDefault();
            call.UpdateCallState(new_state, new_active_call);
        }
Exemple #34
0
 public static void NewFSEvent(object sender, FSEvent evt)
 {
     if (evt.event_id != switch_event_types_t.SWITCH_EVENT_MODULE_LOAD)
         Utils.DebugEventDump(evt);
     String uuid = evt.get_header("Unique-ID");
     switch (evt.event_id) {
         case switch_event_types_t.SWITCH_EVENT_CHANNEL_CREATE:
             handleChannelCreateEvent(evt, uuid);
             break;
         case switch_event_types_t.SWITCH_EVENT_CHANNEL_OUTGOING:
             HandleOutgoingEvent(evt, uuid);
             break;
         case switch_event_types_t.SWITCH_EVENT_CHANNEL_HANGUP_COMPLETE:
             HandleHangupCompleteEvent(evt, uuid);
             break;
         case switch_event_types_t.SWITCH_EVENT_CHANNEL_ANSWER:
             HandleChannelAnswerEvent(evt, uuid);
             break;
         case switch_event_types_t.SWITCH_EVENT_CUSTOM:
             HandleCustomEvent(evt, uuid);
             break;
         case switch_event_types_t.SWITCH_EVENT_CHANNEL_DESTROY:
             channels.Remove(uuid);
             break;
         case switch_event_types_t.SWITCH_EVENT_DTMF:
             HandleDTMFEvent(evt, uuid);
             break;
     }
 }
Exemple #35
0
 //capture an outgoing call the other leg
 public static void HandleOutgoingEvent(FSEvent evt, String uuid)
 {
     String other_leg = evt.get_header("Other-Leg-Unique-ID");
     Call call = (from c in calls where c.leg_a_uuid == other_leg select c).SingleOrDefault();
     if (call == null || !call.is_outgoing)
         return;
     call.leg_b_uuid = uuid;
 }
Exemple #36
0
        private static void HandleChannelAnswerEvent(FSEvent evt, String uuid)
        {
            Call call = (from c in calls where c.leg_b_uuid == uuid select c).SingleOrDefault();
            if (call == null || call.state == CALL_STATE.Answered)
                return;

            if (call.state == CALL_STATE.Ringing || (call.state == CALL_STATE.Hold_Ringing && !call.is_outgoing))
                call.UpdateCallState(CALL_STATE.Answered, call.is_outgoing ? active_call : call);
            else if (call.state == CALL_STATE.Hold_Ringing)
                call.UpdateCallState(CALL_STATE.Hold, active_call);
            else
                throw new Exception("Unknown state, call answered but was not in a state of hold_ring or ringing");
        }
Exemple #37
0
 private static void handleChannelCreateEvent(FSEvent evt, string uuid)
 {
     Channel c;
     if (!channels.TryGetValue(uuid, out c)) {
         c = new Channel();
         channels.Add(uuid, c);
     }
     String gateway = evt.get_header("variable_sip_gateway");
     if (!String.IsNullOrEmpty(gateway))
         c.gateway_id = gateway;
 }
Exemple #38
0
 private static void HandleCustomEvent(FSEvent evt, string uuid)
 {
     if (evt.subclass_name == "portaudio::ringing") {
         Utils.DebugEventDump(evt);
         if ((from c in calls where c._leg_a_uuid == uuid select c).Count() > 0)//only care about first ring
             return;
         Call call = new Call();
         call.SetCallInfoFromEvent(evt);
         String gw_id = (from c in channels where c.Key == call.leg_b_uuid select c.Value.gateway_id).SingleOrDefault();
         call.account = (from a in Account.accounts where a.gateway_id == gw_id select a).SingleOrDefault();
         calls.Add(call);
         call.UpdateCallState(CALL_STATE.Ringing, active_call ?? call);
     }
     else if (evt.subclass_name == "portaudio::makecall") {
         Utils.DebugEventDump(evt);
         if (evt.get_header("fail") == "true") {
             MessageBox.Show("Make Call failed!!!, came from portaudio not sure why");
             return;
         }
         Call call = new Call();
         call.is_outgoing = true;
         call.SetCallInfoFromEvent(evt);
         calls.Add(call);
         call.UpdateCallState(CALL_STATE.Ringing, call);
     }
     else if (evt.subclass_name == "portaudio::callheld" || evt.subclass_name == "portaudio::callresumed") {
         String paid_str = evt.get_header("variable_pa_call_id");
         if (String.IsNullOrEmpty(paid_str))
             return;
         int portaudio_id = Int32.Parse(paid_str);
         Call call = (from c in calls where c.portaudio_id == portaudio_id select c).SingleOrDefault();
         if (call == null)
             return;
         if (evt.subclass_name == "portaudio::callresumed")
             call.UpdateCallState(CALL_STATE.Answered, call);
         else
             call.UpdateCallState(call.state == CALL_STATE.Ringing ? CALL_STATE.Hold_Ringing : CALL_STATE.Hold, call == active_call ? null : active_call);
     }
 }
Exemple #39
0
 private void BroadcastEvent(FSEvent evt)
 {
     if (NewEvent != null)
         NewEvent(this, evt);
 }
Exemple #40
0
        private void SetCallInfoFromEvent(FSEvent evt)
        {
            leg_a_uuid = evt.get_header("Unique-ID");
            leg_b_uuid = evt.get_header("Other-Leg-Unique-ID");
            if (is_outgoing) {
                Match match = Regex.Match(evt.get_header("Caller-Destination-Number"), "sofia/gateway/([0-9]+)/(.+)");
                if (match.Success && match.Groups.Count == 3) {
                    String gw_id = match.Groups[1].Value;
                    account = (from a in Account.accounts where a.gateway_id == gw_id select a).SingleOrDefault();
                    other_party_number = match.Groups[2].Value;
                }
            }
            else {
                other_party_name = evt.get_header("Caller-Caller-ID-Name");
                other_party_number = evt.get_header("Caller-Caller-ID-Number");
            }
            if (String.IsNullOrEmpty(other_party_name))
                other_party_name = other_party_number;

            String paid_str = evt.get_header("variable_pa_call_id");
            if (!String.IsNullOrEmpty(paid_str))
                portaudio_id = Int32.Parse(paid_str);
        }