/// <summary>
        /// Charge une matrice de régions
        /// </summary>
        /// <param name="dimensions">Dimensions de la scène</param>
        /// <param name="hotspots">Liste de hotspots</param>
        /// <param name="matrixPrecision"></param>
        /// <returns>Matrice d'octets</returns>
        public void CreateRegionMatrix(VO_Stage stage, System.Drawing.Size dimensions, List <VO_StageRegion> hotspots, int matrixPrecision)
        {
            if (!Directory.Exists(PathTools.GetProjectPath(Enums.ProjectPath.Matrixes)))
            {
                Directory.CreateDirectory(PathTools.GetProjectPath(Enums.ProjectPath.Matrixes));
            }
            StreamWriter sw = new StreamWriter(PathTools.GetProjectPath(Enums.ProjectPath.Matrixes) + stage.Id.ToString() + "_r");

            byte[,] matrix = new byte[4096, 4096];

            int height = dimensions.Height / matrixPrecision;
            int width  = dimensions.Width / matrixPrecision;

            for (int y = 0; y <= height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    matrix[x, y] = (byte)stage.Region;
                    foreach (VO_StageRegion hotspot in hotspots)
                    {
                        if (FormsTools.PointInPolygon(new Point(x, y), ConvertPointsForMatrix(matrixPrecision, hotspot.Points)))
                        {
                            matrix[x, y] = (byte)ConvertTools.CastInt(hotspot.Ratio);
                        }
                    }
                    sw.Write(GetValueFromByte(matrix[x, y]));
                }
                sw.Write("\r\n");
            }
            sw.Close();
        }
Ejemplo n.º 2
0
        void sliderBody_LocationChanging(object sender, DUILocationChangingEventArgs e)
        {
            OnScroll();
            int value = ConvertTools.ChineseRounding(this.LeftToRight ? (this.sliderBody.X / this.sliderBody.ChangeStepX) : (this.sliderBody.Y / this.sliderBody.ChangeStepY));

            if (this.value != value)
            {
                this.value = value + this.Minimum;
                OnValueChanging();
            }
        }
Ejemplo n.º 3
0
        private async Task OnReceiveMessageHandler(string roomId, string message, string loginToken)
        {
            var messageContent = message.Replace("\u0000", string.Empty).Trim();
            var websockets     = new Dictionary <string, WebSocket>();

            var userModel = _userService.Get(new GetByLoginTokenRequest
            {
                LoginToken = loginToken
            }).User;

            var messageModel = new LearningRoomMessageModel
            {
                CreatedByNickName    = userModel.NickName,
                Content              = messageContent,
                CreatedOn            = DateTimeUtil.GetNow(),
                IsCreatedByRequester = false
            };

            if (_websockets.TryGetValue(roomId, out websockets))
            {
                var bufferToMember = new ArraySegment <byte>(ConvertTools.StringToBytes(JsonConvert.SerializeObject(messageModel)));
                websockets
                .Where(w => !w.Key.Equals(loginToken))
                .Select(w => w.Value)
                .ToList()
                .ForEach(async w => await w.SendAsync(bufferToMember,
                                                      WebSocketMessageType.Text, true, CancellationToken.None));

                messageModel.IsCreatedByRequester = true;
                var bufferToRequester = new ArraySegment <byte>(ConvertTools.StringToBytes(JsonConvert.SerializeObject(messageModel)));
                await websockets
                .FirstOrDefault(w => w.Key.Equals(loginToken)).Value
                .SendAsync(bufferToRequester,
                           WebSocketMessageType.Text, true, CancellationToken.None);
            }

            try
            {
                await _learningRoomService.CreateChatMessage(loginToken, roomId, messageContent);

                LogService.Info <ChatMessageHub>(
                    "Message Saved" + Environment.NewLine +
                    "Message: " + messageContent + Environment.NewLine +
                    "Room Id: " + roomId + Environment.NewLine +
                    "login Token: " + loginToken);
            }
            catch (Exception e)
            {
                LogService.Info <ChatMessageHub>(
                    e.Message + Environment.NewLine +
                    e.StackTrace);
            }
        }
        /// <summary>
        /// Lors de la fermeture du ressource manager
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ResourcesManager_FormClosing(object sender, FormClosingEventArgs e)
        {
            FormsManager.Instance.ResourcesManager.FormClosing -= new FormClosingEventHandler(ResourcesManager_FormClosing);
            CurrentAnimation.ResourcePath = FormsManager.Instance.ResourcesManager.SelectedFilePath;
            LoadAnimation(CurrentAnimation.Id);

            if (AnimationType == Enums.AnimationType.CharacterAnimation)
            {
                int newValue = _OriginalResourceSize.Height / GameCore.Instance.Game.Project.MovementDirections;
                if (newValue <= 0)
                {
                    newValue = 1;
                }
                ddpSpriteH.Value = newValue;
            }
            _CurrentSprite.Y = ConvertTools.CastInt(ddpRows.Value) * _CurrentSprite.Height;
        }
Ejemplo n.º 5
0
        private async Task WebsocketLifeCycle(WebSocket webSocket, string roomId, string loginToken)
        {
            await OnConnectEvent(webSocket, roomId, loginToken);

            while (webSocket.State == WebSocketState.Open)
            {
                var result = await webSocket.ReceiveAsync(_buffer, CancellationToken.None);

                if (result.MessageType != WebSocketMessageType.Close)
                {
                    var byteReceive = _buffer.AsSpan <byte>().Slice(0, result.Count).ToArray();
                    var message     = ConvertTools.BytesToString(byteReceive).Trim();
                    await OnReceiveMessageEvent(roomId, message, loginToken);
                }
            }

            await OnDisconnectEvent(webSocket, roomId, loginToken);
        }
Ejemplo n.º 6
0
        private async void InitializeData()
        {
            //загрузка данных из БД
            try
            {
                var result = await client.GetAsync("api/faces");

                result.EnsureSuccessStatusCode();
                var faces = await result.Content.ReadAsAsync <Shared.Face[]>();

                categories.Clear();
                foreach (var face in faces)
                {
                    categories.AddCategoryFace(ConvertTools.ToClient(face));
                }
            }
            catch (System.Net.Http.HttpRequestException)
            {
                MessageBox.Show("Не удается установить соединение сервером", "Ошибка загрузки");
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Charge une matrice de régions
 /// </summary>
 /// <param name="dimensions">Dimensions de la scène</param>
 /// <param name="hotspots">Liste de hotspots</param>
 /// <param name="matrixPrecision"></param>
 /// <returns>Matrice d'octets</returns>
 public void LoadRegionMatrix(System.Drawing.Size dimensions, List <VO_StageRegion> hotspots, int matrixPrecision)
 {
     if (!_RegionsCreated)
     {
         int height = dimensions.Height / matrixPrecision;
         int width  = dimensions.Width / matrixPrecision;
         if (File.Exists(PathTools.GetProjectPath(Enums.ProjectPath.Matrixes) + _Stage.Id.ToString() + "_r"))
         {
             StreamReader myFile = new StreamReader(PathTools.GetProjectPath(Enums.ProjectPath.Matrixes) + _Stage.Id.ToString() + "_r");
             for (int y = 0; y < height; y++)
             {
                 string line = myFile.ReadLine();
                 for (int x = 0; x < width; x++)
                 {
                     int nX = 3 * x;
                     _RegionsMatrix[x, y] = Convert.ToByte(line[nX].ToString() + line[nX + 1].ToString() + line[nX + 2].ToString());
                 }
             }
             myFile.Close();
         }
         else
         {
             for (int y = 0; y <= height; y++)
             {
                 for (int x = 0; x < width; x++)
                 {
                     _RegionsMatrix[x, y] = (byte)_Stage.Region;
                     foreach (VO_StageRegion hotspot in hotspots)
                     {
                         if (Tools.PointInPolygon(new Point(x, y), ConvertPointsForMatrix(matrixPrecision, hotspot.Points)))
                         {
                             _RegionsMatrix[x, y] = (byte)ConvertTools.CastInt(hotspot.Ratio);
                         }
                     }
                 }
             }
         }
         _RegionsCreated = true;
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// 根据费用单id查询审批详情列表
        /// </summary>
        /// <param name="costId"></param>
        /// <returns></returns>
        public List <cost_approval> QueryApproval(int costId)
        {
            List <cost_approval> ListApproval = new List <cost_approval>();
            string    sql       = "select * from cost_approval where cost_id=" + costId;
            DataTable dataTable = SqlHelper.ExecuteDataset(ConStr, CommandType.Text, sql).Tables[0];

            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                DataRow       row      = dataTable.Rows[i];
                cost_approval approval = new cost_approval
                {
                    id          = (int)row["id"],
                    cost_id     = (int)row["cost_id"],
                    approval_id = (int)row["approval_id"]
                };
                approval.result  = (bool?)ConvertTools.DbNullConvert(row["result"]);
                approval.time    = (DateTime?)ConvertTools.DbNullConvert(row["time"]);
                approval.opinion = (string)ConvertTools.DbNullConvert(row["opinion"]);
                ListApproval.Add(approval);
            }
            return(ListApproval);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// La valeur du textbox a changé
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void ddpValue_ValueChanged(object sender, EventArgs e)
 {
     CurrentVariable.Value = ConvertTools.CastInt(ddpValue.Value);
 }
 /// <summary>
 /// Déplace le curseur d'animation sur une autre ligne.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ddpRows_ValueChanged(object sender, EventArgs e)
 {
     _CurrentSprite.Y     = Convert.ToInt32(ddpRows.Value) * _CurrentSprite.Height;
     CurrentAnimation.Row = ConvertTools.CastInt(ddpRows.Value);
     ResetPreview(false);
 }
        /// <summary>
        /// Méthode qui charge l'animation courante
        /// </summary>
        public void LoadAnimation(Guid guid)
        {
            Cursor.Current = Cursors.WaitCursor;

            //Suppression des eventhandler
            this.ddpSpriteW.ValueChanged   -= new System.EventHandler(this.ddpSpriteW_ValueChanged);
            this.ddpSpriteH.ValueChanged   -= new System.EventHandler(this.ddpSpriteH_ValueChanged);
            this.ddpFrequency.ValueChanged -= new System.EventHandler(this.ddpFrequency_ValueChanged);
            this.ddpRows.ValueChanged      -= new System.EventHandler(this.ddpRows_ValueChanged);
            this.txtName.TextChanged       -= new System.EventHandler(this.txtName_TextChanged);

            //Stop Timer
            _FrequencyTimer.Stop();

            //Anim courante
            if (AnimationType == Enums.AnimationType.CharacterAnimation)
            {
                CurrentAnimation = _Service.LoadVOObject(ParentCharacter, guid);
            }
            else
            {
                CurrentAnimation = _Service.LoadVOObject(AnimationType, guid);
            }

            if (CurrentAnimation.ResourcePath != null)
            {
                //Mise en place du sprite root.
                _CurrentSprite.X      = 0;
                _CurrentSprite.Width  = CurrentAnimation.SpriteWidth;
                _CurrentSprite.Height = CurrentAnimation.SpriteHeight;
                _CurrentSprite.Y      = CurrentAnimation.Row * CurrentAnimation.SpriteHeight;
                if (!string.IsNullOrEmpty(CurrentAnimation.ResourcePath))
                {
                    _Service.LoadSurfaceFromURI(PathTools.GetProjectPath(AnimationType) + CurrentAnimation.ResourcePath);
                }
                else
                {
                    _Service.LoadSurfaceFromURI(string.Empty);
                }

                //Timer
                _FrequencyTimer.Interval = 10000 / CurrentAnimation.Frequency;
                _FrequencyTimer.Start();
            }
            else
            {
                _Service.LoadEmptySurface();
                _CurrentSprite.X              = 0;
                CurrentAnimation.SpriteWidth  = 1;
                CurrentAnimation.SpriteHeight = 1;
                _CurrentSprite.Width          = CurrentAnimation.SpriteWidth;
                _CurrentSprite.Height         = CurrentAnimation.SpriteHeight;
            }

            //Récupération de la taille de la ressource originale
            _OriginalResourceSize = _Service.GetSizeOfResource();

            //Mise à niveau de la taille des sprites
            if (CurrentAnimation.SpriteWidth > _OriginalResourceSize.Width)
            {
                CurrentAnimation.SpriteWidth = _OriginalResourceSize.Width;
            }
            if (CurrentAnimation.SpriteHeight > _OriginalResourceSize.Height)
            {
                CurrentAnimation.SpriteHeight = _OriginalResourceSize.Height;
            }

            //Mise en place des contrôles
            txtName.Text = CurrentAnimation.Title;

            _NbrRows = GetNbrRowsFromResource();
            if (_NbrRows > 0)
            {
                ddpRows.Maximum = _NbrRows - 1;
            }
            if (CurrentAnimation.Row > ddpRows.Maximum)
            {
                CurrentAnimation.Row = ConvertTools.CastInt(ddpRows.Maximum);
            }
            ddpRows.Value      = CurrentAnimation.Row;
            ddpFrequency.Value = CurrentAnimation.Frequency;
            _CurrentWidth      = CurrentAnimation.SpriteWidth;
            _CurrentHeight     = CurrentAnimation.SpriteHeight;
            ddpSpriteW.Maximum = _OriginalResourceSize.Width;
            ddpSpriteH.Maximum = _OriginalResourceSize.Height;
            if (CurrentAnimation.SpriteWidth > ddpSpriteW.Maximum)
            {
                ddpSpriteW.Value = ddpSpriteW.Maximum;
            }
            else
            {
                ddpSpriteW.Value = CurrentAnimation.SpriteWidth;
            }
            if (CurrentAnimation.SpriteHeight > ddpSpriteH.Maximum)
            {
                ddpSpriteH.Value = ddpSpriteH.Maximum;
            }
            else
            {
                ddpSpriteH.Value = CurrentAnimation.SpriteHeight;
            }

            if (CurrentAnimation.ParentCharacter != new Guid())
            {
                ddpRows.Enabled    = false;
                ddpSpriteH.Enabled = false;
                lblRows.Enabled    = false;
                lblX.Enabled       = false;
            }
            else
            {
                ddpRows.Enabled    = true;
                ddpSpriteH.Enabled = true;
                lblRows.Enabled    = true;
                lblX.Enabled       = true;
            }

            this.ddpSpriteW.ValueChanged   += new System.EventHandler(this.ddpSpriteW_ValueChanged);
            this.ddpSpriteH.ValueChanged   += new System.EventHandler(this.ddpSpriteH_ValueChanged);
            this.ddpFrequency.ValueChanged += new System.EventHandler(this.ddpFrequency_ValueChanged);
            this.ddpRows.ValueChanged      += new System.EventHandler(this.ddpRows_ValueChanged);
            this.txtName.TextChanged       += new System.EventHandler(this.txtName_TextChanged);

            grpInformations.Visible = true;
            grpPreview.Visible      = true;
            grpResource.Visible     = true;

            RefreshPreview();

            Cursor.Current = DefaultCursor;
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Grid Height
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ddpGridHeight_ValueChanged(object sender, EventArgs e)
 {
     Menu.GridHeight             = ConvertTools.CastInt(ddpGridHeight.Value);
     crdInventoryPosition.Coords = new Rectangle(Menu.InventoryCoords, new Size(Menu.GridWidth * Menu.ItemWidth, Menu.GridHeight * Menu.ItemHeight));
     Menu.Update();
 }