private void btnmOK_Click(object sender, EventArgs e) { Medicine m; if (mlist.SelectedIndex < 0) { m = new Medicine(); m.id = -1; setMedicine(m); DBParser.addMedicine(Database.medicineDB, m); if (m.id > 0) { Database.medicineDB.Add(m); } mlist.Items.Add(m.name); //mlist.SelectedIndex = mlist.Items.Count - 1; pmlist.Items.Add(m.name); btnmNew_Click(sender, e); } else { m = Database.medicineDB[mlist.SelectedIndex]; setMedicine(m); DBParser.updateMedicine(m); mlist.Items[mlist.SelectedIndex] = m.name; pmlist.Items[mlist.SelectedIndex] = m.name; mlist_SelectedIndexChanged(sender, e); } txtmName.Focus(); }
private void btnpOK_Click(object sender, EventArgs e) { Prescript p; if (plist.SelectedIndex < 0) { p = new Prescript(); p.id = -1; setPrescript(p); DBParser.addPrescript(Database.prescriptDB, p); if (p.id > 0) { Database.prescriptDB.Add(p); } plist.Items.Add(p.name); //plist.SelectedIndex = plist.Items.Count - 1; btnpNew_Click(sender, e); } else { p = Database.prescriptDB[plist.SelectedIndex]; setPrescript(p); DBParser.updatePrescript(p); plist.Items[plist.SelectedIndex] = p.name; plist_SelectedIndexChanged(sender, e); } txtpName.Focus(); }
public DBParser OpenDb(byte[] bytes) { DBParser db = new DBParser(); db.OpenDbFromMemory(bytes); return(db); }
public DBParser OpenDb(string path) { DBParser db = new DBParser(); db.InitDBFile(path); return(db); }
public IDBCDStorage Load(string tableName, string build = null, Locale locale = Locale.None) { var dbcStream = dbcProvider.StreamForTableName(tableName, build); var dbdStream = dbdProvider.StreamForTableName(tableName, build); var builder = new DBCDBuilder(locale); var dbReader = new DBParser(dbcStream); var definition = builder.Build(dbReader, dbdStream, tableName, build); var type = typeof(DBCDStorage <>).MakeGenericType(definition.Item1); return((IDBCDStorage)Activator.CreateInstance(type, new object[2] { dbReader, definition.Item2 })); }
private void BtnExtract_Click(object sender, RoutedEventArgs e) { try { if (string.IsNullOrEmpty(this.tbFilePath.Text)) { throw new Exception("Enter FileName."); } string sqlText = RemovePackage(File.ReadAllText(tbFilePath.Text)); ParseResult result = DBParser.ExtractColumns(sqlText); this.txtResults.Text = string.Join(Environment.NewLine, result.Columnlist); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
static void Main(string[] args) { log.Info("Application starts"); string host = ConfigurationManager.AppSettings["host"]; string port = ConfigurationManager.AppSettings["port"]; string service = ConfigurationManager.AppSettings["service"]; string protocol = ConfigurationManager.AppSettings["protocol"]; bool CarpoolingEnabled = bool.Parse(ConfigurationManager.AppSettings["CarpoolingEnabled"]); bool TrafficEnabled = bool.Parse(ConfigurationManager.AppSettings["TrafficEnabled"]); double TrafficPropagationMaxDistance = float.Parse(ConfigurationManager.AppSettings["TrafficPropagationMaxDistance"]); int CarpoolingMaxConnectionsPerTNode = int.Parse(ConfigurationManager.AppSettings["CarpoolingMaxConnectionsPerTNode"]); /* This variable is used to decide if update at startup the external carpooling rides to the network or wait the midnight */ bool updateExtRidesAtStartup = bool.Parse(ConfigurationManager.AppSettings["ExtCarpoolingRideUpdateAtStartup"]); //var host = Dns.GetHostAddresses(Dns.GetHostName())[0]; string url = protocol + "://" + host + ":" + port + service; log.Info(url); Notification.SendMessageByEmail(Notification.AlarmType.INFO, DateTime.Now.ToString() + "\r\nWebAPI starts at " + url + "\r\nBuilding network..."); /* Get the site timeZone from the GTFS data (needed for the carpooling date caonversion) */ string timeZone = null; timeZone = DBParser.GetTimeZoneFromAgencyTable(); /* Get the boundaries from the OSM Map (needed for the backend carpooling http requests) */ Point MapMinPoint = null, MapMaxPoint = null; string OSMXMLMapFilePath = System.IO.Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory + ConfigurationManager.AppSettings["dataPath"] + ConfigurationManager.AppSettings["OSMXMLMapFile"]); log.Info("Parsing " + OSMXMLMapFilePath + " OSM."); routingNetwork1 = new Routing.RoutingNetwork(); OSM.XMLParser Parser = new OSM.XMLParser(); Parser.GetBoundaries(OSMXMLMapFilePath, ref MapMinPoint, ref MapMaxPoint); if ((MapMinPoint != null) && (MapMaxPoint != null)) { log.Info("Map Boundaries: minlat:" + MapMinPoint.Latitude + ", minlon:" + MapMinPoint.Longitude + ", maxlat:" + MapMaxPoint.Latitude + ", maxlon:" + MapMaxPoint.Longitude); } else { string message = "Application ends\r\nMap boundaries not found into the OSM map: minlat:" + MapMinPoint.Latitude + ", minlon:" + MapMinPoint.Longitude + ", maxlat:" + MapMaxPoint.Latitude + ", maxlon:" + MapMaxPoint.Longitude; log.Error(message); Notification.SendMessageByEmail(Notification.AlarmType.ERROR, DateTime.Now.ToString() + "\r\n" + message); Environment.Exit(0); } /* Get the dynamic data version from the backend web service */ DynamicData = HTTPRequests.getDynamicDataVersionFromBackend(MapMinPoint, MapMaxPoint); if (DynamicData != null) { if (CarpoolingEnabled) { /* Set the Carpooling data version */ CarPooling.Version = new CarpoolerVersion(DynamicData.sites.First().carpooling_info.version, DynamicData.sites.First().carpooling_info.updated, DynamicData.sites.First().name, DynamicData.sites.First().carpooling_info.nightly_version, DynamicData.sites.First().carpooling_info.nightly_updated); log.Info("CARPOOLING Version:" + CarPooling.Version.version + " Timestamp:" + CarPooling.Version.timestampVersion + " NightlyVersion:" + CarPooling.Version.nightly_version + " NightlyTimestamp: " + CarPooling.Version.nightly_timestampVersion); bool updateExternalRides = false; if ((updateExtRidesAtStartup) || ((DateTime.Now.Hour < ExtCarpoolingAvailableUpdateTimeFrom) && (DateTime.Now.Hour >= ExtCarpoolingAvailableUpdateTimeTo))) { updateExternalRides = true; } /* Get the carpooling rides list from the backend web service */ CarPooling.Carpoolers = HTTPRequests.getCarpoolingDataFromBackend(MapMinPoint, MapMaxPoint, updateExternalRides); } if (TrafficEnabled) { /* Set the Traffic/incidents data version */ Traffic.Version = new TrafficVersion(DynamicData.sites.First().reports_info.version, DynamicData.sites.First().reports_info.updated, DynamicData.sites.First().name); log.Info("TRAFFIC Version:" + Traffic.Version.version + " Timestamp:" + Traffic.Version.timestampVersion); /* Get the Traffic/incidents data from the backend web service */ Traffic.TrafficReport = HTTPRequests.getTrafficDataFromBackend(MapMinPoint, MapMaxPoint, TrafficPropagationMaxDistance); } } /* Build the network */ routingNetwork1 = RoutePlanner.Globals.BuildNetwork(ref CParser, ref TParser, CarPooling.Carpoolers, Traffic.TrafficReport, TrafficPropagationMaxDistance, CarpoolingMaxConnectionsPerTNode); /* Copy the network */ //routingNetwork2 = new RoutingNetwork { }; //routingNetwork1.duplicateNetwork(ref routingNetwork2); log.Info("Starting server at " + url); Notification.SendMessageByEmail(Notification.AlarmType.INFO, DateTime.Now.ToString() + "\r\nService is running at " + url); HTTPAsyncServer Server = new HTTPAsyncServer(url); log.Error("Application ends"); Notification.SendMessageByEmail(Notification.AlarmType.ERROR, "Application ends"); }
protected void generateGame() { _relationshipMap = new Dictionary <string, Dictionary <string, IRelationship> >(); _requests = new Dictionary <string, ItemRequestRelationship>(); _areaRooms = new Dictionary <string, Room>(); _areaConnections = new Dictionary <string, List <string> >(); _lockedAreaConnections = new Dictionary <string, List <AreaConnectionRelationship> >(); _itemNames = new HashSet <string>(); _startRoom = null; _startArea = null; // Let's make a puzzle! Database.Instance.removeExtensions(); Database.Instance.addExtension(new ChangesExtension()); Database.Instance.addExtension(new ChangedbyExtension()); Database.Instance.addExtension(new ParentExtension()); Database.Instance.addExtension(new FilledbyExtension()); Database.Instance.addExtension(new MakesExtension()); Database.Instance.addExtension(new GivesExtension()); Globals.shuffle(_puzzleMaps); PuzzleOutput output = null; int puzzleI = 0; int numTries = 0; while (output == null && numTries < MAX_TRIES) { Database.Instance.clearDatabase(); DBParser.createDatabaseFromXml(new string[] { "database" }); Database.Instance.runExtensions(); BuildingBlock puzzle = PuzzleMapParser.createBuildingBlockFromXml(_puzzleMaps[puzzleI]); output = puzzle.generatePuzzle("sandwich"); puzzleI = (puzzleI + 1) % _puzzleMaps.Count; numTries++; } foreach (IRelationship rel in output.Relationships) { rel.addRelationshipToGame(this); Debug.Log(rel.ToString()); } // Now add all the relationships and items foreach (PuzzleItem item in output.Items) { spawnItem(item); } createAreaConnections(); createAuxiliaryRelationships(); // Add the player to the start room. GameObject playerObj = GameObject.Instantiate(PlayState.instance.playerPrefab) as GameObject; _player = playerObj.GetComponent <Player>(); _startRoom.addPiece(_player); }
static void Main(string[] args) { List <Medicine> ms = new List <Medicine>(); List <Prescript> ps = new List <Prescript>(); //Medicine m = new Medicine(); //Prescript p = new Prescript(); //m.name = "test"; //m.mild = 0.0; //m.merdian[1] = 1.0; //m.merdian[3] = 1.0; //p.name = "testtoo"; //p.add(m, 1.0, 0.0); //DBParser.addMedicine(ms, m); //DBParser.addPrescript(ps, p); //DBParser.removeMedicine(1); //DBParser.removePrescript(1); ms = DBParser.medicineDB(); ps = DBParser.prescriptDB(ms); bodym = new double[][] { //new double[] {100.00,80.38,53.67,41.03,22.52,17.64,12.48,6.94,3.96,2.63,1.79,1.18}, new double[] { 100.00, 37.06, 43.74, 17.35, 9.22, 5.96, 3.98, 2.03, 1.66, 1.64, 2.04, 1.18 }, new double[] { 100.00, 93.06, 55.16, 17.98, 9.59, 6.28, 2.20, 1.54, 1.25, 0.79, 0.43, 1.18 }, new double[] { 100.00, 41.10, 40.97, 17.23, 7.18, 5.27, 2.68, 2.82, 1.29, 1.58, 1.00, 1.18 }, new double[] { 100.00, 50.06, 50.85, 33.10, 14.91, 13.26, 12.50, 8.35, 4.48, 2.54, 2.33, 1.18 }, new double[] { 100.00, 41.14, 28.95, 41.27, 20.56, 11.40, 15.90, 9.59, 6.59, 3.33, 3.95, 1.18 } }; int testid = 3; double[] ef, efm, e; double s, sm; List <Prescript> result = new List <Prescript>(); BodyCondition body = new BodyCondition(); body.bodyM = bodym[testid]; ef = body.bodyconditionE(); s = body.scoreBodyCondition(ef); foreach (Prescript x in ps) { e = x.prescriptE(); efm = body.eatmedicineE(e); sm = body.scoreBodyCondition(efm); if (sm < s) { x.extra = true; x.extrascore = sm; result.Add(x); } } result.Sort(); foreach (Prescript x in result) { Debug.WriteLine(string.Format(x.name + " [E]{0:F}", ((s - x.extrascore) / s * 100))); } }
internal Tuple <Type, DBCDInfo> Build(DBParser dbcReader, Stream dbd, string name, string build) { var dbdReader = new DBDReader(); if (name == null) { name = Guid.NewGuid().ToString(); } var databaseDefinition = dbdReader.Read(dbd); Structs.VersionDefinitions?versionDefinition = null; if (!string.IsNullOrWhiteSpace(build)) { var dbBuild = new Build(build); locStringSize = GetLocStringSize(dbBuild); Utils.GetVersionDefinitionByBuild(databaseDefinition, dbBuild, out versionDefinition); } if (versionDefinition == null && dbcReader.LayoutHash != 0) { var layoutHash = dbcReader.LayoutHash.ToString("X8"); Utils.GetVersionDefinitionByLayoutHash(databaseDefinition, layoutHash, out versionDefinition); } if (versionDefinition == null) { throw new FileNotFoundException("No definition found for this file."); } if (locStringSize > 1 && (int)locale >= locStringSize) { throw new FormatException("Invalid locale for this file."); } var typeBuilder = moduleBuilder.DefineType(name, TypeAttributes.Public); var fields = versionDefinition.Value.definitions; var columns = new List <string>(); bool localiseStrings = locale != Locale.None; foreach (var fieldDefinition in fields) { var columnDefinition = databaseDefinition.columnDefinitions[fieldDefinition.name]; bool isLocalisedString = columnDefinition.type == "locstring" && locStringSize > 1; var fieldType = FieldDefinitionToType(fieldDefinition, columnDefinition, localiseStrings); var field = typeBuilder.DefineField(fieldDefinition.name, fieldType, FieldAttributes.Public); columns.Add(fieldDefinition.name); if (fieldDefinition.isID) { AddAttribute <IndexAttribute>(field, fieldDefinition.isNonInline); } if (fieldDefinition.arrLength > 1) { AddAttribute <CardinalityAttribute>(field, fieldDefinition.arrLength); } if (isLocalisedString) { if (localiseStrings) { AddAttribute <LocaleAttribute>(field, (int)locale, locStringSize); } else { AddAttribute <CardinalityAttribute>(field, locStringSize); // add locstring mask field typeBuilder.DefineField(fieldDefinition.name + "_mask", typeof(uint), FieldAttributes.Public); columns.Add(fieldDefinition.name + "_mask"); } } } var type = typeBuilder.CreateTypeInfo(); var info = new DBCDInfo { availableColumns = columns.ToArray(), tableName = name }; return(new Tuple <Type, DBCDInfo>(type, info)); }