/// <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 (can be null)</param> /// <param name="xukAble">The source <see cref="IXukAble"/> (cannot be null)</param> /// <param name="writer">The destination <see cref="XmlWriter"/> (cannot be null)</param> public SaveXukAction(Project proj, IXukAble xukAble, Uri destUri, XmlWriter writer) { m_Project = proj; if (writer == null) { throw new exception.MethodParameterIsNullException( "The destination Writer 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; mXmlWriter = writer; XmlTextWriter txtWriter = writer as XmlTextWriter; if (txtWriter != null) { mDestStream = txtWriter.BaseStream; } }
/// <summary> /// Constructor /// </summary> /// <param name="sourceUri">The <see cref="Uri"/> of the source (can be null)</param> /// <param name="xukAble">The destination <see cref="IXukAble"/> (cannot be null)</param> /// <param name="sourceStream">The source <see cref="Stream"/> (cannot be null)</param> //public OpenXukAction(IXukAble xukAble, Uri sourceUri, Stream sourceStream) //{ // if (sourceStream == null) // throw new exception.MethodParameterIsNullException( // "The source Stream of the OpenXukAction cannot be null"); // if (xukAble == null) // throw new exception.MethodParameterIsNullException( // "The destination IXukAble of the OpenXukAction cannot be null"); // mSourceUri = sourceUri; // mDestXukAble = xukAble; // mSourceStream = sourceStream; // initializeXmlReader(mSourceStream); //} /// <summary> /// Constructor (DO NOT USE ! THE STREAM IS NULL. USE THE STREAM-BASED CTOR instead) /// </summary> /// <param name="sourceUri">The <see cref="Uri"/> of the source (can be null)</param> /// <param name="xukAble">The destination <see cref="IXukAble"/> (cannot be null)</param> /// <param name="reader">The source <see cref="XmlReader"/> (cannot be null)</param> //public OpenXukAction(IXukAble xukAble, Uri sourceUri, XmlReader reader) //{ // if (reader == null) // throw new exception.MethodParameterIsNullException( // "The source XmlReader of the OpenXukAction cannot be null"); // if (xukAble == null) // throw new exception.MethodParameterIsNullException( // "The destination IXukAble of the OpenXukAction cannot be null"); // mSourceUri = sourceUri; // mDestXukAble = xukAble; // mXmlReader = reader; // XmlTextReader txtReader = reader as XmlTextReader; // if (txtReader != null) // { // //TODO: where can we get the underlying stream ?? // //mSourceStream = txtReader.BaseStream; // } //} /// <summary> /// Constructor /// </summary> /// <param name="sourceUri">The <see cref="Uri"/> of the source file (cannot be null)</param> /// <param name="xukAble">The destination <see cref="IXukAble"/> (cannot be null)</param> public OpenXukAction(IXukAble xukAble, Uri sourceUri) { if (sourceUri == null) { throw new exception.MethodParameterIsNullException( "The source URI of the OpenXukAction cannot be null"); } if (xukAble == null) { throw new exception.MethodParameterIsNullException( "The destination IXukAble of the OpenXukAction cannot be null"); } mSourceUri = sourceUri; mDestXukAble = 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; }; if (!mSourceUri.IsFile) { throw new exception.XukException("The XUK URI must point to a local file!"); } mSourceStream = new FileStream(mSourceUri.LocalPath, FileMode.Open, FileAccess.Read, FileShare.Read); XmlReaderSettings settings = XmlReaderWriterHelper.GetDefaultXmlReaderConfiguration(false, false, false); if (!mDestXukAble.PrettyFormat) { // } else { // } mXmlReader = XmlReader.Create(mSourceStream, settings, mSourceUri.ToString()); }
/// <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; } }