Beispiel #1
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            GetResourceResponse response = new GetResourceResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("ResourceDescription", targetDepth))
                {
                    var unmarshaller = ResourceDescriptionUnmarshaller.Instance;
                    response.ResourceDescription = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("TypeName", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.TypeName = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
Beispiel #2
0
        public static async Task <Resource> GetResourceAsync(this IMediator mediator, ResourceKey key, CancellationToken cancellationToken = default)
        {
            EnsureArg.IsNotNull(mediator, nameof(mediator));
            EnsureArg.IsNotNull(key, nameof(key));

            GetResourceResponse result = await mediator.Send(new GetResourceRequest(key), cancellationToken);

            return(result.Resource);
        }
        void ProcGet()
        {
            OutputManager.Ui.Write("What is the name the resource to get?");
            string resourceName = Console.ReadLine();
            string resourceId   = EZHash.GetHashString(resourceName);

            Messages.GetResourceRequest  grr         = new GetResourceRequest(this.localNode, resourceId);
            Messages.Message             tmpResponse = this.localNode.SendMessage(grr);
            Messages.GetResourceResponse rep         = new GetResourceResponse(tmpResponse.ToString());
            if (rep.resourceFoundSuccessfully)
            {
                OutputManager.Ui.Write(rep.resourceContent);
            }
            else
            {
                OutputManager.Ui.Write("A resource with that name could not be found.");
            }
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            GetResourceResponse response = new GetResourceResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("id", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.Id = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("parentId", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.ParentId = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("path", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.Path = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("pathPart", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.PathPart = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("resourceMethods", targetDepth))
                {
                    var unmarshaller = new DictionaryUnmarshaller <string, Method, StringUnmarshaller, MethodUnmarshaller>(StringUnmarshaller.Instance, MethodUnmarshaller.Instance);
                    response.ResourceMethods = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
        // Send a Message to a remote node
        public Message SendMessage(Message msg)
        {
            Message responseMsg; // Use to send the response

            if (msg is AddResourceRequest && this.succNode.Id == this.Id)
            {
                AddResourceRequest arm = msg as AddResourceRequest;
                SetLocalResource(arm.resourceId, arm.resourceName, arm.resourceContent);
                responseMsg = new AddResourceResponse(this, arm.resourceId, arm.resourceName);
            }
            else if (msg is GetResourceRequest && this.succNode.Id == this.Id)
            {
                GetResourceRequest grm     = msg as GetResourceRequest;
                string             content = GetLocalResource(grm.resourceId);
                responseMsg = new GetResourceResponse(this, grm.resourceId, "LOCALNODE ERR: RESOURCE NAME UNKNOWN!", content);
            }
            else
            {
                responseMsg = clientComponent.SendMsg(msg);
            }
            return(responseMsg);
        }