public void ImportProducts() { if (listFileName == null) { GetListFileNames(); } int imports = 0; var watch = System.Diagnostics.Stopwatch.StartNew(); foreach (var item in listFileName) { var File = GetFileProduct(item); if (File != "") { using (WebClient client = new WebClient()) using (Stream stream = client.OpenRead(Environment.CurrentDirectory + "//" + item.Replace(".gz", ""))) using (StreamReader streamReader = new StreamReader(stream)) using (JsonTextReader reader = new JsonTextReader(streamReader)) { reader.SupportMultipleContent = true; var serializers = new JsonSerializer(); int limit = 0; while (reader.Read() && limit < 100) { if (reader.TokenType == JsonToken.StartObject) { Product product = serializers.Deserialize <Product>(reader); product.Code = product.Code.Replace(@"""", ""); product.Imported_t = DateTime.Now; product.Status = StatusEnum.published; var _producDb = _products.Find(p => p.Code == product.Code).FirstOrDefault(); if (_producDb != null) { _products.ReplaceOne(p => p.Code == product.Code, product); imports++; } else { _products.InsertOne(product); imports++; } } limit++; } } } } if (imports > 0) { CronImportations cron = new CronImportations(); cron.ImportDateTime = DateTime.Now; cron.NumberofObjects = imports; watch.Stop(); cron.ImportTime = watch.ElapsedMilliseconds.ToString(); _cronImportations.InsertOne(cron); } else { watch.Stop(); } }
public CronImportations AddCron(CronImportations cron) { _cron.InsertOne(cron); return(cron); }