This repository was archived by the owner on Nov 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Creating a Data Request
brian barnes edited this page Apr 3, 2018
·
4 revisions
A data request is an operation that requires the user provide additional data to the server.
In order to request data, you must have the following information ready:
- The URI (Unique Request Interface). This is the name that identifies which request you want to use. For example, if you want to show a menu to the user, you would use the
rcmd_smenuURI. - The Message: This will be the message the user sees when the request is sent.
- Arguments: The data that will be used to build the request (Like the options in a menu)
- The Metadata: Any additional settings that will be passed to the client (Menu option color, background color, etc.) Most of these things you don't need to mess around, because there are libraries that abstract these details.
In order to make a data Request, execute this line of code:
Dictionary<string, string> arguments = new Dictionary<string, string>();
arguments.Add("1", "Exit");
Dictionary<string, string> metadata = new Dictionary<string, string>();
metadata.Add("HeaderBackColor", "Green");
RemotePlusLibrary.RequestBuilder builder = new RemotePlusLibrary.RequestBuilder("rcmd_smenu", "Please select an option.", arguments);
RemotePlusLibrary.ReturnData data = ServerManager.DefaultService.Remote.Client.ClientCallback.RequestInformation(builder);
Console.WriteLine(data.Data.ToString());In order to build a data request, you must follow these steps:
- Create a class and implement
IDataRequest - Register the request into the global request store on the client
We are going to build a data request that forces a user to select a file.
A request is just a class that implements the IDataRequest interface.
Here is a basic framework:
using RemotePlusLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ClientTools
{
public class ExampleRequest : IDataRequest
{
public bool ShowProperties => false;
public string FriendlyName => "Example Request";
public string Description => "A request that shows a show file dialog.";
public RawDataRequest RequestData(RequestBuilder builder)
{
throw new NotImplementedException();
}
public void Update(string message)
{
throw new NotImplementedException();
}
public void UpdateProperties()
{
throw new NotImplementedException();
}
}
}- The
ShowPropertiesproperty determines whether a user can access saved settings for this request. This feature has been deprecated. -
FriendlyNameis what is shown in the list of all registered requests in the request store. -
Descriptionis what the request does. It is shown in the list of all registired requests in the request store. -
RequestData(RequestBuilder builder)is called when the server requests data from the client. TheRequestBuilderclass contains all the data required to build a request. -
Update(string message)is called when a server needs to update a request about a certain activity. -
UpdateProperties()is called when a user wants to update a request's settings andShowPropertiesis true
Here is when the request class is finished:
using RemotePlusLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ClientTools
{
public class FileRequest : IDataRequest
{
public bool ShowProperties => false;
public string FriendlyName => "File Request";
public string Description => "A request that shows a show file dialog.";
public RawDataRequest RequestData(RequestBuilder builder)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = builder.Message;
if(builder.Metadata.ContainsKey("Filter"))
{
ofd.Filter = builder.Metadata["Filter"];
}
if(ofd.ShowDialog() == DialogResult.OK)
{
RawDataRequest response = RawDataRequest.Success(ofd.FileName);
return response;
}
else
{
return RawDataRequest.Cancel();
}
}
public void Update(string message)
{
throw new NotImplementedException();
}
public void UpdateProperties()
{
throw new NotImplementedException();
}
}
}In your client extension library's Startup.cs file, add the following lines of code:
using RemotePlusClient.ExtensionSystem;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RemotePlusLibrary.Extension;
using RemotePlusClient.CommonUI;
namespace ClientTools
{
public class Startup : IClientLibraryStartup
{
public void ClientInit(ILibraryBuilder builder, IInitEnvironment env)
{
RequestStore.Add("fileRequest", new FileRequest());
}
}
}RequestStore.Add contains two parameters:
- The URI (Unique Request Interface).
- The request.
Before running a command that uses your new request, make sure that the client extension library is loaded first.