コード例 #1
0
        public void RunTask()
        {
            try
            {
                // Lets download the JSON file
                string jsonString;
                using (System.Net.WebClient w = new System.Net.WebClient())
                {
                    jsonString = w.DownloadString(ConfigurationManager.AppSettings["WazeDownloadURL"]);
                }
                Console.WriteLine(jsonString);

                var welcome          = WazeDownload.FromJson(jsonString);
                var connectionString = ConfigurationManager.ConnectionStrings["WazeDownloader.WazeDownloadContext"].ConnectionString;

                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    string query = "INSERT INTO dbo.WazeDownloadsRaw (FullText) VALUES (@title)";

                    using (SqlCommand command = new SqlCommand(query, connection))
                    {
                        command.Parameters.AddWithValue("@title", jsonString);
                        connection.Open();
                        int result = command.ExecuteNonQuery();

                        // Check Error
                        if (result < 0)
                        {
                            Console.WriteLine("Error inserting data into Database!");
                        }
                    }
                }

                using (var db = new WazeDownloadContext())
                {
                    db.WazeDownloads.Add(welcome);
                    db.SaveChanges();
                }
            }
            catch
            {
            }
        }
コード例 #2
0
 public static string ToJson(this WazeDownload self) => JsonConvert.SerializeObject(self, WazeDownloader.Converter.Settings);