public override object ReadObject(XmlReader reader) { NestedClass NestedClassField = null; if (IsParentStartElement(reader, false, true)) { NestedClassField = new NestedClass(); reader.Read(); MtomDataDataContractSerializer MTDataDCS = new MtomDataDataContractSerializer("MTData", "http://schemas.datacontract.org/2004/07/WcfMtomService", "http://schemas.datacontract.org/2004/07/WcfMtomService"); MTDataDCS.BodyParts = this.BodyParts; NestedClassField.MTData = ((MtomData)(MTDataDCS.ReadObject(reader))); if (IsChildStartElement(reader, "MyData", true, false)) { reader.Read(); if (IsAttribute(reader, "href")) { string contentID; contentID = reader.Value; reader.MoveToElement(); reader.ReadStartElement("Include", "http://www.w3.org/2004/08/xop/include"); reader.ReadEndElement(); NestedClassField.MyData = GetBodyPartContent(contentID, BodyParts); } else { NestedClassField.MyData = ConvertBase64.FromBase64String(reader.ReadString()); reader.ReadEndElement(); } } reader.ReadEndElement(); } return(NestedClassField); }
public ProductCart GetProductCart(Guid id) { ProductCart products = new ProductCart(); var data = _applicationContext.Products.Where(x => x.Id == id).Select(x => new { Name = x.Name, Id = x.Id, Cost = x.Cost, Image = _applicationContext.Images.Where(p => p.ProductId == x.Id).Select(img => new { Path = "data:image/png;base64, " + ConvertBase64.GetBase64StringForImage(img.Path) }) }); foreach (var item in data) { products.Id = item.Id; products.Name = item.Name; products.Cost = item.Cost; foreach (var image in item.Image) { products.Path = image.Path; } } return(products); }
public override object ReadObject(XmlReader reader) { MtomData MtomDataField = null; if (IsParentStartElement(reader, false, true)) { MtomDataField = new MtomData(); reader.Read(); if (IsChildStartElement(reader, "Data", true, false)) { reader.Read(); if (IsAttribute(reader, "href")) { string contentID; contentID = reader.Value; reader.MoveToElement(); reader.ReadStartElement("Include", "http://www.w3.org/2004/08/xop/include"); reader.ReadEndElement(); MtomDataField.Data = GetBodyPartContent(contentID, BodyParts); } else { MtomDataField.Data = ConvertBase64.FromBase64String(reader.ReadString()); reader.ReadEndElement(); } } reader.ReadEndElement(); } return(MtomDataField); }
public List <object> FindProductByName(string name) { var product = _applicationContext.Products.Where(x => x.Name.StartsWith(name)).Select(x => new { Name = x.Name, Id = x.Id, Cost = x.Cost, Code = x.Code, Sale = x.Sale, ShortDescription = x.ShortDescription, FullDescription = x.FullDescription, Created = x.CreatedDate, Image = _applicationContext.Images.Where(p => p.ProductId == x.Id).Select(img => new { Path = "data:image/png;base64, " + ConvertBase64.GetBase64StringForImage(img.Path) }).ToList() }).ToList(); List <object> products = new List <object>(); foreach (var item in product) { products.Add(item); } return(products); }
public List <object> GetProductDetails(Guid id) { var product = _applicationContext.Products.Select(x => new { Name = x.Name, Id = x.Id, Cost = x.Cost, Code = x.Code, Sale = x.Sale, ShortDescription = x.ShortDescription, FullDescription = x.FullDescription, Quantity = x.Quantity, Status = _applicationContext.StatusProducts.Where(p => p.Id == x.StatusProductId).Select(n => n.Name), Provider = _applicationContext.Providers.Where(p => p.Id == x.ProviderId).Select(n => n.Name), Created = x.CreatedDate, Image = _applicationContext.Images.Where(p => p.ProductId == x.Id).Select(img => new { Path = "data:image/png;base64, " + ConvertBase64.GetBase64StringForImage(img.Path) }).ToList() }).Where(x => x.Id == id); List <object> products = new List <object>(); foreach (var item in product) { products.Add(item); } return(products); }
public List <object> GetListDiscountProducts() { var product = _applicationContext.Products .Where(x => x.View >= 100) .Select(x => new { Name = x.Name, Id = x.Id, Cost = x.Cost, Code = x.Code, Sale = x.Sale, Created = x.CreatedDate, Image = _applicationContext.Images.Where(p => p.ProductId == x.Id).Select(img => new { Path = "data:image/png;base64, " + ConvertBase64.GetBase64StringForImage(img.Path) }).ToList() }).OrderBy(x => x.Sale).Take(8).ToList(); List <object> products = new List <object>(); foreach (var item in product) { products.Add(item); } return(products); }
public override object ReadObject(XmlReader reader) { OneWayAttachmentRequest OneWayAttachmentRequestField = null; if (IsParentStartElement(reader, false, true)) { OneWayAttachmentRequestField = new OneWayAttachmentRequest(); OneWayAttachmentRequestField.AnyAttr = ReadAnyAttribute(reader); reader.Read(); if (IsChildStartElement(reader, "Param", true, true)) { reader.Read(); if (IsAttribute(reader, "href")) { string contentID; contentID = reader.Value; reader.MoveToElement(); reader.ReadStartElement("Include", "http://www.w3.org/2004/08/xop/include"); reader.ReadEndElement(); OneWayAttachmentRequestField.Param = GetBodyPartContent(contentID, BodyParts); } else { OneWayAttachmentRequestField.Param = ConvertBase64.FromBase64String(reader.ReadString()); reader.ReadEndElement(); } } OneWayAttachmentRequestField.Any = ReadAnyElement(reader, false); reader.ReadEndElement(); } return(OneWayAttachmentRequestField); }
public void FromTest() { var input = "N0pvaXRqckZMbFU="; var expected = "7JoitjrFLlU"; var s = ConvertBase64.From(input); Assert.Equal(expected, s); }
public void ToTest2() { var input = "nY-aVdc_qu4"; var expected = "blktYVZkY19xdTQ="; var s = ConvertBase64.To(input); Assert.Equal(expected, s); }
public List <object> GetProductByCategory(Guid name) { var product = _applicationContext.Products .Join(_applicationContext.StatusProducts, stt => stt.StatusProductId, st => st.Id, (stt, st) => new { stt, st }) .Join(_applicationContext.Providers, sp => sp.stt.ProviderId, spp => spp.Id, (sp, spp) => new { sp, spp }) .Join(_applicationContext.Units, us => us.sp.stt.UnitId, usp => usp.Id, (us, usp) => new { us, usp }) .Join(_applicationContext.ProductTypes, pt => pt.us.sp.stt.ProductTypeId, ptp => ptp.Id, (pt, ptp) => new { pt, ptp }) .Join(_applicationContext.Categeries, ct => ct.pt.us.sp.stt.CategoryId, ctp => ctp.Id, (ct, ctp) => new { ct, ctp }) .Where(x => x.ctp.Id == name) .Select(prd => new { CreatedDate = prd.ct.pt.us.sp.stt.CreatedDate, Name = prd.ct.pt.us.sp.stt.Name, Id = prd.ct.pt.us.sp.stt.Id, Code = prd.ct.pt.us.sp.stt.Code, View = prd.ct.pt.us.sp.stt.View, Cost = prd.ct.pt.us.sp.stt.Cost, CostOld = prd.ct.pt.us.sp.stt.CostOld, Mass = prd.ct.pt.us.sp.stt.Mass, ShortDescription = prd.ct.pt.us.sp.stt.ShortDescription, FullDescription = prd.ct.pt.us.sp.stt.FullDescription, Quantity = prd.ct.pt.us.sp.stt.Quantity, Sale = prd.ct.pt.us.sp.stt.Sale, Category = prd.ctp.Name, Provider = prd.ct.pt.us.spp.Name, StatusProduct = prd.ct.pt.us.sp.st.Name, Unit = prd.ct.pt.usp.Name, Image = _applicationContext.Images.Where(p => p.ProductId == prd.ct.pt.us.sp.stt.Id).Select(img => new { Path = "data:image/png;base64, " + ConvertBase64.GetBase64StringForImage(img.Path) }).ToList() }).ToList(); List <object> products = new List <object>(); foreach (var item in product) { products.Add(item); } return(products); }
public List <object> GetListOrder(Guid id) { var data = _applicationContext.Orders.Where(x => x.UserId == id) .Join(_applicationContext.OrderDetails, o => o.Id, od => od.OrderId, (o, od) => new { o, od }) .Join(_applicationContext.Products, p => p.od.ProductId, pd => pd.Id, (p, pd) => new { p, pd }) .Join(_applicationContext.StatusCarts, st => st.p.od.StatusCartId, sc => sc.Id, (st, sc) => new { st, sc }) .Select(s => new { ProductName = s.st.pd.Name, Quantity = s.st.p.od.Quantity, TotalCost = s.st.p.od.TotalCost, StatusOrder = s.sc.Name, Images = _applicationContext.Images.Where(x => x.ProductId == s.st.pd.Id).Select( im => "data:image/png;base64, " + ConvertBase64.GetBase64StringForImage(im.Path) ).ToList() }); List <object> list = new List <object>(); foreach (var item in data) { list.Add(item); } return(list); }
public void SendMail(EmailAddress from, EmailAddressCollection to, EmailAddressCollection cc, string subject, string body) { Connect(); Debug.Print(ReadLine()); if (_requireAuth) { string str = WriteReadLine("EHLO test.domain.com"); Debug.Print(str); while (str[3] == '-') { Debug.Print(str = ReadLine()); } byte[] buf = new byte[2 + _user.Length + _password.Length]; buf[0] = 0; byte[] userData = Encoding.UTF8.GetBytes(_user); Array.Copy(userData, 0, buf, 1, userData.Length); buf[1 + userData.Length] = 0; byte[] passData = Encoding.UTF8.GetBytes(_password); Array.Copy(passData, 0, buf, 2 + userData.Length, passData.Length); Debug.Print(WriteReadLine("AUTH PLAIN " + ConvertBase64.ToBase64String(buf))); } else { Debug.Print(WriteReadLine("HELO test.domain.com")); } Debug.Print(WriteReadLine("MAIL FROM: <" + from.Address + ">")); if (to != null) { foreach (EmailAddress toAddress in to) { Debug.Print(WriteReadLine("RCPT TO: <" + toAddress.Address + ">")); } } if (cc != null) { foreach (EmailAddress ccAddress in cc) { Debug.Print(WriteReadLine("RCPT TO: <" + ccAddress.Address + ">")); } } Debug.Print(WriteReadLine("DATA\r\n")); #region send data WriteLine("From: \"" + from.Name + "\" <" + from.Address + ">"); if (to != null) { foreach (EmailAddress toAddress in to) { WriteLine("To: \"" + toAddress.Name + "\" <" + toAddress.Address + ">"); } } if (cc != null) { foreach (EmailAddress ccAddress in cc) { WriteLine("Cc: \"" + ccAddress.Name + "\" <" + ccAddress.Address + ">"); } } WriteLine("Subject: " + subject + "\r\n"); WriteLine(body); Debug.Print(WriteReadLine(".")); #endregion Debug.Print(WriteReadLine("QUIT")); Disconnect(); }
/// <summary> /// Parses request from client. /// Fills /// - HTTP Verb. /// - HTTP version. /// - Content Length. /// - Fills generic value name pair in WEB header collection. /// </summary> internal void ParseHTTPRequest() { // This is the request line. m_RequestString = m_clientStream.Read_HTTP_Line(HttpWebRequest.maxHTTPLineLength).Trim(); // Split request line into 3 strings - VERB, URL and HTTP version. char[] delimiter = { ' ' }; string[] requestStr = m_RequestString.Split(delimiter); // requestStr should consist of 3 parts. if (requestStr.Length < 3) { throw new ProtocolViolationException("Invalid HTTP request String: " + m_RequestString); } // We have at least 3 strings. Fills the proper fields m_requestVerb = requestStr[0]; m_rawURL = requestStr[1]; // Process third string. It should be either http/1.1 or http/1.0 string httpVerLowerCase = requestStr[2].ToLower(); if (httpVerLowerCase.Equals("http/1.1")) { m_requestHttpVer = HttpVersion.Version11; } else if (httpVerLowerCase.Equals("http/1.0")) { m_requestHttpVer = HttpVersion.Version10; } else { throw new ProtocolViolationException("Unsupported HTTP version: " + requestStr[2]); } // Now it is list of HTTP headers: string line; int headersLen = m_maxResponseHeadersLen; while ((line = m_clientStream.Read_HTTP_Header(HttpWebRequest.maxHTTPLineLength)).Length > 0) { // line.Length is used for the header. Substruct it. headersLen -= line.Length; // If total length used for header is exceeded, we break if (headersLen < 0) { throw new ProtocolViolationException("Http Headers exceeding: " + m_maxResponseHeadersLen); } int sepIdx = line.IndexOf(':'); if (sepIdx == -1) { throw new ProtocolViolationException("Invalid HTTP Header: " + line); } string headerName = line.Substring(0, sepIdx).Trim(); string headerValue = line.Substring(sepIdx + 1).Trim(); string matchableHeaderName = headerName.ToLower(); // Adds new header to collection. m_httpRequestHeaders.AddInternal(headerName, headerValue); // Now we check the value - name pair. For some of them we need to initilize member variables. headerName = headerName.ToLower(); // If it is connection header if (headerName == "connection") { // If value is "Keep-Alive" ( lower case now ), set m_KeepAlive to true; headerValue = headerValue.ToLower(); m_KeepAlive = headerValue == "keep-alive"; } // If user supplied user name and password - parse it and store in m_NetworkCredentials if (headerName == "authorization") { int sepSpace = headerValue.IndexOf(' '); string authType = headerValue.Substring(0, sepSpace); if (authType.ToLower() == "basic") { string authInfo = headerValue.Substring(sepSpace + 1); // authInfo is base64 encoded username and password. byte[] authInfoDecoded = ConvertBase64.FromBase64String(authInfo); char[] authInfoDecChar = System.Text.Encoding.UTF8.GetChars(authInfoDecoded); string strAuthInfo = new string(authInfoDecChar); // The strAuthInfo comes in format username:password. Parse it. int sepColon = strAuthInfo.IndexOf(':'); if (sepColon != -1) { m_NetworkCredentials = new NetworkCredential(strAuthInfo.Substring(0, sepColon), strAuthInfo.Substring(sepColon + 1)); } } } } // Http headers were processed. Now we search for content length. string strContentLen = m_httpRequestHeaders[HttpKnownHeaderNames.ContentLength]; if (strContentLen != null) { try { m_contentLength = Convert.ToInt32(strContentLen); } catch (Exception) { throw new ProtocolViolationException("Invalid content length in request: " + strContentLen); } } }
public async Task <IActionResult> AddToCarts(ProductCarts id) { try { var getSession = SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart"); var ids = new Guid(id.Id); ProductCart products = new ProductCart(); var data = _applicationContext.Products.Where(x => x.Id == ids).Select(x => new { Name = x.Name, Id = x.Id, Cost = x.Cost, Image = _applicationContext.Images.Where(p => p.ProductId == x.Id).Select(img => new { Path = "data:image/png;base64, " + ConvertBase64.GetBase64StringForImage(img.Path) }) }); foreach (var item in data) { products.Id = item.Id; products.Name = item.Name; products.Cost = item.Cost; foreach (var image in item.Image) { products.Path = image.Path; } } if (products == null) { return(Ok(new Result() { Code = (int)HttpStatusCode.OK, Data = "Không tìm thấy sản phẩm", Error = "Không tìm thấy sản phẩm" })); } else { if (getSession == null) { List <Item> cart = new List <Item>(); cart.Add(new Item { ProductCart = products, Quantity = 1 }); SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart); } else { List <Item> cart = getSession; int index = IsExist(ids); if (index != -1) { cart[index].Quantity++; } else { cart.Add(new Item { ProductCart = products, Quantity = 1 }); } SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart); } return(Ok(new Result() { Code = (int)HttpStatusCode.OK, Data = "Thêm sản phẩm vào giỏ hàng thành công", Error = null })); } } catch (Exception ex) { _logger.LogError("Thêm sản phẩm vào giỏ hàng thất bại: " + ex); return(Ok(new Result() { Code = (int)HttpStatusCode.OK, Data = null, Error = "Thêm sản phẩm vào giỏ hàng thất bại" })); } }
private string toAuthorizationHeader() { return("Basic " + ConvertBase64.ToBase64String(Encoding.UTF8.GetBytes(this.Username + ":" + this.password))); }