/// <summary> /// Gets the HTTP response message. /// </summary> /// <param name="message">The message.</param> /// <returns></returns> private HttpResponseMessage GetHttpResponseMessage(ApiBaseModel message) { var httpmessage = new HttpResponseMessage(); var jsonmedia = new JsonMediaTypeFormatter(); httpmessage.Content = new ObjectContent(typeof(ApiBaseModel), message, jsonmedia); return httpmessage; }
public void AddUser_Hosting() { var controller = new HostingWindowsController(new HostingServiceWindowsPanel()); UserInfo user = new UserInfo(); user.UserId = 0; user.Role = UserRole.User; user.StatusId = 1; user.OwnerId = 2; user.IsDemo = false; user.IsPeer = false; user.FirstName = "firstNamexzxz"; user.LastName = "lastNamexzxz"; user.Email = "*****@*****.**"; user.Username = "******"; user.Password = "******"; string message = ""; ApiBaseModel model = new ApiBaseModel() { PanelApiUsername = apiUser, PanelApiCryptokey = key, PanelApiPassword = pwd, PanelApiUrl = url }; var result = controller.AddUser(user, model, out message); Assert.IsNotNull(result); Assert.AreEqual(result.ToString(), "1"); }
private void AddEvent(ApiBaseModel model, string description) { Data.Data.Events.Add(new Data.Event() { Name = model.Type, SerialNumber = model.Serial, When = DateTime.Now.ToString(), Description = description }); }
public void AddPackage_Hosting() { var controller = new HostingWindowsController(new HostingServiceWindowsPanel()); string message = ""; ApiBaseModel model = new ApiBaseModel() { PanelApiUsername = apiUser, PanelApiCryptokey = key, PanelApiPassword = pwd, PanelApiUrl = url }; var result = controller.AddPackageWithResources(model, 986, 6, targetDomainName, targetDomainName, out message); Assert.IsNotNull(result); Assert.AreEqual(result.ToString(), "1"); }
public void Update_Hosting() { var controller = new HostingWindowsController(new HostingServiceWindowsPanel()); string serviceId = "2"; string wspipaddressid = ""; string message = ""; ApiBaseModel model = new ApiBaseModel() { PanelApiUsername = apiUser, PanelApiCryptokey = key, PanelApiPassword = pwd, PanelApiUrl = url }; var result = controller.UpdateServiceSettings(model, serviceId, wspipaddressid, out message); Assert.IsNotNull(result); Assert.AreEqual(result.ToString(), "1"); }
//User adding Step3 public IHttpActionResult AddUser(UserInfo userInfo, ApiBaseModel model, out string message) { message = ""; try { if (!ModelState.IsValid) { return(JSendBadRequest(ModelState)); } var result = _hostingService.AddUser(userInfo, model, out message); return(JSendCreated("", result)); } catch (Exception ex) { return(JSendError(HttpStatusCode.InternalServerError, ex.Message)); } }
public IHttpActionResult UpdateServiceSettings([FromBody] ApiBaseModel model, string serviceId, string wspIpAddressId, out string message) { message = ""; try { if (!ModelState.IsValid) { return(JSendBadRequest(ModelState)); } var result = _hostingService.UpdateServiceSettings(model, serviceId, wspIpAddressId, out message); return(JSendCreated("", result)); } catch (Exception ex) { return(JSendError(HttpStatusCode.InternalServerError, ex.Message)); } }
//Package adding Step4 public IHttpActionResult AddPackageWithResources(ApiBaseModel model, int userId, int planId, string panelPlanName, string domainName, out string message, int statusId = 1, bool sendLater = false, bool createResource = true, bool tempdomain = true, bool createWebSite = true, bool createFtpAccount = true, string ftpAccountName = null, bool createMailAccount = false, string hostName = "") { message = ""; try { if (!ModelState.IsValid) { return(JSendBadRequest(ModelState)); } var result = _hostingService.AddPackageWithResources(model, userId, planId, panelPlanName, hostName, domainName, out message, statusId, sendLater, createResource, tempdomain, createWebSite, createFtpAccount, ftpAccountName, createMailAccount); return(JSendCreated("", result)); } catch (Exception ex) { return(JSendError(HttpStatusCode.InternalServerError, ex.Message)); } }
public async Task <ApiBaseModel <T> > Call <T>(HttpMethods method, string path, object callParams) where T : class { var objResult = new ApiBaseModel <T>(); try { _accessToken = Convert.ToString(App.GetPropertyValue("MobileApiToken")); _serverUrl = Convert.ToString(App.GetPropertyValue("MobileApiBaseURL")); string requestUriString = string.Format("{0}/{1}", _serverUrl, path); var httpWebRequest = (HttpWebRequest)WebRequest.Create(requestUriString); httpWebRequest.Method = method.ToString(); if (callParams != null && callParams != "") { if (method == HttpMethods.Get || method == HttpMethods.Delete) { httpWebRequest = (HttpWebRequest)WebRequest.Create(string.Format("{0}?{1}", requestUriString, callParams)); } if (method == HttpMethods.Post || method == HttpMethods.Put) { //using (new MemoryStream()) //{ // using (var streamWriter = new StreamWriter(await httpWebRequest.GetRequestStreamAsync())) // { // streamWriter.Write(callParams); // } //} using (var stream = new StreamWriter(httpWebRequest.GetRequestStream())) { var serialized = JsonConvert.SerializeObject(callParams); stream.Write(serialized); } } } httpWebRequest.ContentType = DefaultContentType; //httpWebRequest.Headers.Add("Authorization", string.Format("Bearer {0}", _accessToken)); httpWebRequest.Headers["Authorization"] = string.Format("Bearer {0}", _accessToken); httpWebRequest.Method = ((object)method).ToString(); var httpWebResponse = (HttpWebResponse)await httpWebRequest.GetResponseAsync(); string encodedData = string.Empty; using (Stream responseStream = httpWebResponse.GetResponseStream()) { if (responseStream != null) { using (var streamReader = new StreamReader(responseStream)) { encodedData = streamReader.ReadToEnd(); if (typeof(T) != typeof(object)) { objResult = JsonConvert.DeserializeObject <ApiBaseModel <T> > (encodedData); } } } } return(objResult); } catch (WebException ex) { //if ((ex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.Unauthorized) //{ //} //else //{ using (var stream = ex.Response.GetResponseStream()) using (var reader = new StreamReader(stream)) { objResult.ErrorMessage = ex.Message; } //} } catch (Exception ex) { objResult.ErrorMessage = ex.Message; } return(objResult); }
public void Add_Hosting() { var controller = new HostingWindowsController(new HostingServiceWindowsPanel()); HostingPlanInfo hpi = new HostingPlanInfo() { UserId = 2, PlanId = 0, IsAddon = false, PlanName = "varsayilan-plan-markumdestek", PlanDescription = null, Available = true, SetupPrice = 0, RecurringPrice = 0, RecurrenceLength = 1, RecurrenceUnit = 2, PackageId = 2, ServerId = 0, }; hpi.Groups = new HostingPlanGroupInfo[] { new HostingPlanGroupInfo() { CalculateBandwidth = true, CalculateDiskSpace = true, GroupId = 1 }, new HostingPlanGroupInfo() { CalculateBandwidth = true, CalculateDiskSpace = true, GroupId = 2 }, new HostingPlanGroupInfo() { CalculateBandwidth = true, CalculateDiskSpace = true, GroupId = 3 }, new HostingPlanGroupInfo() { CalculateBandwidth = true, CalculateDiskSpace = true, GroupId = 11 }, new HostingPlanGroupInfo() { CalculateBandwidth = true, CalculateDiskSpace = true, GroupId = 7 }, new HostingPlanGroupInfo() { CalculateBandwidth = true, CalculateDiskSpace = true, GroupId = 8 }, new HostingPlanGroupInfo() { CalculateBandwidth = true, CalculateDiskSpace = true, GroupId = 22 }, }; hpi.Quotas = new HostingPlanQuotaInfo[] { new HostingPlanQuotaInfo() { QuotaId = 70, QuotaValue = 1 }, new HostingPlanQuotaInfo() { QuotaId = 106, QuotaValue = 250 }, new HostingPlanQuotaInfo() { QuotaId = 107, QuotaValue = 1 }, new HostingPlanQuotaInfo() { QuotaId = 108, QuotaValue = 1 }, new HostingPlanQuotaInfo() { QuotaId = 211, QuotaValue = 2 }, new HostingPlanQuotaInfo() { QuotaId = 212, QuotaValue = 2 }, new HostingPlanQuotaInfo() { QuotaId = 213, QuotaValue = 50 }, new HostingPlanQuotaInfo() { QuotaId = 214, QuotaValue = 1 }, new HostingPlanQuotaInfo() { QuotaId = 215, QuotaValue = 1 }, new HostingPlanQuotaInfo() { QuotaId = 216, QuotaValue = 1 }, new HostingPlanQuotaInfo() { QuotaId = 217, QuotaValue = 20 }, }; string message = ""; ApiBaseModel model = new ApiBaseModel() { PanelApiUsername = apiUser, PanelApiCryptokey = key, PanelApiPassword = pwd, PanelApiUrl = url }; var result = controller.AddHosting(hpi, model, out message); Assert.IsNotNull(result); Assert.AreEqual(result.ToString(), "1"); }
public void EmulateHostingCreating() { ApiBaseModel model = new ApiBaseModel() { PanelApiUsername = apiUser, PanelApiCryptokey = key, PanelApiPassword = pwd, PanelApiUrl = url }; // validation will be implemented before service call in panel and core projects if (_isReseller) { var controller = new HostingWindowsController(new HostingServiceWindowsPanel()); HostingPlanInfo hpi = new HostingPlanInfo() { UserId = 1, PlanId = 0, IsAddon = false, PlanName = "Standart Plan", PlanDescription = "", Available = true, SetupPrice = 0, RecurringPrice = 0, RecurrenceLength = 1, RecurrenceUnit = 2, PackageId = 808, ServerId = 0, }; hpi.Groups = new HostingPlanGroupInfo[] { new HostingPlanGroupInfo() { CalculateBandwidth = true, CalculateDiskSpace = true, GroupId = 1 }, new HostingPlanGroupInfo() { CalculateBandwidth = true, CalculateDiskSpace = true, GroupId = 2 }, new HostingPlanGroupInfo() { CalculateBandwidth = true, CalculateDiskSpace = true, GroupId = 3 }, new HostingPlanGroupInfo() { CalculateBandwidth = true, CalculateDiskSpace = true, GroupId = 11 }, new HostingPlanGroupInfo() { CalculateBandwidth = true, CalculateDiskSpace = true, GroupId = 7 }, new HostingPlanGroupInfo() { CalculateBandwidth = true, CalculateDiskSpace = true, GroupId = 8 }, new HostingPlanGroupInfo() { CalculateBandwidth = true, CalculateDiskSpace = true, GroupId = 22 }, }; hpi.Quotas = new HostingPlanQuotaInfo[] { new HostingPlanQuotaInfo() { QuotaId = 70, QuotaValue = 1 }, new HostingPlanQuotaInfo() { QuotaId = 106, QuotaValue = 250 }, new HostingPlanQuotaInfo() { QuotaId = 107, QuotaValue = 1 }, new HostingPlanQuotaInfo() { QuotaId = 108, QuotaValue = 1 }, new HostingPlanQuotaInfo() { QuotaId = 211, QuotaValue = 2 }, new HostingPlanQuotaInfo() { QuotaId = 212, QuotaValue = 2 }, new HostingPlanQuotaInfo() { QuotaId = 213, QuotaValue = 50 }, new HostingPlanQuotaInfo() { QuotaId = 214, QuotaValue = 1 }, new HostingPlanQuotaInfo() { QuotaId = 215, QuotaValue = 1 }, new HostingPlanQuotaInfo() { QuotaId = 216, QuotaValue = 1 }, new HostingPlanQuotaInfo() { QuotaId = 217, QuotaValue = 20 }, }; string message = ""; var result = controller.AddHosting(hpi, model, out message); //var result = controller.AddHosting(hpi, url, apiUser, parola, key, out message); } //s1------------------------------------------- var controller2 = new HostingWindowsController(new HostingServiceWindowsPanel()); string serviceId = "2"; string wspipaddressid = null; string message2 = ""; if (wspipaddressid != null) { var result2 = controller2.UpdateServiceSettings(model, serviceId, wspipaddressid, out message2); //var result2 = controller2.UpdateServiceSettings(url, apiUser, parola, key, serviceId, wspipaddressid, out message2); } //s2-------------------- var controller3 = new HostingWindowsController(new HostingServiceWindowsPanel()); UserInfo user = new UserInfo(); user.UserId = 0; user.Role = UserRole.User; user.StatusId = 1; user.OwnerId = 2; user.IsDemo = false; user.IsPeer = false; user.FirstName = "hamit"; user.LastName = "yildirim"; user.Email = "*****@*****.**"; user.Username = "******"; user.Password = "******"; string message3 = ""; var result3 = controller3.AddUser(user, model, out message3); //var result3 = controller3.AddUser(user, url, apiUser, parola, key, out message3); //s3 -------------------------------- var controller4 = new HostingWindowsController(new HostingServiceWindowsPanel()); string message4 = ""; var result4 = controller4.AddPackageWithResources(model, 808, 808, "Standart Plan", targetDomainName, out message4); //var result4 = controller4.AddPackageWithResources(url, apiUser, parola, key, 986, 6, targetDomainName, out message4); }