public async Task receive_and_not_enqueue_stream_event_when_not_eligible()
        {
            var cts = new CancellationTokenSource(10000);
            var mockStreamStateRepo   = new Mock <IStreamStateRepo>();
            var mockResolver          = new Mock <IBusinessEventResolver>();
            var mockQueue             = new Mock <IResolutionQueue>();
            var regionId              = "r";
            var streamId              = "s";
            var newPosition           = 1;
            var eventType             = "x";
            var lastAttemptedPosition = 0;
            var firstPositionInStream = 0;
            var streamState           = new StreamState(lastAttemptedPosition, true);
            var manager     = new ResolutionManager(NullStandardLogger.Instance, mockResolver.Object, mockStreamStateRepo.Object, mockQueue.Object, null);
            var streamEvent = new StreamEvent(streamId, newPosition, null, eventType, new byte[] { });

            mockStreamStateRepo.Setup(x => x.LoadStreamStateAsync(streamId)).ReturnsAsync(streamState);
            mockResolver.Setup(x => x.CanResolve(eventType)).Returns(false);             // Make this event ineligible.

            await manager.ReceiveStreamEventAsync(regionId, streamEvent, firstPositionInStream, cts.Token);

            if (cts.IsCancellationRequested)
            {
                throw new TimeoutException();
            }

            mockQueue.VerifyNoOtherCalls();
        }
Exemplo n.º 2
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            ResolutionManager.BeginDraw(); // Clear and viewport fix


            base.Draw(gameTime);
        }
        public async Task wait_for_enqueue_when_managing_and_no_events_in_queue()
        {
            var cts                   = new CancellationTokenSource(10000);
            var mockResolver          = new Mock <IBusinessEventResolver>();
            var mockQueue             = new Mock <IResolutionQueue>();
            var mockSortingManager    = new Mock <ISortingManager>();
            var manager               = new ResolutionManager(NullStandardLogger.Instance, mockResolver.Object, null, mockQueue.Object, mockSortingManager.Object);
            var streamId              = "s";
            var position              = 1;
            var eventType             = "x";
            var data                  = new byte[] { };
            var streamEvent           = new StreamEvent(streamId, position, null, eventType, data);
            var mockBusinessEvent     = new Mock <IBusinessEvent>();
            var awaitingEnqueueSignal = new ManualResetEventSlim(false);
            var mockEnqueueSignal     = new ManualResetEventSlim(false);

            mockResolver.Setup(x => x.Resolve(eventType, data)).Returns(mockBusinessEvent.Object);
            mockQueue.Setup(x => x.TryDequeue(out It.Ref <ResolutionStreamEvent> .IsAny)).Returns(false);
            mockQueue.Setup(x => x.AwaitEnqueueSignalAsync()).Callback(() => awaitingEnqueueSignal.Set()).Returns(mockEnqueueSignal.WaitHandle.AsTask());

            var manageTask = manager.ManageAsync(cts.Token);

            await Task.WhenAny(new[] { awaitingEnqueueSignal.WaitHandle.AsTask(), cts.Token.WaitHandle.AsTask() });

            if (cts.IsCancellationRequested)
            {
                throw new TimeoutException();
            }

            cts.Cancel();
        }
Exemplo n.º 4
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>
        protected override void Initialize()
        {
            //MapData tmp = new MapData();
            //Library.Serialization<MapData>.SerializeToXmlFile(tmp, "map");

            // Initialize resolution and scaling
            ResolutionManager.Init(ref _graphics);
            ResolutionManager.SetVirtualResolution(1920, 1080); // TODO magic resolution values.
            ResolutionManager.SetResolution(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height, fullscreen);

            // Initialize Simulator Unit to Pixel ratio
            ConvertUnits.SetDisplayUnitToSimUnitRatio(35f);     // 35 pixels = 1 meter

            // Create a new spritebatch and add it as service for access by other classes
            _spriteBatch = new SpriteBatch(GraphicsDevice);
            Services.AddService(typeof(SpriteBatch), _spriteBatch);

            // Load all content into a static library
            Library.Loader.Initialize(Content);

            // ------------------------------------------------------------
            // Adds menu screen to ScreenManager
            // ------------------------------------------------------------
            ScreenManager.InitializeScreenManager(this);
            Components.Add(ScreenManager.Instance);

            base.Initialize(); // Initializes all components
        }
        public async Task manage_until_cancelled()
        {
            var cts                   = new CancellationTokenSource();
            var mockQueue             = new Mock <IResolutionQueue>();
            var manager               = new ResolutionManager(NullStandardLogger.Instance, null, null, mockQueue.Object, null);
            var awaitingEnqueueSignal = new ManualResetEventSlim(false);
            var mockEnqueueSignal     = new ManualResetEventSlim(false);

            mockQueue.Setup(x => x.TryDequeue(out It.Ref <ResolutionStreamEvent> .IsAny)).Returns(false);
            mockQueue.Setup(x => x.AwaitEnqueueSignalAsync()).Callback(() => awaitingEnqueueSignal.Set()).Returns(mockEnqueueSignal.WaitHandle.AsTask());

            var manageTask = manager.ManageAsync(cts.Token);

            var timeoutToken1 = new CancellationTokenSource(10000).Token;
            await Task.WhenAny(new[] { awaitingEnqueueSignal.WaitHandle.AsTask(), timeoutToken1.WaitHandle.AsTask() });

            if (timeoutToken1.IsCancellationRequested)
            {
                throw new TimeoutException();
            }

            cts.Cancel();

            var timeoutToken2 = new CancellationTokenSource(10000).Token;
            await Task.WhenAny(new[] { manageTask, timeoutToken2.WaitHandle.AsTask() });

            if (timeoutToken2.IsCancellationRequested)
            {
                throw new TimeoutException();
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Handles the ItemCommand event of the grdResolutions control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.DataGridCommandEventArgs"/> instance containing the event data.</param>
        protected void grdResolutions_ItemCommand(object sender, DataGridCommandEventArgs e)
        {
            Resolution m;
            var        itemIndex = e.Item.ItemIndex;

            switch (e.CommandName)
            {
            case "up":
                //move row up
                if (itemIndex == 0)
                {
                    return;
                }
                m            = ResolutionManager.GetById(Convert.ToInt32(e.CommandArgument));
                m.SortOrder -= 1;
                ResolutionManager.SaveOrUpdate(m);
                break;

            case "down":
                //move row down
                if (itemIndex == grdResolutions.Items.Count - 1)
                {
                    return;
                }
                m            = ResolutionManager.GetById(Convert.ToInt32(e.CommandArgument));
                m.SortOrder += 1;
                ResolutionManager.SaveOrUpdate(m);
                break;
            }
            BindResolutions();
        }
Exemplo n.º 7
0
        public override void Draw(GameTime gameTime)
        {
            ResolutionManager.BeginDraw();

            spriteBatch.Begin(SpriteSortMode.FrontToBack,
                              BlendState.AlphaBlend,
                              SamplerState.PointClamp,
                              null,
                              null,
                              null,
                              Camera2D.GetTransformMatrix());

            mapManager.Draw(spriteBatch);
            spriteBatch.End();

            spriteBatch.Begin(SpriteSortMode.FrontToBack,
                              BlendState.AlphaBlend,
                              SamplerState.PointClamp,
                              null,
                              null,
                              null,
                              ResolutionManager.GetTransformationMatrix());
            windowManager.Draw(spriteBatch);

            spriteBatch.End();
        }
Exemplo n.º 8
0
 public void ApplyGraphicChanges()
 {
     graphics.PreferredBackBufferWidth  = ResolutionManager.GetPreferredScreenWidth();
     graphics.PreferredBackBufferHeight = ResolutionManager.GetPreferredScreenHeight();
     graphics.IsFullScreen = ResolutionManager.IsFullScreen();
     graphics.ApplyChanges();
 }
Exemplo n.º 9
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.SetRenderTarget(_VirtualRenderTarget);
            GraphicsDevice.Clear(BackgroundColor);

            // The real drawing happens inside the screen manager component.
            base.Draw(gameTime);

            // Reset the device to the back buffer
            GraphicsDevice.SetRenderTarget(null);
            GraphicsDevice.Clear(BackgroundColor);

            _VirtualTexture2D = (Texture2D)_VirtualRenderTarget;

            _SpriteBatch.Begin();
            _SpriteBatch.Draw(_VirtualTexture2D, ResolutionManager.PhysicalFullscreen, Color.White);
            _SpriteBatch.End();

            // Apply device changes
            if (GameSettingsManager.ResolutionChangesToApply)
            {
                ResolutionManager.ApplyResolutionChanges();
                GameSettingsManager.ResolutionChangesToApply = false;
                _VirtualRenderTarget = new RenderTarget2D(GraphicsDevice, ResolutionManager.VirtualWidth, ResolutionManager.VIRTUAL_HEIGHT);

                ResetElapsedTime();
            }
        }
Exemplo n.º 10
0
    /// <summary>
    /// Scale the source retangle in the GUIMember with a certain scale based on the default resolution set in the ResolutionManager.cs.
    /// </summary>
    public static Rect ResolutionRect(Rect rectangle, ResolutionManager.scaleMode mode)
    {
        Rect returnRect = new Rect(0, 0, 0, 0);

        scaleX = Screen.width / ResolutionManager.GetDefaultResolution().x;
        scaleY = Screen.height / ResolutionManager.GetDefaultResolution().y;

        //Different scaling modes for each GUIMember. (Default is ScaleWithResolution)
        switch (mode)
        {
        case ResolutionManager.scaleMode.keepPixelSize:
            returnRect = new Rect(rectangle.x * scaleX, rectangle.y * scaleY, rectangle.width, rectangle.height);
            break;

        case ResolutionManager.scaleMode.scaleWidth:
            returnRect = new Rect(rectangle.x * scaleX, rectangle.y * scaleY, rectangle.width * scaleX, rectangle.height);
            break;

        case ResolutionManager.scaleMode.scaleHeight:
            returnRect = new Rect(rectangle.x * scaleX, rectangle.y * scaleY, rectangle.width, rectangle.height * scaleY);
            break;

        case ResolutionManager.scaleMode.scaleWithResolution:
            returnRect = new Rect(rectangle.x * scaleX, rectangle.y * scaleY, rectangle.width * scaleX, rectangle.height * scaleY);
            break;
        }

        //The return value of the scaled rectangle of the source rect.
        returnRect = new Rect(Mathf.Round(returnRect.x), Mathf.Round(returnRect.y), Mathf.Round(returnRect.width), Mathf.Round(returnRect.height));

        return(returnRect);
    }
Exemplo n.º 11
0
    void OnEnable()
    {
        instance      = this;
        resoText.text = "Width:" + Screen.width + " Height:" + Screen.height;

        if (Screen.width == 1024 || Screen.width == 2048)                           //iPAD 1024*768 OR 2048*1536
        {
            UIRootPanel.transform.localScale = new Vector3(1, 1, 1);
            GamePanel.transform.localScale   = new Vector3(1, 1, 1);
            BG.transform.localScale          = new Vector3(1, 1.3f, 1);
            PauseBtn.transform.localScale    = new Vector3(1, 1, 1);
            PausePanel.transform.localScale  = new Vector3(1, 1, 1);
        }
        else if (Screen.width == 960)                             //iPOD & iPHONE 960*640
        {
            UIRootPanel.transform.localScale = new Vector3(1, 1.05f, 1);
            GamePanel.transform.localScale   = new Vector3(1, 1.05f, 1);
            PauseBtn.transform.localScale    = new Vector3(1.3f, 1.3f, 1.3f);
            PausePanel.transform.localScale  = new Vector3(1.2f, 1.2f, 1.2f);
        }
        else if (Screen.width == 1136)                             //iPOD & iPHONE 1136*940
        {
            UIRootPanel.transform.localScale = new Vector3(0.85f, 1f, 1);
            GamePanel.transform.localScale   = new Vector3(0.85f, 1f, 1);
            BG.transform.localScale          = new Vector3(1.2f, 1.3f, 1);
            PauseBtn.transform.localScale    = new Vector3(1.4f, 1.4f, 1.4f);
            PausePanel.transform.localScale  = new Vector3(1.2f, 1.2f, 1.2f);
        }
    }
Exemplo n.º 12
0
    public void OnApply()
    {
        Resolution finalSelection = mAvailableResolutions[mSelectedResolution];

        ResolutionManager.ChangeResolution(finalSelection.width, finalSelection.height, mFullScreen);

        Close();
    }
Exemplo n.º 13
0
 public SpaceInvaders()
 {
     GameGraphicsDeviceManager = new GraphicsDeviceManager(this);
     m_ResolutionManager       = new ResolutionManager(this);
     Content.RootDirectory     = "Content";
     IsMouseVisible            = true;
     this.GameEnd += BaseGame_GameEnd;
     createGameEntities();
 }
	// Use this for initialization
	void Start () 
	{
		//Calibrates the myInstance static variable
        instances++;

        if (instances > 1)
            Debug.Log("Warning: There are more than one Player Manager at the level");
        else
            myInstance = this;
	}
Exemplo n.º 15
0
    public void Start()
    {
        resolutionManager = this;

        /*_Resolution = resolutionType.big;
         * Screen.SetResolution(1920, 1080, FullScreenMode.Windowed);*/
        _Resolution = resolutionType.big;
        Screen.SetResolution(1920, 1080, FullScreenMode.Windowed);
        SetBigUi();
        MousePointer.mousePointer.UpdateMapRect();
    }
        public async Task rethrow_exception_when_managing()
        {
            var cts       = new CancellationTokenSource(10000);
            var ex        = new TestException();
            var mockQueue = new Mock <IResolutionQueue>();
            var manager   = new ResolutionManager(NullStandardLogger.Instance, null, null, mockQueue.Object, null);

            mockQueue.Setup(x => x.TryDequeue(out It.Ref <ResolutionStreamEvent> .IsAny)).Throws(ex);

            await Assert.ThrowsAsync <TestException>(() => manager.ManageAsync(cts.Token));
        }
Exemplo n.º 17
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>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();

            resolutionManager = new ResolutionManager(this, graphics);
            resolutionManager.Initialize();
            position = new Vector2(0, 0);
            camera   = new Camera(resolutionManager);
        }
Exemplo n.º 18
0
        protected override void Draw(GameTime gameTime)
        {
            spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.BackToFront,
                              SaveStateMode.None, ResolutionManager.GetGlobalTransformation());

            controller.Draw(spriteBatch);

            spriteBatch.End();

            base.Draw(gameTime);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Binds the milestones.
        /// </summary>
        private void BindResolutions()
        {
            grdResolutions.Columns[1].HeaderText = GetGlobalResourceObject("SharedResources", "Resolution").ToString();
            grdResolutions.Columns[2].HeaderText = GetGlobalResourceObject("SharedResources", "Image").ToString();
            grdResolutions.Columns[3].HeaderText = GetGlobalResourceObject("SharedResources", "Order").ToString();

            grdResolutions.DataSource   = ResolutionManager.GetByProjectId(ProjectId);
            grdResolutions.DataKeyField = "Id";
            grdResolutions.DataBind();

            grdResolutions.Visible = grdResolutions.Items.Count != 0;
        }
Exemplo n.º 20
0
        public Camera2D()
        {
            CameraMovedEvent += Camera2D_CameraMovedEvent;

            resolution = ResolutionManager.Instance;

            _zoom     = 1;
            _rotation = 0.0f;
            Position  = new Vector2(Viewport.Width / 2, Viewport.Height / 2);

            RecalculateTransformationMatrices();
        }
Exemplo n.º 21
0
 protected override void Initialize()
 {
     Window.AllowUserResizing = false;
     this.Window.Title        = NAME;
     controller = Controller.GetInstance();
     controller.Initialize(this);
     ResolutionManager.Initialize();
     ApplyGraphicChanges();
     base.Initialize();
     AudioManager.Initialize();
     ScreenManager.GetInstance().AddScreen(new Screen.MainMenuScreen());
 }
Exemplo n.º 22
0
 public void Start()
 {
     if (instance == null)
     {
         instance = this;
     }
     else if (instance == this)
     {
         Destroy(gameObject);
     }
     DontDestroyOnLoad(gameObject);
     InitializeResolutionManager();
 }
Exemplo n.º 23
0
        /// <summary>
        /// Deletes the milestone.
        /// </summary>
        /// <param name="s">The s.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.DataGridCommandEventArgs"/> instance containing the event data.</param>
        protected void grdResolutions_Delete(Object s, DataGridCommandEventArgs e)
        {
            var    id = (int)grdResolutions.DataKeys[e.Item.ItemIndex];
            string cannotDeleteMessage;

            if (!ResolutionManager.Delete(id, out cannotDeleteMessage))
            {
                ActionMessage.ShowErrorMessage(cannotDeleteMessage);
                return;
            }

            BindResolutions();
        }
Exemplo n.º 24
0
    void Awake()
    {
        instance = this;

        GameObject[] objs = GameObject.FindGameObjectsWithTag("ResolutionManager");

        if (objs.Length > 1)
        {
            Destroy(this.gameObject);
        }

        DontDestroyOnLoad(this.gameObject);
    }
Exemplo n.º 25
0
 public void ChangeCurrentResolution(int index)
 {
     if (!Application.isEditor)
     {
         string     listData   = GetDataFromDropdownList(index);
         Resolution resolution = GetParsedResolution(listData);
         ResolutionManager.UpdateResolution(resolution.width, resolution.height);
     }
     else
     {
         Debug.Log("Changing resolution doesn't work in editor mode. Works only in the build.");
     }
 }
        public async Task stream_eligible_for_resolution_throws_non_sequential_position_and_stream_state_not_exists()
        {
            var mockStreamStateRepo   = new Mock <IStreamStateRepo>();
            var streamId              = "s";
            var newPosition           = 1;   // Must be first position in stream + 1 for this test.
            var eventType             = "x";
            var firstPositionInStream = 0;
            var manager     = new ResolutionManager(NullStandardLogger.Instance, null, mockStreamStateRepo.Object, null, null);
            var streamEvent = new StreamEvent(streamId, newPosition, null, eventType, new byte[] { });

            mockStreamStateRepo.Setup(x => x.LoadStreamStateAsync(streamId)).ReturnsAsync((StreamState)null);

            await Assert.ThrowsAsync <InvalidOperationException>(() => manager.IsStreamEventEligibleForResolution(streamEvent, firstPositionInStream));
        }
    // Use this for initialization
    void Start()
    {
        //Calibrates the myInstance static variable
        instances++;

        if (instances > 1)
        {
            Debug.Log("Warning: There are more than one Player Manager at the level");
        }
        else
        {
            myInstance = this;
        }
    }
Exemplo n.º 28
0
    public IEnumerator Start()
    {
        ResolutionManager.SetupResolution();

        Application.targetFrameRate = 60;

        StartCoroutine(PlayLogoAnimation());

        yield return(new WaitForSeconds(2.5f));

        Game.instance.transitionManager.TransitionToScreen("Title");

        Game.instance.soundManager.PlayRandomMusicInCategory("TitleMusic");
    }
Exemplo n.º 29
0
 private void Start()
 {
     ResolutionManager.presets.Clear();
     foreach (Resolution resolution in Screen.resolutions)
     {
         if (!this.FindResolution(resolution))
         {
             ResolutionManager.presets.Add(new ResolutionManager.ResolutionPreset(resolution));
         }
     }
     ResolutionManager.preset     = PlayerPrefs.GetInt("SavedResolutionSet", ResolutionManager.presets.Count - 1);
     ResolutionManager.fullscreen = (PlayerPrefs.GetInt("SavedFullscreen", 1) != 0);
     ResolutionManager.RefreshScreen();
 }
Exemplo n.º 30
0
 public static void ChangeResolution(int id)
 {
     if (id == 0)
     {
         ResolutionManager.fullscreen = !ResolutionManager.fullscreen;
         PlayerPrefs.SetInt("SavedFullscreen", (!ResolutionManager.fullscreen) ? 0 : 1);
     }
     else
     {
         ResolutionManager.preset = Mathf.Clamp(ResolutionManager.preset + id, 0, ResolutionManager.presets.Count - 1);
         PlayerPrefs.SetInt("SavedResolutionSet", ResolutionManager.preset);
     }
     ResolutionManager.RefreshScreen();
 }
Exemplo n.º 31
0
        /// <summary>
        /// Binds the options.
        /// </summary>
        private void BindOptions()
        {
            List <ITUser> users = UserManager.GetUsersByProjectId(ProjectId, true);

            //Get Type
            DropIssueType.DataSource = IssueTypeManager.GetByProjectId(ProjectId);
            DropIssueType.DataBind();

            //Get Priority
            DropPriority.DataSource = PriorityManager.GetByProjectId(ProjectId);
            DropPriority.DataBind();

            //Get Resolutions
            DropResolution.DataSource = ResolutionManager.GetByProjectId(ProjectId);
            DropResolution.DataBind();

            //Get categories
            var categories = new CategoryTree();

            DropCategory.DataSource = categories.GetCategoryTreeByProjectId(ProjectId);
            DropCategory.DataBind();

            //Get milestones
            DropMilestone.DataSource = MilestoneManager.GetByProjectId(ProjectId);
            DropMilestone.DataBind();

            DropAffectedMilestone.DataSource = MilestoneManager.GetByProjectId(ProjectId);
            DropAffectedMilestone.DataBind();

            //Get Users
            DropAssignedTo.DataSource = users;
            DropAssignedTo.DataBind();

            DropOwned.DataSource = users;
            DropOwned.DataBind();

            DropStatus.DataSource = StatusManager.GetByProjectId(ProjectId);
            DropStatus.DataBind();

            lblDateCreated.Text  = DateTime.Now.ToString("f");
            lblLastModified.Text = DateTime.Now.ToString("f");

            if (!User.Identity.IsAuthenticated)
            {
                return;
            }

            lblReporter.Text       = Security.GetDisplayName();
            lblLastUpdateUser.Text = Security.GetDisplayName();
        }
 void Awake()
 {
     Instance = this;
 }
Exemplo n.º 33
0
 public void Awake()
 {
     _selfReference = this;
 }