private void _check(CommandTargetFlags flags) { bool require_app = (flags & CommandTargetFlags.RequireApplication) != 0; bool require_document = (flags & CommandTargetFlags.RequireDocument) != 0; bool require_page = (flags & CommandTargetFlags.RequirePage) != 0; require_app = require_app || require_document || require_page; require_document = require_document || require_page; this.Application = this._client.Application.GetApplication(); if (require_app && this.Application == null) { string msg = string.Format("{0}: No Visio Application available", nameof(CommandTarget)); throw new System.ArgumentException(msg); } if (require_document && this.ActiveDocument == null) { var doc = this.Application.ActiveDocument; string errmsg; this.ActiveDocument = doc; bool is_drawing = IsDocumentADrawing(this.Application, this.ActiveDocument, out errmsg); if (is_drawing) { this._client.Output.WriteVerbose("{0}: Verified a drawing is available for use", nameof(CommandTarget)); } else { string msg = string.Format("{0}: The Document is not a drawing document", nameof(CommandTarget)); throw new VisioOperationException(msg); } } if (require_document && this.ActiveDocument == null) { string msg = string.Format("{0}: No Document", nameof(CommandTarget)); throw new VisioOperationException(msg); } if (require_page && this.ActivePage == null) { if (this.Application == null) { string msg = string.Format("{0}: Internal error application should never be null in this case", nameof(CommandTarget)); throw new VisioOperationException(msg); } this.ActivePage = this.Application.ActivePage; } if (require_page && this.ActivePage == null) { string msg = string.Format("{0}: No Page", nameof(CommandTarget)); throw new VisioOperationException(msg); } }
public CommandTarget GetCommandTarget(CommandTargetFlags flags) { var ct = new CommandTarget(this, flags); return(ct); }
public CommandTarget(Client client, CommandTargetFlags flags) { this._client = client; _check(flags); }