Beispiel #1
0
        public IpcScope(IBrowserService browserService, WebviewIpcMessage message)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException($"{nameof(IpcScope)}");
            }

            _browserService = browserService;
            _message        = new WebviewIpcMessage(message.Id);
        }
Beispiel #2
0
        /// <summary>
        /// Attach additional data to the response message
        /// </summary>
        /// <param name="params"></param>
        /// <param name="error"></param>
        public void FulfillRequest(JToken @params, string error = null)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException($"{nameof(FulfillRequest)}");
            }

            _message = error.IsNullOrWhiteSpace() ?
                       new WebviewIpcMessage(_message.Id, @params) :
                       new WebviewIpcMessage(_message.Id, @params, new JValue(error));
        }
Beispiel #3
0
        /// <summary>
        /// Attach an error, if any, to the response
        /// </summary>
        /// <param name="error"></param>
        public void FulfillRequest(string error)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException($"{nameof(FulfillRequest)}");
            }

            if (error.IsNullOrWhiteSpace())
            {
                return;
            }

            _message = new WebviewIpcMessage(_message.Id, _message.Params, new JValue(error));
        }
Beispiel #4
0
        public static WebviewIpcMessage Parse(JToken token)
        {
            string method = null;

            try {
                method = token.Value <string>("method");
                return(new WebviewIpcMessage(token.Value <string>("id"),
                                             method, token.Value <JToken>("params"),
                                             token.Value <JToken>("error")));
            }
            catch (Exception ex) {
                Log.Error(ex, "Token could not be parsed. Type={Type}", method);
            }

            return(WebviewIpcMessage.New());
        }
Beispiel #5
0
 /// <summary>
 /// Creates a scope, that if not completed, sends a generic response message
 /// </summary>
 /// <param name="ipc"></param>
 /// <param name="message"></param>
 /// <returns></returns>
 public static IpcScope Create(IBrowserService ipc, WebviewIpcMessage message)
 {
     return(new IpcScope(ipc, message));
 }