Esempio n. 1
0
        public string Retrieve(int i) {
            lock (this) {
                NetworkStream siso = sock.GetStream();
                SL.WriteLine(siso, "RETR " + i);

                if ((resp = Resp.ReadFrom(siso)).Ok != true) throw new CommandFailedException();

                StringBuilder res = new StringBuilder(1024 * 1024);
                while (true) {
                    string s = RL.ReadLine(siso);
                    if (s.Equals(".")) break;
                    res.Append(s).Append("\r\n");
                }
                return res.ToString();
            }
        }
Esempio n. 2
0
        public POP3(String host, int port, String user, String pass) {
            sock = new TcpClient();
            sock.Connect(host, port);
            NetworkStream siso = sock.GetStream();

            if ((resp = Resp.ReadFrom(siso)).Ok != true) throw new CommException();

            Match M = Regex.Match(resp.Message, "(\\<.+\\>)");
            if (M.Success) {
                byte[] hasher = Encoding.ASCII.GetBytes(M.Groups[1].Value + pass);

                SL.WriteLine(siso, "APOP " + user + " " + Ut.H2S(MD5.Create().ComputeHash(hasher)));

                if ((resp = Resp.ReadFrom(siso)).Ok != true) throw new APOPCommandFailedException(resp.Message);
            }
            else throw new CommandFailedException();
        }
Esempio n. 3
0
        public List<UidlItem> GetUidl() {
            lock (this) {
                NetworkStream siso = sock.GetStream();
                SL.WriteLine(siso, "UIDL");

                if ((resp = Resp.ReadFrom(siso)).Ok != true) throw new CommandFailedException();

                List<UidlItem> al = new List<UidlItem>();
                while (true) {
                    string s = RL.ReadLine(siso);
                    if (s.StartsWith(".")) break;
                    string[] cols = s.Split(' ');
                    UidlItem o = new UidlItem();
                    o.i = int.Parse(cols[0]);
                    o.uidl = cols[1];
                    al.Add(o);
                }
                return al;
            }
        }
Esempio n. 4
0
        public void Status_cannot_contain_a_newline()
        {
            response = new Resp { Status = "\n200 OK" };
            AssertErrorMessage("Status cannot include a newline: \n200 OK");

            response = new Resp { Status = "200 OK\n" };
            AssertErrorMessage("Status cannot include a newline: 200 OK\n");
        }
Esempio n. 5
0
        private void buttonEjecutar_Click(object sender, EventArgs e)
        {
            if (comboBoxPaciente.SelectedItem == null)
            {
                var r = new Resp(Resources.MSG_Select_Patient);
                r.ShowDialog(this);
                return;
            }
            if (comboBoxTest.SelectedItem == null)
            {
                var r = new Resp(Resources.MSG_Select_Test);
                r.ShowDialog(this);
                return;
            }
            if (ap.Paciente != null)
            {
                #region OTHERS tests
                //if (this.comboBoxTest.Text == Resources.ComboValue_MF)
                //{
                //    int presentacion = (int)this.numericUpDown1.Value;
                //    int muestra = (int)this.numericUpDown2.Value;
                //    FullScreenBlack f = new FullScreenBlack(presentacion, muestra);
                //    f.ShowDialog(this);
                //    this.ap.Adicionar_Resultado(f.Resultado);
                //    if (this.checkBoxMostrarResultado.Checked)
                //    {
                //        Reporte r = new Reporte(ap.Paciente, f.Resultado);
                //        r.ShowDialog(this);
                //    }
                //    return;
                //}
                //if (this.comboBoxTest.Text == Resources.ComboValue_PVA)
                //{
                //    //FullScreenBlack f = new FullScreenBlack(p, "PVA");
                //    int presentacion = this.ap.Configuracion.Presentacion_PVA;
                //    int muestra = this.ap.Configuracion.Muestra_PVA;
                //    int descanso = this.ap.Configuracion.Descanso_PVA;
                //    Color[] colores = new Color[]{this.ap.Configuracion.Colores_PVA[0],
                //                                  this.ap.Configuracion.Colores_PVA[1],
                //                                  this.ap.Configuracion.Colores_PVA[2],
                //                                  this.ap.Configuracion.Colores_PVA[3],
                //                                  this.ap.Configuracion.Colores_PVA[4],
                //                                  this.ap.Configuracion.Colores_PVA[5]};
                //    FullScreenBlack f = new FullScreenBlack(presentacion, muestra, descanso, colores, false, this.ap.Configuracion.Imagenes_PVA);
                //    f.ShowDialog(this);
                //    if (f.Resultado == null) return;
                //    this.ap.Adicionar_Resultado(f.Resultado);
                //    if (this.checkBoxResultado.Checked)
                //    {
                //        Reporte r = new Reporte(ap.Paciente, f.Resultado);
                //        r.ShowDialog(this);
                //    }
                //    return;
                //}
                //if (this.comboBoxTest.Text == Resources.ComboValue_PVA2)
                //{
                //    //FullScreenBlack f = new FullScreenBlack(p, "PVA");
                //    int presentacion = this.ap.Configuracion.Presentacion_PVA;
                //    int muestra = this.ap.Configuracion.Muestra_PVA;
                //    int descanso = this.ap.Configuracion.Descanso_PVA;
                //    Color[] colores = new Color[]{this.ap.Configuracion.Colores_PVA[0],
                //                                  this.ap.Configuracion.Colores_PVA[1],
                //                                  this.ap.Configuracion.Colores_PVA[2],
                //                                  this.ap.Configuracion.Colores_PVA[3],
                //                                  this.ap.Configuracion.Colores_PVA[4],
                //                                  this.ap.Configuracion.Colores_PVA[5]};
                //    FullScreenBlack f = new FullScreenBlack(presentacion, muestra, descanso, colores, true, this.ap.Configuracion.Imagenes_PVA);
                //    f.ShowDialog(this);
                //    this.ap.Adicionar_Resultado(f.Resultado);
                //    if (this.checkBoxResultado.Checked)
                //    {
                //        Reporte r = new Reporte(ap.Paciente, f.Resultado);
                //        r.ShowDialog(this);
                //    }
                //    return;
                //}
                //if (this.comboBoxTest.Text == Resources.ComboValue_AM)
                //{
                //    int digito = ap.Configuracion.Exp_Digito_AM;
                //    int intervalo = ap.Configuracion.Intervalo_AM;
                //    int reaccion = ap.Configuracion.Reaccion_AM;
                //    int desasiertos = ap.Configuracion.Desasiertos_AM;
                //    NumScreen n = new NumScreen(digito, intervalo, reaccion, desasiertos);
                //    n.ShowDialog(this);
                //    this.ap.Adicionar_Resultado(n.Resultado);
                //    if (this.checkBoxResultado.Checked)
                //    {
                //        Reporte r = new Reporte(ap.Paciente, n.Resultado);
                //        r.ShowDialog(this);
                //    }
                //    return;
                //}
                //if (this.comboBoxTest.Text == Resources.ComboValue_TRC)
                //{
                //    Complementos.Figura figura = this.ap.Configuracion.Figura_TRC;
                //    int estimulos = this.ap.Configuracion.MaxEstimulos_TRC;
                //    int visualizacion = this.ap.Configuracion.TiempoVisualizacion_TRC;
                //    int reaccion = this.ap.Configuracion.TiempoReaccion_TRC;
                //    int tecla_reaccion = (this.ap.Configuracion.Tecla1_TRC == "[Enter]") ? 13 : 32;
                //    int tecla_reaccion1 = (this.ap.Configuracion.Tecla1_TRC == "[Enter]") ? 13 : 32;
                //    Color color = this.ap.Configuracion.Color1_TRC;
                //    Color color1 = this.ap.Configuracion.Color2_TRC;

                //    FormTR f = new FormTR(color, color1, estimulos, visualizacion, reaccion, tecla_reaccion, tecla_reaccion1, figura);
                //    f.ShowDialog(this);
                //    this.ap.Adicionar_Resultado(f.Resultado);
                //    if (this.checkBoxResultado.Checked)
                //    {
                //        Reporte r = new Reporte(ap.Paciente, f.Resultado);
                //        r.ShowDialog(this);
                //    }
                //    return;
                //}
                //if (this.comboBoxTest.Text == Resources.ComboValue_TRS)
                //{
                //    Complementos.Figura figura = this.ap.Configuracion.Figura_TRS;
                //    int estimulos = this.ap.Configuracion.MaxEstimulos_TRS;
                //    int visualizacion = this.ap.Configuracion.TiempoVisualizacion_TRS;
                //    int reaccion = this.ap.Configuracion.TiempoReaccion_TRS;
                //    int tecla_reaccion = (this.ap.Configuracion.Tecla1_TRS == "[Enter]") ? 13 : 32;
                //    Color color = this.ap.Configuracion.Color1_TRS;
                //    FormTRS f = new FormTRS(tecla_reaccion, color, estimulos, visualizacion, reaccion, figura);
                //    f.ShowDialog(this);
                //    this.ap.Adicionar_Resultado(f.Resultado);
                //    if (this.checkBoxResultado.Checked)
                //    {
                //        Reporte r = new Reporte(ap.Paciente, f.Resultado);
                //        r.ShowDialog(this);
                //    }
                //    return;
                //}
                //if (this.comboBoxTest.Text == Resources.ComboValue_RL)
                //{
                //    int vis1 = this.ap.Configuracion.TiempoVisualizacion1_RL;
                //    int oc1 = this.ap.Configuracion.TiempoOcultamiento1_RL;
                //    int vis15 = this.ap.Configuracion.TiempoVisualizacion15_RL;
                //    int vis2 = this.ap.Configuracion.TiempoVisualizacion2_RL;
                //    int oc2 = this.ap.Configuracion.TiempoOcultamiento2_RL;
                //    int teclacorrecta = (this.ap.Configuracion.Tecla1_TRS == "[Enter]") ? 13 : 32;
                //    int teclaincorrecta = (this.ap.Configuracion.Tecla1_TRS == "[Enter]") ? 13 : 32;
                //    Recuerdo r = new Recuerdo(this, vis1, oc1, vis15, vis2, oc2, teclacorrecta, teclaincorrecta);
                //    r.ShowDialog(this);
                //    this.ap.Adicionar_Resultado(r.Resultado);

                //    if (this.checkBoxResultado.Checked)
                //    {
                //        Reporte rep = new Reporte(ap.Paciente, r.Resultado);
                //        rep.ShowDialog(this);
                //    }
                //    r = null;
                //    return;
                //}
                //if (this.comboBoxTest.Text == Resources.Combovalue_EM)
                //{
                //    int maxEst = (int)this.numericUpDown1.Value;
                //    int interv = (int)this.numericUpDown2.Value;
                //    int anchEst = (int)this.numericUpDown3.Value;
                //    int altoEst = (int)this.numericUpDown4.Value;
                //    int anchoZO = (int)this.numericUpDown5.Value;
                //    int areaCorrecta = (int)this.numericUpDown6.Value;
                //    Color colorEst = this.panelColor1.BackColor;
                //    Color colorZO = this.panelColor2.BackColor;
                //    int teclaReaccion = (this.comboBox1.Text == "[Espacio]") ? 32 : 13;

                //    TimeEstimation t = new TimeEstimation(maxEst, interv, anchEst, altoEst, anchoZO, areaCorrecta, colorEst, colorZO, teclaReaccion);
                //    t.ShowDialog(this);
                //    this.ap.Adicionar_Resultado(t.r);

                //    if (this.checkBoxMostrarResultado.Checked)
                //    {
                //        Reporte rep = new Reporte(ap.Paciente, t.r);
                //        rep.ShowDialog(this);
                //    }
                //}
                #endregion

                // PARCHE PARA TEST POR EDADES
                //if (!CorrectTestForAge())
                //{
                //    var r = new Resp(string.Format(Resources.MSG_Select_Test, ap.Paciente.Edad));
                //    r.ShowDialog(this);
                //    return;
                //}

                if (this.comboBoxTest.Text == Resources.ComboValue_ASS)
                {
                    int     bloques        = this.ap.Configuracion.Bloques_ASS;
                    int     estimulos      = this.ap.Configuracion.EstimulosBloques_ASS;
                    int     visualizacion  = this.ap.Configuracion.TiempoVisualizacion_ASS;
                    int     ocultamiento   = this.ap.Configuracion.TiempoOcultamiento_ASS;
                    int     tecla_reaccion = (this.ap.Configuracion.TeclaTarget_ASS == "[Enter]") ? 13 : 32;
                    int     index          = this.ap.Configuracion.ImageIndex_ASS;
                    FormASS f2             = this.ap.Configuracion.Estimulo_ASS == 0 ?
                                             new FormASS(false, this.ap.Paciente.Codigo, this.ap.Configuracion.Imagenes_ASS_IMG, index, bloques, estimulos, visualizacion, ocultamiento, tecla_reaccion, this.ap.Configuracion.Color_Fondo_ASS, (TypeOf_AS_Test)this.ap.Configuracion.Estimulo_ASS) :
                                             new FormASS(false, this.ap.Paciente.Codigo, this.ap.Configuracion.Imagenes_ASS_FIG, index, bloques, estimulos, visualizacion, ocultamiento, tecla_reaccion, this.ap.Configuracion.Color_Fondo_ASS, (TypeOf_AS_Test)this.ap.Configuracion.Estimulo_ASS);
                    this.ap.ManageRunTest(this, f2, 10, true);
                    if (this.checkBoxResultado.Checked)
                    {
                        Resultado_AS res = ap.ExtractResultFromPaciente();
                        if (res == null)
                        {
                            var resp = new Resp("Este paciente no ha realizado ninguna prueba", "Paciente sin consultarse");
                            resp.ShowDialog(this);
                            return;
                        }
                        var r = new FormExport2PDF(ap.Paciente, res);
                        r.ShowDialog(this);
                    }
                    return;
                }
                if (this.comboBoxTest.Text == Resources.ComboValue_ASS_L)
                {
                    int   bloques        = this.ap.Configuracion.Bloques_ASS_L;
                    int   estimulos      = this.ap.Configuracion.EstimulosBloques_ASS_L;
                    int   visualizacion  = this.ap.Configuracion.TiempoVisualizacion_ASS_L;
                    int   ocultamiento   = this.ap.Configuracion.TiempoOcultamiento_ASS_L;
                    int   tecla_reaccion = (this.ap.Configuracion.TeclaTarget_ASS_L == "[Enter]") ? 13 : 32;
                    int   index          = this.ap.Configuracion.Letra_Diana_ASS_L;
                    Color color          = this.ap.Configuracion.Color_Letras_ASS_L;
                    var   f2             = new FormASSL(false, this.ap.Paciente.Codigo, this.ap.Configuracion.Letras_ASS_L, index, bloques, estimulos, visualizacion, ocultamiento, tecla_reaccion, this.ap.Configuracion.Color_Fondo_ASS_L, color);
                    this.ap.ManageRunTest(this, f2, 10, true);
                    if (this.checkBoxResultado.Checked)
                    {
                        Resultado_AS res = ap.ExtractResultFromPaciente();
                        if (res == null)
                        {
                            var resp = new Resp("Este paciente no ha realizado ninguna prueba", "Paciente sin consultarse");
                            resp.ShowDialog(this);
                            return;
                        }
                        var r = new FormExport2PDF(ap.Paciente, res);
                        r.ShowDialog(this);
                    }
                    return;
                }
                if (this.comboBoxTest.Text == Resources.ComboValue_ASC)
                {
                    int bloques        = this.ap.Configuracion.Bloques_ASC;
                    int estimulos      = this.ap.Configuracion.EstimulosBloques_ASC;
                    int visualizacion  = this.ap.Configuracion.TiempoVisualizacion_ASC;
                    int ocultamiento   = this.ap.Configuracion.TiempoOcultamiento_ASC;
                    int tecla_reaccion = (this.ap.Configuracion.TeclaTarget_ASS == "[Enter]") ? 13 : 32;
                    int index          = this.ap.Configuracion.ImageIndex1_ASC;
                    int index1         = this.ap.Configuracion.ImageIndex2_ASC;

                    FormASC f2 = this.ap.Configuracion.Estimulo_ASC == 0 ?
                                 new FormASC(false, this.ap.Paciente.Codigo, index, index1, this.ap.Configuracion.Imagenes_ASC_IMG, bloques, estimulos, visualizacion, ocultamiento, tecla_reaccion, this.ap.Configuracion.Color_Fondo_ASC, (TypeOf_AS_Test)this.ap.Configuracion.Estimulo_ASC) :
                                 new FormASC(false, this.ap.Paciente.Codigo, index, index1, this.ap.Configuracion.Imagenes_ASC_FIG, bloques, estimulos, visualizacion, ocultamiento, tecla_reaccion, this.ap.Configuracion.Color_Fondo_ASC, (TypeOf_AS_Test)this.ap.Configuracion.Estimulo_ASC);
                    this.ap.ManageRunTest(this, f2, 10, true);
                    if (this.checkBoxResultado.Checked)
                    {
                        Resultado_AS res = ap.ExtractResultFromPaciente();
                        if (res == null)
                        {
                            var resp = new Resp("Este paciente no ha realizado ninguna prueba", "Paciente sin consultarse");
                            resp.ShowDialog(this);
                            return;
                        }
                        var r = new FormExport2PDF(ap.Paciente, res);
                        r.ShowDialog(this);
                    }
                    return;
                }
                if (this.comboBoxTest.Text == Resources.ComboValue_ASC_L)
                {
                    int bloques        = this.ap.Configuracion.Bloques_ASC_L;
                    int estimulos      = this.ap.Configuracion.EstimulosBloques_ASC_L;
                    int visualizacion  = this.ap.Configuracion.TiempoVisualizacion_ASC_L;
                    int ocultamiento   = this.ap.Configuracion.TiempoOcultamiento_ASC_L;
                    int tecla_reaccion = (this.ap.Configuracion.TeclaTarget_ASC_L == "[Enter]") ? 13 : 32;
                    int index          = this.ap.Configuracion.Index_Diana1_ASC_L;
                    int index1         = this.ap.Configuracion.Index_Diana2_ASC_L;
                    //string secuencia_letras = this.ap.Configuracion.Letras_ASC_L;
                    var f2 = new FormASCL(false, this.ap.Paciente.Codigo, index, index1, this.ap.Configuracion.Letras_ASC_L, bloques, estimulos, visualizacion, ocultamiento, tecla_reaccion, this.ap.Configuracion.Color_Fondo_ASC, this.ap.Configuracion.Color_Letras_ASC_L);
                    this.ap.ManageRunTest(this, f2, 10, true);
                    if (this.checkBoxResultado.Checked)
                    {
                        Resultado_AS res = ap.ExtractResultFromPaciente();
                        if (res == null)
                        {
                            var resp = new Resp("Este paciente no ha realizado ninguna prueba", "Paciente sin consultarse");
                            resp.ShowDialog(this);
                            return;
                        }
                        var r = new FormExport2PDF(ap.Paciente, res);
                        r.ShowDialog(this);
                    }
                    return;
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="appInfo"></param>
        /// <param name="res"></param>
        protected void ResponseExceptionEnd(AuthorizationFilterContext context, AppIdentity appInfo, Resp res)
        {
            string rUrl = res.IsRespType(RespTypes.UserUnLogin)
                ? InterReqHelper.GetUnloginPage(context.HttpContext, appInfo)
                : InterReqHelper.GetErrorPage(context.HttpContext, appInfo, res);

            if (string.IsNullOrEmpty(rUrl))
            {
                context.Result = new ContentResult()
                {
                    ContentType = "application/json; charset=utf-8",
                    Content     = $"{{\"ret\":{res.ret},\"msg\":\"{res.msg}\"}}"
                };
                return;
            }

            context.Result = new RedirectResult(rUrl);
            return;
        }
Esempio n. 7
0
 /// <summary>
 ///  【业务响应】是否是Success
 /// </summary>
 /// <param name="res"></param>
 /// <returns></returns>
 public static bool IsSuccess(this Resp res) =>
 res.ret == 0;
Esempio n. 8
0
 /// <summary>
 ///  【系统响应】
 /// </summary>
 /// <param name="res"></param>
 /// <returns></returns>
 public static bool IsSysOk(this Resp res) =>
 res.sys_ret == 0;
Esempio n. 9
0
 public void Headers_cannot_be_null()
 {
     response = new Resp { Headers = null };
     AssertErrorMessage("Headers cannot be null");
 }
Esempio n. 10
0
        //
        // Make external XMLRPC request
        //
        private Hashtable GenericXMLRPCRequest(Hashtable ReqParams, string method)
        {
            if (m_debug)
            {
                m_log.DebugFormat("[{0}]: GenericXMLRPCRequest Method:{1}", m_moduleName, method);
            }
            ArrayList SendParams = new ArrayList();

            SendParams.Add(ReqParams);

            // Send Request
            XmlRpcResponse Resp;

            try
            {
                XmlRpcRequest Req = new XmlRpcRequest(method, SendParams);
                Resp = Req.Send(m_SearchServer, 30000);
                if (m_debug)
                {
                    string reqDebug = Resp.ToString();
                    m_log.DebugFormat("[{0}]: Answer from SearchServer: {1}", m_moduleName, reqDebug);
                }
            }
            catch (WebException ex)
            {
                m_log.ErrorFormat("[{0}]: (1) Unable to connect to Search Server {1}.  Exception {2}", m_moduleName, m_SearchServer, ex);

                Hashtable ErrorHash = new Hashtable();
                ErrorHash["success"]      = false;
                ErrorHash["errorMessage"] = "Unable to search at this time. ";
                ErrorHash["errorURI"]     = "";

                return(ErrorHash);
            }
            catch (SocketException ex)
            {
                m_log.ErrorFormat("[{0}]: (2) Unable to connect to Search Server {1}. Exception {2}", m_moduleName, m_SearchServer, ex);

                Hashtable ErrorHash = new Hashtable();
                ErrorHash["success"]      = false;
                ErrorHash["errorMessage"] = "Unable to search at this time. ";
                ErrorHash["errorURI"]     = "";

                return(ErrorHash);
            }
            catch (XmlException ex)
            {
                m_log.ErrorFormat("[{0}]: (3GetHashCode) Unable to connect to Search Server {1}. Exception {2}", m_moduleName, m_SearchServer, ex.GetHashCode());
                m_log.ErrorFormat("[{0}]: (3data) Unable to connect to Search Server {1}. Exception {2}", m_moduleName, m_SearchServer, ex.GetType());
                m_log.ErrorFormat("[{0}]: (3HelpLink) Unable to connect to Search Server {1}. Exception {2}", m_moduleName, m_SearchServer, ex.HelpLink);
                m_log.ErrorFormat("[{0}]: (3InnerException) Unable to connect to Search Server {1}. Exception {2}", m_moduleName, m_SearchServer, ex.InnerException);
                m_log.ErrorFormat("[{0}]: (3LineNumber) Unable to connect to Search Server {1}. Exception {2}", m_moduleName, m_SearchServer, ex.LineNumber);
                m_log.ErrorFormat("[{0}]: (3LinePosition) Unable to connect to Search Server {1}. Exception {2}", m_moduleName, m_SearchServer, ex.LinePosition);
                m_log.ErrorFormat("[{0}]: (3Source) Unable to connect to Search Server {1}. Exception {2}", m_moduleName, m_SearchServer, ex.Source);
                m_log.ErrorFormat("[{0}]: (3SourceUri) Unable to connect to Search Server {1}. Exception {2}", m_moduleName, m_SearchServer, ex.SourceUri);
                m_log.ErrorFormat("[{0}]: (3StackTrace) Unable to connect to Search Server {1}. Exception {2}", m_moduleName, m_SearchServer, ex.StackTrace);
                m_log.ErrorFormat("[{0}]: (3TargetSite) Unable to connect to Search Server {1}. Exception {2}", m_moduleName, m_SearchServer, ex.TargetSite);
                m_log.ErrorFormat("[{0}]: (3ToString) Unable to connect to Search Server {1}. Exception {2}", m_moduleName, m_SearchServer, ex.ToString());
                Hashtable ErrorHash = new Hashtable();
                ErrorHash["success"]      = false;
                ErrorHash["errorMessage"] = "Unable to search at this time. ";
                ErrorHash["errorURI"]     = "";

                return(ErrorHash);
            }
            if (Resp.IsFault)
            {
                m_log.ErrorFormat("[{0}]: response (IsFault): {1}", m_moduleName, Resp.ToString());
                Hashtable ErrorHash = new Hashtable();
                ErrorHash["success"]      = false;
                ErrorHash["errorMessage"] = "Unable to search at this time. ";
                ErrorHash["errorURI"]     = "";
                return(ErrorHash);
            }
            Hashtable RespData = (Hashtable)Resp.Value;

            return(RespData);
        }
Esempio n. 11
0
        /// <summary>
        /// 根据片段获取可能的主题名字, 只拿 10 条
        /// </summary>
        /// <param name="segment"></param>
        /// <returns></returns>
        public static async Task <Resp> GetTypeAheadBySegmentAsync(string segment)
        {
            List <string> list = await GetThemeNameBySegmentAsync(segment, 10);

            return(Resp.Success(list));
        }
Esempio n. 12
0
 public NoneOauthAdapter()
 {
     _errResp=new Resp().WithResp(SysRespTypes.NotImplement, "未知Oauth应用平台!");
 }
Esempio n. 13
0
        private void UserAuthErrorReponse(AuthorizationFilterContext context, AppIdentity appInfo, Resp res)
        {
            if (!res.IsRespType(RespTypes.UnLogin))
            {
                ResponseExceptionEnd(context, res);
                return;
            }

            // 重定向用户登录页
            if (!string.IsNullOrEmpty(AppWebInfoHelper.LoginUrl) &&
                appInfo.SourceMode == AppSourceMode.Browser)
            {
                var req  = context.HttpContext.Request;
                var rUrl = string.Concat(req.Path, req.QueryString);

                var newUrl = string.Concat(AppWebInfoHelper.LoginUrl, "?rurl=" + rUrl.UrlEncode());

                context.Result = new RedirectResult(newUrl);
                return;
            }
            context.Result = new JsonResult(res);
            return;
        }
Esempio n. 14
0
 private void Callback() => Resp.TrySetCanceled();
Esempio n. 15
0
        public static string MoneyToString(decimal Amount)
        {
            try
            {
                string Resp, Tien, DOC, Dem, Nhom, Chu, So1, So2, So3, Dich;
                int    S;
                if (Amount == 0)
                {
                    Resp = "Không đồng";
                }
                else
                {
                    if (Amount > 999999999999)
                    {
                        Resp = "Số quá lớn";
                    }
                    else
                    {
                        if (Amount < 0)
                        {
                            Resp = "Trừ";
                        }
                        else
                        {
                            Resp = string.Empty;
                        }
                        Tien = string.Format("{0:###########0.00}", double.Parse(Amount.ToString()));
                        Tien = (Tien.PadLeft(15));
                        DOC  = Dem = string.Empty;
                        DOC  = DOC + "trăm  mươi  tỷ    ";
                        DOC  = DOC + "trăm  mươi  triệu ";
                        DOC  = DOC + "trăm  mươi  ngàn  ";
                        DOC  = DOC + "trăm  mươi  đồng  ";
                        DOC  = DOC + "trăm  mươi  xu    ";
                        Dem  = Dem + "một  hai  ba   bốn  năm  ";
                        Dem  = Dem + "sáu  bảy  tám  chín";


                        for (int i = 1; i < 6; i++)
                        {
                            Nhom = Tien.Substring(i * 3 - 3, 3);
                            if (Nhom != "".PadRight(3))
                            {
                                switch (Nhom)
                                {
                                case "000":
                                    Chu = (i == 4 ? "đồng " : "");
                                    break;

                                case ".00":
                                    Chu = "chẵn";
                                    break;

                                default:
                                    So1 = Nhom.Substring(0, 1);
                                    So2 = Nhom.Substring(1, 1);
                                    So3 = Nhom.Substring(Nhom.Length > 1 ? Nhom.Length - 1 : 0, 1);
                                    Chu = "";
                                    for (int j = 1; j < 4; j++)
                                    {
                                        Dich = "";
                                        if (int.TryParse(Nhom.Substring(j - 1, 1), out S) == false)
                                        {
                                            S = -1;
                                        }
                                        if (S > 0)
                                        {
                                            Dich  = Dem.Substring(S * 5 - 5, 4).Trim() + " ";
                                            Dich += DOC.Substring((i - 1) * 18 + j * 6 - 5 - 1, 5) + " ";
                                        }
                                        switch (j)
                                        {
                                        case 2:
                                            if (S == 1)
                                            {
                                                Dich = "mười ";
                                            }
                                            else if (S == 0 && So3 != "0")
                                            {
                                                if ((int.Parse(So1) >= 1 && int.Parse(So1) <= 9) ||
                                                    (So1 == "0" && i == 4))
                                                {
                                                    Dich = "lẻ ";
                                                }
                                            }
                                            break;

                                        case 3:
                                            if (S == 0 && Nhom != "".PadRight(2) + "0")
                                            {
                                                Dich = DOC.Substring((i - 1) * 18 + j * 6 - 5 - 1, 5).Trim() + "".PadRight(1);
                                            }
                                            else if (S == 5 && So2 != "".PadRight(1) && So2 != "0")
                                            {
                                                Dich = "l" + Dich.Substring(1);
                                            }
                                            break;

                                        default:
                                            break;
                                        }
                                        Chu += Dich;
                                    }
                                    break;
                                }
                                Chu   = Chu.Replace("  ", " ");
                                Resp += Chu.Replace("mươi một", "mươi mốt");
                            }
                        }
                    }
                }
                return(Resp.Substring(0, 1).ToUpper() + Resp.Substring(1));
            }
            catch (Exception)
            {
                return("");
            }
        }
Esempio n. 16
0
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="index"></param>
        /// <param name="rows"></param>
        /// <param name="search"></param>
        /// <returns></returns>
        public async Task <Resp> GetListAsync(int index, int rows, string search)
        {
            Resp result = await GetListAsync(index, rows, search, Segment.SegmentState.NotSelected);

            return(result);
        }
Esempio n. 17
0
 public ActionResult _401()
 {
     return(Pack(Resp.NeedLogin(null, "请重新登录")));
 }
Esempio n. 18
0
        public void Status_must_start_with_integer_status_followed_by_a_space_and_a_reason_phrase()
        {
            response = new Resp { Status = "200" };
            AssertErrorMessage("Status must include integer status followed by a space and a reason phrase: 200");

            response = new Resp { Status = "200 " };
            AssertErrorMessage("Status must include integer status followed by a space and a reason phrase: 200 ");

            response = new Resp { Status = " Hi" };
            AssertErrorMessage("Status must include integer status followed by a space and a reason phrase:  Hi");

            response = new Resp { Status = "200 Foo" };
            AssertValid();

            response = new Resp { Status = "200 Foo Bar" };
            AssertValid();
        }
Esempio n. 19
0
 public NoneOauthAdapter(Resp errResp)
 {
     _errResp = errResp;
 }
Esempio n. 20
0
 public void Can_raise_exception_if_validation_fails()
 {
     response = new Resp { Status = null };
     Owin.Lint.Validate(response);
 }
Esempio n. 21
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="context"></param>
 /// <param name="res"></param>
 protected void ResponseExceptionEnd(AuthorizationFilterContext context, Resp res)
 {
     throw new RespException(res.sys_ret, res.ret, res.msg);
 }
Esempio n. 22
0
 public ActionResult NotFound401()
 {
     return(Pack(Resp.NeedLogin(Resp.NONE, "请重新登录")));
 }
Esempio n. 23
0
 public void BeforeEach()
 {
     response      = new Resp();
     ErrorMessages = null;
 }
Esempio n. 24
0
        //
        // Make external XMLRPC request
        //
        private Hashtable GenericXMLRPCRequest(Hashtable ReqParams, string method)
        {
            ArrayList SendParams = new ArrayList();

            SendParams.Add(ReqParams);

            // Send Request
            XmlRpcResponse Resp;

            try
            {
                XmlRpcRequest Req = new XmlRpcRequest(method, SendParams);
                Resp = Req.Send(m_SearchServer, 30000);
//				m_log.ErrorFormat("[SEARCH]response: "+Resp.ToString());
            }
            catch (WebException ex)
            {
                m_log.ErrorFormat("[SEARCH]1: Unable to connect to Search " +
                                  "Server {0}.  Exception {1}", m_SearchServer, ex);

                Hashtable ErrorHash = new Hashtable();
                ErrorHash["success"]      = false;
                ErrorHash["errorMessage"] = "Unable to search at this time. ";
                ErrorHash["errorURI"]     = "";

                return(ErrorHash);
            }
            catch (SocketException ex)
            {
                m_log.ErrorFormat(
                    "[SEARCH]2: Unable to connect to Search Server {0}. " +
                    "Exception {1}", m_SearchServer, ex);

                Hashtable ErrorHash = new Hashtable();
                ErrorHash["success"]      = false;
                ErrorHash["errorMessage"] = "Unable to search at this time. ";
                ErrorHash["errorURI"]     = "";

                return(ErrorHash);
            }
            catch (XmlException ex)
            {
                m_log.ErrorFormat(
                    "[SEARCH]3: Unable to connect to Search Server {0}. " +
                    "Exception {1}", m_SearchServer, ex);

                Hashtable ErrorHash = new Hashtable();
                ErrorHash["success"]      = false;
                ErrorHash["errorMessage"] = "Unable to search at this time. ";
                ErrorHash["errorURI"]     = "";

                return(ErrorHash);
            }
            if (Resp.IsFault)
            {
                m_log.ErrorFormat("[SEARCH]response (IsFault): " + Resp.ToString());
                Hashtable ErrorHash = new Hashtable();
                ErrorHash["success"]      = false;
                ErrorHash["errorMessage"] = "Unable to search at this time. ";
                ErrorHash["errorURI"]     = "";
                return(ErrorHash);
            }
            Hashtable RespData = (Hashtable)Resp.Value;

            return(RespData);
        }
Esempio n. 25
0
 /// <summary>   接受微信支付通知后需要返回的信息 </summary>
 public string GetCallBackReturnXml(Resp res)
 {
     return(string.Format(
                $"<xml><return_code><![CDATA[{(res.IsSuccess() ? "SUCCESS" : "FAIL")}]]></return_code><return_msg><![CDATA[{res.msg}]]></return_msg></xml>"));
 }
Esempio n. 26
0
 /// <summary>
 /// 【业务响应】是否是对应的类型
 /// </summary>
 /// <param name="res"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 public static bool IsRespType(this Resp res, RespTypes type) =>
 res.ret == (int)type;
Esempio n. 27
0
        private async Task MyMiddleware(HttpContext context)
        {
            dataRepository dr      = new dataRepository(Configuration, xenvironment);
            var            bodyStr = "";

            byte[] data;
            Resp   resp = await dr.postRepository(bodyStr);

            var    req         = context.Request;
            string contentType = context.Request.ContentType;

            req.EnableRewind();
            using (StreamReader reader
                       = new StreamReader(req.Body, Encoding.UTF8, true, 1024, true))
            {
                bodyStr = reader.ReadToEnd();
            }
            req.Body.Position = 0;
            string metod        = context.Request.Method;
            string stringHeader = (context.Request.ContentType == null ? "": context.Request.ContentType);

            if (stringHeader.ToLower() == "application/json")
            {
                if ((bodyStr.Trim() != ""))
                {
                    string verbType = context.Request.Method;
                    if (verbType.ToLower() == "post")
                    {
                        resp = await dr.postRepository(bodyStr);

                        context.Response.StatusCode = resp.resp;
                        data = Encoding.UTF8.GetBytes(resp.message);
                        context.Response.ContentType = "application/json";
                        await context.Response.Body.WriteAsync(data, 0, data.Length);

                        return;
                    }
                    else if (verbType.ToLower() == "put")
                    {
                    }
                    else
                    {
                        context.Response.StatusCode = 400;
                        data = Encoding.UTF8.GetBytes("{\"message\": \"El verbo " + verbType + " no ha sido habilitado en la API \"}");
                        context.Response.ContentType = "application/json";
                        await context.Response.Body.WriteAsync(data, 0, data.Length);

                        return;
                    }
                }
                else
                {
                    context.Response.StatusCode = 400;
                    data = Encoding.UTF8.GetBytes("{\"message\": \"Debe incluir información en el Body de la petición \"}");
                    context.Response.ContentType = "application/json";
                    await context.Response.Body.WriteAsync(data, 0, data.Length);

                    return;
                }
            }
            else
            {
                context.Response.StatusCode = 500;
                data = Encoding.UTF8.GetBytes("{\"message\": \"No se aceptan solicitudes " + stringHeader.ToLower() + "\"}");
                context.Response.ContentType = "application/json";
                await context.Response.Body.WriteAsync(data, 0, data.Length);

                return;
            }
        }
Esempio n. 28
0
 /// <summary>
 /// 【系统响应】是否是对应的类型
 /// </summary>
 /// <param name="res"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 public static bool IsSysRespType(this Resp res, SysRespTypes type) =>
 res.sys_ret == (int)type;
Esempio n. 29
0
        /// <summary>
        /// 验证list集合里面的代理IP
        /// </summary>
        /// <param name="msg"></param>
        public static void ProxyVerification(object msg, string name)
        {
            if (null == msg)
            {
                return;
            }
            ProxyViewModel proxy = (ProxyViewModel)msg;

            try
            {
                using (WebClient web = new WebClient())
                {
                    try
                    {
                        HttpWebRequest  Req;
                        HttpWebResponse Resp;
                        WebProxy        proxyObject = new WebProxy(proxy.ProxyIP, proxy.ProxyPort);
                        Req         = WebRequest.Create("https://www.baidu.com") as HttpWebRequest;
                        Req.Proxy   = proxyObject; //设置代理
                        Req.Timeout = 3000;        //超时
                        Resp        = (HttpWebResponse)Req.GetResponse();
                        Encoding bin = Encoding.GetEncoding("UTF-8");
                        using (StreamReader sr = new StreamReader(Resp.GetResponseStream(), bin))
                        {
                            string str = sr.ReadToEnd();
                            if (str.Contains("百度"))
                            {
                                Resp.Close();
                                // 更新验证时间
                                proxy.CreateTime = DateTime.Now;
                                // 更新验证状态
                                proxy.State = 1;
                                // 验证通过,归队
                                QueueOperation(proxy, IQueueType.EnQueue);
                                ip_agency_data info = new ip_agency_data()
                                {
                                    ip_address    = proxy.ProxyIP,
                                    ip_port       = proxy.ProxyPort.ToString(),
                                    ip_createtime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")),
                                    ip_sourcename = name
                                };
                                //插入到数据库
                                Program.Add_IPAddress(info);

                                System.Console.WriteLine("{0}> [{2}]自动验证成功{1}", DateTime.Now.ToString("s"), proxy.Id, name);
                            }
                            else
                            {
                                System.Console.WriteLine("{0}> [{2}]自动验证失败{1}", DateTime.Now.ToString("s"), proxy.Id, name);
                            }
                        }
                    }
                    catch (Exception ex)
                    { }
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine("{0}> [{3}]自动验证异常{1} {2}", DateTime.Now.ToString("s"), proxy.Id, e.Message, name);
            }
        }
Esempio n. 30
0
        private void buttonEnsayo_Click(object sender, EventArgs e)
        {
            if (comboBoxTest.SelectedItem == null)
            {
                var r = new Resp(Resources.MSG_Select_Test);
                r.ShowDialog(this);
                return;
            }
            if (comboBoxPaciente.SelectedItem == null)
            {
                var r = new Resp(Resources.MSG_Select_Patient);
                r.ShowDialog(this);
                return;
            }

            if (ap.Paciente != null)
            {
                if (this.comboBoxTest.Text == Resources.ComboValue_MF)
                {
                    //FullScreenBlack f = new FullScreenBlack("E_MF");
                    //f.ShowDialog(this);
                    //return;
                }
                if (this.comboBoxTest.Text == Resources.ComboValue_ASS)
                {
                    int     bloques        = this.ap.Configuracion.Bloques_ASS;
                    int     estimulos      = this.ap.Configuracion.EstimulosBloques_ASS;
                    int     visualizacion  = this.ap.Configuracion.TiempoVisualizacion_ASS;
                    int     ocultamiento   = this.ap.Configuracion.TiempoOcultamiento_ASS;
                    int     tecla_reaccion = (this.ap.Configuracion.TeclaTarget_ASS == "[Enter]") ? 13 : 32;
                    int     index          = this.ap.Configuracion.ImageIndex_ASS;
                    FormASS f2             = this.ap.Configuracion.Estimulo_ASS == 0 ?
                                             new FormASS(true, this.ap.Paciente.Codigo, this.ap.Configuracion.Imagenes_ASS_IMG, index, bloques, estimulos, visualizacion, ocultamiento, tecla_reaccion, this.ap.Configuracion.Color_Fondo_ASS, (TypeOf_AS_Test)this.ap.Configuracion.Estimulo_ASS) :
                                             new FormASS(true, this.ap.Paciente.Codigo, this.ap.Configuracion.Imagenes_ASS_FIG, index, bloques, estimulos, visualizacion, ocultamiento, tecla_reaccion, this.ap.Configuracion.Color_Fondo_ASS, (TypeOf_AS_Test)this.ap.Configuracion.Estimulo_ASS);

                    f2.ShowDialog(this);
                    return;
                }
                if (this.comboBoxTest.Text == Resources.ComboValue_ASC)
                {
                    int bloques        = this.ap.Configuracion.Bloques_ASC;
                    int estimulos      = this.ap.Configuracion.EstimulosBloques_ASC;
                    int visualizacion  = this.ap.Configuracion.TiempoVisualizacion_ASC;
                    int ocultamiento   = this.ap.Configuracion.TiempoOcultamiento_ASC;
                    int tecla_reaccion = (this.ap.Configuracion.TeclaTarget_ASS == "[Enter]") ? 13 : 32;
                    int index          = this.ap.Configuracion.ImageIndex1_ASC;
                    int index1         = this.ap.Configuracion.ImageIndex2_ASC;

                    FormASC f2 = this.ap.Configuracion.Estimulo_ASC == 0 ?
                                 new FormASC(true, this.ap.Paciente.Codigo, index, index1, this.ap.Configuracion.Imagenes_ASC_IMG, bloques, estimulos, visualizacion, ocultamiento, tecla_reaccion, this.ap.Configuracion.Color_Fondo_ASC, (TypeOf_AS_Test)this.ap.Configuracion.Estimulo_ASC) :
                                 new FormASC(true, this.ap.Paciente.Codigo, index, index1, this.ap.Configuracion.Imagenes_ASC_FIG, bloques, estimulos, visualizacion, ocultamiento, tecla_reaccion, this.ap.Configuracion.Color_Fondo_ASC, (TypeOf_AS_Test)this.ap.Configuracion.Estimulo_ASC);

                    f2.ShowDialog(this);

                    return;
                }
                if (this.comboBoxTest.Text == Resources.ComboValue_ASC_L)
                {
                    int bloques        = this.ap.Configuracion.Bloques_ASC_L;
                    int estimulos      = this.ap.Configuracion.EstimulosBloques_ASC_L;
                    int visualizacion  = this.ap.Configuracion.TiempoVisualizacion_ASC_L;
                    int ocultamiento   = this.ap.Configuracion.TiempoOcultamiento_ASC_L;
                    int tecla_reaccion = (this.ap.Configuracion.TeclaTarget_ASC_L == "[Enter]") ? 13 : 32;
                    int index          = this.ap.Configuracion.Index_Diana1_ASC_L;
                    int index1         = this.ap.Configuracion.Index_Diana2_ASC_L;
                    //string secuencia_letras = this.ap.Configuracion.Letras_ASC_L;
                    var f2 = new FormASCL(true, this.ap.Paciente.Codigo, index, index1, this.ap.Configuracion.Letras_ASC_L, bloques, estimulos, visualizacion, ocultamiento, tecla_reaccion, this.ap.Configuracion.Color_Fondo_ASC, this.ap.Configuracion.Color_Letras_ASC_L);
                    f2.ShowDialog(this);
                    return;
                }
                if (this.comboBoxTest.Text == Resources.ComboValue_ASS_L)
                {
                    int   bloques        = this.ap.Configuracion.Bloques_ASS_L;
                    int   estimulos      = this.ap.Configuracion.EstimulosBloques_ASS_L;
                    int   visualizacion  = this.ap.Configuracion.TiempoVisualizacion_ASS_L;
                    int   ocultamiento   = this.ap.Configuracion.TiempoOcultamiento_ASS_L;
                    int   tecla_reaccion = (this.ap.Configuracion.TeclaTarget_ASS_L == "[Enter]") ? 13 : 32;
                    int   index          = this.ap.Configuracion.Letra_Diana_ASS_L;
                    Color color          = this.ap.Configuracion.Color_Letras_ASS_L;
                    var   f2             = new FormASSL(true, this.ap.Paciente.Codigo, this.ap.Configuracion.Letras_ASS_L, index, bloques, estimulos, visualizacion, ocultamiento, tecla_reaccion, this.ap.Configuracion.Color_Fondo_ASS_L, color);
                    f2.ShowDialog(this);
                    return;
                }
                if (this.comboBoxTest.Text == Resources.ComboValue_PVA)
                {
                    //FullScreenBlack f = new FullScreenBlack("E_PVA", this.ap.Configuracion.Imagenes_Ej);
                    //f.ShowDialog(this);
                    //return;
                }
            }
        }
Esempio n. 31
0
 public static async Task SendResp(WebSocket ws, Resp resp)
 {
     byte[] respBytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(resp));
     await ws.SendAsync(new ArraySegment <byte>(respBytes), WebSocketMessageType.Text, true,
                        CancellationToken.None);
 }
Esempio n. 32
0
        public void Status_cannot_be_null_or_blank()
        {
            response = new Resp { Status = null };
            AssertErrorMessage("Status cannot be null");

            response = new Resp { Status = " " };
            AssertErrorMessage("Status cannot be blank");

            response = new Resp { Status = "200 OK" };
            AssertValid();
        }
Esempio n. 33
0
        void aa(HttpListenerContext context)
        {
            //取得请求的对象
            HttpListenerRequest request = context.Request;
            Resp resp = new Resp();
            HttpListenerResponse response = context.Response;

            response.ContentEncoding = Encoding.UTF8;
            response.ContentType     = "application/json; charset=utf-8";
            if (request.LocalEndPoint.Address.Equals(IPAddress.Loopback))
            {
                var reader = new StreamReader(request.InputStream);
                var msg    = reader.ReadToEnd();
                if (request.HttpMethod.ToUpper() == "GET")
                {
                    resp.Code = 0;
                    resp.Msg  = DateTime.Now.ToString("F");
                }
                else
                if (request.HttpMethod.ToUpper() == "POST")
                {
                    var req = De(msg, new { ActionType = "" });
                    switch (req.ActionType)
                    {
                    case "StartProcess":
                        var yy = Serialize(new
                        {
                            ActionType = "StartProcess",
                            ActionData = new
                            {
                                FileName    = @"c:\windows\system32\notepad.exe",
                                WorkingPath = @"d:\temp",
                                Para        = @"test.txt"
                            }
                        }
                                           );
                        var ss = De(msg, new { ActionData = new { FileName = "", WorkingPath = "", Para = "" } }).ActionData;
                        if (ss != null)
                        {
                            //    string[] command = new string[]{
                            //        $" cmd /c  \"{Path.GetFileName(ss.FileName)}\" /D \"{ss.WorkingPath}\" \"{ss.FileName}\" \"{ss.WorkingPath}\" ",
                            //        //$" start  \"{Path.GetFileName(ss.FileName)}\" /D \"{ss.WorkingPath}\" \"{ss.FileName}\" \"{ss.WorkingPath}\" ",
                            //        "exit"
                            //    };
                            string outputResult;
                            resp.Code = exec(ss.FileName, ss.WorkingPath, ss.Para, out outputResult) ? 0 : 1;
                            //resp.Code = exec(command, out outputResult) ? 1 : 0;
                            resp.Msg  = outputResult;
                            resp.Data = msg;
                        }
                        else
                        {
                            resp.Code = 1;
                            resp.Msg  = "参数无效";
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
            else
            {
                //安全性,不支持从外部访问连接,但暂时无法禁止低权限用户使用该接口获得高权限程序运行能力,后续应该增加可使用的程序清单
                resp.Code = 1;
                resp.Msg  = $"仅限本机访问{request.LocalEndPoint},{request.RemoteEndPoint}";
            }
            byte[] buff   = Encoding.UTF8.GetBytes(Serialize(resp));
            Stream output = response.OutputStream;

            output.Write(buff, 0, buff.Length);
            output.Close();
        }
Esempio n. 34
0
 public void Status_can_only_contain_ASCII_characters()
 {
     response = new Resp { Status = "200 OK™½Neat" };
     AssertErrorMessage("Status cannot contain non-ASCII characters: 200 OK™½Neat");
 }
Esempio n. 35
0
 public static Resp ReadFrom(NetworkStream si) {
     Resp o = new Resp();
     String s = "";
     while (true) {
         int r = si.ReadByte();
         if (r < 0) throw new EndOfStreamException();
         if (r == (int)'\n') break;
         if (r != (int)'\r') s += (char)r;
     }
     o.Ok = s.StartsWith("+OK");
     o.Message = s;
     return o;
 }
Esempio n. 36
0
 public void BeforeEach()
 {
     response = new Resp();
     ErrorMessages = null;
 }
 public PatientProfileAcknowledgementResponse(Guid requestId, DateTime timestamp, Acknowledgement acknowledgement, Resp resp, Error error)
 {
     RequestId       = requestId;
     Timestamp       = timestamp;
     Acknowledgement = acknowledgement;
     Resp            = resp;
     Error           = error;
 }
Esempio n. 38
0
 public void Can_raise_exception_with_many_messaegs_if_validation_fails()
 {
     response = new Resp { Status = null, Headers = null };
     Owin.Lint.Validate(response);
 }
 public HipLinkContextConfirmation(string requestId, DateTime timestamp,
                                   AddContextsAcknowledgement acknowledgement, Error error, Resp resp)
 {
     RequestId       = requestId;
     Timestamp       = timestamp;
     Acknowledgement = acknowledgement;
     Error           = error;
     Resp            = resp;
 }
Esempio n. 40
0
        public static string Return(Resp resp, string originReq, string filter)
        {
            if (resp == Resp.Unmodified)
            {
                // res-hdr: ResponseHeader starts right after this message
                // res-body: ResponseBody starts after the header, thus ResponseHeader byte length
                // req-hdr=0 -> if reqmod so no reqheader redirected
                // null-body
                StringBuilder ICAPHeader = new StringBuilder();
                ICAPHeader.AppendLine("ICAP/1.0 200 OK");
                ICAPHeader.AppendLine("Server: LibICAP/0.1.0");
                ICAPHeader.AppendLine($"Date: {Tools.GetCurrentICAPDate()}");
                ICAPHeader.AppendLine("Connection: close");
                ICAPHeader.AppendLine("ISTag: W3E4R7U9-L2E4-2"); // ddd MMM dd yyyy HH:mm:ss 'GMT'
                ICAPHeader.AppendLine($"Encapsulated: req-hdr=0, null-body={originReq.ToString().CountBytes() + 2}");

                StringBuilder ResponseBuilder = new StringBuilder();

                ResponseBuilder.Append(ICAPHeader);
                ResponseBuilder.Append("\r\n");
                ResponseBuilder.Append(originReq + "\r\n");
                ResponseBuilder.Append("\r\n");

                return(ResponseBuilder.ToString());
            }
            else if (resp == Resp.NotAllowed)
            {
                var template = File.ReadAllText(@"./Models/Template.html"); //TODO: remove hardcoded path. Expl: used to modify template on the fly
                template = template.Replace("{AAP_POLICY}", filter);

                HTMLResponse response = new HTMLResponse
                {
                    Content = template
                };

                // Hex-Length: Chunk sizes within an encapsulated body (used to send message in chunks, splitting not needed for a static response)
                StringBuilder ResponseBody = new StringBuilder();
                ResponseBody.AppendLine($"{response.HexLength}");
                ResponseBody.AppendLine(response.Content);
                ResponseBody.AppendLine("0");
                //ResponseBody.Append("\r\n");
                //ResponseBody.Append("\r\n");

                StringBuilder ResponseHeader = new StringBuilder();
                ResponseHeader.AppendLine($"HTTP/1.1 403 Forbidden");
                ResponseHeader.AppendLine($"Date: {Tools.GetCurrentICAPDate()}");
                ResponseHeader.AppendLine("Server: Apache/1.3.12 (Unix)");
                ResponseHeader.AppendLine("Last-Modified: Thu, 02 Nov 2000 13:51:37 GMT");
                ResponseHeader.AppendLine("ETag: \"63600-1989-3a017169\"");
                ResponseHeader.AppendLine($"Content-Length: {response.Length}");
                ResponseHeader.AppendLine("Content-Type: text/html");
                //ResponseHeader.Append("\r\n");

                // res-hdr: ResponseHeader starts right after this message
                // res-body: ResponseBody starts after the header, thus ResponseHeader byte length
                StringBuilder ICAPHeader = new StringBuilder();
                ICAPHeader.AppendLine("ICAP/1.0 200 OK");
                ICAPHeader.AppendLine($"Date: {Tools.GetCurrentICAPDate()}");
                ICAPHeader.AppendLine("Server: LibICAP/1.0");
                ICAPHeader.AppendLine("Connection: close");
                ICAPHeader.AppendLine("ISTag: \"W3E4R7U9-L2E4-2\"");
                ICAPHeader.AppendLine($"Encapsulated: res-hdr=0, res-body={ResponseHeader.ToString().CountBytes() + 2}");
                //ICAPHeader.Append("\r\n");

                StringBuilder ResponseBuilder = new StringBuilder();

                ResponseBuilder.Append(ICAPHeader);
                ResponseBuilder.Append("\r\n");
                ResponseBuilder.Append(ResponseHeader);
                ResponseBuilder.Append("\r\n");
                ResponseBuilder.Append(ResponseBody);
                ResponseBuilder.Append("\r\n");
                ResponseBuilder.Append("\r\n");

                return(ResponseBuilder.ToString());
            }
            else if (resp == Resp.MovedPermanently)
            {
                StringBuilder ResponseHeader = new StringBuilder();
                ResponseHeader.AppendLine($"HTTP/1.1 301 Moved Permanently");
                ResponseHeader.AppendLine($"Location: http://www.example.org/index.asp");
                //ResponseHeader.Append("\r\n");


                StringBuilder ICAPHeader = new StringBuilder();
                ICAPHeader.AppendLine("ICAP/1.0 200 OK");
                ICAPHeader.AppendLine($"Date: {Tools.GetCurrentICAPDate()}");
                ICAPHeader.AppendLine("Server: LibICAP/1.0");
                ICAPHeader.AppendLine("Connection: close");
                ICAPHeader.AppendLine("ISTag: \"W3E4R7U9-L2E4-2\"");
                ICAPHeader.AppendLine($"Encapsulated: res-hdr=0, res-body={ResponseHeader.ToString().CountBytes() + 2}");

                StringBuilder ResponseBuilder = new StringBuilder();
                ResponseBuilder.Append(ICAPHeader);
                ResponseBuilder.Append("\r\n");
                ResponseBuilder.Append(ResponseHeader);
                ResponseBuilder.Append("\r\n");
                ResponseBuilder.Append("\r\n");
            }
            else if (resp == Resp.Example)
            {
                #region example
                //HTMLResponse response = new HTMLResponse
                //{
                //    Content = ""
                //};

                //StringBuilder ResponseBody = new StringBuilder();
                //ResponseBody.AppendLine("HTTP/1.1 200 OK");
                //ResponseBody.AppendLine("Date: Mon, 10 Jan 2000  09:55:21 GMT");
                //ResponseBody.AppendLine("Via: 1.0 icap.example.org (ICAP Example RespMod Service 1.1)");
                //ResponseBody.AppendLine("Server: Apache/1.3.6 (Unix)");
                //ResponseBody.AppendLine("ETag: \"63840-1ab7-378d415b\"");
                //ResponseBody.AppendLine("Content-Type: text/html");
                //ResponseBody.AppendLine($"Content-Length: {response.Length}");


                //StringBuilder ResponseFooter = new StringBuilder();
                //ResponseFooter.AppendLine($"{response.HexLength}");
                //ResponseFooter.AppendLine(response.Content);
                //ResponseFooter.AppendLine("0");

                //StringBuilder ResponseHeader = new StringBuilder();
                //ResponseHeader.AppendLine("ICAP/1.0 200 OK");
                //ResponseHeader.AppendLine($"Date: {Tools.GetCurrentICAPDate()}");
                //ResponseHeader.AppendLine("Server: LibICAP/1.0");
                //ResponseHeader.AppendLine("Connection: close");
                //ResponseHeader.AppendLine("ISTag: \"W3E4R7U9-L2E4-2\"");
                //ResponseHeader.AppendLine($"Encapsulated: res-hdr=0, res-body={ResponseBody.ToString().CountBytes() + 2}");


                //StringBuilder ResponseBuilder = new StringBuilder();

                //ResponseBuilder.Append(ResponseHeader);
                //ResponseBuilder.Append("\r\n");
                //ResponseBuilder.Append(ResponseBody);
                //ResponseBuilder.Append("\r\n");
                //ResponseBuilder.Append(ResponseFooter);
                //ResponseBuilder.Append("\r\n");
                //ResponseBuilder.Append("\r\n");

                //return ResponseBuilder.ToString();

                #endregion

                string[] split   = originReq.Split("\r\n\r\n"); // 0 = HTTP/1.1, 1 = <html>...
                string   content = split[2];

                HTMLResponse response = new HTMLResponse
                {
                    Content = content
                };

                // 0, 1
                //StringBuilder ResponseBody = new StringBuilder();
                //ResponseBody.AppendLine("HTTP/1.1 301 Moved Permanently");
                //ResponseBody.AppendLine("Location: http://example.com/");
                //ResponseBody.AppendLine("Via: 1.0 icap.example.org (ICAP Example RespMod Service 1.1)");
                //ResponseBody.AppendLine("Server: Apache/1.3.6 (Unix)");
                //ResponseBody.AppendLine("ETag: \"63840-1ab7-378d415b\"");
                //ResponseBody.AppendLine("Content-Type: text/html");
                //ResponseBody.AppendLine($"Content-Length: {response.Length}");

                // 0,2
                StringBuilder ResponseFooter = new StringBuilder();
                ResponseFooter.AppendLine($"{response.HexLength}");
                ResponseFooter.AppendLine(response.Content);
                ResponseFooter.AppendLine("0");

                StringBuilder ResponseHeader = new StringBuilder();
                ResponseHeader.AppendLine("ICAP/1.0 200 OK");
                ResponseHeader.AppendLine($"Date: {Tools.GetCurrentICAPDate()}");
                ResponseHeader.AppendLine("Server: LibICAP/1.0");
                ResponseHeader.AppendLine("Connection: close");
                ResponseHeader.AppendLine("ISTag: \"W3E4R7U9-L2E4-2\"");
                ResponseHeader.AppendLine($"Encapsulated: res-hdr=0, res-body={split[0].CountBytes() + 2}");
                // http://google.de

                StringBuilder ResponseBuilder = new StringBuilder();

                ResponseBuilder.Append(ResponseHeader);
                ResponseBuilder.Append("\r\n");
                ResponseBuilder.Append(split[0]);
                ResponseBuilder.Append("\r\n");
                ResponseBuilder.Append(ResponseFooter);
                ResponseBuilder.Append("\r\n");
                ResponseBuilder.Append("\r\n");

                string m = ResponseBuilder.ToString();

                return(ResponseBuilder.ToString());
            }
            return("");
        }
 public GatewayRevokedConsentRepresentation(Guid requestId, DateTime timestamp,
                                            ConsentUpdateResponse acknowledgement, Error error, Resp resp)
 {
     RequestId       = requestId;
     Timestamp       = timestamp;
     Acknowledgement = acknowledgement;
     Resp            = resp;
     Error           = error;
 }
Esempio n. 42
0
		private void AttachQueryResult (QueryResult qres, Resp resp)
		{
			if (qres != null) {
			
				qres.HitsAddedEvent += OnHitsAdded;
				qres.HitsSubtractedEvent += OnHitsSubtracted;
				qres.FinishedEvent += OnFinished;
				qres.CancelledEvent += OnCancelled;

				result.Add(qres, resp);
			}
		}
Esempio n. 43
0
		public string doQuery(webArgs wargs)
		{				 
			if (wargs.sessId == null || wargs.searchString == null || wargs.searchString == "")
				return NO_RESULTS;
						 
			log.Debug("WebBackEnd: Got Search String: " + wargs.searchString); 
			
			Query query = new Query();
			query.AddText (wargs.searchString);
			if (wargs.searchSource != null && wargs.searchSource != "")
			{
				query.AddSource(wargs.searchSource);
				query.AddDomain(QueryDomain.System);
			}
			else	
				query.AddDomain (wargs.globalSearch ? QueryDomain.Global:QueryDomain.System);

			QueryResult qres = new QueryResult ();
									
			//Note: QueryDriver.DoQuery() local invocation is used. 
			//The root tile is used only for adding hits and generating html.
			BT.SimpleRootTile root = new BT.SimpleRootTile (); 							
			root.Query = query;
			//root.SetSource (searchSource); Do not SetSource on root! 
											
			ResultPair rp = new ResultPair(root);
			bufferRenderContext bctx = new bufferRenderContext(rp);
			Resp resp = new Resp(rp, bctx, wargs.isLocalReq);

			AttachQueryResult (qres, resp);

			//Add sessionId-Resp mapping
			if (sessionResp.Contains(wargs.sessId)) 
				sessionResp[wargs.sessId] = resp;
			else
				sessionResp.Add(wargs.sessId, resp);	

			log.Info("WebBackEnd: Starting Query for string \"{0}\"", wargs.searchString);

			QueryDriver.DoQueryLocal (query, qres);

			//Wait only till we have enough results to display
			while ((result.Contains(qres)) && 
					(root.HitCollection.NumResults < 10)) 
				Thread.Sleep(100);
				
			if (root.HitCollection.IsEmpty)
				return NO_RESULTS;
						
			lock (root) {			
				root.Render(bctx);				
				return (getResultsLabel(root) + (wargs.isLocalReq ? bctx.buffer:bctx.bufferForExternalQuery));
			}			
		}
Esempio n. 44
0
        public string Top(int i, int cnt) {
            lock (this) {
                NetworkStream siso = sock.GetStream();
                SL.WriteLine(siso, "TOP " + i + " " + cnt);

                if ((resp = Resp.ReadFrom(siso)).Ok != true) throw new CommandFailedException(resp.Message);

                StringBuilder res = new StringBuilder();
                while (true) {
                    string s = RL.ReadLine(siso);
                    if (s.Equals(".")) break;
                    res.Append(s).Append("\r\n");
                }
                return res.ToString();
            }
        }
 public OnFetchAuthModeRequest(string requestId, DateTime timestamp, AuthModeFetch auth, Error error, Resp resp)
 {
     RequestId = requestId;
     Timestamp = timestamp;
     Auth      = auth;
     Error     = error;
     Resp      = resp;
 }