public void RunApplication(string[] args) { try { _parms.Parse(args); // Scan the specified directory ScanDirectory(); // Save the manifest if (File.Exists(_parms.Manifest)) { File.Delete(_parms.Manifest); } ManifestInput.Serialize(_parms.Manifest, _manifestInput); Environment.ExitCode = 0; } catch (CommandLineException e) { Console.WriteLine(e.Message); _parms.PrintUsage(Console.Out); Environment.ExitCode = -1; } catch (Exception e) { Console.WriteLine("Unexpected exception when generating manifest input: {0}", e.Message); Environment.ExitCode = -1; } }
public static ManifestInput Deserialize(string filename) { XmlSerializer theSerializer = new XmlSerializer(typeof(ManifestInput)); using (FileStream fs = new FileStream(filename, FileMode.Open)) { ManifestInput input = (ManifestInput)theSerializer.Deserialize(fs); return(input); } }
public static void Serialize(string filename, ManifestInput input) { using (FileStream fs = new FileStream(filename, FileMode.CreateNew)) { XmlSerializer theSerializer = new XmlSerializer(typeof(ManifestInput)); XmlWriterSettings settings = new XmlWriterSettings { Indent = true, IndentChars = " ", Encoding = Encoding.UTF8, }; XmlWriter writer = XmlWriter.Create(fs, settings); if (writer != null) { theSerializer.Serialize(writer, input); } fs.Flush(); fs.Close(); } }
public void RunApplication(string[] args) { try { _cmdLine.Parse(args); List <ManifestInput> list = new List <ManifestInput>(); foreach (string filename in _cmdLine.Positional) { string[] files = filename.Split(new[] { ';' }); foreach (string f in files) { list.Add(ManifestInput.Deserialize(f)); } } if (_cmdLine.Package) { if (string.IsNullOrEmpty(_cmdLine.ProductManifest)) { throw new ApplicationException("ProductManifest not specified on the command line"); } if (string.IsNullOrEmpty(_cmdLine.PackageName)) { throw new ApplicationException("PackageName not specified on the command line"); } _manifest.PackageManifest = new PackageManifest { Package = new Package() }; _manifest.PackageManifest.Package.Manifest = _cmdLine.Manifest; _manifest.PackageManifest.Package.Name = _cmdLine.PackageName; _manifest.PackageManifest.Package.Product = new Product { Name = string.Empty }; LoadReferencedProduct(); } else { _manifest.ProductManifest = new ProductManifest { Product = new Product() }; _manifest.ProductManifest.Product.Manifest = _cmdLine.Manifest; } ProcessFiles(list); ProcessConfiguration(list); //TODO: get rid of "manifest" constant Derive from Platform.ManifestDirectory string manifestPath = Path.Combine(_cmdLine.DistributionDirectory, "manifest"); manifestPath = Path.Combine(manifestPath, _cmdLine.Manifest); if (File.Exists(manifestPath)) { File.Delete(manifestPath); } XmlDocument doc = ClearCanvasManifest.Serialize(_manifest); // Generate a signing key. RSACryptoServiceProvider rsaCsp; if (string.IsNullOrEmpty(_cmdLine.Certificate)) { rsaCsp = new RSACryptoServiceProvider(2048); } else { X509Certificate2 certificate = new X509Certificate2(_cmdLine.Certificate, _cmdLine.Password ?? string.Empty); rsaCsp = (RSACryptoServiceProvider)certificate.PrivateKey; } ManifestSignature.SignXmlFile(doc, manifestPath, rsaCsp); Environment.ExitCode = 0; } catch (CommandLineException e) { Platform.Log(LogLevel.Error, e, "Command line exception when generating manifest."); Console.WriteLine(e.Message); _cmdLine.PrintUsage(Console.Out); Environment.ExitCode = -1; } catch (Exception e) { Platform.Log(LogLevel.Error, e, "Unexpected exception when generating manifest."); string message = String.Format("Unexpected exception when generating manifest: {0}", e.Message); string stackTrace = e.StackTrace; Console.WriteLine(message); Console.WriteLine(stackTrace); Environment.ExitCode = -1; } }
public static void Serialize(string filename, ManifestInput input) { using (FileStream fs = new FileStream(filename, FileMode.CreateNew)) { XmlSerializer theSerializer = new XmlSerializer(typeof (ManifestInput)); XmlWriterSettings settings = new XmlWriterSettings { Indent = true, IndentChars = " ", Encoding = Encoding.UTF8, }; XmlWriter writer = XmlWriter.Create(fs, settings); if (writer != null) theSerializer.Serialize(writer, input); fs.Flush(); fs.Close(); } }