public ActionResult Create(FormCollection collection) { try { // TODO: Add insert logic here string name = collection.Get("Name"); Precipitation precipitation = new Precipitation() { Name = name }; IRepository <Precipitation> repo = new PrecipitationRepository(); repo.Save(precipitation); return(RedirectToAction("Index")); } catch { return(View()); } }
static async Task Main(string[] args) { Console.CancelKeyPress += (sender, eventArgs) => { Console.WriteLine("Cancel event triggered"); Environment.Exit(-1); }; string storageConnectionString = Environment.GetEnvironmentVariable("CLIMATE_COMPARISON_STORAGE_ACCOUNT"); var storageAccount = CloudStorageAccount.Parse(storageConnectionString); var tableClient = storageAccount.CreateCloudTableClient(); var progressRepository = new ProgressRepository(tableClient); int start = await progressRepository.Get(OPERATION) ?? 0; Console.WriteLine($"Starting from {start}"); var repository = new PrecipitationRepository(tableClient); string sqlConnectionString = Environment.GetEnvironmentVariable("CLIMATE_COMPARISON_ConnectionStrings__ConnectionString"); using (var sqlConnection = new SqlConnection(sqlConnectionString)) { sqlConnection.Open(); for (; ;) { var placeIds = GetPlaceIds(start, PLACES_BATCH_SIZE, sqlConnection).ToList(); if (placeIds.Count == 0) { break; } foreach (int id in placeIds) { double[] precipitation; try { precipitation = GetPrecipitation(id, sqlConnection).ToArray(); } catch (SqlException sqlException) when(sqlException.ErrorCode == -2146232060) { Console.WriteLine($"can't get precipitation for {id}"); Console.WriteLine(sqlException); continue; } await repository.Save(id, precipitation); Console.WriteLine($"Processed {id}"); start = id; } await progressRepository.Set(OPERATION, start); Console.WriteLine($"Saved progress {start}"); } } }