Beispiel #1
0
        private void TryGetFlashAirThumb(MetroTile tile, FlashAirFileInformation fileInformation)
        {
            try
            {
                _log.Debug($"Download thumbnail {fileInformation.Directory} {fileInformation.Filename}");
                var thumBitmap = _connection.DownloadThumbnail(fileInformation.Directory, fileInformation.Filename, Properties.Settings.Default.ImageFileTypes);
                if (thumBitmap == null)
                {
                    tile.Style = MetroColorStyle.Red;
                    return;
                }
                Image.GetThumbnailImageAbort myCallback = ThumbnailCallback;
                var thumb = thumBitmap.GetThumbnailImage(_metroTileSize, _metroTileSize, myCallback, IntPtr.Zero);

                tile.Style = MetroColorStyle.Blue;

                tile.TileImage = thumb;

                tile.UseTileImage = true;
                tile.Refresh();
            }
            catch (Exception ex)
            {
                // Could not download Thumb after 5 retries. Well. Just a thumb. Let's ignore this

                _log.Error(ex);
            }
        }
Beispiel #2
0
        private string CreateTargetFolder(FlashAirFileInformation fileInfo, string cardId, string appId)
        {
            // cardID=0, appId=1, Date=2
            var targetFolderName = string.Format(_connection.Settings.FolderFomat, cardId, appId, fileInfo.PictureTaken);

            var downloadFolder = new DirectoryInfo(_connection.Settings.LocalPath);

            return(!downloadFolder.Exists ? null : Directory.CreateDirectory(Path.Combine(downloadFolder.FullName, targetFolderName)).FullName);
        }
Beispiel #3
0
        private void DoCopy(FlashAirFileInformation fileInfo)
        {
            if (FileCopyStarted != null)
            {
                FileCopyStarted.Invoke(this, new EventArgs());
            }
            var    doDelete         = _connection.Settings.DeleteFiles;
            var    cardId           = _connection.GetCid();
            var    appId            = _connection.GetAppName();
            var    targetFolder     = CreateTargetFolder(fileInfo, cardId, appId);
            var    targetFile       = Path.Combine(targetFolder, fileInfo.Filename);
            Stream sourceFileStream = null;

            try
            {
                sourceFileStream = _connection.DownloadFile(fileInfo.Directory, fileInfo.Filename);
            }
            catch (Exception ex)
            {
                _log.Error(ex);

                if (ex is WebException && ((WebException)ex).Status == WebExceptionStatus.NameResolutionFailure)
                {
                    _log.Warn("Connection lost, should retry");
                }
                else
                {
                    _log.Error(ex);
                }
            }
            if (sourceFileStream == null)
            {
                return;
            }
            try
            {
                using (var fileStream = File.Create(targetFile))
                {
                    try
                    {
                        sourceFileStream.CopyTo(fileStream);
                    }
                    catch (Exception ex)
                    {
                        _log.Error(ex);
                        doDelete = false;
                    }
                }

                if (doDelete)
                {
                    _connection.DeleteFile(fileInfo.Directory, fileInfo.Filename);
                }
                if (FileCopyFinished != null)
                {
                    FileCopyFinished.Invoke(this, new EventArgs());
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex);
            }
        }