Ejemplo n.º 1
0
        public string GetPDFInvoice(FacturaElectronica payload, string accountId)
        {
            DataBase.Account accountData;
            IAccount         accountImp;
            string           imageQR, htmlInvoice, pdfInvoice;

            try
            {
                accountImp  = new AccountImp();
                accountData = accountImp.GetAccountById(accountId);
                if (accountData != null)
                {
                    imageQR     = Utils.BuildLinkAndQRCode(payload.Clave, payload.Emisor.Identificacion.Numero);
                    htmlInvoice = BuildHtmlInvoice(payload, imageQR, accountData.logoImage);
                    pdfInvoice  = BuildPDFInvoice(htmlInvoice);
                }
                else
                {
                    throw new Exception(Constants.Constants.fail_Get_account_data);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(pdfInvoice);
        }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (HttpContext.Current.Session["user"] == null)
                { // 如果当前登录会话结束,则返回主页
                    Response.Redirect("login.aspx");
                }

                if (Request.HttpMethod == "GET") //the request for the origin login page
                {
                    //
                }
                else if (Request.HttpMethod == "POST")
                {
                    // 删除该用户指定编号的任务
                    int        u_no = Convert.ToInt32(HttpContext.Current.Session["no"]);
                    AccountDao acc  = new AccountImp();
                    int        t_no = Convert.ToInt32(Request.Form["delete"]);
                    acc.DeleteTask(t_no, u_no);
                    Response.Write("<script>alert('删除成功!')</script>");
                    Response.Write("<script>window.location ='user.aspx'</script>");
                }
            }
        }
Ejemplo n.º 3
0
        public List <Task> GetAllTasks()
        {
            AccountDao acc = new AccountImp();

            int no = Convert.ToInt32(HttpContext.Current.Session["no"]);

            return(acc.GetTaskList(no));
        }
Ejemplo n.º 4
0
        public async Task <string> AuthenticationMHById(string accountId)
        {
            string valid_token = string.Empty;
            AuthenticationResponse authResponse, newAuthResponse;
            IAccount accountImp = new AccountImp();

            DataBase.Account accountInfo;
            bool             resultget;

            try
            {
                authResponse = new AuthenticationResponse();
                accountInfo  = accountImp.GetAccountById(accountId);

                lock (syncLockoAuthData)
                {
                    resultget = oAuthDataDictionary.TryGetValue(accountId, out authResponse);
                }

                if (!resultget)
                {
                    #region Agrega el registro por primera vez

                    authResponse = await AuthenticationMH(accountInfo.userATV, accountInfo.passwordATV);

                    if (authResponse != null)
                    {
                        authResponse.currentDateTime = DateTime.Now;
                        lock (syncLockoAuthData)
                        {
                            oAuthDataDictionary.GetOrAdd(accountId, authResponse);
                        }
                        valid_token = authResponse.access_token;
                    }
                    else
                    {
                        throw new Exception(Constants.Constants.fail_while_authenticate_against_oauth);
                    }

                    #endregion
                }
                else
                {
                    if (authResponse.expires_in > Utils.DifferenceInSeconds(authResponse.currentDateTime, DateTime.Now))
                    {
                        valid_token = authResponse.access_token;
                    }
                    else
                    {
                        newAuthResponse = await AuthenticationMH(accountInfo.userATV, accountInfo.passwordATV);

                        if (newAuthResponse != null)
                        {
                            lock (syncLockoAuthData)
                            {
                                oAuthDataDictionary.AddOrUpdate(accountId, authResponse, (k, v) => newAuthResponse);
                            }
                            valid_token = newAuthResponse.access_token;
                        }
                        else
                        {
                            throw new Exception(Constants.Constants.fail_while_authenticate_against_oauth);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(valid_token);
        }
Ejemplo n.º 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (HttpContext.Current.Session["user"] == null)
                { // 如果当前登录会话结束,则返回主页
                    Response.Redirect("login.aspx");
                }
                if (Request.HttpMethod == "GET") //the request for the origin login page
                {
                    //
                }
                else if (Request.HttpMethod == "POST")
                {
                    // POST 方法用来传输实体的主体
                    // user no
                    int no = (int)(HttpContext.Current.Session["no"]);
                    // time
                    string     time = DateTime.Now.ToString();
                    Task       task = new Task();
                    AccountDao acc  = new AccountImp();

                    if (Request.Form["go"] != null)
                    {
                        // 执行前往导航点
                        int instr = 1;
                        acc.BookTask(no, instr, time);
                        // 调用接口
                        string goal = Request.Form["dis"];
                        string note = task.func(instr, goal, "?", "?");

                        // 成功后返回
                        Response.Write("<script>alert('" + note + "')</script>");
                        Response.Write("<script>window.location ='user.aspx'</script>");
                    }
                    if (Request.Form["move"] != null)
                    {
                        // 执行移动
                        int instr = 2;
                        acc.BookTask(no, instr, time);
                        // 调用接口
                        string turn = Request.Form["moveInstr"];
                        string mile = Request.Form["mile"];
                        string note = task.func(instr, "?", turn, mile);

                        // 成功后返回
                        Response.Write("<script>alert('" + note + "')</script>");
                        Response.Write("<script>window.location ='user.aspx'</script>");
                    }
                    if (Request.Form["capture"] != null)
                    {
                        // 执行抓取
                        int instr = 3;
                        acc.BookTask(no, instr, time);
                        // 调用接口
                        string note = task.func(instr, "?", "?", "?");
                        // 成功后返回
                        Response.Write("<script>alert('" + note + "')</script>");
                        Response.Write("<script>window.location ='user.aspx'</script>");
                    }
                    if (Request.Form["cast"] != null)
                    {
                        // 执行天气
                        int instr = 4;
                        acc.BookTask(no, instr, time);
                        // 调用接口
                        string note = task.func(instr, "?", "?", "?");

                        // 成功后返回
                        Response.Write("<script>alert('" + note + "')</script>");
                        Response.Write("<script>window.location ='user.aspx'</script>");
                    }
                    if (Request.Form["voice"] != null)
                    {
                        // 执行语音输入
                        int instr = 5;
                        acc.BookTask(no, instr, time);
                        // 调用接口
                        string note = task.func(instr, "?", "?", "?");

                        // 成功后返回
                        Response.Write("<script>alert('" + note + "')</script>");
                        Response.Write("<script>window.location ='user.aspx'</script>");
                    }
                }
                else
                {
                }
            }
        }
Ejemplo n.º 6
0
        public static void SignXML(string fechaEmision, ref XmlDocument xml, string accountId = "", X509Certificate2 certificate = null)
        {
            XmlDocument xmlDocSignature;

            DataBase.Account accountData;
            X509Certificate2 cert;
            IAccount         accountImp;
            string           singIdentifier, xmlSignature;
            SHA256           sha256;
            SHA1             sha1;

            try
            {
                accountImp      = new AccountImp();
                xmlDocSignature = new XmlDocument();
                sha256          = new SHA256CryptoServiceProvider();
                sha1            = new SHA1CryptoServiceProvider();

                singIdentifier = ConfigurationManager.AppSettings[Constants.Constants.SignIdentifier];

                if (certificate == null)
                {
                    if (!string.IsNullOrEmpty(accountId))
                    {
                        accountData = accountImp.GetAccountById(accountId);
                        if (accountData != null)
                        {
                            cert = new X509Certificate2(Convert.FromBase64String(accountData.certificate), accountData.certificatePIN.ToString());
                        }
                        else
                        {
                            throw new Exception(Constants.Constants.fail_Get_account_data);
                        }
                    }
                    else
                    {
                        throw new Exception(Constants.Constants.fail_CertificateInfo_incomplete);
                    }
                }
                else
                {
                    cert = certificate;
                }

                xmlDocSignature.Load(string.Format(Constants.Constants.RequestApiFormat_2, AppDomain.CurrentDomain.BaseDirectory, ConfigurationManager.AppSettings[Constants.Constants.signTemplate]));

                #region Estructura para firma digital

                /************************************************
                 * 0 : id
                 * 1 : XML document base64
                 * 2 : (no se que es) Properties
                 * 3 : current datetime
                 * 4 : certificate data base64
                 * 5 : X509IssuerName
                 * 6 : X509SerialNumber
                 * 7 : Identifier
                 * 8 : Identifier sha256
                 ***********************************************/
                xmlSignature = xmlDocSignature.OuterXml;
                List <string> parameters = new List <string>();
                parameters.Add(Guid.NewGuid().ToString("N"));                                                                 // 0
                parameters.Add(Convert.ToBase64String(sha256.ComputeHash(Encoding.UTF8.GetBytes(xmlDocSignature.OuterXml)))); // 1
                parameters.Add("5JVZPTwN5Lj0sGTfFzaUeMKCo/xbCAj7fw6TLUFtZIk=");                                               // 2
                parameters.Add(fechaEmision);                                                                                 // 3
                parameters.Add(Convert.ToBase64String(sha1.ComputeHash(Encoding.ASCII.GetBytes(cert.ToString(true)))));       // 4
                parameters.Add(cert.IssuerName.ToString());                                                                   // 5
                parameters.Add(cert.SerialNumber);                                                                            // 6
                parameters.Add(singIdentifier);                                                                               // 7
                parameters.Add(Convert.ToBase64String(sha256.ComputeHash(Encoding.UTF8.GetBytes(singIdentifier))));           // 8

                xmlSignature = string.Format(xmlSignature, parameters.ToArray());

                #endregion

                XmlDocumentFragment xFrag = xml.CreateDocumentFragment();
                xFrag.InnerXml = xmlSignature;
                xml.ChildNodes[0].AppendChild(xFrag);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }