/// <summary> /// Gets the Monitoring Info for the Server and populates it into the model /// </summary> /// <param name="apiClient"></param> /// <param name="authInfo"></param> /// <param name="serversDetails"></param> /// <param name="detailsModel"></param> /// <remarks> /// Date: 24/06/2018 /// Author: Stephen McCutcheon /// </remarks> private static void GetMonitoringInfo(MyServersApiClient apiClient, AuthInfo authInfo, ServerInfo serversDetails, ServerDetailModel detailsModel) { var monitorReport = apiClient.GetServerStatus(authInfo, serversDetails.ServiceID); detailsModel.MonitorStatus = new List <MonitorStatusModel>(); if (monitorReport != null) { foreach (var mon in monitorReport) { var monitormodel = new MonitorStatusModel { TestId = mon.TestId, TestName = mon.TestName, TestType = mon.TestType, StatusCode = mon.StatusCode, MonitoredIp = mon.MonitoredIp, StatusDetail = mon.StatusDetail, LastUpdated = mon.LastUpdated, LastStatusChange = mon.LastStatusChange }; detailsModel.MonitorStatus.Add(monitormodel); } } }
/// <summary> /// This displays a list of serveres on the view /// </summary> /// <returns></returns> /// <remarks> /// Date: 24/06/2018 /// Author: Stephen McCutcheon /// </remarks> public ActionResult Index() { using (var apiClient = new MyServersApiClient()) { var authInfo = new AuthInfo { Username = Settings.Default.APIUserName, Password = Settings.Default.APIPassword }; //Get all the server details var servers = apiClient.GetAllServerDetails(authInfo); //populate the server details into the model var viewModels = new ServerViewIndexModel() { Servers = new List <ServerViewIndexItem>() }; foreach (var server in servers) { var serverViewModel1 = new ServerViewIndexItem() { ServerDescription = server.YourReference, ServerId = server.ServiceID }; viewModels.Servers.Add(serverViewModel1); } return(View(viewModels)); } }
/// <summary> /// Loads the Model with Information on ONload of the Page /// </summary> /// <returns></returns> /// <remarks> /// Date: 24/06/2018 /// Author: Stephen McCutcheon /// </remarks> public ActionResult Index() { using (var apiClient = new MyServersApiClient()) { var authInfo = new AuthInfo { Username = Settings.Default.APIUserName, Password = Settings.Default.APIPassword }; //Calls the Web api to Get the Account Summary var accountSummary = apiClient.GetAccountSummary(authInfo); //Populates the apprioprate data into the View Model var viewModels = new AccountSummaryViewModel { Balance = accountSummary.Balance.ToString("C"), NextPaymentAmount = accountSummary.NextPaymentAmount.ToString("C"), NextPaymentDate = accountSummary.NextPaymentDate, OverdueInvoices = accountSummary.OverdueInvoices, UnpaidInvoices = accountSummary.UnpaidInvoices }; //Returns the model to the View return(View(viewModels)); } }
/// <summary> /// Initialise the store with a username and password. /// </summary> /// <param name="username">Username for API access</param> /// <param name="password">Password for API access</param> public MyServersApiStore(string username, string password) { _credentials = new AuthInfo(); _credentials.Username = username; _credentials.Password = password; _client = new MyServersApiClient(); }
/// <summary> /// On Loading the FAQ Page, get all the sections, questions and answers /// </summary> /// <param name="selectedSectionId"></param> /// <returns></returns> /// <remarks> /// Date: 24/06/2018 /// Author: Stephen McCutcheon /// </remarks> public ActionResult Index(int?selectedSectionId) { using (var apiClient = new MyServersApiClient()) { var authInfo = new AuthInfo { Username = Settings.Default.APIUserName, Password = Settings.Default.APIPassword }; //Get the FAQ Data rom the WEB API var faq = apiClient.GetFAQ(authInfo); //Initiate the Model for the View var faqModels = new FaqModelView { HeaderText = faq.HeaderText, FooterText = faq.FooterText, Sections = new List <FaqSectionItem>() }; //Determine what section to show if (selectedSectionId != null) { faqModels.SelectedSectionId = selectedSectionId.Value; } else { var firstSection = faq.Sections.FirstOrDefault(); if (firstSection != null) { faqModels.SelectedSectionId = firstSection.SectionID; } } //Load the selected section into the View Model LoadQuestionsIntoViewModel(faq, faqModels, apiClient, authInfo); //Populate the section drop down with all the sections in the FAQ faqModels.SectionsDropDown = (from x in faq.Sections select new SelectListItem { Text = x.Section, Value = x.SectionID.ToString() }).ToList(); return(View(faqModels)); } }
/// <summary> /// Gets the Server Details /// </summary> /// <param name="serverId"></param> /// <param name="apiClient"></param> /// <param name="authInfo"></param> /// <param name="detailsModel"></param> /// <returns></returns> /// <remarks> /// Date: 24/06/2018 /// Author: Stephen McCutcheon /// </remarks> private static ServerInfo GetServerDetails(string serverId, MyServersApiClient apiClient, AuthInfo authInfo, out ServerDetailModel detailsModel) { var serversDetails = apiClient.GetServerDetails(authInfo, serverId); detailsModel = new ServerDetailModel() { ServerId = serversDetails.ServiceID, ServerDescription = serversDetails.YourReference, ServiceDescription = serversDetails.ServiceDescription, IpAddresses = serversDetails.IPAddresses, ReverseDns = new List <ServerDetailReverseDns>(), HasReverseDnsEntry = false, NoReverseDnsEntryMessage = Settings.Default.NoDNSInfo }; return(serversDetails); }
protected void Application_Start(object sender, EventArgs e) { // Code that runs on application startup RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); var authInfo = new AuthInfo() { Username = ConfigurationManager.AppSettings["MyServersApiUsername"], Password = ConfigurationManager.AppSettings["MyServersApiPassword"], }; var apiClient = new MyServersApiClient(); GlobalSettings.authInfo = authInfo; GlobalSettings.apiClient = apiClient; ConfigureServices(); }
/// <summary> /// Gets the bandwith width info from the server and populautes it into the model /// </summary> /// <param name="apiClient"></param> /// <param name="authInfo"></param> /// <param name="serversDetails"></param> /// <param name="detailsModel"></param> /// <remarks> /// Date: 24/06/2018 /// Author: Stephen McCutcheon /// </remarks> private static void GetBandWidthInfo(MyServersApiClient apiClient, AuthInfo authInfo, ServerInfo serversDetails, ServerDetailModel detailsModel) { var bandwithReport = apiClient.GetServerBandwidthReport(authInfo, serversDetails.ServiceID, true); detailsModel.BandWidthInfo = new BandwithInfo { Bw24HIn = bandwithReport.BW24hIn, Bw24HOutField = bandwithReport.BW24hOut, Bw4HInField = bandwithReport.BW4hIn, Bw4HOutField = bandwithReport.BW4hOut, BwPredicted14DInField = bandwithReport.BWPredicted14dIn, BwPredicted14DOutField = bandwithReport.BWPredicted14dOut, BwPredicted24HInField = bandwithReport.BWPredicted24hIn, BwPredicted24HOutField = bandwithReport.BWPredicted24hOut, BwSofarThisMonthInField = bandwithReport.BWSofarThisMonthIn, BwSofarThisMonthOutField = bandwithReport.BWSofarThisMonthOut }; }
/// <summary> /// On Selecting a server, this retuens the details to the model /// </summary> /// <param name="serverId"></param> /// <returns></returns> /// <remarks> /// Date: 24/06/2018 /// Author: Stephen McCutcheon /// </remarks> public ActionResult Details(string serverId) { using (var apiClient = new MyServersApiClient()) { var authInfo = new AuthInfo { Username = Settings.Default.APIUserName, Password = Settings.Default.APIPassword }; ServerDetailModel detailsModel; var serversDetails = GetServerDetails(serverId, apiClient, authInfo, out detailsModel); GetReversDnsDetails(serversDetails, detailsModel); GetBandWidthInfo(apiClient, authInfo, serversDetails, detailsModel); GetMonitoringInfo(apiClient, authInfo, serversDetails, detailsModel); return(View(detailsModel)); } }
/// <summary> /// This loads teh view from the model and implements paging so /// not all rows are returend on 10 at a time /// </summary> /// <param name="pageNumber"></param> /// <returns></returns> /// <remarks> /// Date: 24/06/2018 /// Author: Stephen McCutcheon /// </remarks> public ActionResult Index(int?pageNumber) { using (var apiClient = new MyServersApiClient()) { var authInfo = new AuthInfo { Username = Settings.Default.APIUserName, Password = Settings.Default.APIPassword }; //Gets all the Top Level Domains Details var topLevelDomains = apiClient.GetAllTLDs(authInfo); //Page checks to ensure the page number does not go off the //end of pages. Basically if you try and access a page before or after //itdefaults back to the first or last page accordingly int startPos; var viewModels = SetMaxAndMinPagesViewModels(pageNumber, topLevelDomains, out startPos); //Set the apprioprate values in the Modl foreach (var domain in topLevelDomains.Skip(startPos).Take(10)) { var domainItem = new DomainItem { DomainId = domain.TLD, DomainCost = domain.Cost.ToString("C"), MaxPeriod = domain.MaxPeriod, MinPeriod = domain.MinPeriod }; viewModels.Items.Add(domainItem); } return(View(viewModels)); } }
/// <summary> /// Loads the Questions for each section into the FAQ Model /// </summary> /// <param name="faq"></param> /// <param name="faqModels"></param> /// <param name="apiClient"></param> /// <param name="authInfo"></param> /// <remarks> /// Date: 24/06/2018 /// Author: Stephen McCutcheon /// </remarks> private static void LoadQuestionsIntoViewModel(FAQ faq, FaqModelView faqModels, MyServersApiClient apiClient, AuthInfo authInfo) { var sectioncounter = 0; var questionCounter = 0; //Loads in all the sections and Questions for the selected section var section = (from x in faq.Sections where x.SectionID == faqModels.SelectedSectionId select x).FirstOrDefault(); if (section != null) { var sectionModel = new FaqSectionItem { SectionId = "Section" + sectioncounter, SectionIdDataSource = "#Section" + sectioncounter, Section = section.Section, Questions = new List <FaqQuestionItem>() }; var quest1 = apiClient.GetAllQuestions(authInfo, section.SectionID); foreach (var question in quest1) { var questionModel = new FaqQuestionItem { QuestionId = "Question" + questionCounter, QuestionIdDataSource = "#Question" + questionCounter, Question = question.Question, Answer = question.Answer }; sectionModel.Questions.Add(questionModel); questionCounter = questionCounter + 1; } faqModels.SelectedSection = sectionModel; faqModels.Sections.Add(sectionModel); } }
public ReverseDnsService(MyServersApiClient apiClient) { _apiClient = apiClient; }
public ForwardDnsService(MyServersApiClient apiClient) { _apiClient = apiClient; }
public ServersService(MyServersApiClient apiClient) { _apiClient = apiClient; }
/// <summary> /// Initialise the store with the given Authorisation object. /// </summary> /// <param name="credentials">AuthInfo object containing the username and password credentials</param> public MyServersApiStore(AuthInfo credentials) { _credentials = credentials; _client = new MyServersApiClient(); }
static void Main(string[] args) { var creditCardPaymentService = new CreditCardPaymentService(); var creditCardPaymentInput = new CreditCardPaymentInput() { VendorTxCode = Guid.NewGuid().ToString(), CardholderName = "Card Holder", CardNumber = "4929000000006", ExpiryDate = "1120", SecurityCode = "123", Amount = 2000, CustomerFirstName = "Sam", CustomerLastName = "Jones", BillingAddress1 = "88 St. John Street", BillingCity = "London", BillingPostalCode = "412", BillingCountry = "GB", CustomerEmail = "*****@*****.**", CustomerPhone = "0845 111 4455", TransactionDescription = "Testing", ShippingRecipientFirstName = "Sam", ShippingRecipientLastName = "Jones", ShippingAddress1 = "407 St John Street", ShippingCity = "London", ShippingPostalCode = "EC1V 4AB", ShippingCountry = "GB", }; var transactionResult = creditCardPaymentService.ProcessPayment(creditCardPaymentInput); var apiClient = new MyServersApiClient(); var authInfo = new AuthInfo() { Username = MyServersApiUsername, Password = MyServersApiPassword, }; //server details actions string testServiceID = "TEST-00001"; // var chassisForSale = apiClient.GetAllChassisForSale(authInfo, new Guid("479B1314-8CFE-42CB-AD93-784509575029"), string.Empty); var chassisForSale = apiClient.GetChassisForSale(authInfo, new Guid("479B1314-8CFE-42CB-AD93-784509575029")); //var testServerDetails = apiClient.GetServerDetails(authInfo, testServiceID); //Console.WriteLine($"Before suspension: {testServerDetails.Suspended}"); //toggles testServerDetails.Suspended flag //apiClient.SuspendServer(authInfo, testServiceID, "For testing"); //testServerDetails = apiClient.GetServerDetails(authInfo, testServiceID); //Console.WriteLine($"After suspension: {testServerDetails.Suspended}"); //apiClient.UnsuspendServer(authInfo, testServiceID); //testServerDetails = apiClient.GetServerDetails(authInfo, testServiceID); //Console.WriteLine($"After unsuspension: {testServerDetails.Suspended}"); //var powerCycleServerStatus = apiClient.PowerCycleServer(authInfo, testServiceID); //var requestKvmStatus = apiClient.RequestKvm(authInfo, testServiceID); //var requestRecoverySessionStatus = apiClient.RequestRecoverySession(authInfo, testServiceID); //test actions //var testTypesTest = apiClient.GetTestTypes(); //int newTest = apiClient.AddTest(authInfo, testServiceID, "SwitchPort", "10.0.0.1", ""); //int newTest = apiClient.AddTest(authInfo, testServiceID, "Http", "10.0.0.1", ""); //var serverIDs = apiClient.GetAllServerIDs(authInfo); //var firstServer = serverDetails.ToList().First(); //var firstServerDetail = apiClient.GetServerDetails(authInfo, firstServer.ServiceID); //var firstServerTests = apiClient.GetServerStatus(authInfo, firstServer.ServiceID); //var firstServerAlerts = apiClient.GetAlerts(authInfo, firstServer.ServiceID); //alert actions //alert on warn or alert on fail has to be true //init delay must be at least 5 //repeat delay must be at least 15 //destination must be a valaid phone no if alertType=SMS (i.e. +441234567890) //int newAlert = apiClient.AddAlert(authInfo, testServiceID, "SMS", "+441234567890", 5, 15, true, false); //forward dns domain actions //hosting type = Primary/Secondary //domain name must be unique //int newForwardDnsDomain = apiClient.AddForwardDnsDomain(authInfo, "codingchallengedomaintest1.com", "Primary", "127.0.0.1"); //apiClient.DeleteForwardDnsDomain(authInfo, 3); //reverse dns entry actions //apiClient.SetReverseDnsEntry(authInfo, "10.0.0.2", "codingchallenge1.foo.com"); //apiClient.SetReverseDnsEntry(authInfo, "10.0.0.2", ""); int serverDetailIndex = 0; var allServerDetails = apiClient.GetAllServerDetails(authInfo); foreach (var allServerDetail in allServerDetails.ToList()) { Console.WriteLine($"Server {serverDetailIndex + 1}"); //server list Console.WriteLine($"Service ID: {allServerDetail.ServiceID}"); Console.WriteLine($"Service type field: {allServerDetail.ServiceType}"); Console.WriteLine($"Primary IP: {allServerDetail.PrimaryIP}"); Console.WriteLine($"Location: {allServerDetail.Location}"); Console.WriteLine($"Your reference: {allServerDetail.YourReference}"); Console.WriteLine($"Status: {allServerDetail.Status}\n"); //server details var serverStatuses = apiClient.GetServerStatus(authInfo, allServerDetail.ServiceID); int serverStatusesIndex = 0; Console.WriteLine("Service Statuses\n"); foreach (var serverStatus in serverStatuses) { Console.WriteLine($"Server status {serverStatusesIndex + 1}"); Console.WriteLine($"Status code: {serverStatus.StatusCode}"); Console.WriteLine($"Test Id: {serverStatus.TestId}"); Console.WriteLine($"Test name: {serverStatus.TestName}"); //Used for tests Console.WriteLine($"Test arg1: {serverStatus.TestArg1}"); Console.WriteLine($"Monitored Ip: {serverStatus.MonitoredIp}"); Console.WriteLine($"Last updated: {serverStatus.LastUpdated.ToString("dd MMM yyyy")}\n"); serverStatusesIndex++; } var serverDetails = apiClient.GetServerDetails(authInfo, allServerDetail.ServiceID); Console.WriteLine("Server details\n"); Console.WriteLine($"Bandwidth url base: {serverDetails.BandwidthUrlBase}"); Console.WriteLine($"Your reference: {serverDetails.YourReference}"); Console.WriteLine($"Location: {serverDetails.Location}"); Console.WriteLine($"Primary IP: {serverDetails.PrimaryIP}"); Console.WriteLine($"Service description: {serverDetails.ServiceDescription}\n"); var testTypes = apiClient.GetTestTypes(); int testTypesIndex = 0; Console.WriteLine("Test types\n"); foreach (var testType in testTypes) { Console.WriteLine($"Test type {testTypesIndex + 1}"); Console.WriteLine($"Test type: {testType}\n"); testTypesIndex++; } var alerts = apiClient.GetAlerts(authInfo, allServerDetail.ServiceID); int alertIndex = 0; Console.WriteLine("Alerts\n"); foreach (var alert in alerts) { Console.WriteLine($"Alert {alertIndex + 1}"); Console.WriteLine($"Alert type: {alert.AlertType}"); Console.WriteLine($"Destination: {alert.Destination}"); Console.WriteLine($"Initial delay: {alert.InitialDelay}"); Console.WriteLine($"Repeat delay: {alert.RepeatDelay}"); Console.WriteLine($"Alert on failure: {(alert.AlertOnFailure ? "Fail" : string.Empty)}\n"); alertIndex++; } //var testHistoryResults = apiClient.GetTestHistory(authInfo, allServerDetail.ServiceID, 1, 0); //var testIDs = serverStatuses.Select(x => x.TestId).ToList(); //Console.WriteLine("Tests\n"); //foreach (var testID in testIDs) //{ // var testHistoryResults = apiClient.GetTestHistory(authInfo, allServerDetail.ServiceID, testID, 0); // int testHistoryResultIndex = 0; // foreach (var testHistoryResult in testHistoryResults) // { // Console.WriteLine($"Test history result {testHistoryResultIndex + 1}"); // Console.WriteLine($"Date: {testHistoryResult.Date.ToString("dd MM yyy")}"); // Console.WriteLine($"Status code: {testHistoryResult.StatusCode}"); // Console.WriteLine($"Status detail: {testHistoryResult.StatusDetail}\n"); // testHistoryResultIndex++; // } //} var bandwidthReport = apiClient.GetServerBandwidthReport(authInfo, allServerDetail.ServiceID, true); Console.WriteLine("Bandwidth reports\n"); Console.WriteLine($"Last 4 Hours"); Console.WriteLine($"BW4h In: {bandwidthReport.BW4hIn}"); Console.WriteLine($"BW4h Out: {bandwidthReport.BW4hOut}"); Console.WriteLine($"BW4h Total: {bandwidthReport.BW4hIn + bandwidthReport.BW4hOut}\n"); Console.WriteLine($"Last 24 Hours"); Console.WriteLine($"BW24h In: {bandwidthReport.BW24hIn}"); Console.WriteLine($"BW24h Out: {bandwidthReport.BW24hOut}"); Console.WriteLine($"BW24h Total: {bandwidthReport.BW24hIn + bandwidthReport.BW24hOut}\n"); Console.WriteLine($"So far this month"); Console.WriteLine($"BW so far this month in: {bandwidthReport.BWSofarThisMonthIn}"); Console.WriteLine($"BW so far this month out: {bandwidthReport.BWSofarThisMonthOut}"); Console.WriteLine($"BW so far this month total: {bandwidthReport.BWSofarThisMonthIn + bandwidthReport.BWSofarThisMonthOut}\n"); Console.WriteLine($"Predicted this month (24h)"); Console.WriteLine($"BW predicted 24h in: {bandwidthReport.BWPredicted24hIn}"); Console.WriteLine($"BW predicted 24h out: {bandwidthReport.BWPredicted24hOut}"); Console.WriteLine($"BW predicted 24h total: {bandwidthReport.BWPredicted24hIn + bandwidthReport.BWPredicted24hOut}\n"); Console.WriteLine($"Predicted this month (14d)"); Console.WriteLine($"BW predicted 24h in: {bandwidthReport.BWPredicted14dIn}"); Console.WriteLine($"BW predicted 24h out: {bandwidthReport.BWPredicted14dOut}"); Console.WriteLine($"BW predicted 24h total: {bandwidthReport.BWPredicted14dIn + bandwidthReport.BWPredicted14dOut}\n"); var monthlyBandwidthReports = apiClient.GetMonthlyBandwidthReport(authInfo, allServerDetail.ServiceID, true); Console.WriteLine($"Monthly Bandwidth Reports\n"); int monthlyBandwidthReportIndex = 0; foreach (var monthlyBandwidthReport in monthlyBandwidthReports) { Console.WriteLine($"Monthly bandwidth report {monthlyBandwidthReportIndex + 1}"); Console.WriteLine($"Month: {monthlyBandwidthReport.Month.ToString("MMM yyyy")}"); Console.WriteLine($"BW in: {monthlyBandwidthReport.BWIn}"); Console.WriteLine($"BW out: {monthlyBandwidthReport.BWOut}"); Console.WriteLine($"BW total: {monthlyBandwidthReport.BWTotal}"); Console.WriteLine($"BW 95th percentile: {monthlyBandwidthReport.BW95thPercentile}\n"); monthlyBandwidthReportIndex++; } //Console.WriteLine($"Server {serverDetailIndex+1}"); //Console.WriteLine($"Service ID: {serverDetail.ServiceID}"); //Console.WriteLine($"Service Description: {serverDetail.ServiceDescription}"); ////Console.WriteLine($"Service Description: {serverDetail.ServiceTypeField}"); //var latestMonitor = apiClient.GetServerStatus(authInfo, serverDetail.ServiceID).ToList().Last(); //Console.WriteLine($"Latest monitoring status : {latestMonitor.StatusCode}"); //Console.WriteLine($"Bandwidth Url Base: {serverDetail.BandwidthUrlBase}"); //Console.WriteLine($"IP Addresses: {string.Join(", ", serverDetail.IPAddresses)}"); //Console.WriteLine($"Reverse Dns Entries: {string.Join(", ", serverDetail.ReverseDnsEntries ?? new ReverseDnsEntry[0])}\n"); serverDetailIndex++; } //server details var forwardDnsDomains = apiClient.GetForwardDnsDomains(authInfo); int forwardDnsDomainIndex = 0; Console.WriteLine($"Forward Dns Domains\n"); foreach (var forwardDnsDomain in forwardDnsDomains.ToList()) { Console.WriteLine($"Forward Dns Domain {forwardDnsDomainIndex + 1}"); Console.WriteLine($"Domain Id: {forwardDnsDomain.DomainId}"); Console.WriteLine($"Domain Name: {forwardDnsDomain.DomainName}"); Console.WriteLine($"Hosting type: {forwardDnsDomain.HostingType}"); Console.WriteLine($"Expiry date: {forwardDnsDomain.ExpiryDate?.ToString("dd MM yy") ?? string.Empty}"); Console.WriteLine($"Primary NS: {forwardDnsDomain.PrimaryNS}"); Console.WriteLine($"Authority status: {forwardDnsDomain.AuthorityStatus}"); Console.WriteLine($"Secondary transfer status: {forwardDnsDomain.SecondaryTransferStatus}\n"); forwardDnsDomainIndex++; } var reverseDnsEntries = apiClient.GetReverseDnsEntries(authInfo); int reverseDnsIndex = 0; Console.WriteLine($"Reverse Dns Entries"); foreach (var reverseDnsEntry in reverseDnsEntries.ToList()) { Console.WriteLine($"Reverse DNS Entry {reverseDnsIndex + 1}"); Console.WriteLine($"IP Address: {reverseDnsEntry.IPAddress}"); Console.WriteLine($"Host Name: {reverseDnsEntry.HostName}\n"); reverseDnsIndex++; } Console.WriteLine("\nPress any key to continue..."); Console.ReadLine(); }