Exemple #1
0
 public void Write()
 {
     DateAndVersion.Write(this);
 }
Exemple #2
0
        private void CheckObjects(object objDlPath, IZipClient zipClient)
        {
            var    configuration = GetConfiguration();
            string dsDlPath      = Path.Combine(System.Configuration.ConfigurationSettings.AppSettings["PrivateObjectsManifest"], configuration.FilterSet);
            Uri    objManifest   = new Uri(Path.Combine(dsDlPath, "manifest.txt"));

            //only check if we need to update filters if the CDN is available
            if (CanPing.TryPing(objManifest.Host))
            {
                try
                {
                    _mreFilterBlock.Reset();

                    string dlPath          = objDlPath.ToString();
                    string lastCheckedPath = Path.Combine(dlPath, LAST_CHECKED);

                    _logger.Debug("CheckObjects lastCheckedPath: {0}", lastCheckedPath);

                    using (WebClient mwc = new WebClient())
                    {
                        string dlList = mwc.DownloadString(objManifest);
                        if (!string.IsNullOrWhiteSpace(dlList))
                        {
                            _logger.Debug("CheckObjects manifest: {0}", dlList);

                            string[] objToCheck = dlList.Split(new string[] { System.Environment.NewLine, "\n" }, StringSplitOptions.RemoveEmptyEntries);
                            foreach (string toCheck in objToCheck)
                            {
                                try
                                {
                                    string         txtPath    = Path.Combine(dlPath, Path.ChangeExtension(toCheck, "txt"));
                                    DateAndVersion lastUpdate = new DateAndVersion(txtPath);
                                    Uri            comPath    = new Uri(Path.Combine(dsDlPath, toCheck));
                                    WebRequest     request    = WebRequest.Create(comPath);
                                    request.Method = "HEAD";

                                    _logger.Debug("CheckObjects check: {0}", comPath);

                                    using (WebResponse wr = request.GetResponse())
                                    {
                                        DateTime lmDate;
                                        if (DateTime.TryParse(wr.Headers[HttpResponseHeader.LastModified], out lmDate))
                                        {
                                            _logger.Debug("CheckObjects lmDate: {0} StoredDate", lmDate, lastUpdate.StoredDate);
                                            if (lmDate > lastUpdate.StoredDate)
                                            {
                                                //download the updated component
                                                using (WebClient fd = new WebClient())
                                                {
                                                    fd.DownloadProgressChanged += fd_DownloadProgressChanged;
                                                    byte[] comBin = fd.DownloadData(comPath);
                                                    if (comBin.Length > 0)
                                                    {
                                                        try
                                                        {
                                                            string dirPath = Path.Combine(dlPath, Path.GetFileNameWithoutExtension(toCheck));
                                                            if (Directory.Exists(dirPath))
                                                            {
                                                                Directory.Delete(dirPath, true);
                                                            }
                                                        }
                                                        catch (Exception ex)
                                                        {
                                                            _logger.Error("CheckObjects Delete: {0}", ex.Message);
                                                        }

                                                        ExtractBytes(comBin, dlPath, zipClient);
                                                        //using (MemoryStream ms = new MemoryStream(comBin))
                                                        //{
                                                        //    _logger.Debug("CheckObjects extract: {0}", dlPath);
                                                        //    zipClient.ExtractAll(ms, dlPath, true);
                                                        //}

                                                        DateAndVersion.Write(new DateAndVersion(txtPath, lmDate, ExeVersion));
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Debug.WriteLine(ex.Message);
                                }
                            }
                        }
                    }

                    DateAndVersion.Write(new DateAndVersion(lastCheckedPath, DateTime.Now, ExeVersion));
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
                finally
                {
                    _mreFilterBlock.Set();
                }
            }
        }