public void SaveGesture()
        {
            if (_newGesture)
            {
                Id = _provider.SaveNewDynamicGestureClass(Name, null);                 // Need to get id
            }

            var editedGesture  = new DGClass(Instances);
            var sampleInstance = (Instances.Any()) ? Instances.FirstOrDefault().Instance : null;

            var gestureWrapper = new DGClassWrapper()
            {
                Id             = this.Id,
                Name           = this.Name,
                Gesture        = editedGesture,
                SampleInstance = sampleInstance
            };

            _provider.SaveDynamicGestureClass(gestureWrapper);

            if (Changeset.ChangesExist())
            {
                // Update the StaticGestureInstances table
                foreach (int instanceId in Changeset.DeletedGestureInstances)
                {
                    _provider.DeleteDynamicGestureInstance(instanceId);
                }
                foreach (var instance in Changeset.NewGestureInstances)
                {
                    _provider.SaveNewDynamicGestureInstance(Id, instance.Instance);
                }
            }

            _mvm.UpdateDynamicGestureLibrary();
        }
        /// <summary>
        /// Запускает ранее созданные экземпляры vm
        /// </summary>
        private async void StartInstances()
        {
            LoadInstances();

            if (Instances.Count == 0)
            {
                return;
            }

            await CreateInstancesAsync();
            await UploadInputParamsAsync();

            InstancesWatcher.TaskCompleted += async(instance, output) =>
            {
                var viewModel = Instances.FirstOrDefault(p => p.Ec2Instance == instance);
                viewModel.Output = output;

                await TerminateInsatanceAsync(viewModel);
            };

            InstancesWatcher.ExceedMoneyQuota += async(instance) =>
            {
                var viewModel = Instances.FirstOrDefault(p => p.Ec2Instance == instance);

                await TerminateInsatanceAsync(viewModel);
            };

            InstancesWatcher.StartWatchAsync(Instances.Select(p => p.Ec2Instance));
        }
Beispiel #3
0
        public ShadowguardInstance GetAvailableInstance(EncounterType type)
        {
            if (RandomInstances)
            {
                List <ShadowguardInstance> instances;

                if (type == EncounterType.Roof)
                {
                    instances = Instances.Where(e => e.IsRoof && !e.InUse).ToList();
                }
                else
                {
                    instances = Instances.Where(e => !e.IsRoof && !e.InUse).ToList();
                }

                ShadowguardInstance inst = null;

                if (instances.Count > 0)
                {
                    inst = instances[Utility.Random(instances.Count)];
                }

                ColUtility.Free(instances);
                return(inst);
            }

            if (type == EncounterType.Roof)
            {
                return(Instances.FirstOrDefault(e => e.IsRoof && !e.InUse));
            }

            return(Instances.FirstOrDefault(e => !e.IsRoof && !e.InUse));
        }
Beispiel #4
0
            public override void Activate(Order order)
            {
                if (active && order.ExtraData == 0)
                {
                    Deactivate();
                    return;
                }

                if (!available || order.ExtraData != 1)
                {
                    return;
                }

                var power = Instances.FirstOrDefault(i => !i.IsTraitPaused);

                if (power == null)
                {
                    return;
                }

                active = true;

                // Only play the activation sound once!
                power.PlayLaunchSounds();

                foreach (var p in Instances)
                {
                    ((GrantPrerequisiteChargeDrainPower)p).Activate(p.Self, this);
                }
            }
 internal static EncryptedInstance GetTrackedInstance(object obj)
 {
     if (Instances.Count % 3 == 0)
     {
         PruneGCedInstanceReferences();
     }
     return(Instances.FirstOrDefault(i => i.References(obj)));
 }
Beispiel #6
0
        private void OnServerUpdated(ServerInfo serverInfo)
        {
            //The server doesn't have performance data yet
            if (serverInfo == null)
            {
                return;
            }

            this.AvailableCompletionPortThreads = serverInfo.AvailableCompletionPortThreads;
            this.AvailableWorkingThreads        = serverInfo.AvailableWorkingThreads;
            this.CpuUsage = serverInfo.CpuUsage;
            this.MaxCompletionPortThreads = serverInfo.MaxCompletionPortThreads;
            this.MaxWorkingThreads        = serverInfo.MaxWorkingThreads;
            this.PhysicalMemoryUsage      = serverInfo.PhysicalMemoryUsage;
            this.TotalThreadCount         = serverInfo.TotalThreadCount;

            var newInstanceFound = false;

            foreach (var instance in serverInfo.Instances)
            {
                var newFound = false;

                var targetInstance = Instances.FirstOrDefault(i => i.Name.Equals(instance.Name, StringComparison.OrdinalIgnoreCase));

                if (targetInstance == null)
                {
                    targetInstance   = new InstanceViewModel(this, instance.Name);
                    newFound         = true;
                    newInstanceFound = true;
                }

                targetInstance.CurrentConnectionCount = instance.CurrentConnectionCount;
                targetInstance.IsRunning            = instance.IsRunning;
                targetInstance.Listeners            = instance.Listeners;
                targetInstance.MaxConnectionCount   = instance.MaxConnectionCount;
                targetInstance.RequestHandlingSpeed = instance.RequestHandlingSpeed;
                targetInstance.StartedTime          = instance.StartedTime;

                if (newFound || (targetInstance.State == InstanceState.NotConnected || targetInstance.State == InstanceState.Connecting))
                {
                    targetInstance.State = targetInstance.IsRunning ? InstanceState.Running : InstanceState.NotStarted;
                }

                if (newFound)
                {
                    Instances.Add(targetInstance);
                }
            }

            if (newInstanceFound)
            {
                Messenger.Default.Send <IEnumerable <InstanceViewModel> >(null);
            }
        }
        public void ViewInstance(SGInstanceWrapper instance)
        {
            SelectedInstance = instance ?? Instances.FirstOrDefault();

            if (instance != null)
            {
                _mvm.ViewStaticGesture(instance.Gesture);
            }
            else
            {
                _mvm.ViewStaticGesture(null);
            }
        }
        public bool TryGetExtension(object service, [MaybeNullWhen(false)] out IExtensionInstance extensionInstance)
        {
            if (service is null)
            {
                throw new ArgumentNullException(nameof(service));
            }

            var assembly = service.GetType().Assembly;

            extensionInstance = Instances.FirstOrDefault(i => i.IsInExtension(assembly));

            return(extensionInstance is not null);
        }
Beispiel #9
0
        public static void TryRemoveDragon(SkeletalDragon dragon)
        {
            if (Instances == null)
            {
                return;
            }

            var bell = Instances.FirstOrDefault(x => x.Dragon == dragon);

            if (bell != null)
            {
                bell.Dragon = null;
            }
        }
Beispiel #10
0
 public static IWindowWrapper Default()
 {
     try
     {
         var mainDispatcher = CoreApplication.MainView.Dispatcher;
         return(Instances.FirstOrDefault(x => x.Window.Dispatcher == mainDispatcher) ??
                Instances.FirstOrDefault());
     }
     catch (COMException)
     {
         //MainView might exist but still be not accessible
         return(Instances.FirstOrDefault());
     }
 }
Beispiel #11
0
 private void loadTaskData()
 {
     if (taskDataLoaded)
     {
         return;
     }
     if (CurrentTask == null)
     {
         CurrentTask = GyomuDataAccess.SelectTaskData(TaskDataID);
     }
     TaskDataParameter = CurrentTask.parameter;
     Instances         = GyomuDataAccess.SelectTaskInstanceByTaskData(CurrentTask);
     LatestInstance    = Instances.FirstOrDefault();
     LatestInstanceID  = LatestInstance.id;
     AccessList        = GyomuDataAccess.SelectTaskAccessLists(ApplicationID, TaskInfoID);
     taskDataLoaded    = true;
 }
        public void SaveGesture()
        {
            Dictionary <string, int> featureWeightsDict = null;

            if (_newGesture)
            {
                Id = _provider.SaveNewStaticGestureClass(Name, null);                 // Need to get id
            }
            else
            {
                // Fill featureWeightsDict
                featureWeightsDict = new Dictionary <string, int>();
                foreach (var fw in FeatureWeights)
                {
                    featureWeightsDict.Add(fw.Name, fw.Weight);
                }
            }

            var editedGesture  = new SGClass(Instances, featureWeightsDict);
            var sampleInstance = (Instances.Any()) ? Instances.FirstOrDefault().Gesture : null;

            var gestureWrapper = new SGClassWrapper()
            {
                Id             = this.Id,
                Name           = this.Name,
                Gesture        = editedGesture,
                SampleInstance = sampleInstance
            };

            _provider.SaveStaticGestureClass(gestureWrapper);

            if (Changeset.ChangesExist())
            {
                // Update the StaticGestureInstances table
                foreach (int instanceId in Changeset.DeletedGestureInstances)
                {
                    _provider.DeleteStaticGestureInstance(instanceId);
                }
                foreach (var instance in Changeset.NewGestureInstances)
                {
                    _provider.SaveNewStaticGestureInstance(Id, instance.Gesture);
                }
            }

            _mvm.UpdateStaticGestureLibrary();
        }
Beispiel #13
0
 public CobieCreatedInfo SetDefaultEntityInfo(DateTime date, string email, string givenName, string familyName)
 {
     _entityInfo = Instances.New <CobieCreatedInfo>(ci =>
     {
         ci.CreatedOn = date;
         ci.CreatedBy =
             Instances.FirstOrDefault <CobieContact>(
                 c => c.Email == email && c.GivenName == givenName && c.FamilyName == familyName) ??
             Instances.New <CobieContact>(
                 c =>
         {
             c.Created    = ci;
             c.Email      = email;
             c.GivenName  = givenName;
             c.FamilyName = familyName;
         });
     });
     EntityNew      += SetEntityCreatedInfo;
     EntityModified += SetEntityCreatedInfo;
     return(_entityInfo);
 }
Beispiel #14
0
        public bool TryGetInstance(GameState state, out Game instance)
        {
            instance = Instances.FirstOrDefault(x => x.Value.State == state).Value;

            return(instance != null);
        }
Beispiel #15
0
 public AbcInstance FindInstance(Func <AbcInstance, bool> predicate)
 {
     return(Instances.FirstOrDefault(predicate));
 }
Beispiel #16
0
 public InstanceSave GetInstance(string name)
 {
     return(Instances.FirstOrDefault(i => i.Name == name));
 }
Beispiel #17
0
        static void Main(string[] args)
        {
            using (var gl = new GameLogic())
            {
                new Player {
                    Name = "Alex", Color = System.Drawing.Color.Blue
                };
                new Player {
                    Name = "Randy", Color = System.Drawing.Color.Red
                };

                Player Alex = Instances.FirstOrDefault(x => x.Name == nameof(Alex));
                Alex.Board.Printer.SetBid(Alex.Tokens.OfType <Gold>().Take(2));
                Alex.Board.Apothecary.SetBid(Alex.Tokens.OfType <Blackmail>().Take(1));

                Player Randy = Instances.FirstOrDefault(x => x.Name == nameof(Randy));
                Randy.Board.Printer.SetBid(Randy.Tokens.OfType <Gold>().Take(3));
                Randy.Board.General.SetBid(Randy.Tokens.OfType <Force>().Take(1));


                var actionsWithBids = Instances.Select(x => x.Board).SelectMany(x => x.Actions.Where(y => y.Bid.Any()));

                var winners = actionsWithBids
                              .Select(x => x.GetType().Name)
                              .Distinct()
                              .ToList()
                              .Select(x =>
                {
                    var z = actionsWithBids.Where(y => y.GetType().Name == x).OrderByDescending(y => y.Bid.ToInt()).FirstOrDefault();
                    return(new
                    {
                        ActionName = x,
                        z.Bid,
                        z.PlayerBoard.Player
                    });
                })
                              .ToList();

                winners.ForEach(x =>
                {
                    var pi = typeof(PlayerBoard).GetProperty(x.ActionName);
                    var pa = pi?.GetValue(x.Player.Board) as GameLogic.Action;
                    pa?.Resolve();
                });
            }
            var rv = SDL.Init(SDL2.SDL.INIT_EVERYTHING);
            var sdlIntitialized = !Convert.ToBoolean(rv);

            if (sdlIntitialized)
            {
                var mode         = new SDL.SDL_DisplayMode();
                var displayRect  = new SDL.Rect();
                var displayCount = SDL.GetNumVideoDisplays();
                SDL.GetDisplayBounds(0, out displayRect);
                SDL.GetCurrentDisplayMode(0, out mode);
                int width = 1280, height = 720;//720p

                var left = (int)((mode.w - width) * .5);
                var top  = (int)((mode.h - height) * .5);


                using (var window = new Window(nameof(Revolution), left, top, width, height, SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN, true))
                {
                    if (window.IsValid())
                    {
                        window.Show();
                        window.Raise();
                    }
                    SetupTimerCallback(60, null);
                    var  @event = new SDL.SDL_Event();
                    bool run    = true;

                    //RecipeCardDeck recipeDeck = new RecipeCardDeck();
                    //var recipeTextures = gameLogic.Recipes.ToList().ToDictionary(x => x.GetHashCode(), x => window.Renderer.LoadTexture(x.Source));

                    var tokenTextures = new Dictionary <char, Texture>
                    {
                        { 'b', window.Renderer.LoadTexture("images/blackmail.png") },
                        { 'g', window.Renderer.LoadTexture("images/money.png") },
                        { 'p', window.Renderer.LoadTexture("images/force.png") }
                    };

                    window.Scene = new List <Sprite>();

                    var boardTexture = window.Renderer.LoadTexture("images/board.png");


                    var boardSprite = boardTexture.CreateSprite();
                    boardSprite.X     = 0;
                    boardSprite.Y     = 0;
                    boardSprite.Z     = 0;
                    boardSprite.Scale = 1f;
                    window.Scene.Add(boardSprite);

                    //Debug.WriteLine(gameLogic.FishMarket);

                    int xc = boardSprite.Width;
                    tokenTextures.ToList().ForEach(x =>
                    {
                        var s = new Sprite(x.Value)
                        {
                            Y = 500, X = xc += x.Value.Width, Z = 0, Scale = 1.0f
                        };
                        window.Scene.Add(s);
                        xc += s.Width;
                    });


                    //var s2 = test.CreateSprite();
                    //s2.X = 100;
                    //s2.Y = 100;
                    //s2.Z = 1;
                    //s2.Scale = 1f;
                    //window.Scene.Add(s2);

                    //var s3 = new Sprite(test)
                    //{
                    //    X = 150,
                    //    Y = 150,
                    //    Z = 2,
                    //    Scale = 1f,
                    //};
                    //window.Scene.Add(generalMarketSprite);
                    SDL.SetHint(SDL.SDL_HINT_RENDER_SCALE_QUALITY, "1");
                    window.Clear();
                    window.Present();

                    while (run)
                    {
                        SDL.SDL_PollEvent(out @event);
                        //while ( != 0)
                        //{
                        switch (@event.type)
                        {
                        case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN:
                            var button = @event.button;
                            var point  = new SDL.Point()
                            {
                                x = button.x, y = button.y
                            };
                            var timestamp = new DateTime(button.timestamp);
                            var matches   = window.Scene.Where(sprite => sprite.Contains(point)).ToList();
                            var brown     = window.Scene.First();
                            matches.ForEach(sprite => sprite.MouseDown(@event));
                            //button.button  1   byte
                            //button.clicks  1   byte
                            //button.padding1    0   byte
                            //button.state   1   byte
                            //button.timestamp   140630  uint
                            //button.@type   SDL_MOUSEBUTTONDOWN SDL2.SDL.SDL_EventType
                            //button.which   0   uint
                            //button.windowID    1   uint
                            //button.x   182 int
                            //button.y   169 int

                            break;

                        case SDL.SDL_EventType.SDL_QUIT:
                            run = false;
                            break;

                        case SDL.SDL_EventType.SDL_FIRSTEVENT:
                            Debug.WriteLine("First Event");
                            break;

                        case SDL.SDL_EventType.SDL_LASTEVENT:
                            Debug.WriteLine("Last Event");
                            break;
                        }
                        //}
                    }
                    //SDL.SDL_WaitEvent(out @event);
                    //var quit = @event.quit;
                }
            }
        }