public void ValidaForm(Data.DB _db, ModelStateDictionary _modelState, FormularioVersao _formPost)
        {
            foreach (var comp in _formPost.Componentes)
            {
                foreach (var elemento in comp.Elementos)
                {
                    ValidacaoElementos(_db, elemento, _modelState);
                }

                foreach (var compExp in comp.ListaComponenteExpansao)
                {
                    foreach (var elemExp in compExp.Elementos)
                    {
                        ValidacaoElementos(_db, elemExp, _modelState);
                    }
                }
            }
        }
Beispiel #2
0
        /*
        * Send a message to the remote party.
        */
        private void SendMessage(Command cmd, EndPoint sendToEP)
        {
            try
            {
                //Create the message to send.
                Data msgToSend = new Data();

                msgToSend.strName = "用户名";   //Name of the user.
                msgToSend.cmdCommand = cmd;         //Message to send.
                msgToSend.vocoder = vocoder;        //Vocoder to be used.

                byte[] message = msgToSend.ToByte();

                //Send the message asynchronously.
                clientSocket.BeginSendTo(message, 0, message.Length, SocketFlags.None, sendToEP, new AsyncCallback(OnSend), null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "VoiceChat-SendMessage ()", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #3
0
        /*
         * Commands are received asynchronously. OnReceive is the handler for them.
         */
        private void OnReceive(IAsyncResult ar)
        {
            try
            {
                EndPoint receivedFromEP = new IPEndPoint(IPAddress.Any, 0);

                //Get the IP from where we got a message.
                clientSocket.EndReceiveFrom(ar, ref receivedFromEP);

                //Convert the bytes received into an object of type Data.
                Data msgReceived = new Data(byteData);

                //Act according to the received message.
                switch (msgReceived.cmdCommand)
                {
                    //We have an incoming call.
                    case Command.Invite:
                        {
                            if (bIsCallActive == false)
                            {
                                //We have no active call.

                                //Ask the user to accept the call or not.
                                if (MessageBox.Show(msgReceived.strName + "邀请你进行语音通话.\r\n\r\n接受吗?",
                                    "通话邀请", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                                {
                                    SendMessage(Command.OK, receivedFromEP);
                                    vocoder = msgReceived.vocoder;
                                    otherPartyEP = receivedFromEP;
                                    otherPartyIP = (IPEndPoint)receivedFromEP;
                                    InitializeCall();
                                }
                                else
                                {
                                    //The call is declined. Send a busy response.
                                    SendMessage(Command.Busy, receivedFromEP);
                                }
                            }
                            else
                            {
                                //We already have an existing call. Send a busy response.
                                SendMessage(Command.Busy, receivedFromEP);
                            }
                            break;
                        }

                    //OK is received in response to an Invite.
                    case Command.OK:
                        {
                            //Start a call.
                            InitializeCall();
                            break;
                        }

                    //Remote party is busy.
                    case Command.Busy:
                        {
                            MessageBox.Show("User busy.", "VoiceChat", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            break;
                        }

                    case Command.Bye:
                        {
                            //Check if the Bye command has indeed come from the user/IP with which we have
                            //a call established. This is used to prevent other users from sending a Bye, which
                            //would otherwise end the call.
                            if (receivedFromEP.Equals(otherPartyEP) == true)
                            {
                                //End the call.
                                UninitializeCall();

                                senderThread.Suspend();
                                receiverThread.Suspend();

                            }
                            break;
                        }
                }

                byteData = new byte[1024];
                //Get ready to receive more commands.
                clientSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref receivedFromEP, new AsyncCallback(OnReceive), null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "VoiceChat-OnReceive ()", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #4
0
        /*
         * Commands are received asynchronously. OnReceive is the handler for them.
         */
        private void OnReceive(IAsyncResult ar)
        {
            try
            {
                if (receivedFromEP==null)
                {
                    receivedFromEP = new IPEndPoint(IPAddress.Any, 0);
                }

                //Get the IP from where we got a message.
                clientSocket.EndReceiveFrom(ar, ref receivedFromEP);

                //Convert the bytes received into an object of type Data.
                Data msgReceived = new Data(byteData);

                //Act according to the received message.
                switch (msgReceived.cmdCommand)
                {
                    //We have an incoming call.
                    case Command.Invite:
                        {
                            if (bIsCallActive == false)
                            {
                                //We have no active call.

                                //Ask the user to accept the call or not.
                                if (MessageBox.Show(msgReceived.strName + "邀请你进行语音通话.\r\n\r\n接受吗?",
                                    "通话邀请", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                                {
                                    SendMessage(Command.OK, receivedFromEP);
                                    vocoder = msgReceived.vocoder;
                                    otherPartyEP = receivedFromEP;
                                    otherPartyIP = (IPEndPoint)receivedFromEP;
                                    InitializeCall();
                                }
                                else
                                {
                                    //The call is declined. Send a busy response.
                                    SendMessage(Command.Busy, receivedFromEP);
                                }
                            }
                            else
                            {
                                //We already have an existing call. Send a busy response.
                                SendMessage(Command.Busy, receivedFromEP);
                            }
                            break;
                        }

                    //OK is received in response to an Invite.
                    case Command.OK:
                        {
                            //Start a call.
                            string ip = receivedFromEP.ToString().Split(':')[0];
                            //将远程同意邀请的用户IP写到教师机的  聊天室列表中
                            addChatRoom(ip, ((OnlineUser)(LoginRoler.OnlineUserDic[ip])).ChatName);

                            //更新在线用户的  isChating 值改成true
                            updateOnlineUser(ip,true);
                            //同时需要通知其他学生机更新目前最新的聊天室用户IP列表  而这个操作需要由一开始登录的Socket来做
                            updateNetNewChatRoomUsersToStudent();
                            loadOnlineUses();
                            InitializeCall();
                            break;
                        }

                    //Remote party is busy.
                    case Command.Busy:
                        {
                            MessageBox.Show("User busy.", "VoiceChat", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            break;
                        }

                    case Command.Bye:
                        {
                            //Check if the Bye command has indeed come from the user/IP with which we have
                            //a call established. This is used to prevent other users from sending a Bye, which
                            //would otherwise end the call.
                            if (receivedFromEP.Equals(otherPartyEP) == true)
                            {
                                //End the call.
                                UninitializeCall();
                            }
                            break;
                        }
                }

                byteData = new byte[1024];
                //Get ready to receive more commands.
                clientSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref receivedFromEP, new AsyncCallback(OnReceive), null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "VoiceChat-OnReceive ()", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public void ValidacaoElementos( Data.DB _db, FormularioElemento elemento, ModelStateDictionary _modelState)
        {
            //eh tenso buscar no banco, mas elimina os engracadinhos mexendo nas propriedades no client
            //caso, reclamem de performance tempo, coloca no cliente, alimenta as view e manter as propriedades de validacao no get
            elemento.Validacoes = _db.getValidacoesElemento(elemento.Id);

            if (elemento.IdTipoElemento == 2) //textbox
            {
                //OBRIGATORIO, é propriedade do elemento
                if (elemento.IsObrigatorio && (elemento.Respostas.DsResposta == null || elemento.Respostas.DsResposta.Length == 0))
                    _modelState.AddModelError(elemento.NameClient + ".Respostas.DsResposta", elemento.Titulo + " é obrigatório.");

                //aqui embaixo é relacionamento, criando Registro na Validação, precisa implementar algo em algum tipo de elemento, neste está no textbox
                //mas se quiser criar para outros tipos de elementos, funcionará tranquilamente
                bool IsValido;
                foreach (var val in elemento.Validacoes)
                {
                    IsValido = true;
                    //validacoes
                    switch (val.Codigo)
                    {
                        case "CPF":
                            {
                                break;
                            }
                        case "MINCHAR3":
                            {
                                if (elemento.Respostas.DsResposta != null && elemento.Respostas.DsResposta.Length < 3)
                                    IsValido = false;
                                break;
                            }
                        case "MAXCHAR50":
                            {
                                if (elemento.Respostas.DsResposta != null && elemento.Respostas.DsResposta.Length > 50)
                                    IsValido = false;
                                break;
                            }
                        default:
                            break;
                    }

                    if (IsValido == false)
                        _modelState.AddModelError(elemento.NameClient + ".Respostas.DsResposta", elemento.Titulo + " " + val.MensErro);
                }
            }
            if (elemento.IdTipoElemento == 5) //combo
            {
                //OBRIGATORIO, é propriedade do elemento
                if (elemento.IsObrigatorio)
                {
                    int idValor = 0;
                    bool converteu = int.TryParse(elemento.Respostas.DsValor, out idValor);
                    if (idValor == 0)
                        _modelState.AddModelError(elemento.NameClient + ".Respostas.DsValor", elemento.Titulo + " é obrigatório.");
                }
            }
        }
        public void Salvar(Data.DB _db, int idFluxo, FormularioVersao _form, int idProjeto)
        {
            Edicao edicao = _db.getEdicao(_form.Id, idFluxo);
            List<Resposta> ListaRespostaOld = _db.getRespostas(_form.Id, idFluxo, idProjeto);
            List<Resposta> ListaRespostasNew = new List<Resposta>();

            //essa var, serve para quando o usuario quiser apenas salvar sem validar, implementar isso
            bool IsValidado = true;

            Resposta respostaOld;
            foreach (var componente in _form.Componentes)
            {
                foreach (var elemento in componente.Elementos)
                {
                    respostaOld = ListaRespostaOld.FirstOrDefault(r => r.IdComponenteElemento == elemento.Id && r.IdComponenteExpansao == 0); //sem expansao
                    if (respostaOld == null)
                        ListaRespostasNew.Add(elemento.Respostas);
                    else
                        if (elemento.IdTipoElemento == 5 || elemento.IdTipoElemento == 7) //comparar valor
                        {
                            if (respostaOld.DsValor != elemento.Respostas.DsValor)
                            {
                                ListaRespostasNew.Add(elemento.Respostas);
                            }
                        }
                        else //comparar texto(resposta)
                        {
                            if (respostaOld.DsResposta != elemento.Respostas.DsResposta)
                            {
                                ListaRespostasNew.Add(elemento.Respostas);
                            }
                        }
                }

                //componentes
                foreach (var componenteExpansao in componente.ListaComponenteExpansao)
                {
                    if (componenteExpansao.Id == 0) //inserir expansao
                    {
                        componenteExpansao.IdFormularioComponente = componente.Id;
                        componenteExpansao.IdProjeto = idProjeto;
                        int idComponenteExpansao = _db.gravarComponenteExpansao(componenteExpansao);
                        componenteExpansao.Id = idComponenteExpansao;
                    }
                    foreach (var elemento in componenteExpansao.Elementos)
                    {
                        elemento.Respostas.IdComponenteExpansao = componenteExpansao.Id; //colcando a expansao no objeto
                        respostaOld = ListaRespostaOld.FirstOrDefault(r => r.IdComponenteElemento == elemento.Id && r.IdComponenteExpansao == componenteExpansao.Id);
                        if (respostaOld == null)
                            ListaRespostasNew.Add(elemento.Respostas);
                        else
                            if (elemento.IdTipoElemento == 5 || elemento.IdTipoElemento == 7) //comparar valor
                            {
                                if (respostaOld.DsValor != elemento.Respostas.DsValor)
                                {
                                    ListaRespostasNew.Add(elemento.Respostas);
                                }
                            }
                            else //comparar texto(resposta)
                            {
                                if (respostaOld.DsResposta != elemento.Respostas.DsResposta)
                                {
                                    ListaRespostasNew.Add(elemento.Respostas);
                                }
                            }
                    }
                }
            }

            if (ListaRespostasNew.Count > 0)
            {
                int idEdicao = _db.gravarEdicao(_form.Id, idFluxo, edicao.Versao + 1, IsValidado, idProjeto);
                foreach (var _resposta in ListaRespostasNew)
                {
                    _db.gravarResposta(_resposta, idEdicao);
                }
            }

            //inativar expansoes
            if (Session["ExpansoesParaInativar"] != null)
            {
                List<int> listaCompInativar = (List<int>)Session["ExpansoesParaInativar"];
                foreach (var idCompExpInativar in listaCompInativar)
                {
                    _db.inativarComponenteExpansao(idCompExpInativar);
                }
            }
        }
        public FormularioVersao BuscaForm(Data.DB _db, int? idFormulario, int idProjeto, bool IsPost, FormularioVersao _formPost)
        {
            Projeto _projeto = _db.getProjeto(idProjeto);

            //BUSCANDO OS FORMS DO FLUXO
            List<Formulario> _listaForms = listaForms(idProjeto).OrderBy(f => f.Ordem).ToList();

            //BUSCANDO AS VERSOES DOS FORMULARIOS
            List<FormularioVersao> _listaFormsVersao = new List<FormularioVersao>();
            foreach (var item in _listaForms)
            {
                _listaFormsVersao.Add(listaFormsVersao(item.Id, item.Ordem, _projeto.DtCriacao));
            }

            ViewBag.Forms = _listaFormsVersao;
            ViewBag.IdProjeto = idProjeto;

            FormularioVersao formRenderizado = _listaFormsVersao.FirstOrDefault(f => idFormulario == null || f.IdFormulario == idFormulario.Value);
            ViewBag.Message = formRenderizado.Nome;

            formRenderizado.Componentes = _db.getFormComponentes(formRenderizado.Id, idProjeto).OrderBy(e => e.Ordem).ToList();
            int idFluxo = Convert.ToInt32(Session["FluxoId"]);//Session?


            List<Resposta> ListaRespostasOld = new List<Resposta>();

            if (!IsPost)
                ListaRespostasOld = _db.getRespostas(formRenderizado.Id, idFluxo, idProjeto);

            Resposta respostaOld = null;
            FormularioComponente _comp;
            FormularioElemento _elem;
            foreach (var componente in formRenderizado.Componentes)
            {
                componente.Elementos = _db.getComponenteElementos(componente.IdComponente).OrderBy(e => e.Linha).ThenBy(e => e.Ordem).ToList();

                foreach (var elemento in componente.Elementos)
                {
                    if (IsPost)
                    {
                        //se a chave mudar para permitir ter varios componentes iguais, mudar aqui a busca para chave primaria!
                        _comp = _formPost.Componentes.FirstOrDefault(c => c.IdComponente == elemento.IdComponente);

                        //complemento no formulario postado deve existir, nem todos os componentes são mandados no Post                        
                        if (_formPost.Componentes.FirstOrDefault(c => c.IdComponente == elemento.IdComponente) != null)
                        {
                            _elem = _comp.Elementos.FirstOrDefault(e => e.Id == elemento.Id);
                            if (_elem != null)//nem todos os elementos vem no Post, por isso verificar se algum deve salvar
                                respostaOld = _elem.Respostas;
                        }
                    }
                    else
                        respostaOld = ListaRespostasOld.FirstOrDefault(r => r.IdComponenteElemento == elemento.Id && r.IdComponenteExpansao == 0); //soh o original do modelo do form tera expansao nula

                    if (respostaOld != null)
                        elemento.Respostas = respostaOld;

                    if (elemento.IdTipoElemento == 5 || elemento.IdTipoElemento == 7) //combo || radio
                        elemento.Valores = _db.getFormElementoValores(elemento.Id);
                }

                ComponenteExpansao compExp;
                respostaOld = null;
                //agora os expandidos, pegar os elementos e respostas
                if (componente.IsExpansivel)
                {
                    _comp = new FormularioComponente();
                    if (IsPost)
                    {
                        _comp = _formPost.Componentes.FirstOrDefault(c => c.Id == componente.Id); //pegando o componente que foi postado
                        componente.ListaComponenteExpansao = _comp.ListaComponenteExpansao; //pegar o que cliente modificou, no caso soh posta as expansoes modificadas
                    }

                    foreach (var item in componente.ListaComponenteExpansao)
                    {
                        item.Elementos = _db.getComponenteElementos(componente.IdComponente).OrderBy(e => e.Linha).ThenBy(e => e.Ordem).ToList();

                        foreach (var elemento in item.Elementos)
                        {
                            if (IsPost)
                            {
                                compExp = _comp.ListaComponenteExpansao.FirstOrDefault(ce => ce.Id == item.Id);
                                if (compExp != null)
                                {
                                    //buscar elementos da expansao
                                    _elem = compExp.Elementos.FirstOrDefault(e => e.Id == elemento.Id);
                                    if (_elem != null)//nem todos os elementos vem no Post, por isso verificar se algum deve salvar
                                        respostaOld = _elem.Respostas;
                                }
                            }
                            else
                                respostaOld = ListaRespostasOld.FirstOrDefault(r => r.IdComponenteElemento == elemento.Id && r.IdComponenteExpansao == item.Id); //todas expansoes tem id

                            if (respostaOld != null)
                                elemento.Respostas = respostaOld;

                            if (elemento.IdTipoElemento == 5 || elemento.IdTipoElemento == 7) //combo || radio
                                elemento.Valores = _db.getFormElementoValores(elemento.Id);
                        }
                    }
                }
            }

            return formRenderizado;
        }