/// <summary> /// Constructor /// </summary> /// <param name="destUri">The <see cref="Uri"/> of the destination (can be null)</param> /// <param name="xukAble">The source <see cref="IXukAble"/> (cannot be null)</param> /// <param name="destStream">The destination <see cref="Stream"/> (cannot be null)</param> public SaveXukAction(Project proj, IXukAble xukAble, Uri destUri, Stream destStream) { m_Project = proj; if (destStream == null) { throw new exception.MethodParameterIsNullException( "The destination Stream of the SaveXukAction cannot be null"); } if (xukAble == null) { throw new exception.MethodParameterIsNullException( "The source XukAble of the SaveXukAction cannot be null"); } mDestUri = destUri; mSourceXukAble = xukAble; mDestStream = destStream; bool pretty = mSourceXukAble.PrettyFormat; XmlWriterSettings settings = XmlReaderWriterHelper.GetDefaultXmlWriterConfiguration(pretty); mXmlWriter = XmlWriter.Create(mDestStream, settings); if (pretty && mXmlWriter is XmlTextWriter) { ((XmlTextWriter)mXmlWriter).Formatting = Formatting.Indented; } }
/// <summary> /// Constructor /// </summary> /// <param name="destUri">The <see cref="Uri"/> of the destination (cannot be null)</param> /// <param name="xukAble">The source <see cref="IXukAble"/>(cannot be null)</param> public SaveXukAction(Project proj, IXukAble xukAble, Uri destUri, bool skipBackup) { if (proj == null) { throw new exception.MethodParameterIsNullException( "The source Project of the SaveXukAction cannot be null"); } if (destUri == null) { throw new exception.MethodParameterIsNullException( "The destination URI of the SaveXukAction cannot be null"); } if (xukAble == null) { throw new exception.MethodParameterIsNullException( "The source XukAble of the SaveXukAction cannot be null"); } m_Project = proj; mDestUri = destUri; mSourceXukAble = xukAble; int currentPercentage = 0; EventHandler <ProgressEventArgs> progressing = delegate(object sender, ProgressEventArgs e) { double val = e.Current; double max = e.Total; int percent = (int)((val / max) * 100); if (percent != currentPercentage) { currentPercentage = percent; reportProgress_Throttle(currentPercentage, val + " / " + max); //backWorker.ReportProgress(currentPercentage); } if (RequestCancellation) { e.Cancel(); } }; Progress += progressing; Finished += delegate(object sender, FinishedEventArgs e) { Progress -= progressing; }; Cancelled += delegate(object sender, CancelledEventArgs e) { Progress -= progressing; }; string path = mDestUri.LocalPath; string parentdir = Path.GetDirectoryName(path); if (!Directory.Exists(parentdir)) { FileDataProvider.CreateDirectory(parentdir); } if (!skipBackup) { Backup(path); } mDestStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None); bool pretty = mSourceXukAble.PrettyFormat; XmlWriterSettings settings = XmlReaderWriterHelper.GetDefaultXmlWriterConfiguration(pretty); mXmlWriter = XmlWriter.Create(mDestStream, settings); if (pretty && mXmlWriter is XmlTextWriter) { ((XmlTextWriter)mXmlWriter).Formatting = Formatting.Indented; } }