///<summary>Execute Open project Command</summary> void DoOpenProjectCmd(object prm = null) { FileAccessRequest far = new FileAccessRequest(); far.IsForReading = true; far.IsMultiSelect = false; far.ExtensionFilter = "Media Rat project (*.xmr)|*.xmr|Media Rat project (*.xmv)|*.xmv|XML Documents (*.xml)|*.xml|All files (*.*)|*.*"; far.ExtensionFilterIndex = 1; InformationRequest irq = new InformationRequest() { ResultType = typeof(System.IO.File), Prompt = "Select Media Rat project file", Tag = far }; string sourceFileName = null; irq.CompleteMethod = (rq) => { if (rq.Result != null) { sourceFileName = rq.Result.ToString(); } }; UIBus uiBus = AppContext.Current.GetServiceViaLocator <UIBus>(); uiBus.Send(new UIMessage(this, UIBusMessageTypes.InformationRequest, irq)); OpenFile(sourceFileName); }
///<summary>Execute Add Source Command</summary> void DoAddSrcCmd(object prm = null) { this.Status.Clear(); FileAccessRequest far = new FileAccessRequest(); far.IsForReading = true; far.IsMultiSelect = false; far.ExtensionFilter = "Video files (*.mts;*.mp4;*.mov;*.avi)|*.mts;*.mp4;*.mov;*.avi|Audio Files (*.mp3;*.m4a)|*.mp3;*.m4a|All files (*.*)|*.*"; far.ExtensionFilterIndex = 1; InformationRequest irq = new InformationRequest() { ResultType = typeof(System.IO.File), Prompt = "Select source media file", Tag = far }; string sourceFileName = null; irq.CompleteMethod = (rq) => { if (rq.Result != null) { sourceFileName = rq.Result.ToString(); } }; UIBus uiBus = AppContext.Current.GetServiceViaLocator <UIBus>(); uiBus.Send(new UIMessage(this, UIBusMessageTypes.InformationRequest, irq)); AddMediaSource(sourceFileName); }
///<summary>Execute Export media sheet Command</summary> void DoExportMediaSheetCmd(object prm = null) { try { FileAccessRequest far = new FileAccessRequest(); far.IsForReading = false; far.IsMultiSelect = false; far.ExtensionFilter = "XML Documents (*.xml)|*.xml|All files (*.*)|*.*"; far.ExtensionFilterIndex = 1; far.SuggestedFileName = "MyProject.xml"; InformationRequest irq = new InformationRequest() { ResultType = typeof(System.IO.File), Prompt = "Save as XML Media List file", Tag = far }; string fileName = null; List <MediaFile> src = new List <MediaFile>(this.GetSelectedMedia()); // Get the work set irq.CompleteMethod = (rq) => { if (rq.Result != null) { fileName = rq.Result.ToString(); } }; UIBus uiBus = AppContext.Current.GetServiceViaLocator <UIBus>(); uiBus.Send(new UIMessage(this, UIBusMessageTypes.InformationRequest, irq)); if (fileName != null) { XElement xrt = new XElement("mediaList", new XAttribute(XNames.xaName, this.Project.Title), new XAttribute("timestamp", DateTime.Now)); XDocument xdc = new XDocument(new XDeclaration("1.0", Encoding.UTF8.EncodingName, null), xrt); XElement xr; foreach (var mf in src) { if (null != (xr = mf.GetMediaListEntry())) { xrt.Add(xr); } } xdc.Save(fileName); this.Status.SetPositive(string.Format("Media List file {0} has been created.", fileName)); } } catch (BizException bx) { this.Status.SetError(bx.Message); } catch (Exception x) { this.Status.SetError(x.ToShortMsg("Save Media List")); } }
///<summary>Execute Export to Movie Maker Project Command</summary> void DoMovMakerProjectCmd(object prm = null) { try { FileAccessRequest far = new FileAccessRequest(); far.IsForReading = false; far.IsMultiSelect = false; far.ExtensionFilter = "Movie Maker project (*.wlmp)|*.wlmp|XML Documents (*.xml)|*.xml|All files (*.*)|*.*"; far.ExtensionFilterIndex = 1; far.SuggestedFileName = "MyProject.wlmp"; InformationRequest irq = new InformationRequest() { ResultType = typeof(System.IO.File), Prompt = "Save as Movie Maker Project file", Tag = far }; string fileName = null; irq.CompleteMethod = (rq) => { if (rq.Result != null) { fileName = rq.Result.ToString(); } }; UIBus uiBus = AppContext.Current.GetServiceViaLocator <UIBus>(); uiBus.Send(new UIMessage(this, UIBusMessageTypes.InformationRequest, irq)); if (fileName != null) { MovieMakerHelper.MovieOptions options = new MovieMakerHelper.MovieOptions() { ImgDisplayTime = 7, TargetFileName = fileName, Name = this.Project.Title, MediaFiles = new List <MediaFile>(this.GetSelectedMedia()) }; MovieMakerHelper mmHelper = new MovieMakerHelper(options); mmHelper.CreateMMakerProject().Save(fileName); this.Status.SetPositive(string.Format("MovieMaker project file {0} has been created.", fileName)); } } catch (BizException bx) { this.Status.SetError(bx.Message); } catch (Exception x) { this.Status.SetError(string.Format("Faield to save Movie Maker project. {0}: {1}", x.GetType().Name, x.Message), x); } }
void SelectFileName(InformationRequest request) { FileAccessRequest far = (FileAccessRequest)request.Tag; if (far.IsForReading) { OpenFileDialog ofd = new OpenFileDialog() { Filter = far.ExtensionFilter, Multiselect = far.IsMultiSelect }; if (far.ExtensionFilterIndex > 0) { ofd.FilterIndex = far.ExtensionFilterIndex; } if (ofd.ShowDialog() == true) { request.Result = ofd.FileName; request.CompleteMethod(request); } } else { SaveFileDialog sfd = new SaveFileDialog() { DefaultExt = string.IsNullOrEmpty(far.SuggestedFileName) ? string.Empty : System.IO.Path.GetExtension(far.SuggestedFileName), Filter = far.ExtensionFilter }; if (far.ExtensionFilterIndex > 0) { sfd.FilterIndex = far.ExtensionFilterIndex; } if (sfd.ShowDialog() == true) { //Func<Stream> openWriteStream= () => sfd.OpenFile(); request.Result = sfd.FileName; request.CompleteMethod(request); } } }
void SaveProject(VideoProject prj, bool askAltName = false) { if (!string.IsNullOrEmpty(prj.ProjectFileName) && !askAltName) { prj.Save(prj.ProjectFileName); return; } FileAccessRequest far = new FileAccessRequest(); far.IsForReading = false; far.IsMultiSelect = false; far.ExtensionFilter = "Media Rat Video Project (*.xmv)|*.xmv|XML Documents (*.xml)|*.xml|All files (*.*)|*.*"; far.ExtensionFilterIndex = 1; far.SuggestedFileName = "MyProject.xmv"; InformationRequest irq = new InformationRequest() { ResultType = typeof(System.IO.File), Prompt = "Save project file", Tag = far }; string fileName = null; irq.CompleteMethod = (rq) => { if (rq.Result != null) { fileName = rq.Result.ToString(); } }; UIBus uiBus = AppContext.Current.GetServiceViaLocator <UIBus>(); uiBus.Send(new UIMessage(this, UIBusMessageTypes.InformationRequest, irq)); if (fileName != null) { prj.Save(fileName); } }