Exemplo n.º 1
0
        void ProcAddResource()
        {
            OutputManager.Ui.Write("What is the name of this new resouce?");
            string resourceName = Console.ReadLine();

            OutputManager.Ui.Write("What is the contents of this new resouce?");
            string resourceContent = Console.ReadLine();
            string resourceId      = EZHash.GetHashString(resourceName);

            Messages.AddResourceRequest  addResourceReq      = new AddResourceRequest(this.localNode, resourceId, resourceName, resourceContent);
            Messages.Message             tmpResponse         = localNode.SendMessage(addResourceReq);
            Messages.AddResourceResponse addResourceResponse = new AddResourceResponse(tmpResponse.ToString());
            if (addResourceResponse.resourceAddedSuccessfully)
            {
                OutputManager.Ui.Write($"The resource \"{resourceName}\" was added successfully.");
            }
            else
            {
                OutputManager.Ui.Write($"Failed to add the resource \"{resourceName}\"");
            }
        }
Exemplo n.º 2
0
        // 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);
        }