コード例 #1
0
        // PUBLIC INTERFACE METHODS SECTION
        //---------------------------------------------------------------------

        #region IGuideService members

        public GuidesCollection GetGuides()
        {
            var serviceStateAgrs = new GuideServiceEventArgs();

            FtpConfiguration    ftpConfiguration    = _ftpConfigManager.Get();
            GuidesConfiguration guidesConfiguration = _guidesConfigManager.Get();

            var ftpClient = new FtpClient(ftpConfiguration.Uri,
                                          ftpConfiguration.User, ftpConfiguration.Password);


            string[]        ftpFolderMetadata = ftpClient.GetFtpFolderMetadata();
            List <FileMeta> filesMetadata     = ParseFtpFolderMetadata(ftpFolderMetadata);

            serviceStateAgrs.Message = "Checking guides for download.";
            OnStageChanged(serviceStateAgrs);

            var isForDownload = CheckGuidesForDownload(filesMetadata, guidesConfiguration.Guides);

            if (isForDownload)
            {
                try
                {
                    serviceStateAgrs.Message = "Downloading guides.";
                    OnStageChanged(serviceStateAgrs);

                    DownloadGuides(ftpClient, filesMetadata, guidesConfiguration.Path);
                    UpdateDates(filesMetadata, guidesConfiguration);
                }
                catch (HttpListenerException ex)
                {
                    throw new RemoteServerException(ex.Message, ex);
                }
                catch (IOException ex)
                {
                    throw new FileSaveException(ex.Message, ex);
                }
            }

            serviceStateAgrs.Message = "Loading guides.";
            OnStageChanged(serviceStateAgrs);

            var guides = LoadGuides(guidesConfiguration);

            return(guides);
        }
コード例 #2
0
 private void OnStageChanged(GuideServiceEventArgs e)
 {
     StateChanged?.Invoke(this, e);
 }