Ejemplo n.º 1
0
 private void CommitPackageSource()
 {
     if (_currentPackageSource != null && typeof(T) == typeof(PackageSource))
     {
         _result.Add((T)(object)_currentPackageSource);
     }
     _currentPackageSource = null;
 }
Ejemplo n.º 2
0
        private IEnumerable <string> _UnpackArchive(string localFilename, string destinationFolder, Object requestImpl)
        {
            var info      = new ZipInfo(localFilename);
            var files     = info.GetFiles();
            var percent   = 0;
            var index     = 0;
            var processed = new List <string>();

            using (var request = requestImpl.As <Request>()) {
                // request.Debug("Unpacking {0} {1}", localFilename, destinationFolder);
                var pid = request.StartProgress(0, "Unpacking Archive '{0}' ", Path.GetFileName(localFilename));
                try {
                    info.Unpack(destinationFolder, (sender, args) => {
                        if (args.ProgressType == ArchiveProgressType.FinishFile)
                        {
                            processed.Add(Path.Combine(destinationFolder, args.CurrentFileName));
                            index++;
                            var complete = (index * 100) / files.Count;
                            if (complete != percent)
                            {
                                percent = complete;
                                request.Progress(pid, percent, "Unpacked {0}", args.CurrentFileName);
                            }

                            /*
                             * Does not currently support cancellation .
                             * Todo: add cancellation support to DTF compression classes.
                             * */
                            if (request.IsCancelled())
                            {
                                throw new OperationCanceledException("cancelling");
                            }
                        }
                    });
                } catch (OperationCanceledException) {
                    // no worries.
                } catch (Exception e) {
                    e.Dump();
                }

                // request.Debug("DONE Unpacking {0} {1}", localFilename, destinationFolder);
                request.CompleteProgress(pid, true);
            }
            // return the list of files to the parent.
            return(processed.ToArray());

#if manually
            var result = new CancellableBlockingCollection <string>();
            Task.Factory.StartNew(() => {
                using (var request = requestImpl.As <Request>()) {
                    request.Debug("Unpacking {0} {1}", localFilename, destinationFolder);

                    var info  = new ZipInfo(localFilename);
                    var files = info.GetFiles();
                    request.Debug("File Count", files.Count);

                    var percent = 0;
                    var index   = 0;

                    foreach (var zipfile in info)
                    {
                        index++;
                        var complete = (index * 100) / files.Count;
                        if (complete != percent)
                        {
                            percent = complete;
                            request.Debug("Percent Complete {0}", percent);
                        }
                        var outputFilename = Path.Combine(destinationFolder, zipfile.Path, zipfile.Name);
                        zipfile.CopyTo(outputFilename, true);
                        result.Add(outputFilename);
                    }
                    request.Debug("DONE Unpacking {0} {1}", localFilename, destinationFolder);
                    result.CompleteAdding();
                }
            });
            return(CancellableBlockingCollection <string> .ToCancellableEnumerable(result));
#endif

            /*
             * var info = new ZipInfo(localFilename);
             *
             * foreach (var zipfile in info.GetFiles()) {
             *  var outputFilename = Path.Combine(destinationFolder, zipfile.Path, zipfile.Name);
             *  zipfile.CopyTo(outputFilename, true);
             *
             *  yield return outputFilename;
             * }
             * */
        }