示例#1
0
        private async void ImportHandler()
        {
            var fileExt    = Path.GetExtension(TargetFileName);
            var sourceFile = await PlatformService.SelectFileAsync(new string[] { fileExt });

            if (sourceFile == null)
            {
                return;
            }

            var md5 = await CryptographyService.ComputeMD5Async(sourceFile);

            if (md5.ToLowerInvariant() != TargetMD5.ToLowerInvariant())
            {
                var title   = LocalizationService.GetLocalizedString(FileHashMismatchTitleKey);
                var message = LocalizationService.GetLocalizedString(FileHashMismatchMessageKey);
                await DialogsService.AlertAsync(message, title);

                return;
            }

            using (var inStream = await sourceFile.OpenAsync(PCLStorage.FileAccess.Read))
            {
                var targetFile = await TargetFolder.CreateFileAsync(targetFileName, CreationCollisionOption.ReplaceExisting);

                using (var outStream = await targetFile.OpenAsync(PCLStorage.FileAccess.ReadAndWrite))
                {
                    await inStream.CopyToAsync(outStream);

                    await outStream.FlushAsync();
                }

                FileAvailable = true;
            }
        }
        private async Task <bool> SaveFileFromPhotoDetails(Photo photo)
        {
            if (photo.Details != null && photo.Details.CanDownload)
            {
                try
                {
                    var    originalPhoto = photo.Details.Sizes.FirstOrDefault(p => p.Label.ToLower() == "original");
                    string photoFormat   = ".jpg";

                    if (!String.IsNullOrEmpty(photo.Format))
                    {
                        photoFormat = "." + photo.Format;
                    }

                    foreach (char c in System.IO.Path.GetInvalidFileNameChars())
                    {
                        photo.Title = photo.Title.Replace(c, '_');
                    }

                    StorageFile photoFile = null;

                    // Look for a year / month folder for the target folder to download into
                    if (photo.Dates.DateTaken != null && UseFolderStructure)
                    {
                        var yearFolder = await TargetFolder.CreateFolderAsync(photo.Dates.DateTaken.Year.ToString(), CreationCollisionOption.OpenIfExists);

                        var monthFolder = await yearFolder?.CreateFolderAsync(photo.Dates.DateTaken.Month.ToString(), CreationCollisionOption.OpenIfExists);

                        photoFile = await monthFolder?.CreateFileAsync(photo.Title + "_" + photo.Secret + photoFormat, Windows.Storage.CreationCollisionOption.ReplaceExisting);
                    }

                    if (photoFile == null)
                    {
                        photoFile = await TargetFolder?.CreateFileAsync(photo.Title + "_" + photo.Secret + photoFormat, Windows.Storage.CreationCollisionOption.ReplaceExisting);
                    }

                    if (originalPhoto != null && photoFile != null)
                    {
                        HttpClient client = new HttpClient();
                        Debug.WriteLine("Downloading:");
                        Debug.WriteLine(originalPhoto.Source);
                        byte[] buffer = await client.GetByteArrayAsync(originalPhoto.Source); // Download file

                        using (Stream stream = await photoFile.OpenStreamForWriteAsync())
                        {
                            stream.Write(buffer, 0, buffer.Length); // Save
                        }
                        return(true);
                    }
                }
                catch
                {
                    return(false);
                }
            }

            return(false);
        }
        private void btnExport_Click(object sender, RoutedEventArgs e)
        {
            // check input first
            if (string.IsNullOrEmpty(SourceFolder.Text))
            {
                MessageBox.Show("Please select source folder!");
                SourceFolder.Focus();
                return;
            }
            if (Directory.Exists(SourceFolder.Text) == false)
            {
                MessageBox.Show("Source folder does not exist!");
                SourceFolder.Focus();
                return;
            }
            if (string.IsNullOrEmpty(TargetFolder.Text))
            {
                MessageBox.Show("Please select target folder!");
                TargetFolder.Focus();
                return;
            }
            string targetFolder = TargetFolder.Text;

            if (Directory.Exists(targetFolder) == false)
            {
                Directory.CreateDirectory(targetFolder);
            }
            // find all rvt files including sub directories
            var    files = Directory.EnumerateFiles(SourceFolder.Text, "*.rvt", SearchOption.AllDirectories);
            int    count = files.Count(), success = 0;
            double curStep = 0, current = 0, tempVal;

            foreach (var f in files)
            {
                if (exportOneFile(f, targetFolder))
                {
                    success++;
                }
                current++;
                // show progress when more than 5 percent
                tempVal = current * 100 / count;
                if (tempVal - 5 > curStep)
                {
                    curStep           = tempVal;
                    progressBar.Value = curStep;
                    RAPWPF.WpfApplication.DoEvents();
                }
            }
            progressBar.Value = 100;
            RAPWPF.WpfApplication.DoEvents();
            // show summary information
            MessageBox.Show("Export " + success + " files successfully, " + (count - success) + " files failed.");
            Close();
        }
示例#4
0
        public async Task <IFile> GetTargetFileAsync()
        {
            var result = await TargetFolder.CheckExistsAsync(TargetFileName);

            if (result != ExistenceCheckResult.FileExists)
            {
                return(null);
            }

            var output = await TargetFolder.GetFileAsync(TargetFileName);

            return(output);
        }
示例#5
0
        private void btnUpgrade_Click(object sender, RoutedEventArgs e)
        {
            // check input first
            if (string.IsNullOrEmpty(SourceFolder.Text))
            {
                MessageBox.Show("Please select source folder!");
                SourceFolder.Focus();
                return;
            }
            if (Directory.Exists(SourceFolder.Text) == false)
            {
                MessageBox.Show("Source folder does not exist!");
                SourceFolder.Focus();
                return;
            }
            if (string.IsNullOrEmpty(TargetFolder.Text))
            {
                MessageBox.Show("Please select target folder!");
                TargetFolder.Focus();
                return;
            }
            // make sure that the source folder and target folder don't overlap
            string sourceFolder = SourceFolder.Text.TrimEnd('\\'), targetFolder = TargetFolder.Text.TrimEnd('\\');

            if (sourceFolder.IndexOf(targetFolder, StringComparison.OrdinalIgnoreCase) == 0 ||
                targetFolder.IndexOf(sourceFolder, StringComparison.OrdinalIgnoreCase) == 0)
            {
                string extra = "";
                if (sourceFolder.Length > targetFolder.Length)
                {
                    extra = sourceFolder.Substring(targetFolder.Length);
                }
                else
                {
                    extra = targetFolder.Substring(sourceFolder.Length);
                }
                if (extra.Length == 0 || extra[0] == '\\')
                {
                    MessageBox.Show("Target folder cannot be a parent or child folder of source folder!");
                    TargetFolder.Focus();
                    return;
                }
            }
            // at least select one file type
            if (cbRvt.IsChecked == false && cbRfa.IsChecked == false)
            {
                MessageBox.Show("At least check one Revit file type!");
                return;
            }
            upgradeFolder(sourceFolder, targetFolder, (cbRvt.IsChecked == true), (cbRfa.IsChecked == true));
        }
示例#6
0
 public NativeDependencyManager() : base("NativeDependencyManager")
 {
     try
     {
         var a = this.GetType().Assembly;
         //Use CodeBase if it is physical; this means we don't re-download each time we recycle.
         //If it's a URL, we fall back to Location, which is often the shadow-copied version.
         TargetFolder = a.CodeBase.StartsWith("file:///", StringComparison.OrdinalIgnoreCase)
                            ? a.CodeBase
                            : a.Location;
         //Convert UNC paths
         TargetFolder = Path.GetDirectoryName(TargetFolder.Replace("file:///", "").Replace("/", "\\"));
     }catch (SecurityException)
     {
         TargetFolder = null;
     }
 }
        private void btnExport_Click(object sender, RoutedEventArgs e)
        {
            // check select target folder
            if (string.IsNullOrEmpty(TargetFolder.Text))
            {
                MessageBox.Show("Please select target folder!");
                TargetFolder.Focus();
                return;
            }
            string targetFolder = TargetFolder.Text;

            if (Directory.Exists(targetFolder) == false)
            {
                Directory.CreateDirectory(targetFolder);
            }
            int exported = exportFamilies(targetFolder, progressUpdater);

            MessageBox.Show(string.Format("Exported {0} families!", exported));
            Close();
        }
示例#8
0
 public FolderTaskRunner(TargetFolder <TCreator> folder, FolderOrFileTaskCreator <TCreator> taskCreator)
 {
     _folder      = folder;
     _taskCreator = taskCreator;
 }
示例#9
0
 internal static void SetFolderEnable(TargetFolder folder)
 {
     conn.Execute(string.Format("UPDATE Folder SET IsEnable = {1} WHERE Path = '{0}';", folder.Path, folder.Enable));
 }
示例#10
0
 internal static void SetFolder(TargetFolder folder)
 {
     conn.Execute(string.Format("INSERT OR IGNORE INTO Folder(Path, IsEnable, CreateDate) VALUES('{0}', {1}, DATETIME('NOW', 'LOCALTIME'));"
                                , folder.Path, folder.Enable));
 }
示例#11
0
 internal static void DeleteFolder(TargetFolder folder)
 {
     conn.Execute(string.Format("DELETE FROM Folder WHERE Path = '{0}';", folder.Path));
 }
 public Task <IFileInfo> GetTargetFileAsync()
 {
     return(TargetFolder.GetFileAsync(TargetFileName));
 }
示例#13
0
        public async Task <IFileInfo> GetTargetFileAsync()
        {
            var result = await TargetFolder.GetFileAsync(TargetFileName);

            return(result);
        }