Example #1
0
 /// <summary>
 /// Called on UI bus message.
 /// </summary>
 /// <param name="message">The message.</param>
 public void OnMessage(ApplicationMessage <UIBusMessageTypes> message)
 {
     try {
         switch (message.MessageType)
         {
         case UIBusMessageTypes.InformationRequest: {
             InformationRequest irqt = message.Payload as InformationRequest;
             if (irqt != null)
             {
                 WorkspaceViewModel vm = irqt.Tag as WorkspaceViewModel;
                 if (vm != null)
                 {
                     PopupView pw = new PopupView(vm);
                     pw.Owner = this.MainWindow;
                     pw.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                     if (pw.ShowDialog() == true)
                     {
                         irqt.CompleteMethod(irqt);
                     }
                 }
                 else if (irqt.ResultType == typeof(System.IO.File))
                 {
                     SelectFileName(irqt);
                 }
             }
         }
         break;
         }
     }
     catch (Exception x) {
         AppContext.Current.LogTechError(string.Format("Technical error {0}: {1}", x.GetType().Name, x.Message), x);
         System.Diagnostics.Debug.WriteLine(x.GetDetails());
     }
 }
Example #2
0
        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);
                }
            }
        }