/// <summary> /// Updates multiple hosts in a single request /// </summary> /// <param name="body"></param> /// <returns></returns> public void UpdateHosts(HostRequest body) { var path = "/hosts"; path = path.Replace("{format}", "json"); var queryParams = new Dictionary <String, String>(); var headerParams = new Dictionary <String, String>(); var formParams = new Dictionary <String, String>(); var fileParams = new Dictionary <String, FileParameter>(); String postBody = null; postBody = ApiClient.Serialize(body); // http body (model) parameter // authentication setting, if any String[] authSettings = new String[] { }; // make the HTTP request IRestResponse response = (IRestResponse)ApiClient.CallApi(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings); if (((int)response.StatusCode) >= 400) { throw new ApiException((int)response.StatusCode, "Error calling UpdateHosts: " + response.Content, response.Content); } else if (((int)response.StatusCode) == 0) { throw new ApiException((int)response.StatusCode, "Error calling UpdateHosts: " + response.ErrorMessage, response.ErrorMessage); } return; }
protected override void WriteContent(IContext objContext, string strFullName) { // Get request and response HostRequest objRequest = objContext.HostContext.Request; HostResponse objResponse = objContext.HostContext.Response; // Get ResizeMethod and then either Percentage or Width+Height ResizeMethod enmResizeMethod = (ResizeMethod)Enum.Parse(typeof(ResizeMethod), objRequest.QueryString["Method"]); if (enmResizeMethod == ResizeMethod.None) { base.WriteContent(objContext, strFullName); } else if (enmResizeMethod == ResizeMethod.Propotional) { double dblPercentage = double.Parse(objRequest.QueryString["Percent"], System.Globalization.CultureInfo.InvariantCulture); Image objImage = this.ScaleToPercent(strFullName, dblPercentage); this.SaveImageToOutputStream(objResponse.OutputStream, objImage, strFullName); objImage.Dispose(); } else if (enmResizeMethod == ResizeMethod.Size) { int intWidth = int.Parse(objRequest.QueryString["Width"]); int intHeight = int.Parse(objRequest.QueryString["Height"]); Image objImage = this.ScaleToSize(strFullName, intWidth, intHeight); this.SaveImageToOutputStream(objResponse.OutputStream, objImage, strFullName); objImage.Dispose(); } else { throw new ArgumentOutOfRangeException("StaticImageResizeHandle missing resize method"); } }
public ActionResult SubmitRequest(HostRequestViewModel model) { if (!ModelState.IsValid) { return(View("HostingRequestForm", model)); } var selectedAmenities = model.Amenities.Where(m => m.Checked == true).ToList(); var homeAmenities = new List <SelectedAmenity>(); foreach (var amenity in selectedAmenities) { homeAmenities.Add(new SelectedAmenity { Name = amenity.Name }); } model.Home.Amenities = homeAmenities; _context.Homes.Add(model.Home); // Create new host request for the new home HostRequest request = new HostRequest(); request.Home = model.Home; request.UserID = User.Identity.GetUserId(); request.RequestDate = DateTime.Now; request.RequestStatus = "Pending"; _context.HostRequests.Add(request); _context.SaveChanges(); return(RedirectToAction("HostingRequests", "User", null)); }
private byte SendCommandAndHandleResponse(HostRequest command) { LogHelper.Log("PID {0} - Sending command: {1}", this.process.Id, command); this.pipe.WriteByte((byte)command); byte response = (byte)this.pipe.ReadByte(); LogHelper.Log("PID {0} - Received response: {1}", this.process.Id, (HostResponse)response); Assert.IsTrue((response & (byte)HostResponse.Error) == 0); return(response); }
public static void Call(HostRequest req) { var method = req.GetType().Name; string messageJson = JsonUtility.ToJson(req); Debug.Log("Call: " + method + ": " + messageJson); try { hostCallMethod(method, messageJson); } catch (EntryPointNotFoundException) { Debug.Log("hostCallMethod not found"); } }
public static void Main1() { AsyncCallback callBack = new AsyncCallback(ProcessDnsInformation); string host; do { Console.Write(" Enter the name of a host computer or <enter> to finish: "); host = Console.ReadLine(); if (host.Length > 0) { Interlocked.Increment(ref requestCounter); HostRequest request = new HostRequest(host); hostData.Add(request); Dns.BeginGetHostEntry(host, callBack, request); } }while (host.Length > 0); while (requestCounter > 0) { UpdateUserInterface(); } foreach (HostRequest r in hostData) { if (r.ExceptionObject != null) { Console.WriteLine("Request for host {0} returned the following error: {1}.", r.HostName, r.ExceptionObject.Message); } else { IPHostEntry h = r.HostEntry; string[] aliases = h.Aliases; IPAddress[] addresses = h.AddressList; if (aliases.Length > 0) { Console.WriteLine("Aliases for {0}", r.HostName); foreach (string t in aliases) { Console.WriteLine("{0}", t); } } if (addresses.Length > 0) { Console.WriteLine("Addresses for {0}", r.HostName); foreach (IPAddress t in addresses) { Console.WriteLine("{0}", t.ToString()); } } } } }
/// <summary> /// Gets the gateway handler. /// </summary> /// <param name="objContext">Request context.</param> /// <returns></returns> IStaticGatewayHandler IStaticGateway.GetGatewayHandler(IContext objContext) { // Get request and response HostRequest objRequest = objContext.HostContext.Request; HostResponse objResponse = objContext.HostContext.Response; // Get filename and content type from decoded query parameters string strFilename = HttpUtility.UrlDecode(objRequest.QueryString["Qualifier"]); string strContentType = HttpUtility.UrlDecode(objRequest.QueryString["Token"]); // Write it this.Write(objContext, this.getFullName(strFilename), strContentType); return(null); }
private static void ProcessDnsInformation(IAsyncResult result) { HostRequest request = (HostRequest)result.AsyncState; try { IPHostEntry host = Dns.EndGetHostEntry(result); request.HostEntry = host; } catch (SocketException e) { request.ExceptionObject = e; } finally { Interlocked.Decrement(ref requestCounter); } }
/// <summary> /// Updates a host /// </summary> /// <param name="hostName">host name</param> /// <param name="body"></param> /// <returns></returns> public void UpdateHost(string hostName, HostRequest body) { // verify the required parameter 'hostName' is set if (hostName == null) { throw new ApiException(400, "Missing required parameter 'hostName' when calling UpdateHost"); } var path = "/hosts/{hostName}"; path = path.Replace("{format}", "json"); path = path.Replace("{" + "hostName" + "}", ApiClient.ParameterToString(hostName)); var queryParams = new Dictionary <String, String>(); var headerParams = new Dictionary <String, String>(); var formParams = new Dictionary <String, String>(); var fileParams = new Dictionary <String, FileParameter>(); String postBody = null; postBody = ApiClient.Serialize(body); // http body (model) parameter // authentication setting, if any String[] authSettings = new String[] { }; // make the HTTP request IRestResponse response = (IRestResponse)ApiClient.CallApi(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings); if (((int)response.StatusCode) >= 400) { throw new ApiException((int)response.StatusCode, "Error calling UpdateHost: " + response.Content, response.Content); } else if (((int)response.StatusCode) == 0) { throw new ApiException((int)response.StatusCode, "Error calling UpdateHost: " + response.ErrorMessage, response.ErrorMessage); } return; }
public void Get(string path, HostRequest reqFunction) { var cb = new Callback(path, reqFunction, RequestType.GET); _registeredCallbacks.Add(cb); }
public Callback(string url, HostRequest req, RequestType type) { Url = url; RequestDelegate = req; RequestType = type; }
/// <summary> /// Register a GET callback to the server with specified function that handles the input and performs the output. /// </summary> /// <param name="path">The path that the server has to be listening to.</param> /// <param name="reqFunction">The function that performs all the calculations.</param> public void Get(string path, HostRequest reqFunction) { _listener.Get(path, reqFunction); }