示例#1
0
        /// <summary>
        ///     Create a new PebbleBundle from a .pwb file and parse its metadata.
        /// </summary>
        /// <param name="bundle">The stream to the bundle.</param>
        /// <param name="zip">The zip library implementation.</param>
        public void Load(Stream bundle, IZip zip)
        {
            //TODO: This needs to be refactored, probably put into a Load method
            if (false == zip.Open(bundle))
            {
                throw new InvalidOperationException("Failed to open pebble bundle");
            }

            using (Stream manifestStream = zip.OpenEntryStream("manifest.json"))
            {
                if (manifestStream == null)
                {
                    throw new InvalidOperationException("manifest.json not found in archive - not a valid Pebble bundle.");
                }
                var serializer = new DataContractJsonSerializer(typeof(BundleManifest));
                Manifest = (BundleManifest)serializer.ReadObject(manifestStream);
            }

            HasResources = (Manifest.Resources.Size != 0);

            if (HasResources)
            {
                using (Stream resourcesBinary = zip.OpenEntryStream(Manifest.Resources.Filename))
                {
                    if (resourcesBinary == null)
                    {
                        throw new PebbleException("Could not find resource entry in the bundle");
                    }

                    Resources = Util.GetBytes(resourcesBinary);
                }
            }

            LoadData(zip);
        }
示例#2
0
 public DownloadController(IUpdate updateService, IZip zipService, IWebHostEnvironment environment, IValidate validateService)
 {
     _updateService      = updateService;
     _zipService         = zipService;
     _hostingEnvironment = environment;
     _validateService    = validateService;
 }
示例#3
0
        public void Save(string sHistoryFileName, string sSettingsFileName,
                         ClipboardList listMain, ClipboardList listFavorites)
        {
            globalSettings.Save(sSettingsFileName);

            try
            {
                IZip zip = null;
                try { zip = new DotNetZip(GetZipFilePath(sHistoryFileName), true); }
                catch (Exception err)
                {
                    FormClipboard.TraceLn(true, "Settings", "Save",
                                          "Create Zip: {0} Error: {1}", sHistoryFileName, err.Message);
                }//end catch

                XmlDocument doc  = new XmlDocument();
                XmlNode     root = doc.CreateNode(XmlNodeType.Element, "Settings", "");
                root = doc.AppendChild(root);

                listMain.Save(root, zip);
                listFavorites.Save(root, zip);

                doc.PreserveWhitespace = true;
                XmlUtil.SaveXmlDocFormatted(doc, sHistoryFileName);

                zip.Add(sHistoryFileName);
                zip.Close();
                File.Delete(sHistoryFileName);
            }//end try
            catch (Exception err)
            {
                FormClipboard.TraceLn(true, "Settings", "Save", "Exception: {0}", err.Message);
            } //end catch
        }     //end save
示例#4
0
 public ZipObserver(object gate, IZip parent, int index)
 {
     _gate   = gate;
     _parent = parent;
     _index  = index;
     _values = new Queue <T>();
 }
示例#5
0
        public static void TestInitialize(TestContext testContext)
        {
            _mockObjForExecuteUrl       = new Mock <IGitCommandExecute>();
            _mockObjForZipOperation     = new Mock <IZip>();
            _mockObjForSendOperation    = new Mock <ISendInput>();
            _mockObjCompareOperation    = new Mock <ICompare>();
            _mockObjForCleanUpOperation = new Mock <IDataRemove>();

            _helper           = new Helper();
            _zip              = new ZipGitRepo();
            _dataExtract      = new CsvDataExtractor();
            _thresholdRecieve = new QualityThresholdListRecieve();
            _dataRemove       = new TemporaryDataRemover();
            _sendInput        = new SendProjectPathAsInput();
            _testHelper       = new TestHelper();


            _recievedThresholdList = new List <string>()
            {
                "Error", "Warning", "Error", "Warning"
            };
            _targetThresholdList = new List <string>()
            {
                "error: 3", "Warning: 3"
            };
        }
示例#6
0
        /// <summary>
        ///     Create a new PebbleBundle from a .pwb file and parse its metadata.
        /// </summary>
        /// <param name="bundle">The stream to the bundle.</param>
        /// <param name="zip">The zip library implementation.</param>
        public void Load(Stream bundle, IZip zip)
        {
            //TODO: This needs to be refactored, probably put into a Load method
            if (false == zip.Open(bundle))
                throw new InvalidOperationException("Failed to open pebble bundle");

            using (Stream manifestStream = zip.OpenEntryStream("manifest.json"))
            {
                if (manifestStream == null)
                {
                    throw new InvalidOperationException("manifest.json not found in archive - not a valid Pebble bundle.");
                }
                var serializer = new DataContractJsonSerializer(typeof(BundleManifest));
                Manifest = (BundleManifest)serializer.ReadObject(manifestStream);
            }

            HasResources = (Manifest.Resources.Size != 0);

            if (HasResources)
            {
                using (Stream resourcesBinary = zip.OpenEntryStream(Manifest.Resources.Filename))
                {
                    if (resourcesBinary == null)
                        throw new PebbleException("Could not find resource entry in the bundle");

                    Resources = Util.GetBytes(resourcesBinary);
                }
            }

            LoadData(zip);
        }
示例#7
0
        protected override void LoadData(IZip zip)
        {
            if (string.IsNullOrWhiteSpace(Manifest.Application.Filename))
            {
                throw new PebbleException("Bundle does not contain pebble app");
            }

            using (Stream binStream = zip.OpenEntryStream(this.PlatformSubdirectory() + Manifest.Application.Filename))
            {
                if (binStream == null)
                {
                    throw new Exception(string.Format("App file {0} not found in archive", Manifest.Application.Filename));
                }

                App = Util.GetBytes(binStream);

                AppMetadata = BinarySerializer.ReadObject <ApplicationMetadata>(App);
            }
            //note, appinfo.json is NOT under the platform subdir
            using (Stream appinfoStream = zip.OpenEntryStream("appinfo.json"))
            {
                if (appinfoStream != null)
                {
                    var serializer = new DataContractJsonSerializer(typeof(PebbleSharp.Core.AppInfo));
                    AppInfo = (PebbleSharp.Core.AppInfo)serializer.ReadObject(appinfoStream);
                }
            }
        }
示例#8
0
 private BundleManifest LoadManifest(IZip zip)
 {
     using (var manifestStream = zip.OpenEntryStream(PlatformSubdirectory() + "manifest.json"))
     {
         var serializer = new DataContractJsonSerializer(typeof(BundleManifest));
         return((BundleManifest)serializer.ReadObject(manifestStream));
     }
 }
示例#9
0
 public ZipObserver(object gate, IZip parent, int index, IDisposable self)
 {
     _gate   = gate;
     _parent = parent;
     _index  = index;
     _self   = self;
     _values = new Queue <T>();
 }
示例#10
0
        public async Task <EpubStructure> CreateStructureAsync(IZip zip)
        {
            var container = await GetContainerAsync(zip).ConfigureAwait(false);

            var opf = await GetOpfAsync(zip, container).ConfigureAwait(false);

            return(new EpubStructure(opf, container, zip));
        }
示例#11
0
        }        //end Load

        public void Save(XmlNode nd, IZip zip)
        {
            nd = XmlUtil.UpdSubNode(nd, "ClipBoardList", "");
            for (int i = 0; i < Count; i++)
            {
                string sImageFileName = GetImageFileName(i);
                GetEntry(i).Save(nd, zip, sImageFileName);
            }    //end for
        }        //end Save
示例#12
0
 public EpubStructure(
     XmlStructureFile opf,
     XmlStructureFile container,
     IZip zip)
 {
     Opf       = opf;
     Container = container;
     Zip       = zip;
 }
示例#13
0
        protected override void LoadData(IZip zip)
        {
            if (string.IsNullOrWhiteSpace(Manifest.Firmware.Filename))
                throw new InvalidOperationException("Bundle does not contain firmware");

            using (Stream binStream = zip.OpenEntryStream(Manifest.Firmware.Filename))
            {
                Firmware = Util.GetBytes(binStream);
            }
        }
示例#14
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += (o, e) =>
            {
                ExitWithError("Oops! It was unexpected.");
            };

            Console.CancelKeyPress += CancelKeyPress;

            var validationResult = CommandLineArgumentsValidator.ValidateArguments(args);

            if (!validationResult.Success)
            {
                ExitWithError(validationResult.ErrorMessage);
            }

            try
            {
                _zipProcessor = new MultithreadedZip();
                string successMessage = "";
                switch (validationResult.Command)
                {
                case CommandLineArgumentsValidator.Command.Compress:
                {
                    Console.WriteLine("Compression started");
                    _zipProcessor.Compress(validationResult.SourceFileInfo, validationResult.DestinationFileInfo);
                    successMessage = "File was successfully compressed";
                    break;
                }

                case CommandLineArgumentsValidator.Command.Decompress:
                {
                    Console.WriteLine("Decompression started");
                    _zipProcessor.Decompress(validationResult.SourceFileInfo, validationResult.DestinationFileInfo);
                    successMessage = "File was successfully decompressed";
                    break;
                }
                }

                if (_zipProcessor.Success)
                {
                    ExitSuccess(successMessage);
                }
                else
                {
                    ExitWithError(_zipProcessor.ErrorMessage);
                }
            }
            catch (Exception e)
            {
                ExitWithError($"Error occured: {e.Message}");
            }
        }
示例#15
0
        protected override void LoadData(IZip zip)
        {
            if (string.IsNullOrWhiteSpace(Manifest.Firmware.Filename))
            {
                throw new PebbleException("Bundle does not contain firmware");
            }

            using (Stream binStream = zip.OpenEntryStream(Manifest.Firmware.Filename))
            {
                Firmware = Util.GetBytes(binStream);
            }
        }
示例#16
0
        public IGitCommandExecute InitExecute(out IZip zip, out ISendInput sendInput, out IDataRemove dataRemove,
                                              out IThresholdRecieve inputRecieve, out IDataExtract dataExtract, out ICompare compare)
        {
            IGitCommandExecute execute = new GitCloneExecute();

            zip        = new ZipGitRepo();
            sendInput  = new SendProjectPathAsInput();
            dataRemove = new TemporaryDataRemover();

            inputRecieve = new QualityThresholdListRecieve();
            dataExtract  = new CsvDataExtractor();
            compare      = new QualityThresholdEvaluator();
            return(execute);
        }
示例#17
0
        protected override void LoadData(IZip zip)
        {
            if (string.IsNullOrWhiteSpace(Manifest.Application.Filename))
                throw new InvalidOperationException("Bundle does not contain pebble app");

            using (Stream binStream = zip.OpenEntryStream(Manifest.Application.Filename))
            {
                if (binStream == null)
                    throw new Exception(string.Format("App file {0} not found in archive", Manifest.Application.Filename));

                App = Util.GetBytes(binStream);

                AppMetadata = BinarySerializer.ReadObject<ApplicationMetadata>(App);
            }
        }
示例#18
0
        protected override void LoadData(IZip zip)
        {
            if (string.IsNullOrWhiteSpace(Manifest.Application.Filename))
            {
                throw new InvalidOperationException("Bundle does not contain pebble app");
            }

            using (Stream binStream = zip.OpenEntryStream(Manifest.Application.Filename))
            {
                if (binStream == null)
                {
                    throw new Exception(string.Format("App file {0} not found in archive", Manifest.Application.Filename));
                }

                App = Util.GetBytes(binStream);

                AppMetadata = BinarySerializer.ReadObject <ApplicationMetadata>(App);
            }
        }
示例#19
0
        public void PerformExecute(IGitCommandExecute execute, IZip zip, ISendInput sendInput,
                                   IThresholdRecieve inputRecieve, IDataExtract dataExtract, ICompare compare, IDataRemove dataRemove)
        {
            Console.WriteLine("Enter repo to clone:");
            var urlIn = Console.ReadLine();
            var url   = ExecuteUrl(execute, urlIn);

            Thread.Sleep(10000);
            Console.WriteLine("Zip operation undergoes");
            Thread.Sleep(10000);
            Console.WriteLine("Sending zip to server");
            Thread.Sleep(10000);

            var fileName = url.Split('/')[1].Split('.')[0];

            var zipPath = PerformZipOperation(zip, sendInput, url, fileName);

            PerformSendOperation(sendInput, zipPath);

            PerformComparisonAndCleanUp(inputRecieve, dataExtract, compare, dataRemove, fileName, zipPath, _outputPath);
        }
示例#20
0
        /// <summary>
        ///     Create a new PebbleBundle from a .pwb file and parse its metadata.
        /// </summary>
        /// <param name="bundle">The stream to the bundle.</param>
        /// <param name="zip">The zip library implementation.</param>
        public void Load(IZip zip, Platform platform)
        {
            Platform = platform;
            Manifest = LoadManifest(zip);

            HasResources = (Manifest.Resources.Size != 0);

            if (HasResources)
            {
                using (Stream resourcesBinary = zip.OpenEntryStream(PlatformSubdirectory() + Manifest.Resources.Filename))
                {
                    if (resourcesBinary == null)
                    {
                        throw new PebbleException("Could not find resource entry in the bundle");
                    }

                    Resources = Util.GetBytes(resourcesBinary);
                }
            }

            LoadData(zip);
        }
示例#21
0
		public PebbleViewer (ILogger logger, PebblePlugin plugin, PebbleSharp.Core.Pebble pebble, IZip appBundleZip, Action<Action<ISystemController, IRaceController>> queueCommand)
		{
			_queueCommand = queueCommand;
			_plugin = plugin;
			_logger = logger;
			_pebble = pebble;

			_pebble.ConnectAsync ().Wait ();
			_logger.Info ("Connected to pebble " + _pebble.PebbleID);
			
			_transactionId = 255;

			var progress = new Progress<ProgressValue> (pv => _logger.Debug ("Installing app on pebble " + pebble.PebbleID + ", " + pv.ProgressPercentage + "% complete. " + pv.Message));
			var bundle = new AppBundle ();
			bundle.Load (appBundleZip, _pebble.Firmware.HardwarePlatform.GetPlatform ());
			_uuid = bundle.AppMetadata.UUID;
			_pebble.InstallClient.InstallAppAsync (bundle, progress).Wait ();
			_logger.Info ("Installed app on pebble " + pebble.PebbleID);

			_pebble.RegisterCallback<AppMessagePacket> (Receive);

			InitializeViewer ();
		}
示例#22
0
 protected abstract void LoadData(IZip zip);
示例#23
0
 public ProtocolPackage(IZip zip)
 {
     ZipEnable = false;
     Zip       = zip;
 }
示例#24
0
 private Task <XmlStructureFile> GetContainerAsync(IZip zip)
 {
     return(XmlStructureFile.LoadFromZipAsync(containerXmlPath, zip));
 }
示例#25
0
        private Task <XmlStructureFile> GetOpfAsync(IZip zip, XmlStructureFile container)
        {
            var opfXmlPath = opfPathExtractor.ExtractOpfPath(container);

            return(XmlStructureFile.LoadFromZipAsync(opfXmlPath, zip));
        }
示例#26
0
 public static Task <XmlStructureFile> LoadFromZipAsync(string path, IZip zip)
 {
     using var stream = zip.GetFileStream(path);
     return(LoadFromStreamAsync(path, stream));
 }
示例#27
0
 protected abstract void LoadData(IZip zip);
示例#28
0
 private static void TestZipImplementation(IZip zip)
 {
     
 }
示例#29
0
        public PebbleViewer(ILogger logger, PebblePlugin plugin, PebbleSharp.Core.Pebble pebble, IZip appBundleZip, Action <Action <ISystemController, IRaceController> > queueCommand)
        {
            _queueCommand = queueCommand;
            _plugin       = plugin;
            _logger       = logger;
            _pebble       = pebble;

            _pebble.ConnectAsync().Wait();
            _logger.Info("Connected to pebble " + _pebble.PebbleID);

            _transactionId = 255;

            var progress = new Progress <ProgressValue> (pv => _logger.Debug("Installing app on pebble " + pebble.PebbleID + ", " + pv.ProgressPercentage + "% complete. " + pv.Message));
            var bundle   = new AppBundle();

            bundle.Load(appBundleZip, _pebble.Firmware.HardwarePlatform.GetPlatform());
            _uuid = bundle.AppMetadata.UUID;
            _pebble.InstallClient.InstallAppAsync(bundle, progress).Wait();
            _logger.Info("Installed app on pebble " + pebble.PebbleID);

            _pebble.RegisterCallback <AppMessagePacket> (Receive);

            InitializeViewer();
        }
示例#30
0
 public string PerformZipOperation(IZip zip, ISendInput sendInput, string url, string fileName)
 {
     return(zip.Zip(fileName));
 }
示例#31
0
        }        //end CreateEmpty

        public void Save(XmlNode ndParent, IZip zip, string sImageFileName)
        {
            if (_data == null)
            {
                return;
            }

            string Value = "";
            string Type  = "";

            if (_dataType == DataFormats.Text ||
                _dataType == DataFormats.UnicodeText ||
                _dataType == DataFormats.Rtf)
            {
                Type  = _dataType;
                Value = (string)_data;
            }            //end if
            else if (_dataType == DataFormats.FileDrop)
            {
                Type = _dataType;
                String[]      sv = (String[])_data;
                StringBuilder sb = new StringBuilder(12);
                for (int i = 0; i < sv.Length; i++)
                {
                    sb.Append(sv[i]);
                    if (i != sv.Length - 1)
                    {
                        sb.Append('|');
                    }
                }        //end for
                Value = sb.ToString();
            }            //end if
            else         //do not know how to save
            {
                return;
            }

            try
            {
                File.Delete(sImageFileName);
                _icoAppFrom.Save(sImageFileName);
                if (zip != null)
                {
                    zip.Add(sImageFileName);
                    File.Delete(sImageFileName);
                }                //end if

                System.Diagnostics.Trace.WriteLine(
                    "File: " + Path.GetFileName(sImageFileName) +
                    " Entry: " + ShortDesc());
            }            //end try
            catch (Exception err)
            {
                System.Diagnostics.Trace.WriteLine("Archiving Error: " + err.ToString());
                FormClipboard.TraceLn(true, "ClipboardEntry", "Save",
                                      "{0} Error: {1}", sImageFileName, err.Message);
            }            //end catch

            XmlNode ndEntry = XmlUtil.AddNewNode(ndParent, "ClipboardEntry", Value);

            XmlUtil.UpdStrAtt(ndEntry, "OwnerType", _ownerType);
            XmlUtil.UpdStrAtt(ndEntry, "Type", Type);
            XmlUtil.UpdStrAtt(ndEntry, "Ico", sImageFileName);
        }        //end Save
示例#32
0
 private static void TestZipImplementation(IZip zip)
 {
 }
示例#33
0
        private Task <File> CreateFileFromManifestItem(ManifestItem item, string opfDirectory, IZip zip)
        {
            var path     = EpubPathHelper.ExpandPath(opfDirectory, item.Href !);
            var fileName = EpubPathHelper.GetFileName(item.Href !);

            return(Task.FromResult(
                       new File(fileName, path, item.ContentType, zip.GetFileContent(path))));
        }
示例#34
0
文件: Form1.cs 项目: Dmitry1102/Voice
        private void DESERIALButt_Click(object sender, EventArgs e)
        {
            Trans.Clear();

            string FileName;
            string FileExtension;
            string FileToDeserialize = "";

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                FileName      = openFileDialog1.FileName;
                FileExtension = Path.GetExtension(FileName);
            }
            else
            {
                return;
            }


            if (FileExtension == ".zip")
            {
                string DllName = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "ZipArchive.dll");
                if (!File.Exists(DllName))
                {
                    Console.Write("Плагин " + DllName + " не найден.");
                    return;
                }

                Assembly AboutAssembly = Assembly.LoadFrom(DllName);

                foreach (Type t in AboutAssembly.GetExportedTypes())
                {
                    if (t.IsClass && typeof(IZip).IsAssignableFrom(t))
                    {
                        IZip about = (IZip)Activator.CreateInstance(t);
                        FileToDeserialize = about.UnZip(FileName, Path.GetFileNameWithoutExtension(FileName));
                        break;
                    }
                }
            }
            else if (FileExtension == ".gz")
            {
                string DllName = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "GzArchive.dll");
                if (!File.Exists(DllName))
                {
                    Console.Write("Плагин " + DllName + " не найден.");
                    return;
                }
                Assembly AboutAssembly = Assembly.LoadFrom(DllName);

                foreach (Type t in AboutAssembly.GetExportedTypes())
                {
                    if (t.IsClass && typeof(IZip).IsAssignableFrom(t))
                    {
                        IZip about = (IZip)Activator.CreateInstance(t);
                        FileToDeserialize = about.UnZip(FileName, Path.GetFileNameWithoutExtension(FileName));
                        break;
                    }
                }
            }
            if (FileExtension == ".bz2")
            {
                string DllName = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Bz2Archive.dll");
                if (!File.Exists(DllName))
                {
                    Console.Write("Плагин " + DllName + " не найден.");
                    return;
                }
                Assembly AboutAssembly = Assembly.LoadFrom(DllName);

                foreach (Type t in AboutAssembly.GetExportedTypes())
                {
                    if (t.IsClass && typeof(IZip).IsAssignableFrom(t))
                    {
                        IZip about = (IZip)Activator.CreateInstance(t);
                        FileToDeserialize = about.UnZip(FileName, Path.GetFileNameWithoutExtension(FileName));
                        break;
                    }
                }
            }
            //if (filename.Contains("cipher_"))

            if (FileToDeserialize == "")
            {
                ChooseYourFighter(FileName, false);
            }
            else
            {
                ChooseYourFighter(FileToDeserialize, false);
            }


            dataGridAndAllListsUpdate();
        }
示例#35
0
 public Task <File[]> ExtractFiles(
     XmlStructureFile opf, IEnumerable <ManifestItem> manifestItems, IZip zip)
 {
     return(Task.WhenAll(manifestItems.Select(
                             item => CreateFileFromManifestItem(item, EpubPathHelper.GetDirectoryName(opf.Path), zip))));
 }