示例#1
0
        public IEnumerable <Product> DeserializeProductTest()
        {
            SynchService          synch     = new SynchService();
            XDocument             xDocument = XDocument.Load(@"E:\temp\Products.xml");
            IEnumerable <Product> products  = synch.CreateProductsFromXDocument(xDocument);

            Assert.True(products.Any());
            return(products);
        }
        public FileResult DownloadOdersXml(SynchModel model)
        {
            IEnumerable<Order> orders;

            if (model.FromLastSynch)
                orders = Repository.Data.Get<Order>().Where(x => x.LastSynchDate == null).All();
            else
                orders = Repository.Data.Get<Order>().Where(x => x.CreateDate >= model.StartSynchDate &&
                        x.CreateDate <= model.EndSynchDate.Value.AddDays(1)).All();

            var service = new SynchService();
            XDocument xDocument = service.ConvertToXDocument(orders);
            Stream stream = new MemoryStream();
            xDocument.Save(stream);
            stream.Position = 0;
            return File(stream, "text/xml", "Orders.xml");
        }
示例#3
0
        public void TryToSerializeProductEntity()
        {
            IEnumerable <Product> product   = Repository.Data.Get <Product>().Where(x => x.Category.Name.Equals("Dairy", StringComparison.CurrentCultureIgnoreCase)).All().Take(5);
            SynchService          synch     = new SynchService();
            XDocument             xDocument = synch.ConvertToXDocument(product);

            xDocument.Save(@"E:\temp\Products.xml");

            List <Order> orders = Repository.Data.Get <Order>().All().Take(3).ToList();
            Order        order  = Repository.Data.Get <Order>().Where(x => x.OrderNumber != null).FirstOrDefault().Value;

            orders.Add(order);
            xDocument = synch.ConvertToXDocument(orders);
            xDocument.Save(@"E:\temp\Orders.xml");

            IEnumerable <Person> persons = Repository.Data.Get <Person>().All().Take(3);

            xDocument = synch.ConvertToXDocument(persons);
            xDocument.Save(@"E:\temp\Persons.xml");
        }
        public FileResult DownloadOdersXml(SynchModel model)
        {
            IEnumerable <Order> orders;

            if (model.FromLastSynch)
            {
                orders = Repository.Data.Get <Order>().Where(x => x.LastSynchDate == null).All();
            }
            else
            {
                orders = Repository.Data.Get <Order>().Where(x => x.CreateDate >= model.StartSynchDate &&
                                                             x.CreateDate <= model.EndSynchDate.Value.AddDays(1)).All();
            }

            var       service   = new SynchService();
            XDocument xDocument = service.ConvertToXDocument(orders);
            Stream    stream    = new MemoryStream();

            xDocument.Save(stream);
            stream.Position = 0;
            return(File(stream, "text/xml", "Orders.xml"));
        }
        public ActionResult UploadProductsAsync(IEnumerable <HttpPostedFileBase> attachments)
        {
            foreach (var file in attachments)
            {
                FileType fileType;
                Enum.TryParse(file.ContentType.Replace("text/", String.Empty), out fileType);

                if (fileType != FileType.other && fileType == FileType.xml)
                {
                    HttpPostedFileBase file1 = file;
                    var synch = new SynchService();
                    IEnumerable <Product> products = synch.CreateProductsFromXDocument(XDocument.Load(file1.InputStream));
                    var synchAction = new SynchActionService();
                    ActionHelper.TryExecute(() => synchAction.InsertProductToRepository(products), ModelState);
                }
                else
                {
                    ModelState.AddModelError("NotSupportedFormat", WebStroreResource.NotSupportedFormat);
                    return(Json(new { status = "Error", message = WebStroreResource.NotSupportedFormat }, "text/plain"));
                }
            }
            return(Content(String.Empty));
        }
        public ActionResult UploadProductsAsync(IEnumerable<HttpPostedFileBase> attachments)
        {
            foreach (var file in attachments)
            {
                FileType fileType;
                Enum.TryParse(file.ContentType.Replace("text/", String.Empty), out fileType);

                if (fileType != FileType.other && fileType == FileType.xml)
                {
                    HttpPostedFileBase file1 = file;
                    var synch = new SynchService();
                    IEnumerable<Product> products = synch.CreateProductsFromXDocument(XDocument.Load(file1.InputStream));
                    var synchAction = new SynchActionService();
                    ActionHelper.TryExecute(() => synchAction.InsertProductToRepository(products), ModelState);
                }
                else
                {
                    ModelState.AddModelError("NotSupportedFormat", WebStroreResource.NotSupportedFormat);
                    return Json(new { status = "Error", message = WebStroreResource.NotSupportedFormat }, "text/plain");
                }
            }
            return Content(String.Empty);
        }
示例#7
0
        public void TryToSerializeProductEntity()
        {
            IEnumerable<Product> product = Repository.Data.Get<Product>().Where( x => x.Category.Name.Equals("Dairy", StringComparison.CurrentCultureIgnoreCase)).All().Take(5);
            SynchService synch = new SynchService();
            XDocument xDocument = synch.ConvertToXDocument(product);
            xDocument.Save(@"E:\temp\Products.xml");

            List<Order> orders = Repository.Data.Get<Order>().All().Take( 3 ).ToList();
            Order order = Repository.Data.Get<Order>().Where(x => x.OrderNumber != null).FirstOrDefault().Value;
            orders.Add(order);
            xDocument = synch.ConvertToXDocument(orders);
            xDocument.Save(@"E:\temp\Orders.xml");

            IEnumerable<Person> persons = Repository.Data.Get<Person>().All().Take(3);
            xDocument = synch.ConvertToXDocument(persons);
            xDocument.Save(@"E:\temp\Persons.xml");
        }
示例#8
0
 public IEnumerable<Product> DeserializeProductTest()
 {
     SynchService synch = new SynchService();
     XDocument xDocument = XDocument.Load(@"E:\temp\Products.xml");
     IEnumerable<Product> products = synch.CreateProductsFromXDocument(xDocument);
     Assert.True(products.Any());
     return products;
 }