public bool HasRedo(object undoManager = null) { if (undoManager == null) { undoManager = GetUndoManager(); } return((bool)ReflectionUtils.CallMethodCom(undoManager, "hasRedo", false)); }
public void ExecuteCommand(string command, params object[] args) { if (command == "PreviewContextMenu") { var ctm = WebBrowser.ContextMenu; ctm.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint; ctm.PlacementTarget = WebBrowser; ctm.IsOpen = true; } if (command == "PrintPreview") { object dom = WebBrowser.Document; ReflectionUtils.CallMethodCom(dom, "execCommand", "print", true, null); } }
public void ExecuteCommand(string command, params object[] args) { if (command == "PreviewContextMenu") { object parms = null; if (args != null && args.Length > 0) { parms = args[0]; } var menu = new PreviewBrowserContextMenu(); menu.ShowContextMenu(new PositionAndDocumentType(parms), Window.Model, WebBrowser); } if (command == "PrintPreview") { object dom = WebBrowser.Document; ReflectionUtils.CallMethodCom(dom, "execCommand", "print", true, null); } }
// /// <summary> // /// Sets the flag that determines whether line numbers are shown // /// </summary> // /// <param name="showLineNumbers"></param> // public void SetShowLineNumbers(bool showLineNumbers) // { // Invoke("setShowLineNumbers", showLineNumbers); // } #region UndoManager /// <summary> /// Returns the JavaScript UndoManager /// </summary> /// <returns></returns> public object GetUndoManager() { var session = ReflectionUtils.GetPropertyExCom(Instance, "editor.session"); return(ReflectionUtils.CallMethodCom(session, "getUndoManager", false)); }
/// <summary> /// Captures an image to file /// </summary> /// <returns></returns> public string CaptureImageToFile() { var OldState = WindowState.Minimized; if (ActiveForm != null) { OldState = ActiveForm.WindowState; ActiveForm.WindowState = WindowState.Minimized; } object snagIt = SnagItCom; try { ReflectionUtils.SetPropertyCom(snagIt, "Input", CaptureMode); } catch { SetError("SnagIt isn't installed - COM Access failed.\r\nPlease install SnagIt from Techsmith Corporation (www.techsmith.com\\snagit)."); return(null); } ReflectionUtils.SetPropertyCom(snagIt, "Input", CaptureMode); ReflectionUtils.SetPropertyCom(snagIt, "Output", 2); // file ReflectionUtils.SetPropertyCom(snagIt, "EnablePreviewWindow", ShowPreviewWindow); ReflectionUtils.SetPropertyExCom(snagIt, "OutputImageFile.Directory", CapturePath); ReflectionUtils.SetPropertyExCom(snagIt, "OutputImageFile.Filename", OutputCaptureFile); ReflectionUtils.SetPropertyExCom(snagIt, "OutputImageFile.Quality", 86); //86% quality int type = (int)OutputFileCaptureFormat; ReflectionUtils.SetPropertyExCom(snagIt, "OutputImageFile.FileType", type); ReflectionUtils.SetPropertyExCom(snagIt, "OutputImageFile.ColorDepth", ColorDepth); ReflectionUtils.SetPropertyCom(snagIt, "IncludeCursor", IncludeCursor); if (DelayInSeconds > 0) { ReflectionUtils.SetPropertyExCom(snagIt, "DelayOptions.EnableDelayedCapture", true); ReflectionUtils.SetPropertyExCom(snagIt, "DelayOptions.DelaySeconds", DelayInSeconds); } if (ActiveForm != null) { // *** Need to delay a little here so that the form has properly minimized first // *** especially under Vista/Win7 for (int i = 0; i < 20; i++) { WindowUtilities.DoEvents(); Thread.Sleep(5); } } // Works but doesn't really add anything. Won't work in .NET Core due to dynamic not working with COM //((dynamic) snagIt).OnStateChange += new Action<CaptureState>(SnagImg_OnStateChange); try { IsDone = false; ReflectionUtils.CallMethodCom(snagIt, "Capture"); while (!IsDone && !HasError) { IsDone = (bool)ReflectionUtils.GetPropertyCom(snagIt, "IsCaptureDone"); if (IsDone) { break; } WindowUtilities.DoEvents(); Thread.Sleep(5); } } catch (Exception ex) { ErrorMessage = "An error occurred during the image capture: " + ex.Message; } // *** No catch let it throw finally { if (IsDone) { _outputCaptureFile = ReflectionUtils.GetPropertyCom(snagIt, "LastFileWritten") as string; } else { _outputCaptureFile = null; ErrorMessage = "Image capture failed."; } if (ActiveForm != null) { // Reactivate Editor ActiveForm.WindowState = OldState; // Make sure it pops on top of SnagIt Editors ActiveForm.Topmost = true; WindowUtilities.DoEvents(); Thread.Sleep(5); ActiveForm.Topmost = false; } Marshal.ReleaseComObject(SnagItCom); } // If deleting the file we'll fire on a new thread and then delay by // a few seconds until Writer has picked up the image. if ((DeleteImageFromDisk)) { new Timer( (imgFile) => { var image = imgFile as string; if (image == null) { return; } try { File.Delete(image); } catch {} }, _outputCaptureFile, 10000, Timeout.Infinite); } return(OutputCaptureFile); }
/// <summary> /// Captures an image to file /// </summary> /// <returns></returns> public bool CaptureImageToClipboard() { var OldState = WindowState.Minimized; if (ActiveForm != null) { OldState = ActiveForm.WindowState; ActiveForm.WindowState = WindowState.Minimized; } object snagIt = SnagItCom; try { ReflectionUtils.SetPropertyCom(snagIt, "Input", CaptureMode); } catch { SetError("SnagIt isn't installed - COM Access failed.\r\nPlease install SnagIt from Techsmith Corporation (www.techsmith.com\\snagit)."); return(false); } ReflectionUtils.SetPropertyCom(snagIt, "Input", CaptureMode); ReflectionUtils.SetPropertyCom(snagIt, "Output", 4); // clipboard ReflectionUtils.SetPropertyCom(snagIt, "EnablePreviewWindow", ShowPreviewWindow); ReflectionUtils.SetPropertyCom(snagIt, "IncludeCursor", IncludeCursor); if (DelayInSeconds > 0) { ReflectionUtils.SetPropertyExCom(snagIt, "DelayOptions.EnableDelayedCapture", true); ReflectionUtils.SetPropertyExCom(snagIt, "DelayOptions.DelaySeconds", DelayInSeconds); } if (ActiveForm != null) { // *** Need to delay a little here so that the form has properly minimized first // *** especially under Vista/Win7 for (int i = 0; i < 20; i++) { WindowUtilities.DoEvents(); Thread.Sleep(5); } } // Works but doesn't really add anything. Won't work in .NET Core due to dynamic not working with COM //((dynamic) snagIt).OnStateChange += new Action<CaptureState>(SnagImg_OnStateChange); Clipboard.Clear(); try { IsDone = false; ReflectionUtils.CallMethodCom(snagIt, "Capture"); while (!IsDone && !HasError) { IsDone = (bool)ReflectionUtils.GetPropertyCom(snagIt, "IsCaptureDone"); if (IsDone) { break; } WindowUtilities.DoEvents(); Thread.Sleep(5); } } catch (Exception ex) { ErrorMessage = "An error occurred during the image capture: " + ex.Message; return(false); } // *** No catch let it throw finally { if (ActiveForm != null) { // Reactivate Editor ActiveForm.WindowState = OldState; // Make sure it pops on top of SnagIt Editors ActiveForm.Topmost = true; WindowUtilities.DoEvents(); Thread.Sleep(5); ActiveForm.Topmost = false; } Marshal.ReleaseComObject(SnagItCom); } return(ClipboardHelper.ContainsImage()); }
/// <summary> /// Process an individual request. Handles only static file based requests /// </summary> /// <param name="context"></param> private void Process(HttpListenerContext context) { string filename = context.Request.Url.AbsolutePath; Console.WriteLine(filename); if (RequestHandler != null) { if ((bool)ReflectionUtils.CallMethodCom(RequestHandler, "Process", context)) { return; } } filename = filename.Substring(1); if (string.IsNullOrEmpty(filename)) { foreach (string indexFile in DefaultDocuments) { if (File.Exists(Path.Combine(_rootDirectory, indexFile))) { filename = indexFile; break; } } } filename = Path.Combine(_rootDirectory, filename); if (File.Exists(filename)) { try { Stream input = new FileStream(filename, FileMode.Open); //Adding permanent http response headers string mime; context.Response.ContentType = _mimeTypeMappings.TryGetValue(Path.GetExtension(filename), out mime) ? mime : "application/octet-stream"; context.Response.ContentLength64 = input.Length; context.Response.AddHeader("Date", DateTime.Now.ToString("r")); context.Response.AddHeader("Last-Modified", File.GetLastWriteTime(filename).ToString("r")); byte[] buffer = new byte[1024 * 32]; int nbytes; while ((nbytes = input.Read(buffer, 0, buffer.Length)) > 0) { context.Response.OutputStream.Write(buffer, 0, nbytes); } input.Close(); context.Response.OutputStream.Flush(); context.Response.StatusCode = (int)HttpStatusCode.OK; } catch (Exception ex) { context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; } } else { context.Response.StatusCode = (int)HttpStatusCode.NotFound; } context.Response.OutputStream.Close(); }
/// <summary> /// Captures an image to file /// </summary> /// <returns></returns> public string CaptureImageToFile() { FormWindowState OldState = this.ActiveForm.WindowState; if (this.ActiveForm != null) { this.ActiveForm.WindowState = FormWindowState.Minimized; } Application.DoEvents(); /// *** Capture first access to check if SnagIt is installed try { ReflectionUtils.SetPropertyExCom(this.SnagItCom, "OutputImageFile.Directory", this.CapturePath); } catch { throw new Exception("SnagIt isn't installed - COM Access failed.\r\nPlease install SnagIt from Techsmith Corporation (www.techsmith.com\\snagit)."); } ReflectionUtils.SetPropertyCom(this.SnagItCom, "EnablePreviewWindow", this.ShowPreviewWindow); ReflectionUtils.SetPropertyExCom(this.SnagItCom, "OutputImageFile.Filename", "captured_Image.png"); ReflectionUtils.SetPropertyExCom(this.SnagItCom, "Input", this.CaptureMode); ReflectionUtils.SetPropertyExCom(this.SnagItCom, "OutputImageFile.FileType", (int)this.OutputFileCaptureFormat); // Removed in SnagIt 11 //ReflectionUtils.SetPropertyExCom(this.SnagItCom,"Filters.ColorConversion.ColorDepth",this.ColorDepth); ReflectionUtils.SetPropertyExCom(this.SnagItCom, "OutputImageFile.ColorDepth", this.ColorDepth); ReflectionUtils.SetPropertyExCom(this.SnagItCom, "IncludeCursor", this.IncludeCursor); if (this.DelayInSeconds > 0) { ReflectionUtils.SetPropertyExCom(this.SnagItCom, "DelayOptions.EnableDelayedCapture", true); ReflectionUtils.SetPropertyExCom(this.SnagItCom, "DelayOptions.DelaySeconds", this.DelayInSeconds); } // *** Need to delay a little here so that the form has properly minimized first // *** especially under Vista/Win7 for (int i = 0; i < 20; i++) { Application.DoEvents(); Thread.Sleep(5); } ReflectionUtils.CallMethodCom(this.SnagItCom, "Capture"); try { bool TimedOut = true; while (true) { if ((bool)ReflectionUtils.GetPropertyCom(this.SnagItCom, "IsCaptureDone")) { TimedOut = false; break; } Thread.Sleep(100); Application.DoEvents(); } } // *** No catch let it throw finally { this._OutputCaptureFile = ReflectionUtils.GetPropertyCom(this.SnagItCom, "LastFileWritten") as string; if (this.ActiveForm != null) { // Reactivate Live Writer this.ActiveForm.WindowState = OldState; Application.DoEvents(); // Make sure it pops on top of SnagIt Editors this.ActiveForm.TopMost = true; Application.DoEvents(); Thread.Sleep(5); this.ActiveForm.TopMost = false; } Marshal.ReleaseComObject(this.SnagItCom); } // *** If deleting the file we'll fire on a new thread and then delay by // *** a few seconds until Writer has picked up the image. if ((this.DeleteImageFromDisk)) { Thread thread = new Thread(new ParameterizedThreadStart(DeleteImage)); thread.Start(this.OutputCaptureFile); } return(this.OutputCaptureFile); }