public void Run() { // check arguments if (string.IsNullOrEmpty(_args.InputFilename)) { throw new ApplicationException(DacChkSumResource.ErrorNoInputFile); } var inputFile = new FileInfo(_args.InputFilename); if (!inputFile.Exists) { throw new FileNotFoundException(_args.InputFilename); } if (!DacPackage.IsDacPac(inputFile)) { throw new FileFormatException(DacChkSumResource.ErrorNotValidDacPac); } if (_args.Verbose) { Console.Out.WriteLine("Starting: [{0}]", DateTime.Now); Console.Out.WriteLine("Input: [{0}]", inputFile.FullName); Console.Out.WriteLine("Update: [{0}]", this._args.Update.ToString(CultureInfo.InvariantCulture)); } using (var package = new DacPackage(inputFile)) { package.Open(); byte[] oldChkSum = package.ReadChecksum(); byte[] newChkSum = package.CalculateChecksum(); Console.Out.WriteLine("Model checksum"); Console.Out.WriteLine("Stored: :[{0}]", DacPackage.ByteArrayToString(oldChkSum)); Console.Out.WriteLine("Calculated:[{0}]", DacPackage.ByteArrayToString(newChkSum)); if ((_args.Update) && (!System.Linq.Enumerable.SequenceEqual(oldChkSum, newChkSum))) { Console.Out.WriteLine("Updating checksum"); package.UpdateChecksum(newChkSum); package.Save(); } package.Close(); } if (_args.Verbose) { Console.Out.WriteLine("Finished: [{0}]", DateTime.Now); } }
public void Run() { // check arguments if (string.IsNullOrEmpty(this._args.InputFilename)) { throw new ArgumentException(DacMergeResource.ErrorNoInputFile); } var inputFile = new FileInfo(this._args.InputFilename); if (!inputFile.Exists) { throw new FileNotFoundException(this._args.InputFilename); } if (!DacPackage.IsDacPac(inputFile)) { throw new FileFormatException(DacMergeResource.ErrorNotValidDacPac); } FileInfo outputFile = null; if (!string.IsNullOrEmpty(this._args.OutputFilename)) { outputFile = new FileInfo(this._args.OutputFilename); if (outputFile.Exists && this._args.Overwrite == false) { throw new InvalidOperationException(string.Format(DacMergeResource.ErrorOutputFileExists, this._args.OutputFilename)); } if (string.Compare(inputFile.FullName, outputFile.FullName, StringComparison.InvariantCulture) == 0) { throw new ApplicationException(DacMergeResource.ErrorInputEqualToOutput); } } DirectoryInfo loadPath = null; loadPath = String.IsNullOrEmpty(this._args.ReferenceLoadPath) ? new DirectoryInfo(Directory.GetCurrentDirectory()) : new DirectoryInfo(this._args.ReferenceLoadPath); if (loadPath != null && !loadPath.Exists) { throw new DirectoryNotFoundException(this._args.ReferenceLoadPath); } LogWriter.WriteMessage(DacMergeResource.Starting); LogWriter.WriteMessage(String.Format(DacMergeResource.InputFileNameArg, inputFile.Name)); LogWriter.WriteMessage(outputFile == null ? String.Format(DacMergeResource.UpdateInplace, inputFile.Name) : String.Format(DacMergeResource.OutputFileNameArg, outputFile.Name)); LogWriter.WriteMessage(String.Format(DacMergeResource.OverwriteArg, this._args.Overwrite.ToString(CultureInfo.InvariantCulture))); LogWriter.WriteMessage(String.Format(DacMergeResource.BackupArg, this._args.Backup.ToString(CultureInfo.InvariantCulture))); LogWriter.WriteMessage(String.Format(DacMergeResource.RelativeLoadPathArg, loadPath.FullName)); if (_args.Backup) { var backupFilePath = Path.Combine(inputFile.DirectoryName, inputFile.Name + ".bak"); inputFile.CopyTo(backupFilePath, true); } Merge(inputFile, outputFile, loadPath); LogWriter.WriteMessage(DacMergeResource.Finished); }