static void Main(string[] args) { { //user input Console.WriteLine("Please enter your postcode to see the next buses at the two nearest bus stops:"); string userInput = Console.ReadLine(); ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; { List <StopPoint> stopPointList = APIClass.GetAPIData(userInput); //Prints it all nicely foreach (StopPoint busStop in stopPointList.Take(2)) { var sortedArrivals = APIClass.GetArrivalsData(busStop.naptanId); Console.WriteLine($"The next buses at {busStop.commonName} are:"); foreach (var bus in sortedArrivals) { Console.WriteLine($"{bus.vehicleId} at {bus.expectedArrival}"); } } Console.ReadLine(); } } }
internal void LoadMapFromFile() { if (validDirectory) { OriginalMap = APIClass.ParseMapFile(); if (suggestionsMap.Count == 0) { suggestionsMap.Add(OriginalMap); IndexMap = suggestionsMap.Count - 1; } monsters.MapLoaded(); monsters.UpdateTrackHistory(); monsters.ReDrawMap(); if (!timer.Enabled) { timer.Elapsed += new ElapsedEventHandler(OnTimedEvent); timer.Enabled = true; timer.AutoReset = true; Console.WriteLine("Timer set"); } else { Console.WriteLine("Timer not set"); } } }
//播放 public void play() { TemStr = ""; TemStr = TemStr.PadLeft(127, Convert.ToChar(" ")); APIClass.mciSendString("play media", TemStr, TemStr.Length, 0); mc.state = State.mPlaying; }
[Route("cheditor/api/deleteclass/{cid}")] // Need this because passed variable was changed from id to cid public IHttpActionResult DeleteClass(int cid) { APIClass TargetClass = db.APIClasses.Find(cid); // Checking if target exists if (TargetClass == null) { JsonResponseObject faliureJsonResult = new JsonResponseObject() { result = false, message = "Target class ID does not exist" }; return(Json(faliureJsonResult)); } // Checking if is not a parent if (che.IsAParent(cid)) { JsonResponseObject faliureJsonResult = new JsonResponseObject() { result = false, message = "Target class is a parent, please delete its children first" }; return(Json(faliureJsonResult)); } // Remove from context db.APIClasses.Remove(TargetClass); // Commit changes db.SaveChanges(); return(Ok(TargetClass)); }
/// <summary> /// Given the version set the selected API version /// </summary> /// <param name="version"></param> public void SetSelectedAPI(string version) { if (installedAPIList != null) { APIClass result = installedAPIList.Find(i => i.Version.Contains(version)); if (result != null) { RegistryKey rkHKCU = Registry.CurrentUser; RegistryKey rkNDKPath = null; try { rkNDKPath = rkHKCU.CreateSubKey("Software\\BlackBerry\\BlackBerryVSPlugin"); rkNDKPath.SetValue("NDKHostPath", result.HostName); rkNDKPath.SetValue("NDKTargetPath", result.TargetName); string qnx_config = System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData) + @"\Research In Motion\BlackBerry Native SDK"; System.Environment.SetEnvironmentVariable("QNX_TARGET", result.TargetName); System.Environment.SetEnvironmentVariable("QNX_HOST", result.HostName); System.Environment.SetEnvironmentVariable("QNX_CONFIGURATION", qnx_config); string ndkpath = string.Format(@"{0}/usr/bin;{1}\bin;{0}/usr/qde/eclipse/jre/bin;", result.HostName, qnx_config) + System.Environment.GetEnvironmentVariable("PATH"); System.Environment.SetEnvironmentVariable("PATH", ndkpath); } catch { } rkNDKPath.Close(); rkHKCU.Close(); } } }
public void Puase() { TemStr = ""; TemStr = TemStr.PadLeft(128, Convert.ToChar(" ")); ilong = APIClass.mciSendString("pause media", TemStr, TemStr.Length, 0); mc.state = State.mPuase; }
public void Resume() { // TemStr = ""; //TemStr = TemStr.PadLeft(128, Convert.ToChar(" ")); ilong = APIClass.mciSendString("resume media", TemStr, TemStr.Length, 0); mc.state = State.mPlaying; }
/// <summary> /// Check to see if API is installed /// </summary> /// <param name="version">Check version number</param> /// <param name="name">Check API name</param> /// <returns>true if installed</returns> private int IsAPIInstalled(string version, string name) { int success = 0; /// Check for 2.1 version if (version.StartsWith("2.1.0")) { version = "2.1.0"; } if (InstalledAPIListSingleton.Instance._installedAPIList != null) { APIClass result = InstalledAPIListSingleton.Instance._installedAPIList.FindLast(i => i.Version.Contains(version)); if (result != null) { success = 1; } } if (InstalledNDKListSingleton.Instance._installedNDKList != null) { APIClass result = InstalledNDKListSingleton.Instance._installedNDKList.FindLast(i => i.Version.Contains(version)); if (result != null) { success = 2; } } return(success); }
/// <summary> /// Check if User exists on the API and sets user details /// </summary> /// <param name="UserName"></param> async public void SetUserDetails(string UserName) { using (var httpClient = new HttpClient()) { var response = await httpClient.GetAsync("REDACTED" + UserName + "REDACTED"); response.EnsureSuccessStatusCode(); string content = await response.Content.ReadAsStringAsync(); APIClass APIReturn = JsonConvert.DeserializeObject <APIClass>(content); if (APIReturn.results.Count == 0) { LoginModule.IfUserExist = false; return; } LoginModule.IfUserExist = true; LoginModule.UserName = UserName; LoginModule.PrimaryGroup = APIReturn.results[0].PrimaryGroup.name; LoginModule.UserPFP = APIReturn.results[0].photoUrl; Properties.Settings.Default.UserIcon = APIReturn.results[0].photoUrl; //MessageBox.Show(pl.results[0].PrimaryGroup.name); //MessageBox.Show(content); } }
//停止 public void StopT() { TemStr = ""; TemStr = TemStr.PadLeft(128, Convert.ToChar(" ")); ilong = APIClass.mciSendString("close media", TemStr, 128, 0); ilong = APIClass.mciSendString("close all", TemStr, 128, 0); mc.state = State.mStop; }
private TimeSpan GetMusicDuration(string fileName) { var durationString = APIClass.GetMusicDurationString(fileName); if (int.TryParse(durationString, out int durationInt)) { return(TimeSpan.FromMilliseconds(durationInt).Subtract(TimeSpan.FromSeconds(4))); } throw new JMBasicException("音乐文件无效!"); }
void AnalyClassLine(List <string> line) { var apiClass = new APIClass(); apiClass.name = line[0]; apiClass.mark = line[1]; apiClass.iconPath = line[2]; classNameToMark.Add(apiClass.name, apiClass.mark); apiClassList.Add(apiClass); }
[Route("cheditor/api/superclasses/{cid}")] // Need this because passed variable was changed from id to cid public IHttpActionResult Superclasses(int cid) //public string Superclasses(int cid) { //return che.GetSuperClasses(cid); // Creat list to store classes List <APIClass> list = new List <APIClass>(); APIClass currentClass = db.APIClasses.Find(cid); int i = 1; while (i != 0) // Condition is always true, but all paths lead to a 'return' statement eventually! { if (currentClass == null) // If passed cid does not exist { if (list == null) // if list is empty { // create an error response body to be srialized into json JsonResponseObject faliureJsonResult = new JsonResponseObject() { result = false, message = "No parent classes found" }; // Serialise and return error response body return(Json(faliureJsonResult)); } else { // Returning the list of classes return(Json(list)); } } // Find parent class where currentClass.pid = cid // Find uses passed value to lookup in the primary key field in the DBContext APIClass parentClass = db.APIClasses.Find(currentClass.pid); // If no parent class found if (parentClass == null)// { // Return the list of classess as a JSON object return(Json(list)); } // Add parent class to list list.Add(parentClass); // Set parent class as current, in preparation for hte next iteration currentClass = parentClass; }//END OF WHILE // Return the list of classess as a JSON object return(Json(list)); }
public IHttpActionResult GetClass(int id) { APIClass foundClass = db.APIClasses.Find(id); if (foundClass == null) { JsonResponseObject faliureJsonResult = new JsonResponseObject() { result = false, message = "Target class ID does not exist" }; return(Json(faliureJsonResult)); } return(Json(foundClass)); // ORIGINAL: works perfectly }
private void button_export_Click(object sender, EventArgs e) { List <Point> selectPoints = USelection.GetSelectedPoints(); if (selectPoints.Count == 0) { Logger.AppendText("No selection, exporting entire solution."); APIClass.SaveMapFile(core.CurrentMap); core.ReloadLOG(); } else { Logger.AppendText("Exporting solution."); APIClass.ExportSelection(core.CurrentMap, core.OriginalMap, selectPoints); core.ReloadLOG(); } }
/// <summary> /// Check to see if API is installed /// </summary> /// <param name="version">Check version number</param> /// <param name="name">Check API name</param> /// <returns>true if installed</returns> private int IsAPIInstalled(string version, string name, bool allowSubstringVersion) { int success = 0; /// Check for 2.1 version if (version.StartsWith("2.1.0")) { version = "2.1.0"; } while ((success == 0) && (version.Contains('.'))) { if (InstalledAPIListSingleton.Instance._installedAPIList != null) { APIClass result = InstalledAPIListSingleton.Instance._installedAPIList.Find(i => i.Version.Contains(version)); if (result != null) { success = 1; } } if (InstalledNDKListSingleton.Instance._installedNDKList != null) { APIClass result = InstalledNDKListSingleton.Instance._installedNDKList.Find(i => i.Version.Contains(version)); if (result != null) { success = 2; } } if (!allowSubstringVersion) { break; } if (success == 0) { version = version.Substring(0, version.LastIndexOf('.')); } } return(success); }
public ActionResult BusInfo(PostcodeSelection selection) { var info = new BusInfo(selection.Postcode); List <StopPoint> stopPointList = APIClass.GetAPIData(selection.Postcode); var BusStop1 = stopPointList[0]; var BusStop2 = stopPointList[1]; var sortedArrivals1 = APIClass.GetArrivalsData(BusStop1.naptanId); var sortedArrivals2 = APIClass.GetArrivalsData(BusStop2.naptanId); info.BusStop1 = BusStop1; info.BusStop2 = BusStop2; info.Arrivals1 = sortedArrivals1; info.Arrivals2 = sortedArrivals2; return(View(info)); }
protected async void BtnLogin_Click(object sender, EventArgs e) { try { //Get products and sales array (Ben. G) await APIClass.GetProductsAsync(); await APIClass.GetSalesAsync(); APIClass.SelectedTagsList = new List <string>(); // Calling Database string dpPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "user.db"); //var db = new SQLiteConnection(dpPath); //var dataTable = db.Table<LoginTable>(); //var dataNode = dataTable.Where(x => x.username == etxtUsername.Text).FirstOrDefault(); // Linq Query if (etxtUsername.Text == "martin" && etxtPassword.Text == "martin") { StartActivity(typeof(ProfileActivity)); } /* * // Check if input matched * if (dataNode != null && BCrypt.Net.BCrypt.Verify(etxtPassword.Text, dataNode.passwordHash)) * { * Toast.MakeText(this, "Login Success!", ToastLength.Short).Show(); * StartActivity(typeof(HomeActivity)); * } * else * { * Toast.MakeText(this, "Username or Password invalid", ToastLength.Short).Show(); * }*/ } catch (Exception exception) { Toast.MakeText(this, exception.ToString(), ToastLength.Long).Show(); } }
[Route("cheditor/api/addclassesjson")] // Need this because passed variable was changed from id to cid public IHttpActionResult Addclassesjson(APIClass jsonReq) { /* * string jsonReq = "[{classes:[{ \"cid\": \"1\",\"name\": \"Vehicle\",\"abstract\": \"true\"}," + * "{ \"cid\": \"2\",\"name\": \"Vehicle2\",\"pid\": \"1\",\"abstract\": \"true\"}" + * "]}]"; */ JsonResponseObject jro = new JsonResponseObject { result = false, message = "This service is still under construction!" }; return(Json(jro)); /* * for(int i = 0; i<classReq.Count(); i++) * { * //ADD VALIDATION OF CID, NAME AND PID, * // COPY THEM FROM ADDCLASS ABOVE * * * db.APIClasses.Add(classReq[i]); * } * * try * { * // Commiting changes to DB * db.SaveChanges(); * } * catch (DbUpdateException) * { * * } */ }
[Route("cheditor/api/addclassjson")] // Need this because passed variable was changed from id to cid public IHttpActionResult AddClassJson(APIClass jsonReq) { //string jsonReq = "{ \"cid\": \"1\",\"name\": \"Vehicle\",\"abstract\": \"true\"}"; // Deserialisong Json object into a class model object //APIClass classReq = JsonConvert.DeserializeObject<APIClass>(jsonReq); try { // Below statement returns throws an exception if invalid JSON obj was received // setting null pid to a first level class if (jsonReq.pid == null) { jsonReq.pid = 0; } } catch (Exception) { JsonResponseObject jro = new JsonResponseObject { result = false, message = "Sent JSON object not valid" }; return(Json(jro)); } // Check CID != PID if (jsonReq.cid == jsonReq.pid) { JsonResponseObject jro = new JsonResponseObject { result = false, message = "Class ID cannot be the same as Parent ID" }; return(Json(jro)); } // Custom made Class model validity check // Validates manditory attributes // Validates CID and Name repototion and PID existance in DB string APIValidityCheck = che.APIClassValidityCheck(jsonReq.cid, jsonReq.name, jsonReq.pid); if (APIValidityCheck == "") { db.APIClasses.Add(jsonReq); try { // Commiting changes to DB db.SaveChanges(); return(Json("{\"ret\": \"true\"}")); } catch (DbUpdateException) { JsonResponseObject jro = new JsonResponseObject { result = false, message = "An error occured while committing changes to database." }; return(Json(jro)); } } else { JsonResponseObject jro = new JsonResponseObject { result = false, message = APIValidityCheck }; return(Json(jro)); } }
private Singleton() { _APIClass = new APIClass(); }
public IHttpActionResult AddClass(int?cid, string name, bool Abstract, int?pid = null) // int? = nullable int, pid = null: makes it possible to not add pid in url { // setting as first level class if (pid == null) { pid = 0; } // Check CID != PID if (cid == pid) { JsonResponseObject jro = new JsonResponseObject { result = false, message = "Class ID cannot be the same as Parent ID" }; return(Json(jro)); } // Checking if CID and Name are not Nulls if (cid == null | name == null) { JsonResponseObject jro = new JsonResponseObject { result = false, message = "Class ID and/or Name cannot be null" }; return(Json(jro)); } // Checking if name is available if (!che.IsNameAvailable(name)) { JsonResponseObject jro = new JsonResponseObject { result = false, message = "Class name already exists" }; return(Json(jro)); } // Checking if pid exists if (!che.IsParentAvailable((int)pid)) { JsonResponseObject jro = new JsonResponseObject { result = false, message = "Parent class does not exist" }; return(Json(jro)); } // Adding request values to a class object APIClass AddClass = new APIClass { cid = (int)cid, name = name, isAbstract = Abstract, pid = pid }; // Adding created obj to DBContext db.APIClasses.Add(AddClass); try { // Commiting changes to DB db.SaveChanges(); } catch (DbUpdateException) { // Checking if cid is available // Dublicate CID will invoke DbUpdateException as CID is a primary key if (!che.IsCidAvailable((int)cid)) { JsonResponseObject jro = new JsonResponseObject { result = false, message = "Class ID already exists" }; return(Json(jro)); } } return(CreatedAtRoute("DefaultApi", new { id = AddClass.cid }, AddClass)); }
public int seekwithoutplay(int position) { APIClass.mciSendString(string.Format("seek " + id.ToString() + " to {0}", position.ToString()), "", 0, 0); return(1); }
private double CalculateNoveltyFitness(Chromosome chromosome) { double fitness = 0; var chromosomeGenes = chromosome.Genes; float cellOffsetPenalty = 0; //var startEndPoints = SearchUtils.FindStartEndPointsCoordinates(chromosome); //start e end points teem de ser walkable!! //if (startEndPoints == null) //{ // Debug.WriteLine("POINTS NULL"); // return 0.0; //} var start = _currentMap.StartPoint; var end = _currentMap.EndPointList[0]; ////make sure start and at least 1 end point are walkable //if (!startEndPoints[0].IsWalkable || !startEndPoints[1].IsWalkable) //{ // Debug.WriteLine("POINTS NOT WALKABLE"); // return 0.0; //} for (int i = 0; i < chromosomeGenes.Count; i++) { //grab a cell from the candidate chromosome Cell c = (Cell)chromosomeGenes[i].ObjectValue; int cellX = c.X, cellY = c.Y; if ((start.x == cellX && start.y == cellY) || (end.x == cellX && end.y == cellY)) { if (!c.IsWalkable) { return(0.0); } } if (_originalMap.Cells[i].CellType != c.CellType) { //Debug.WriteLine("Derp"); //Logger.AppendText("cenas"); fitness += 1; } } fitness = fitness / 1024; //if (UserSelectionPositiveFocus.Count > 0) //Take into account the affect of user selection on fitness function //{ // int dif = 0; // //fetch all cells in selection // foreach (var p in UserSelectionPositiveFocus) // { // Cell c = (Cell)chromosome.Genes[p.Y * _currentMap.Width + p.X].ObjectValue; // if (c != null) // { // if (c.CellType != _currentMap.GetCellAt(c.X, c.Y).CellType) // dif++; // } // else Debug.WriteLine("CELL NULL"); // } // float changePercent = dif / (float)UserSelectionPositiveFocus.Count; // //Logger.AppendText(changePercent.ToString()); // fitness += (changePercent * fitness) * UserSelectionWeight; //} //Debug.WriteLine("Chromosome " + chromosome.Id + " fitness: " + fitness); //normalize with max: walkable cell or whole map cells? cellOffsetPenalty = System.Math.Abs(TargetWalkableCellCount - APIClass.CountWalkableCellsInChromosome(chromosome)) / 1024f; fitness -= cellOffsetPenalty; return(fitness); }