Exemplo n.º 1
0
        private void init()
        {
            m_updateListener = new UpdateListener(this);
            m_updateSubject
            .Synchronize()
            .Throttle(TimeSpan.FromMilliseconds(10))
            .SubscribeOnDispatcher()
            .Subscribe(m_updateListener);

            m_sessionVolumeListener = new AudioSessionVolumeListener(this);
            m_sessionMuteListener   = new AudioSessionMuteListener(this);

            m_coreAudioController = new CoreAudioController();

            m_coreAudioController.DefaultPlaybackDevice.GetCapability <IAudioSessionController>().SessionCreated.Subscribe(new AudioSessionAddedListener(this));
            m_coreAudioController.DefaultPlaybackDevice.GetCapability <IAudioSessionController>().SessionDisconnected.Subscribe(new AudioSessionRemovedListener(this));
            m_coreAudioController.AudioDeviceChanged.Subscribe(new DeviceChangeListener(this));

            var masterVolumeListener = new MasterVolumeListener(this);

            m_coreAudioController.DefaultPlaybackDevice.VolumeChanged.Throttle(TimeSpan.FromMilliseconds(10)).Subscribe(masterVolumeListener);

            m_coreAudioController.DefaultPlaybackDevice.MuteChanged.Throttle(TimeSpan.FromMilliseconds(10)).Subscribe(masterVolumeListener);

            new Thread(() =>
            {
                updateState(null);

                Server = new Server(this);
            }).Start();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add a listener that will be updated as fast a possible by the loop. Also will enable background tasks to run at the same time
        /// as this listener. Those can be added using addBackgroundUpdateListener and giving the same name given here.
        /// You must add the main thread update listener before adding the updates that will run in the background.
        /// </summary>
        /// <param name="listener">The listener to add.</param>
        public void addUpdateListenerWithBackgrounding(String name, UpdateListener listener)
        {
            UpdateListenerWithBackgrounding bgListenerWorker = new UpdateListenerWithBackgrounding(listener);

            multiThreadedWorkerListeners.Add(name, bgListenerWorker);
            addUpdateListener(bgListenerWorker);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Remove a listener from the full speed loop.
        /// </summary>
        /// <param name="listener">The listener to remove</param>
        public void removeUpdateListenerWithBackgrounding(String name, UpdateListener listener)
        {
            UpdateListenerWithBackgrounding bgListenerWorker = multiThreadedWorkerListeners[name];

            removeUpdateListener(bgListenerWorker);
            bgListenerWorker.Dispose();
            multiThreadedWorkerListeners.Remove(name);
        }
Exemplo n.º 4
0
 public static void CompileDeployAddListener(
     string epl,
     string stmtName,
     UpdateListener listener,
     EPRuntime runtime,
     Configuration configuration)
 {
     var compiled = Compile(epl, configuration, new RegressionPath());
     DeployAddListener(compiled, stmtName, listener, runtime);
 }
Exemplo n.º 5
0
 public void AddUpdate(Action <int> callback)
 {
     foreach (Delegate del in UpdateListener.GetInvocationList())
     {
         Action <int> action = (Action <int>)del;
         if (callback.Equals(action))                 //If this callback exists already, ignore this addlistener
         {
             return;
         }
     }
     UpdateListener += callback;
 }
Exemplo n.º 6
0
        /// <summary>
        /// Remove an update listener from the fixed updater part of the timer.
        /// </summary>
        /// <param name="listener">The listener to remove.</param>
        public void removeUpdateListener(UpdateListener listener)
        {
            int index = updateListeners.IndexOf(listener);

            if (index != -1)
            {
                updateListeners.RemoveAt(index);
                //Adjust the iteration index backwards if the element being removed is before or on the index.
                //This way nothing gets skipped.
                if (index <= fixedUpdateIndex)
                {
                    --fixedUpdateIndex;
                }
            }
        }
        public void SetPeriodTest()
        {
            const int    TEST_TIMES              = 4;
            const long   PERIOD_NEW              = 5000;
            const double PERIOD_DELTA            = 1800;
            const string UPDATE_CHANGE_FILE_NAME = "update_change_field_profiles.zip";
            string       sourceFile              = Path.GetFullPath(Path.Combine(DATA_PATH, ZIP_FILE_NAME));
            string       updateFile              = Path.GetFullPath(Path.Combine(DATA_PATH, UPDATE_CHANGE_FILE_NAME));
            string       targetFile              = Path.GetFullPath(Path.Combine(DATA_PATH, TEST_FILE_NAME));

            Assert.True(File.Exists(sourceFile));
            Assert.True(File.Exists(updateFile));
            Uri uri = new Uri(targetFile);

            File.Copy(sourceFile, targetFile, true);
            InstrumentProfileConnection connection = new InstrumentProfileConnection(uri.AbsoluteUri + UPDATE_PERIOD_STR);
            UpdateListener updateListener          = new UpdateListener();

            connection.AddUpdateListener(updateListener);
            connection.Start();

            DateTime time = DateTime.Now;

            while (!updateListener.IsUpdated)
            {
            }
            for (int i = 0; i < TEST_TIMES * 2; i++)
            {
                if (i == TEST_TIMES)
                {
                    connection.UpdatePeriod = PERIOD_NEW;
                }
                updateListener.DropState();
                File.Copy(updateFile, targetFile, true);
                File.SetLastWriteTime(targetFile, DateTime.Now);
                while (!updateListener.IsUpdated)
                {
                }
                Assert.AreEqual(connection.UpdatePeriod, DateTime.Now.Subtract(time).TotalMilliseconds, PERIOD_DELTA);
                time = DateTime.Now;
                //swap source/update files
                string temp = updateFile;
                updateFile = sourceFile;
                sourceFile = temp;
            }

            connection.Close();
        }
Exemplo n.º 8
0
 public static void ReplaceListener(UpdateListener listener, SudokuGrid value, ref SudokuGrid grid)
 {
     if (grid == value)
     {
         return;
     }
     if (grid != null)
     {
         grid.RemoveListener(listener);
     }
     grid = value;
     if (grid != null)
     {
         grid.AddListener(listener);
     }
 }
        public void UpdateRemoveTest()
        {
            const int    UPDATE_ADD_COUNT        = 2;
            const string UPDATE_REMOVE_FILE_NAME = "update_remove_profiles.zip";
            const string PRODUCT_SYMBOL_1        = "/CL";
            const string PRODUCT_SYMBOL_2        = "/TF";
            string       sourceFile = Path.GetFullPath(Path.Combine(DATA_PATH, ZIP_FILE_NAME));
            string       updateFile = Path.GetFullPath(Path.Combine(DATA_PATH, UPDATE_REMOVE_FILE_NAME));
            string       targetFile = Path.GetFullPath(Path.Combine(DATA_PATH, TEST_FILE_NAME));

            Assert.True(File.Exists(sourceFile));
            Assert.True(File.Exists(updateFile));
            Uri uri = new Uri(targetFile);

            File.Copy(sourceFile, targetFile, true);
            InstrumentProfileConnection connection = new InstrumentProfileConnection(uri.AbsoluteUri + UPDATE_PERIOD_STR);
            UpdateListener updateListener          = new UpdateListener();

            connection.AddUpdateListener(updateListener);
            connection.Start();

            while (!updateListener.IsUpdated)
            {
            }
            Assert.AreEqual(IPF_COUNT, updateListener.LastUpdate.Count);

            updateListener.DropState();
            File.Copy(updateFile, targetFile, true);
            File.SetLastWriteTime(targetFile, DateTime.Now);
            while (!updateListener.IsUpdated)
            {
            }
            Assert.AreEqual(UPDATE_ADD_COUNT, updateListener.LastUpdate.Count);
            foreach (InstrumentProfile ip in updateListener.LastUpdate)
            {
                if (ip.GetTypeName().Equals(InstrumentProfileType.REMOVED.Name) &&
                    (ip.GetSymbol().Equals(PRODUCT_SYMBOL_1) || ip.GetSymbol().Equals(PRODUCT_SYMBOL_2)))
                {
                    continue;
                }
                Assert.Fail("Unexpected instrument profiles here!");
            }

            connection.Close();
        }
    /// <summary>
    /// Add a new fixed update listener.
    /// </summary>

    static public void AddOnUpdate(Component mb, OnUpdateCallback callback)
    {
        ProximityManager pro = GetInstance(mb);

        foreach (UpdateListener p in pro.mOnUpdate)
        {
            if (p.mb == mb && p.callback == callback)
            {
                return;
            }
        }

        UpdateListener ent = new UpdateListener();

        ent.mb       = mb;
        ent.callback = callback;
        pro.mOnUpdate.Add(ent);
    }
Exemplo n.º 11
0
        private Task Client_MessageCreated(MessageCreateEventArgs e)
        {
            UpdateListener.CheckMessage(e);
            if (e.Author.IsBot)
            {
                return(Done);                              // explicitly ignore bot messages
            }
            var isKarmaMessage = ExperienceManager.IsExpMessage(e.Message);

            var gaveKarma = false;

            if (isKarmaMessage)
            {
                gaveKarma = ExperienceManager.UserToUserGiveExpAndNotify(e.Channel, e.Author, e.MentionedUsers);
            }

            return(Done);
        }
Exemplo n.º 12
0
        public static void DeployAddListener(
            EPCompiled compiledStmt,
            string stmtName,
            UpdateListener listener,
            EPRuntime runtime)
        {
            try {
                var deployed = runtime.DeploymentService.Deploy(
                    compiledStmt,
                    new DeploymentOptions().WithStatementNameRuntime(ctx => stmtName));
                if (deployed.Statements.Length != 1) {
                    throw new UnsupportedOperationException("This method is designed for a single statement");
                }

                deployed.Statements[0].AddListener(listener);
            }
            catch (EPDeployException e) {
                throw new EPException(e);
            }
        }
    void FixedUpdate()
    {
        for (int i = mList.Count; i > 0;)
        {
            Entry ent = mList[--i];

            if (ent.rb == null)
            {
                mList.RemoveAt(i);
            }
        }

        for (int i = mOnUpdate.Count; i > 0;)
        {
            UpdateListener listener = mOnUpdate[--i];
            if (listener.mb == null || !listener.callback(mList))
            {
                mOnUpdate.RemoveAt(i);
            }
        }
    }
        public void AddListenerTest()
        {
            const string UPDATE_CHANGE_FILE_NAME = "update_change_field_profiles.zip";
            string       sourceFile = Path.GetFullPath(Path.Combine(DATA_PATH, ZIP_FILE_NAME));
            string       updateFile = Path.GetFullPath(Path.Combine(DATA_PATH, UPDATE_CHANGE_FILE_NAME));
            string       targetFile = Path.GetFullPath(Path.Combine(DATA_PATH, TEST_FILE_NAME));

            Assert.True(File.Exists(sourceFile));
            Assert.True(File.Exists(updateFile));
            Uri uri = new Uri(targetFile);

            File.Copy(sourceFile, targetFile, true);
            InstrumentProfileConnection connection = new InstrumentProfileConnection(uri.AbsoluteUri + UPDATE_PERIOD_STR);
            UpdateListener updateListener          = new UpdateListener();

            connection.AddUpdateListener(updateListener);
            connection.Start();

            while (!updateListener.IsUpdated)
            {
            }
            Assert.AreEqual(IPF_COUNT, updateListener.LastUpdate.Count);

            updateListener.DropState();
            File.Copy(updateFile, targetFile, true);
            File.SetLastWriteTime(targetFile, DateTime.Now);
            while (!updateListener.IsUpdated)
            {
            }

            UpdateListener newListener = new UpdateListener();

            connection.AddUpdateListener(newListener);
            while (!newListener.IsUpdated)
            {
            }
            Assert.AreEqual(IPF_COUNT, newListener.LastUpdate.Count);

            connection.Close();
        }
Exemplo n.º 15
0
 public void RemoveListener(UpdateListener listener)
 {
     listeners.Remove(listener);
 }
Exemplo n.º 16
0
 public void AddListener(UpdateListener listener)
 {
     listeners.Add(listener);
 }
Exemplo n.º 17
0
 public int OnUpdate(UpdateListener listener)
 {
     return(Utilities.Add(updateListeners, listener));
 }
Exemplo n.º 18
0
 /// <summary>
 /// Add an update listener to get updates from the fixed updater part of the timer.
 /// </summary>
 /// <param name="listener">The listener to add</param>
 public void addUpdateListener(UpdateListener listener)
 {
     updateListeners.Add(listener);
 }
        public void UpdateChangeTest()
        {
            const int    UPDATE_CHANGE_1_COUNT     = 1;
            const int    UPDATE_CHANGE_2_COUNT     = 3;
            const string UPDATE_CHANGE_1_FILE_NAME = "update_change_field_profiles.zip";
            const string UPDATE_CHANGE_2_FILE_NAME = "update_change_ins_profiles.zip";
            const string CUSTOM_FIELD_ONE_NAME     = "CUSTOM_ONE";
            const string CUSTOM_FIELD_TWO_NAME     = "CUSTOM_TWO";
            const string CUSTOM_FIELD_ONE_VALUE    = "filled_custom_one";
            const string CUSTOM_FIELD_TWO_VALUE    = "filled_custom_two";
            const string UPDATED_FIELD_NAME        = "DESCRIPTION";
            const string UPDATED_FIELD_VALUE       = "Updated Description";
            const string PRODUCT_SYMBOL            = "/6E";
            string       sourceFile = Path.GetFullPath(Path.Combine(DATA_PATH, ZIP_FILE_NAME));
            string       updateFile = Path.GetFullPath(Path.Combine(DATA_PATH, UPDATE_CHANGE_1_FILE_NAME));
            string       targetFile = Path.GetFullPath(Path.Combine(DATA_PATH, TEST_FILE_NAME));

            Assert.True(File.Exists(sourceFile));
            Assert.True(File.Exists(updateFile));
            Uri uri = new Uri(targetFile);

            File.Copy(sourceFile, targetFile, true);
            InstrumentProfileConnection connection = new InstrumentProfileConnection(uri.AbsoluteUri + UPDATE_PERIOD_STR);
            UpdateListener updateListener          = new UpdateListener();

            connection.AddUpdateListener(updateListener);
            connection.Start();

            while (!updateListener.IsUpdated)
            {
            }
            Assert.AreEqual(IPF_COUNT, updateListener.LastUpdate.Count);

            //update#1 - updated one of field
            updateListener.DropState();
            File.Copy(updateFile, targetFile, true);
            File.SetLastWriteTime(targetFile, DateTime.Now);
            while (!updateListener.IsUpdated)
            {
            }
            Assert.AreEqual(UPDATE_CHANGE_1_COUNT, updateListener.LastUpdate.Count);
            foreach (InstrumentProfile ip in updateListener.LastUpdate)
            {
                if (ip.GetTypeName().Equals(InstrumentProfileType.PRODUCT.Name) && ip.GetSymbol().Equals(PRODUCT_SYMBOL))
                {
                    Assert.AreEqual(ip.GetField(UPDATED_FIELD_NAME), UPDATED_FIELD_VALUE);
                    continue;
                }
            }

            //update #2 - new fields inserted
            updateFile = Path.GetFullPath(Path.Combine(DATA_PATH, UPDATE_CHANGE_2_FILE_NAME));
            updateListener.DropState();
            File.Copy(updateFile, targetFile, true);
            File.SetLastWriteTime(targetFile, DateTime.Now);
            while (!updateListener.IsUpdated)
            {
            }
            Assert.AreEqual(UPDATE_CHANGE_2_COUNT, updateListener.LastUpdate.Count);
            foreach (InstrumentProfile ip in updateListener.LastUpdate)
            {
                if (ip.GetTypeName().Equals(InstrumentProfileType.PRODUCT.Name) && ip.GetSymbol().Equals(PRODUCT_SYMBOL))
                {
                    Assert.AreEqual(ip.GetField(CUSTOM_FIELD_ONE_NAME), CUSTOM_FIELD_ONE_VALUE);
                    Assert.AreEqual(ip.GetField(CUSTOM_FIELD_TWO_NAME), CUSTOM_FIELD_TWO_VALUE);
                    continue;
                }
            }

            connection.Close();
        }
Exemplo n.º 20
0
 public void SetUpdateListener(UpdateListener u)
 {
     this.updateListener = u;
 }
Exemplo n.º 21
0
 public void AddListener(UpdateListener listener)
 {
     statement.AddListener(listener);
 }
Exemplo n.º 22
0
 /// <summary>
 /// Processes a single pending update from the queue, or returns immediately
 /// if there are no pending updates.
 /// </summary>
 /// <returns>The snapshot of the state after the last processed update,
 /// and a flag that indicates whether there are more unprocessed updates in the queue.
 /// </returns>
 /// <remarks>
 /// This method should be used in a loop on each frame's update step,
 /// until either there are no more pending updates, or there is not enough
 /// time left to process the remaining updates in this frame.
 /// The caller can stop at any point, and resume processing the transactions
 /// on the next opportunity (for example, on the next frame's update step).
 /// </remarks>
 public (StateSnapshot, bool) ProcessSingleUpdate(UpdateListener listener)
 {
     throw new NotImplementedException();
 }
 public UpdateListenerWithBackgrounding(UpdateListener mainThreadUpdate)
 {
     this.mainThreadUpdate = mainThreadUpdate;
 }
Exemplo n.º 24
0
 public void SetUpdateListener(UpdateListener u)
 {
     this.updateListener = u;
 }