Esempio n. 1
0
        public IDisposable Subscribe(Action <object> onNext)
        {
            var observer = new ObserverAction(onNext);

            Observers.Add(observer);
            return(new INPCListenerDisposer(this, observer));
        }
Esempio n. 2
0
        private void AddObserversFromFile(string path)
        {
            var observerSettingsList = ObserversFile.Load(path);

            if (observerSettingsList.Count == 0)
            {
                using (var centerAligner = new DialogCenterAligner(this))
                {
                    MessageBox.Show(Resources.FailedOpenFile + "\n" + path, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return;
            }
            if (!RecentFiles.Exists || RecentFiles.CanWrite)
            {
                RecentFiles.Add(path);
            }
            var tabPages = new TabPage[observerSettingsList.Count];

            for (int i = 0; i < observerSettingsList.Count; i++)
            {
                var observer = new Observer(ObservedProcess, observerSettingsList[i]);
                Observers.Add(observer);
                var observerTabPage = new ObserverTabPage(Observers.Count - 1, observer);
                tabPages[i] = observerTabPage;
            }
            ObserverTabControl.TabPages.AddRange(tabPages);
        }
Esempio n. 3
0
        public void MoveToObserver(Player player)
        {
            if (State != GameState.Lobby)
            {
                return;
            }
            if (player.Type == (int)PlayerType.Observer)
            {
                return;
            }
            if (IsReady[player.Type])
            {
                return;
            }

            int oldType = player.Type;

            Players[player.Type] = null;
            IsReady[player.Type] = false;
            Observers.Add(player);

            BinaryWriter change = GamePacketFactory.Create(StocMessage.HsPlayerChange);

            change.Write((byte)((player.Type << 4) + (int)PlayerChange.Observe));
            SendToAll(change);

            player.Type = (int)PlayerType.Observer;
            player.SendTypeChange();

            if (OnPlayerMove != null)
            {
                OnPlayerMove(this, new PlayerMoveEventArgs(player, oldType));
            }
        }
Esempio n. 4
0
 public void Add(IList <IObserver> observers)
 {
     foreach (var observer in observers)
     {
         Observers.Add(observer);
     }
 }
 public IDisposable Subscribe(IObserver <Position> observer)
 {
     Observers.Add(observer);
     return(new ActionDisposable(() => {
         Observers.Remove(observer);
     }));
 }
Esempio n. 6
0
 public void Subscribe(IObserver observer)
 {
     if (!Observers.Contains(observer))
     {
         Observers.Add(observer);
     }
 }
Esempio n. 7
0
        public void MoveToObserver(Player player)
        {
            if (State != GameState.Lobby)
            {
                return;
            }
            if (player.Type == (int)PlayerType.Observer)
            {
                return;
            }
            if (IsReady[player.Type])
            {
                return;
            }
            Players[player.Type] = null;
            IsReady[player.Type] = false;
            Observers.Add(player);

            GameServerPacket change = new GameServerPacket(StocMessage.HsPlayerChange);

            change.Write((byte)((player.Type << 4) + (int)PlayerChange.Observe));
            SendToAll(change);

            player.Type = (int)PlayerType.Observer;
            player.SendTypeChange();
        }
Esempio n. 8
0
 public void Register(IObserver observer)
 {
     if (!Observers.Contains(observer))
     {
         Observers.Add(observer);
     }
 }
        public async Task BecomeConsumer(Guid streamId, string streamNamespace, string providerName, bool sendEvensOnly)
        {
            _logger = logger;
            if (logger.IsVerbose)
            {
                logger.Verbose("BecomeConsumer StreamId={0} StreamProvider={1} Filter={2} Grain={3}",
                               streamId, providerName, sendEvensOnly, this.AsReference <IFilteredStreamConsumerGrain>());
            }
            InitStream(streamId, streamNamespace, providerName);

            var observer = new MyStreamObserver <int>(logger);

            StreamFilterPredicate filterFunc;
            object filterData;

            if (sendEvensOnly)
            {
                filterFunc = FilterIsEven;
                filterData = FilterDataEven;
            }
            else
            {
                filterFunc = FilterIsOdd;
                filterData = FilterDataOdd;
            }

            var subsHandle = await State.Stream.SubscribeAsync(observer, null, filterFunc, filterData);

            State.ConsumerSubscriptionHandles.Add(subsHandle);
            Observers.Add(subsHandle, observer);
            await WriteStateAsync();
        }
 public void AddSpectator(PlayerInfo info)
 {
     if (Observers.ContainsKey(info.UserId))
     {
         Observers.Remove(info.UserId);
     }
     Observers.Add(info.UserId, info);
 }
Esempio n. 11
0
 public IDisposable Subscribe(IObserver <Payload> observer)
 {
     if (!Observers.Contains(observer))
     {
         Observers.Add(observer);
     }
     return(new ObservationState(Observers, observer));
 }
Esempio n. 12
0
        ///--------------------------------------------------------------------
        /// Interest Point methods
        ///--------------------------------------------------------------------

        public IDisposable Subscribe(IObserver <bool> observer)
        {
            if (!Observers.Contains(observer))
            {
                Observers.Add(observer);
            }
            return(new Unsubscriber <IObserver <bool> >(Observers, observer));
        }
Esempio n. 13
0
        public void Register(IObserver observer)
        {
            if (observer == null)
            {
                throw new ArgumentNullException(nameof(observer));
            }

            Observers.Add(observer);
        }
Esempio n. 14
0
 public void AddObserver(T observer)
 {
     if (!Observers.Contains(observer))
     {
         Observers.Add(observer);
     }
     //else
     //   UnityEngine.Debug.LogFormat("Doubled observer: [{0}] - [{1}]", Target, observer);
 }
        /// <summary>
        /// Notifies the provider that an observer is to receive notifications.
        /// </summary>
        /// <returns>
        /// A reference to an interface that allows observers to stop receiving notifications before the provider has finished sending them.
        /// </returns>
        /// <param name="observer">The object that is to receive notifications.</param>
        public override IDisposable Subscribe(IObserver <T> observer)
        {
            if (observer == null)
            {
                throw new ArgumentNullException("observer");
            }

            if (_internalSubscription != null)
            {
                _internalSubscription.Dispose();
            }

            Observers.Add(observer);
            _subscribeSubscription = SubscriberScheduler
                                     .Schedule(
                observer,
                (s, o) =>
            {
                _internalSubscription = _trigger
                                        .Select(
                    x =>
                {
                    var filter             = Expression as MethodCallExpression;
                    var parameterBuilder   = new ParameterBuilder(RestClient.ServiceBase, typeof(TSource));
                    IObservable <T> source = null;
                    using (var waitHandle = new ManualResetEventSlim(false))
                    {
                        SubscriberScheduler.Schedule(() =>
                        {
                            try
                            {
                                source = Processor.ProcessMethodCall(
                                    filter,
                                    parameterBuilder,
                                    GetResults,
                                    GetIntermediateResults);
                            }
                            catch (Exception e)
                            {
                                source = Observable.Throw(e, default(T));
                            }
                            finally
                            {
                                waitHandle.Set();
                            }
                        });
                        waitHandle.Wait();
                    }

                    return(source);
                })
                                        .SelectMany(y => y)
                                        .Subscribe(new ObserverPublisher <T>(Observers, ObserverScheduler));
            });
            return(new RestSubscription <T>(observer, Unsubscribe));
        }
Esempio n. 16
0
        public IDisposable Subscribe(IObserver <IWorld> observer)
        {
            if (!Observers.Contains(observer))
            {
                Observers.Add(observer);
                NotifyNewGeneration();
            }

            return(new Unsubscriber(Observers, observer));
        }
Esempio n. 17
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            var observer = new Observer(ObservedProcess);

            Observers.Add(observer);
            var observerTabPage = new ObserverTabPage(Observers.Count - 1, observer);

            ObserverTabControl.TabPages.Add(observerTabPage);
            ObserverTabControl.SelectedTab = observerTabPage;
            RefreshView();
        }
Esempio n. 18
0
        public void AddObserver <V>(V observer) where V : IObserveComponent <T>
        {
            if (!isInitialized)
            {
                Debug.LogAssertion(NotYetObservingMessage);
            }

            Observers.Add(observer);

            DispatchOnBeginObserve(observer);
        }
Esempio n. 19
0
 public IDisposable Subscribe(IObserver <Observation> observer)
 {
     if (!Observers.Contains(observer))
     {
         Observers.Add(observer);
         foreach (var item in Observations)
         {
             observer.OnNext(item);
         }
     }
     return(new Unsubscriber(Observers, observer));
 }
Esempio n. 20
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            var observer = new Observer(TesseractEngine, SpeechSynthesizer);

            observer.Started += Observer_Started;
            observer.Stopped += Observer_Stopped;
            Observers.Add(observer);
            var observerTabPage = new ObserverTabPage(ObserverTabControl, Observers.Count - 1, observer);

            //ObserverTabControl.TabPages.Add(observerTabPage);
            ObserverTabControl.SelectedTab = observerTabPage;
            RefreshView();
        }
Esempio n. 21
0
        public virtual IDisposable Subscribe(IObserver <object> observer)
        {
            if (!Observers.Contains(observer))
            {
                Observers.Add(observer);

                foreach (var value in Values)
                {
                    observer.OnNext(value);
                }
            }

            return(new Unsubscriber <object>(Observers, observer));
        }
Esempio n. 22
0
        public void AddObservers <V>(V[] observers) where V : IObserveComponent <T>
        {
            if (!isInitialized)
            {
                Debug.LogAssertion(NotYetObservingMessage);
            }

            for (int i = 0; i < observers.Length; i++)
            {
                Observers.Add(observers[i]);
            }

            DispatchOnBeginObserveAll();
        }
Esempio n. 23
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        public void Initialize(GameContext context)
        {
            // TODO: Add your initialization logic here
            Observers.Clear();
            Observers.Add(new DebugString(context));


            world = World.getInstance();


            world.Height = context.Height;
            world.Width  = context.Width;

            Vector2 playerPosition = new Vector2(context.GraphicsDevice.Viewport.TitleSafeArea.X, context.GraphicsDevice.Viewport.TitleSafeArea.Y + context.GraphicsDevice.Viewport.TitleSafeArea.Height / 2);//dich

            playerLTH  = new LTH(0.1f, 0.1f, 0.03f, 0.0005f, 50, 75);
            compLTH    = new LTH(0.1f, 0.05f, 0.03f, 0.0005f, 50, 75);
            pulemetTex = context.Content.Load <Texture2D>("projectiles/bullet1");
            Bullet pulemetBullet = new Bullet(Vector2.Zero, 7f, 10, 5, pulemetTex);

            pulemet = new GunType(0.1f, 7f, 20f, pulemetBullet);
            Texture2D plasmaTex    = context.Content.Load <Texture2D>("projectiles/bullet2");
            Bullet    plasmaBullet = new Bullet(Vector2.Zero, 100f, 30, 15, plasmaTex, solid: true);
            GunType   plasmamet    = new GunType(1f, 7f, 5f, plasmaBullet);
            Bullet    magnetBullet = new MagnetBullet(Vector2.Zero, 5f, 10, 10, plasmaTex);
            GunType   magnetmet    = new GunType(0.03f, 7f, 25f, magnetBullet, 0.3f);

            spaceship = new Spaceship(context.Content.Load <Texture2D>("space/s2"), playerLTH, playerPosition, 0.0f);
            spaceship.AddGun(pulemet, new Vector2(0f, 20f));
            spaceship.AddGun(pulemet, new Vector2(0f, -20f));
            spaceship.AddGun(pulemet, new Vector2(40f, 15f));
            spaceship.AddGun(pulemet, new Vector2(40f, -15f));
            //spaceship.AddGun(magnetmet, new Vector2(40f, 0f));
            playerShip       = new PlayerShip(spaceship);
            world.playerShip = spaceship;
            world.players.Add(playerShip);
            Spaceship[] spaceship2 = new Spaceship[10];
            for (int i = 0; i < 5; i++)
            {
                spaceship2[i]       = new Spaceship(context.Content.Load <Texture2D>("space/vs1"), compLTH, playerPosition + new Vector2(1000, -500), 0.0f);
                spaceship2[i].speed = Vector2Extension.Rotate(Vector2.UnitX, i);
                //spaceship2[i].angularSpeed = 0.0f;
                spaceship2[i].angle = (float)-Math.PI / 2;
                spaceship2[i].AddGun(pulemet, new Vector2(20f, 0f));

                world.AddObject(spaceship2[i]);
                world.players.Add(new ComputerShip(spaceship2[i]));
            }
            world.AddObject(spaceship);
        }
Esempio n. 24
0
 public override IDisposable Subscribe(IObserver <ABus> observer)
 {
     // Check whether observer is already registered. If not, add it
     if (!Observers.Contains(observer))
     {
         Observers.Add(observer);
         // Provide observer with existing data.
         foreach (var bus in Busses)
         {
             observer.OnNext(bus);
         }
     }
     return(new Unsubscriber <ABus>(observers, observer));
 }
Esempio n. 25
0
        internal DuelResults AddObserver(Player plr)
        {
            if (Observers.Count == 10)
            {
                return(DuelResults.ObserverMax);
            }

            Observers.Select(x => x.Session).SendAsync(new SDuelRoomBroadcastJoin(plr.Character.Name)).Wait();
            Observers.Add(plr);
            plr.Session.SendAsync(new SDuelRoomBroadcastObservers(Observers.Select(x => x.Character.Name).ToArray())).Wait();
            plr.Character.WarpTo(ObserversGate).Wait();
            plr.Character.Spells.SetBuff(SkillStates.DuelInterface, TimeSpan.FromDays(1));
            BroadcastScore();

            return(DuelResults.NoError);
        }
Esempio n. 26
0
        /// <summary>
        /// Adds a player to the passive Observers list
        /// </summary>
        /// <param name="character">the character to add</param>
        /// <returns></returns>
        public virtual bool AddObserver(ServerCharacterInfo character, ref string msg)
        {
            lock (m_Game.AllObserversSyncRoot)
            {
                if (!CanAddObserver(character, ref msg))
                {
                    return(false);
                }

                Observers.Add(character.ID, character);
                character.SetCurrentGame(this);
                AllObservers = (List <ICharacterInfo>)Observers.Values.ToList <ICharacterInfo>();
                OnObserverAdded(character);
            }

            return(true);
        }
Esempio n. 27
0
        public void OpenObserver(NeuronModel neuron, Scene scene)
        {
            ObserverDefinition definition = CreateObserverDefinition(neuron);
            // TODO(HonzaS): Factory + injection.
            var observer = new CanvasObserver(definition, Conductor.ModelProvider);

            observer.Log = Log;
            var form = new ObserverForm(this, observer);

            form.Text = $"Neuron {neuron.Index}, region {neuron.RegionModel.Index} - '{definition.Type}'";

            var handle = new ObserverHandle(observer, form, scene);

            Observers.Add(handle);
            form.Show();

            RefreshObserverRequests();
        }
Esempio n. 28
0
        public virtual IDisposable Subscribe(IObserver <T> observer)
        {
            if (observer == null)
            {
                throw new ArgumentNullException("observer");
            }

            Observers.Add(observer);
            if (Observers.Count == 1)
            {
                OnObservationStarted();
            }

            return(Disposable.Create(() =>
            {
                Observers.Remove(observer);
                if (Observers.Count == 0)
                {
                    OnObservationStopped();
                }
            }));
        }
        private int RefreshObservers()
        {
            Observers.PurgeDestroyed();

            var refreshItems = this.GetComponents <IOutfitObserver>();

            var count = 0;

            if (refreshItems.Length > 0)
            {
                // Add new items to end.
                foreach (var refreshItem in refreshItems)
                {
                    if (!Observers.Contains(refreshItem))
                    {
                        Observers.Add(refreshItem);
                        count++;
                    }
                }
            }

            return(count);
        }
Esempio n. 30
0
        public void AddPlayer(Player player)
        {
            if (State != GameState.Lobby)
            {
                player.Type = (int)PlayerType.Observer;
                if (State != GameState.End)
                {
                    SendJoinGame(player);
                    player.SendTypeChange();
                    player.Send(GamePacketFactory.Create(StocMessage.DuelStart));
                    Observers.Add(player);
                    if (State == GameState.Duel)
                    {
                        InitNewSpectator(player);
                    }
                }
                if (OnPlayerJoin != null)
                {
                    OnPlayerJoin(this, new PlayerEventArgs(player));
                }
                return;
            }

            if (HostPlayer == null)
            {
                HostPlayer = player;
            }

            int pos = GetAvailablePlayerPos();

            if (pos != -1)
            {
                BinaryWriter enter = GamePacketFactory.Create(StocMessage.HsPlayerEnter);
                enter.WriteUnicode(player.Name, 20);
                enter.Write((byte)pos);
                //padding
                enter.Write((byte)0);
                SendToAll(enter);

                Players[pos] = player;
                IsReady[pos] = false;
                player.Type  = pos;
            }
            else
            {
                BinaryWriter watch = GamePacketFactory.Create(StocMessage.HsWatchChange);
                watch.Write((short)(Observers.Count + 1));
                SendToAll(watch);

                player.Type = (int)PlayerType.Observer;
                Observers.Add(player);
            }

            SendJoinGame(player);
            player.SendTypeChange();

            for (int i = 0; i < Players.Length; i++)
            {
                if (Players[i] != null)
                {
                    BinaryWriter enter = GamePacketFactory.Create(StocMessage.HsPlayerEnter);
                    enter.WriteUnicode(Players[i].Name, 20);
                    enter.Write((byte)i);
                    //padding
                    enter.Write((byte)0);
                    player.Send(enter);

                    if (IsReady[i])
                    {
                        BinaryWriter change = GamePacketFactory.Create(StocMessage.HsPlayerChange);
                        change.Write((byte)((i << 4) + (int)PlayerChange.Ready));
                        player.Send(change);
                    }
                }
            }

            if (Observers.Count > 0)
            {
                BinaryWriter nwatch = GamePacketFactory.Create(StocMessage.HsWatchChange);
                nwatch.Write((short)Observers.Count);
                player.Send(nwatch);
            }

            if (OnPlayerJoin != null)
            {
                OnPlayerJoin(this, new PlayerEventArgs(player));
            }
        }