public static IEditor AddTable(IEditor editor, Point location, MemoTable table, bool useCommandExecutor) { if (table == null || table.RowCount == 0 || table.ColumnCount == 0) { return(null); } using (editor.Figure.DirtManager.BeginDirty()) { var req = new CreateNodeRequest(); req.ModelFactory = new DelegatingModelFactory <MemoTable>( () => { return(table); } ); req.Bounds = new Rectangle(location, new Size(table.ColumnCount * 50, table.RowCount * 20)); req.AdjustSizeToGrid = false; var cmd = editor.GetCommand(req) as CreateNodeCommand; if (useCommandExecutor) { editor.Site.CommandExecutor.Execute(cmd); } else { cmd.Execute(); } return(cmd.CreatedEditor); } }
/// <summary> /// Create a node in a tree. /// </summary> /// <param name="parentTree">The parent tree in which the node is created.</param> /// <returns>The created node.</returns> private async Task <Node> CreateNode(Tree parentTree) { if (parentTree != null) { var createNodeRequest = new CreateNodeRequest { ForestId = parentTree.ForestId, TreeId = parentTree.Id, Id = $"CDMServicesDemo:Org:Node-{Guid.NewGuid().ToString()}", // Optional (if not specified, the service will auto-generate it) Name = "DemoNode", // Optional Links = new string[] // Optional { "frn:DemoLink-01", "frn:DemoLink-02" }, }; Console.WriteLine($"Creating node with ForestId={createNodeRequest.ForestId}, TreeId={createNodeRequest.TreeId}, Id={createNodeRequest.Id}, Name={createNodeRequest.Name}..."); Node node = await this.orgClient.CreateNodeAsync(createNodeRequest).ConfigureAwait(false); Console.Write($"Created node: "); this.PrintNode(node); Console.WriteLine(); return(node); } return(null); }
private static CreateNodeCommand GetAddImageCommand(IEditor editor, Point location, Image img) { using (editor.Figure.DirtManager.BeginDirty()) { if (img == null) { return(null); } var codec = ImageUtil.GetCodec(img); if (codec == null) { codec = ImageUtil.GetCodec(ImageFormat.Png); } using (var encoderParams = ImageUtil.CreateEncoderParameters(100L)) { var imgFilePath = GetNewImageFilePath(); img.Save(imgFilePath, codec, encoderParams); var desc = new FileImageDescription(Path.GetFileName(imgFilePath)); var req = new CreateNodeRequest(); req.ModelFactory = new DelegatingModelFactory <MemoImage>( () => { var ret = MemoFactory.CreateImage(); ret.Image = desc; return(ret); } ); req.Bounds = new Rectangle(location, new Size(img.Width, img.Height)); req.AdjustSizeToGrid = false; return(editor.GetCommand(req) as CreateNodeCommand); } } }
// ======================================== // constructor // ======================================== public CreateNodeTool(IModelFactory modelFactory, INode feedback, Action <INode> nodeInitializer) : base(feedback) { _focusOnCreated = false; _request = new CreateNodeRequest(); _request.ModelFactory = modelFactory; _defaultNodeSize = new Size(80, 64); _nodeInitializer = nodeInitializer; }
/// <summary> /// Initiates the asynchronous execution of the CreateNode operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the CreateNode operation.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns>The task object representing the asynchronous operation.</returns> /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/managedblockchain-2018-09-24/CreateNode">REST API Reference for CreateNode Operation</seealso> public virtual Task <CreateNodeResponse> CreateNodeAsync(CreateNodeRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var options = new InvokeOptions(); options.RequestMarshaller = CreateNodeRequestMarshaller.Instance; options.ResponseUnmarshaller = CreateNodeResponseUnmarshaller.Instance; return(InvokeAsync <CreateNodeResponse>(request, options, cancellationToken)); }
internal virtual CreateNodeResponse CreateNode(CreateNodeRequest request) { var options = new InvokeOptions(); options.RequestMarshaller = CreateNodeRequestMarshaller.Instance; options.ResponseUnmarshaller = CreateNodeResponseUnmarshaller.Instance; return(Invoke <CreateNodeResponse>(request, options)); }
public static ICommand RequestCreateNode(this IEditor editor, IModelFactory modelFactory, Rectangle bounds, bool fitGrid) { var req = new CreateNodeRequest(); req.ModelFactory = modelFactory; req.Bounds = bounds; req.AdjustSizeToGrid = fitGrid; return(editor.PerformRequest(req)); }
/// <summary> /// 创建节点 /// </summary> public async Task <CreateNodeResponse> CreateNodeAsync(CreateNodeRequest createNodeRequest) { Dictionary <string, string> urlParam = new Dictionary <string, string>(); urlParam.Add("cluster_id", createNodeRequest.ClusterId.ToString()); string urlPath = HttpUtils.AddUrlPath("/api/v3/projects/{project_id}/clusters/{cluster_id}/nodes", urlParam); SdkRequest request = HttpUtils.InitSdkRequest(urlPath, "application/json", createNodeRequest); HttpResponseMessage response = await DoHttpRequestAsync("POST", request); return(JsonUtils.DeSerialize <CreateNodeResponse>(response)); }
private void PopulateDecoratorNodes(GenericMenu menu, BonsaiNode node) { var decorators = BonsaiEditor.RegisteredBehaviourNodeTypes.Where(t => t.IsSubclassOf(typeof(BTAuxiliary)) && !t.IsAbstract); foreach (var subclass in decorators) { menu.AddItem(new GUIContent("Decorator/" + subclass.Name), false, () => { CreateNodeRequest?.Invoke("Decorator", subclass); TypeChanged?.Invoke(this, node); }); } }
/// <summary> /// The callback to create the node via typename. /// </summary> /// <param name="o">The typename as a string.</param> private void OnCreateNodeRequest(object o) { CreateNodeRequest?.Invoke(this, o as Type); }
public async Task <Guid> CreateNode([FromBody] CreateNodeRequest request) => await _contentService.CreateNodeAsync(request.Parent, request.Alias, request.Type, request.DisplayName);
/// <summary> /// Creates the node asynchronously /// </summary> /// <param name="authenticationKey">The authentication key.</param> /// <param name="nodeName">Name of the node.</param> /// <param name="boardName">Name of the board.</param> /// <returns></returns> public async Task <NodeToken> CreateNodeAsync(string authenticationKey, string nodeName, string boardName = BoardTypes.WioNode) { var request = new CreateNodeRequest(authenticationKey, nodeName, boardName); return(await this.ProcessRequest <NodeToken>(request)); }
protected void HandleAddTableToolStripButtonClick(object sender, EventArgs e) { if (_EditorCanvas == null) { return; } var dialog = new CreateTableForm(); if (dialog.ShowDialog(this) != DialogResult.OK) { return; } var colCount = dialog.ColumnCount; var rowCount = dialog.RowCount; var target = _EditorCanvas.RootEditor.Content; var bounds = new Rectangle(32, 32, 100, 100); var modelFactory = new DelegatingModelFactory <MemoTable>( () => { var ret = MemoFactory.CreateTable(); return(ret); } ); var req = new CreateNodeRequest(); req.ModelFactory = modelFactory; req.Bounds = bounds; var createdBounds = Rectangle.Empty; var cmd1 = target.GetCommand(req) as CreateNodeCommand; var cmd2 = new DelegatingCommand( () => { var created = cmd1.CreatedEditor; if (created != null) { var table = created.Model as MemoTable; for (int i = 0; i < colCount; ++i) { table.AddColumn(); } for (int i = 0; i < rowCount; ++i) { table.AddRow(); } } }, () => {}, () => { // todo: これでもundo,redoで行,列の幅が復元できない // Boundsは復元される var created = cmd1.CreatedEditor; created.Figure.Bounds = createdBounds; } ); var cmd = cmd1.Chain(cmd2); _EditorCanvas.CommandExecutor.Execute(cmd); createdBounds = cmd1.CreatedEditor.Figure.Bounds; dialog.Dispose(); FocusEditorCanvas(); //var cmd = target.RequestCreateNode(modelFactory, bounds) as CreateNodeCommand; //var created = cmd.CreatedEditor; //if (created != null) { // var colCount = 3; // var rowCount = 3; // var table = created.Model as MemoTable; // for (int i = 0; i < colCount; ++i) { // table.AddColumn(); // } // for (int i = 0; i < rowCount; ++i) { // foreach (var cell in table.AddRow().Cells) { // var run = new Run("テスト" + i); // var para = new Paragraph(run); // para.Padding = new Insets(); // para.HorizontalAlignment = HorizontalAlignment.Left; // var stext = new StyledText(para); // stext.VerticalAlignment = VerticalAlignment.Center; // stext.Font = _facade.Settings.GetDefaultMemoContentFont(); // cell.StyledText = stext; // } // } //} }
// ------------------------------ // private // ------------------------------ //private static ImageCodecInfo GetCodec(ImageFormat format) { // var codecs = ImageCodecInfo.GetImageDecoders(); // foreach (var codec in codecs) { // if (codec.FormatID == format.Guid) { // return codec; // } // } // return null; //} //private static ImageCodecInfo GetCodec(Image image) { // var codecs = ImageCodecInfo.GetImageDecoders(); // foreach (var codec in codecs) { // if (codec.FormatID == image.RawFormat.Guid) { // return codec; // } // } // return null; //} private static IEditor AddTextBase(IEditor editor, Point location, Action <StyledTextFocus> insert, bool useCommandExecutor) { using (editor.Figure.DirtManager.BeginDirty()) { if (editor.Site.FocusManager.FocusedEditor != null) { editor.Site.FocusManager.FocusedEditor.RequestFocusCommit(true); } var req = new CreateNodeRequest(); { req.ModelFactory = new DelegatingModelFactory <MemoText>( () => { var ret = MemoFactory.CreateText(); var defaultFont = MemopadApplication.Instance.Settings.GetDefaultMemoTextFont(); if (defaultFont != null) { ret.StyledText.Font = defaultFont; } return(ret); } ); //req.Bounds = new Rectangle(location + MemopadConsts.MemoTextFirstCharDelta, new Size(40, 8)); req.Bounds = new Rectangle(location, new Size(40, 8)); req.AdjustSizeToGrid = true; } var cmd = editor.GetCommand(req) as CreateNodeCommand; if (useCommandExecutor) { editor.Site.CommandExecutor.Execute(cmd); } else { cmd.Execute(); } /// focus commit commandがこのcreate node commandとマージされるようにしておく //cmd.MergeJudge = next => { // var focusCmd = next as FocusCommand; // if (focusCmd == null) { // return false; // } // return focusCmd.Value == FocusKind.Commit; // //next is FocusCommand; //}; if (cmd != null && cmd.CreatedEditor != null) { var canvasSize = editor.Site.EditorCanvas.ClientSize; var maxWidth = 0; var defaultMaxWidth = MemopadApplication.Instance.WindowSettings.MemoTextDefaultMaxWidth; if (defaultMaxWidth <= 50) { maxWidth = Math.Max((int)(canvasSize.Width * 0.9) - location.X, (int)(canvasSize.Width * 0.5)); } else { maxWidth = defaultMaxWidth; } var maxSize = new Size(maxWidth, int.MaxValue); ((INode)cmd.CreatedEditor.Figure).MaxSize = maxSize; cmd.CreatedEditor.RequestFocus(FocusKind.Begin, location); var focus = editor.Site.FocusManager.Focus as StyledTextFocus; insert(focus); // 1文字目と2文字目が入れ替わってしまう //cmd.CreatedEditor.RequestFocusCommit(true); //cmd.CreatedEditor.RequestFocus(FocusKind.Begin, location); } return(cmd.CreatedEditor); } }
public static IEnumerable <IEditor> AddMetafile(IEditor editor, Point location, Metafile meta, bool useCommandExecutor, bool arrange) { using (editor.Figure.DirtManager.BeginDirty()) using (var mem = new MemoryStream()) { if (useCommandExecutor && arrange) { editor.Site.CommandExecutor.BeginChain(); } var existingEditorBounds = default(Rectangle[]); if (arrange) { existingEditorBounds = editor.Children.Select(e => e.Figure.Bounds).ToArray(); } using (var bmp = new Bitmap(1, 1)) using (var bmpg = Graphics.FromImage(bmp)) { var hdc = bmpg.GetHdc(); using (var mf = new Metafile(mem, hdc)) { bmpg.ReleaseHdc(hdc); using (var g = Graphics.FromImage(mf)) { g.DrawImage(meta, Point.Empty); } } } var imgFilePath = GetNewImageFilePath(); File.WriteAllBytes(imgFilePath, mem.GetBuffer()); var desc = new FileImageDescription(Path.GetFileName(imgFilePath)); var req = new CreateNodeRequest(); req.ModelFactory = new DelegatingModelFactory <MemoImage>( () => { var ret = MemoFactory.CreateImage(); ret.Image = desc; return(ret); } ); req.Bounds = new Rectangle(location, meta.Size); req.AdjustSizeToGrid = false; var cmd = editor.GetCommand(req) as CreateNodeCommand; if (useCommandExecutor) { editor.Site.CommandExecutor.Execute(cmd); } else { cmd.Execute(); } meta.Dispose(); if (arrange) { var newLoc = RectUtil.GetPreferredLocation( cmd.CreatedEditor.Figure.Bounds, existingEditorBounds, editor.Root.Figure.Right, MemopadConsts.DefaultCaretPosition.X, MemopadConsts.DefaultCaretPosition.Y ); var move = new ChangeBoundsCommand( cmd.CreatedEditor, (Size)newLoc - (Size)cmd.CreatedEditor.Figure.Location, Size.Empty, Directions.None, new [] { cmd.CreatedEditor } ); if (useCommandExecutor) { editor.Site.CommandExecutor.Execute(move); } else { move.Execute(); } if (useCommandExecutor) { editor.Site.CommandExecutor.EndChain(); } } return(new[] { cmd.CreatedEditor }); } }
public static IEnumerable <IEditor> AddFile(IEditor target, Point location, string filePath, bool embed, bool useCommandExecutor, bool arrange) { var isFile = File.Exists(filePath); var isDirectory = Directory.Exists(filePath); if (isFile || isDirectory) { var fileName = Path.GetFileName(filePath); var path = filePath; var embeddedId = ""; if (!isFile && !isDirectory) { MessageBox.Show("ファイルが見つかりませんでした。", "ファイルエラー"); return(EmptyEditors); } /// 埋め込む場合はEmbeddedFileRootにコピー if (embed && isFile) { embeddedId = Guid.NewGuid().ToString(); path = Path.Combine(embeddedId, fileName); var fullPath = Path.Combine(MemopadConsts.EmbeddedFileRoot, path); try { PathUtil.EnsureDirectoryExists(Path.GetDirectoryName(fullPath)); File.Copy(filePath, fullPath); } catch { Logger.Warn("File copy failed. source=" + filePath + ",target=" + fullPath); if (Directory.Exists(fullPath)) { Directory.Delete(Path.GetDirectoryName(fullPath), true); } MessageBox.Show("ファイルのコピーに失敗しました。", "ファイルコピーエラー"); } } var bounds = new Rectangle(location, new Size(1, 1)); var modelFactory = new DelegatingModelFactory <MemoFile>( () => { var ret = MemoFactory.CreateFile(); ret.Name = fileName; ret.Path = path; ret.IsEmbedded = embed && isFile; ret.EmbeddedId = embeddedId; return(ret); } ); if (useCommandExecutor && arrange) { target.Site.CommandExecutor.BeginChain(); } var existingEditorBounds = default(Rectangle[]); if (arrange) { existingEditorBounds = target.Children.Select(e => e.Figure.Bounds).ToArray(); } var req = new CreateNodeRequest(); req.ModelFactory = modelFactory; req.Bounds = bounds; req.AdjustSizeToGrid = true; var cmd = target.GetCommand(req) as CreateNodeCommand; var sizeCmd = new DelegatingCommand( () => { var node = cmd.CreatedEditor.Figure as INode; if (node != null) { node.AdjustSize(); } }, () => { cmd.CreatedEditor.Figure.Bounds = bounds; } ); var chain = cmd.Chain(sizeCmd); if (useCommandExecutor) { target.Site.CommandExecutor.Execute(chain); } else { chain.Execute(); } if (arrange) { var newLoc = RectUtil.GetPreferredLocation( cmd.CreatedEditor.Figure.Bounds, existingEditorBounds, target.Root.Figure.Right, MemopadConsts.DefaultCaretPosition.X, MemopadConsts.DefaultCaretPosition.Y ); var move = new ChangeBoundsCommand( cmd.CreatedEditor, (Size)newLoc - (Size)cmd.CreatedEditor.Figure.Location, Size.Empty, Directions.None, new [] { cmd.CreatedEditor } ); if (useCommandExecutor) { target.Site.CommandExecutor.Execute(move); } else { move.Execute(); } if (useCommandExecutor) { target.Site.CommandExecutor.EndChain(); } } return(new[] { cmd.CreatedEditor }); } return(EmptyEditors); }