Exemple #1
0
        public void SaveProductLastDate(ModisProduct ModisProduct, DateTime Date)
        {
            string dateFile = Path.Combine(textBoxArchiveDirectory.Text, ModisProduct.GetProductWithoutVersion());

            dateFile = Path.ChangeExtension(dateFile, "txt");
            File.WriteAllText(dateFile, Date.ToString("yyyy-MM-dd"));
        }
Exemple #2
0
        public DateTime GetProductLastDate(ModisProduct ModisProduct)
        {
            string dateFile = Path.Combine(textBoxArchiveDirectory.Text, ModisProduct.GetProductWithoutVersion());

            dateFile = Path.ChangeExtension(dateFile, "txt");
            if (!File.Exists(dateFile))
            {
                return(ModisProduct.StartDate.AddDays(-ModisProduct.Period));
            }
            string s_lastDate = File.ReadAllText(dateFile),
                   s_year     = s_lastDate.Split('-')[0],
                   s_month    = s_lastDate.Split('-')[1],
                   s_day      = s_lastDate.Split('-')[2];
            int year          = Convert.ToInt32(s_year),
                month         = Convert.ToInt32(s_month),
                day           = Convert.ToInt32(s_day);

            return(new DateTime(year, month, day));
        }
Exemple #3
0
        public void DownloadProduct(ModisProduct ModisProduct, DateTime Date)
        {
            Log($"{ModisProduct.GetProductWithoutVersion()} {Date.ToString("yyyy-MM-dd")} download started!");
            ClearBufer();
            bool ok = false;

            while (!ok)
            {
                try
                {
                    string resource = $"https://n5eil02u.ecs.nsidc.org/egi/request?" +
                                      $"short_name={ModisProduct.GetProductWithoutVersion()}&" +
                                      $"version={ModisProduct.GetProductVersion()}&" +
                                      $"time={Date.ToString("yyyy-MM-dd")},{Date.ToString("yyyy-MM-dd")}&" +
                                      $"bounding_box={textBoxBoundingBox.Text}&" +
                                      $"agent=NO&" +
                                      $"page_size=2000",
                           urs                  = "https://urs.earthdata.nasa.gov",
                           username             = "******",
                           password             = "******";
                    CookieContainer myContainer = new CookieContainer();
                    CredentialCache cache       = new CredentialCache();
                    cache.Add(new Uri(urs), "Basic", new NetworkCredential(username, password));
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(resource);
                    request.Method            = "GET";
                    request.Credentials       = cache;
                    request.CookieContainer   = myContainer;
                    request.PreAuthenticate   = false;
                    request.AllowAutoRedirect = true;
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    long            length   = response.ContentLength;
                    string          type     = response.ContentType;
                    Stream          stream   = response.GetResponseStream();
                    string          fileName = response.Headers["Content-Disposition"].Replace("attachment; filename=", String.Empty).Replace("\"", String.Empty);
                    using (Stream s = File.Create(Path.Combine(textBoxArchiveDirectory.Text, "Bufer", fileName)))
                    {
                        stream.CopyTo(s);
                    }
                    stream.Close();
                    MoveFilesToArchive();
                    SaveProductLastDate(ModisProduct, Date);
                    ok = true;
                }
                catch (WebException webException)
                {
                    if ((HttpWebResponse)webException.Response != null)
                    {
                        if (((HttpWebResponse)webException.Response).StatusCode == HttpStatusCode.NotImplemented)
                        {
                            Log($"{ModisProduct.GetProductWithoutVersion()} {Date.ToString("yyyy-MM-dd")} download error: " +
                                $"{((HttpWebResponse)webException.Response).StatusCode} ({((HttpWebResponse)webException.Response).StatusDescription})");
                            SaveProductLastDate(ModisProduct, Date);
                            ok = true;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Log($"{ModisProduct.GetProductWithoutVersion()} {Date.ToString("yyyy-MM-dd")} download error: {exception.Message}");
                }
            }
            Log($"{ModisProduct.GetProductWithoutVersion()} {Date.ToString("yyyy-MM-dd")} download finished!");
        }