public static void Write(ProjectManager projects, string path, IdTable ids) { foreach ( var p in projects ) { if ( p == Project.Empty ) continue; var f = new XmlWriter(path + p.Name + ".xml"); f.Begin(p, ids); f.Begin("Assignments"); var faclist = new FlatAssignmentCollection[p.Assignments.Count]; lock ( p.Assignments ) p.Assignments.CopyTo(faclist, 0); foreach ( var fac in faclist ) { f.Begin(fac, ids); var falist = new FlatAssignment[fac.Count]; lock ( fac ) fac.CopyTo(falist, 0); foreach ( var fa in falist ) f.Write(fa, ids); f.End(fac); } f.End("Assignments"); f.Begin("Costs"); var costlist = new Cost[p.Costs.Count]; lock ( p.Costs ) p.Costs.CopyTo(costlist, 0); foreach ( var c in costlist ) { f.Begin(c, ids); f.Begin("Options"); var optionslist = new CostOptions[c.Options.Count]; lock ( c.Options ) c.Options.CopyTo(optionslist, 0); foreach ( var o in optionslist ) f.Write(o, ids); f.End("Options"); f.End(c); } f.End("Costs"); f.End(p); f.Close(); } }
public string ToString(string format, IFormatProvider formatProvider) { return(format switch { ClrStructureSettings.FORMAT_ALL => InfoTable.ToString(), ClrStructureSettings.FORMAT_MIN => IdTable.ToString(), _ => IdTable.ToString(), });
private void Start() { instance = this; Page mainMenu = new Page("placeholder"); pagePresenter = new PagePresenter(mainMenu, textBoxHolder, actionGrid, leftPortraits, rightPortraits, header, sound); Menus menus = new Menus(); pagePresenter.Page = menus.Root; IdTable.Init(); }
internal MasterDataRoot(IGameProvider listener) { _shipInfos = new IdTable <ShipInfoId, ShipInfo, IRawShipInfo, MasterDataRoot>(this); _shipTypes = new IdTable <ShipTypeId, ShipTypeInfo, IRawShipTypeInfo, MasterDataRoot>(this); _equipmentTypes = new IdTable <EquipmentTypeId, EquipmentTypeInfo, IRawEquipmentTypeInfo, MasterDataRoot>(this); _equipmentInfos = new IdTable <EquipmentInfoId, EquipmentInfo, IRawEquipmentInfo, MasterDataRoot>(this); _useItems = new IdTable <UseItemId, UseItemInfo, IRawUseItem, MasterDataRoot>(this); _mapAreas = new IdTable <MapAreaId, MapAreaInfo, IRawMapArea, MasterDataRoot>(this); _mapInfos = new IdTable <MapId, MapInfo, IRawMapInfo, MasterDataRoot>(this); _expeditions = new IdTable <ExpeditionId, ExpeditionInfo, IRawExpeditionInfo, MasterDataRoot>(this); listener.MasterDataUpdated += OnMasterDataUpdated; }
private async Task SaveBotIdInAzureStorage(IDialogContext context) { try { if (context.Activity.Recipient.Name.Equals(ConfigurationManager.AppSettings["BotName"])) { await IdTable.SetBotId(context.Activity.Recipient); } } catch (System.Exception e) { Trace.TraceError($"Error setting bot id. {e}"); } }
public void TestDeserialise() { var id = new IdTable(); var refs = new ReferenceTable(); var props = new PropertyManager(); var lessees = new LesseeManager(); var projects = new ProjectManager(); Xml.Read("D:\\Projects\\Olivia2\\Olivia2.Persistence.Test\\Properties.xml", props, refs, id); Xml.Read("D:\\Projects\\Olivia2\\Olivia2.Persistence.Test\\Lessees.xml", lessees, refs, id); Xml.Read("D:\\Projects\\Olivia2\\Olivia2.Persistence.Test\\Abrechnung 2011.xml", projects, refs, id); refs.Update(id); Equals(props[0].Name, "Haus1"); Equals(props[0].Flats[0].Name, "Wohnung A"); Equals(projects.Current.Assignments[0].Flat, props[0].Flats[0]); }
void WriteProperties(object item, IdTable id) { foreach ( var property in item.GetType().GetProperties() ) { if ( !property.HasAttribute(typeof(SerializeAttribute)) ) continue; var value = property.GetValue(item, null); if ( property.PropertyType.HasInterface(typeof(INotifyPropertyChanged)) ) { // Property type is a data model object, serialise its ID by looking it up var idv = value == null ? "null" : id[value].ToString(); WriteLine("<" + property.Name + ">" + idv + "</" + property.Name + ">"); } else { // Integral data type, write down its string representation WriteLine("<" + property.Name + ">" + value + "</" + property.Name + ">"); } } }
public static void Write(PropertyManager properties, string filepath, IdTable ids) { var f = new XmlWriter(filepath); f.Begin("Properties"); var list = new Olivia2.Model.Property[properties.Count]; lock ( properties ) properties.CopyTo(list, 0); foreach (var p in list) { f.Begin(p, ids); f.Begin("Flats"); var flatlist = new Flat[p.Flats.Count]; lock ( p.Flats ) p.Flats.CopyTo(flatlist, 0); foreach ( var flat in flatlist ) f.Write(flat, ids); f.End("Flats"); f.End(p); } f.End("Properties"); f.Close(); }
public static void Write(LesseeManager lessees, string filepath, IdTable ids) { var f = new XmlWriter(filepath); f.Begin("Lessees"); var list = new Lessee[lessees.Count]; lock ( lessees ) lessees.CopyTo(list, 0); foreach ( var l in list ) { f.Begin(l, ids); f.Begin("Payments"); var paymentlist = new AdvancePayment[l.Payments.Count]; lock ( l.Payments ) l.Payments.CopyTo(paymentlist, 0); foreach ( var p in paymentlist ) f.Write(p, ids); f.End("Payments"); f.End(l); } f.End("Lessees"); f.Close(); }
public static void Read(string filepath, PropertyManager properties, ReferenceTable references, IdTable ids) { var xml = new XPathDocument(filepath).CreateNavigator(); var pi = xml.Select("/Properties/Property"); while ( pi.MoveNext() ) { var pnode = pi.Current; var p = properties.Create(); ids[p] = new Guid(pnode.GetAttribute("id", "")); AssignProperties(pnode, p, references); var fi = pnode.Select("Flats/Flat"); while ( fi.MoveNext() ) { var fnode = fi.Current; var f = p.CreateFlat(); ids[f] = new Guid(fnode.GetAttribute("id", "")); AssignProperties(fnode, f, references); } } }
public void TestSerialise() { var id = new IdTable(); var props = new PropertyManager(); var lessees = new LesseeManager(); Xml.Write(props, "Properties.xml", id); Xml.Write(lessees, "Lessees.xml", id); var projects = new ProjectManager(); projects.Add(new Project()); projects.Current.Property = props[0]; projects.Current.CreateCost(); var fac = projects.Current.Assignments.First(a => a.Flat == props[0].Flats[0]); var assignment = new FlatAssignment(projects.Current); assignment.Start = DateTime.Now; assignment.End = DateTime.Now.AddMonths(3); assignment.Lessee = lessees[0]; fac.Add(assignment); Xml.Write(projects, "", id); }
private static async Task SaveAgentChannelIdInAzureStore(IDialogContext context) { try { using (var connectorClient = await BotConnectorUtility.BuildConnectorClientAsync(context.Activity.ServiceUrl)) { var ci = GetChannelId(connectorClient, context, ConfigurationManager.AppSettings["AgentChannelName"]); await IdTable.SetAgentChannel(ci.Name, ci.Id); WebApiConfig.TelemetryClient.TrackEvent("SaveAgentChannelIdInAzureStore", new Dictionary <string, string> { { ci.Name, ci.Id } }); Trace.TraceInformation($"Id of {ci.Name}' is {ci.Id}."); } } catch (System.Exception e) { Trace.TraceError($"Error getting channel id. {e}"); } }
public void CreateObj(GameObject obj, int id, OrderProcessing linkOnFood) { if (GetComponent <SavedItem>().objOnTable == null) { test = Instantiate(obj, GetComponent <SavedItem>().placeObj.transform.position, transform.rotation); test.transform.SetParent(GetComponent <SavedItem>().placeObj.transform); GetComponent <SavedItem>().objOnTable = test; GetComponent <SavedItem>().canTake = true; orderId = GetComponent <SavedItem>().objOnTable.AddComponent <IdTable>(); orderId.id = id; orderId.link = linkOnFood; if (GetComponent <OrderProcessing>() != null) { transform.GetComponent <OrderProcessing>().readyFood = test; // сохраняем сылку на заказ } else { linkOnFood.readyFood = test; } } }
/// <summary> /// /// </summary> /// <param name="other"></param> /// <returns></returns> public int CompareTo(TupleTable other) { return(IdTable.CompareTo(other.IdTable)); }
static bool GetLexem(string name) { if (IsLexem(name)) { int c = 0; for (int i = 0; i < lexem.Length; i++) { if (name == lexem[i]) { c = i + 1; } } LexemTable.Add(new Lexem(++LexemNumber, NumberOfLines, name, c, 0)); return(true); } if (IsId(name)) { string type; if (IsInitialized(name, out type)) { int code = 0; bool key = false; for (int i = 0; i < IdTable.Count; i++) { if ((name == IdTable[i].IdName)) { if (type != IdTable[i].IdType) { return(false); } key = true; code = IdTable[i].IdCode; break; } } if (!key) { IdTable.Add(new Id(name, ++IdCodeNumber, type)); code = IdCodeNumber; } LexemTable.Add(new Lexem(++LexemNumber, NumberOfLines, name, 46, code)); } else { return(false); } return(true); } if (IsConst(name)) { bool key = false; int Number = 0; for (int i = 0; i < ConstCodeNumber; i++) { if (ConstTable[i].ConstName == name) { key = true; Number = ConstTable[i].ConstCode; break; } } if (!key) { ConstTable.Add(new Const(name, ++ConstCodeNumber)); Number = ConstCodeNumber; } LexemTable.Add(new Lexem(++LexemNumber, NumberOfLines, name, 47, Number)); return(true); } return(false); }
public static async Task <string> CreateAgentConversationEx(IDialogContext context, string topicName, AdaptiveCard cardToSend, UserProfile endUserProfile) { string serviceUrl = GetServiceUrl(context); var agentChannelInfo = await IdTable.GetAgentChannelInfo(); ChannelAccount botMsTeamsChannelAccount = context.Activity.ChannelId == ActivityHelper.SmsChannelId ? await IdTable.GetBotId() : context.Activity.From; using (var connectorClient = await BotConnectorUtility.BuildConnectorClientAsync(serviceUrl)) { try { var channelData = new TeamsChannelData { Channel = agentChannelInfo }; IMessageActivity agentMessage = Activity.CreateMessageActivity(); agentMessage.From = botMsTeamsChannelAccount; agentMessage.Recipient = new ChannelAccount(ConfigurationManager.AppSettings["AgentToAssignVsoTasksTo"]); agentMessage.Type = ActivityTypes.Message; agentMessage.ChannelId = ActivityHelper.MsTeamChannelId; agentMessage.ServiceUrl = serviceUrl; agentMessage.Attachments = new List <Attachment> { new Attachment { ContentType = AdaptiveCard.ContentType, Content = cardToSend } }; var agentMessageActivity = (Activity)agentMessage; ConversationParameters conversationParams = new ConversationParameters( isGroup: true, bot: null, members: null, topicName: topicName, activity: agentMessageActivity, channelData: channelData); var conversationResourceResponse = await BotConnectorUtility.BuildRetryPolicy().ExecuteAsync( async() => await connectorClient.Conversations.CreateConversationAsync(conversationParams)); Trace.TraceInformation( $"[SUCCESS]: CreateAgentConversation. response id ={conversationResourceResponse.Id}"); WebApiConfig.TelemetryClient.TrackEvent("CreateAgentConversation", new Dictionary <string, string> { { "endUser", agentMessage.From.Name }, { "agentConversationId", conversationResourceResponse.Id }, }); return(conversationResourceResponse.Id); } catch (System.Exception e) { WebApiConfig.TelemetryClient.TrackException(e, new Dictionary <string, string> { { "function", "CreateAgentConversation" } }); throw; } } }
public static void Read(string filepath, ProjectManager projects, ReferenceTable references, IdTable ids) { var xml = new XPathDocument(filepath).CreateNavigator(); var project = new Project(); var pnode = xml.SelectSingleNode("/Project"); ids[project] = new Guid(pnode.GetAttribute("id", "")); AssignProperties(pnode, project, references); references.Update(ids);// force Project.Property assignment var aci = pnode.Select("Assignments/FlatAssignmentCollection"); while ( aci.MoveNext() ) { var acnode = aci.Current; var flatid = acnode.SelectSingleNode("Flat").Value; var collection = project.Assignments.First(ac => ids[ac.Flat].ToString() == flatid); ids[collection] = new Guid(acnode.GetAttribute("id", "")); AssignProperties(acnode, collection, references); var ai = acnode.Select("FlatAssignment"); while ( ai.MoveNext() ) { var anode = ai.Current; var a = new FlatAssignment(project); ids[a] = new Guid(anode.GetAttribute("id", "")); AssignProperties(anode, a, references); collection.Add(a); } } references.Update(ids);// force Assignments for CostOptions generation var ci = pnode.Select("Costs/Cost"); while ( ci.MoveNext() ) { var cnode = ci.Current; var c = project.CreateCost(); ids[c] = new Guid(cnode.GetAttribute("id", "")); AssignProperties(cnode, c, references); var oi = cnode.Select("Options/CostOptions"); while ( oi.MoveNext() ) { var onode = oi.Current; var lesseeid = onode.SelectSingleNode("Lessee").Value; var option = c.Options.First(o => ids[o.Lessee].ToString() == lesseeid); ids[option] = new Guid(onode.GetAttribute("id", "")); AssignProperties(onode, option, references); } } projects.Add(project); }
public static void Read(string filepath, LesseeManager lessees, ReferenceTable references, IdTable ids) { var xml = new XPathDocument(filepath).CreateNavigator(); var li = xml.Select("/Lessees/Lessee"); var list = new List<Lessee>(); while ( li.MoveNext() ) { var lnode = li.Current; var l = new Lessee(); ids[l] = new Guid(lnode.GetAttribute("id", "")); AssignProperties(lnode, l, references); var pi = lnode.Select("Payments/AdvancePayment"); while ( pi.MoveNext() ) { var pnode = pi.Current; var p = new AdvancePayment(); ids[p] = new Guid(pnode.GetAttribute("id", "")); AssignProperties(pnode, p, references); l.Payments.Add(p); } list.Add(l); } foreach (var i in list.OrderBy(item => item.Name)) lessees.Add(i); }
public NavalBase(GameProvider listener, ITimingService timingService, NotificationManager notification, IStatePersist statePersist, IQuestKnowledges questKnowledges) { Notification = notification; StatePersist = statePersist; this.questKnowledges = questKnowledges; MasterData = new MasterDataRoot(listener); Battle = new BattleManager(listener, this); Quests = new QuestManager(listener, questKnowledges, statePersist); _allEquipment = new IdTable <EquipmentId, HomeportEquipment, RawEquipment, NavalBase>(this); _buildingDocks = new IdTable <BuildingDockId, BuildingDock, RawBuildingDock, NavalBase>(this); _repairingDocks = new IdTable <RepairingDockId, RepairingDock, RawRepairingDock, NavalBase>(this); _useItems = new IdTable <UseItemId, UseItemCount, RawUseItemCount, NavalBase>(this); _allShips = new IdTable <ShipId, HomeportShip, RawShip, NavalBase>(this); _fleets = new IdTable <FleetId, HomeportFleet, RawFleet, NavalBase>(this); _maps = new IdTable <MapId, Map, RawMap, NavalBase>(this); _airForce = new IdTable <(MapAreaId MapArea, AirForceGroupId GroupId), AirForceGroup, RawAirForceGroup, NavalBase>(this); listener.AllEquipmentUpdated += (t, msg) => _allEquipment.BatchUpdate(msg, t); listener.BuildingDockUpdated += (t, msg) => _buildingDocks.BatchUpdate(msg, t); listener.UseItemUpdated += (t, msg) => _useItems.BatchUpdate(msg, t); listener.AdmiralUpdated += (t, msg) => { if (Admiral?.Id != msg.Id) { var @new = new Admiral(msg, this, t); AdmiralChanging?.Invoke(t, Admiral, @new); Admiral = @new; NotifyPropertyChanged(nameof(Admiral)); StatePersist?.Initialize(msg.Id); this.questKnowledges.Load(); } else { Admiral.Update(msg, t); } }; listener.MaterialsUpdated += (t, msg) => { var oldMaterials = Materials; var materials = oldMaterials; msg.Apply(ref materials); if (Materials != materials) { Materials = materials; MaterialsUpdating?.Invoke(t, oldMaterials, materials, msg.Reason); } }; listener.HomeportReturned += (t, msg) => { _allShips.BatchUpdate(msg.Ships, t); CombinedFleet = msg.CombinedFleetType; if (StatePersist != null) { StatePersist.LastHomeportUpdate = t; StatePersist.SaveChanges(); } HomeportUpdated?.Invoke(t, this); }; listener.CompositionChanged += (t, msg) => { var fleet = Fleets[msg.FleetId]; if (msg.ShipId is ShipId shipId) { var ship = AllShips[shipId]; fleet.ChangeComposition(msg.Index, ship); } else { fleet.ChangeComposition(msg.Index, null); } }; listener.FleetsUpdated += (t, msg) => _fleets.BatchUpdate(msg, t); listener.FleetPresetSelected += (t, msg) => Fleets[msg.Id].Update(msg, t); listener.ShipExtraSlotOpened += (t, msg) => AllShips[msg].OpenExtraSlot(); listener.PartialFleetsUpdated += (t, msg) => _fleets.BatchUpdate(msg, t, removal: false); listener.PartialShipsUpdated += (t, msg) => _allShips.BatchUpdate(msg, t, removal: false); listener.RepairingDockUpdated += (t, msg) => _repairingDocks.BatchUpdate(msg, t); listener.ShipSupplied += (t, msg) => { foreach (var raw in msg) { var ship = AllShips[raw.ShipId]; ShipSupplying?.Invoke(t, ship, raw); ship?.Supply(raw); } questKnowledges.OnSingletonEvent(SingletonEvent.ShipSupply); }; listener.RepairStarted += (t, msg) => { var ship = AllShips[msg.ShipId]; if (ship == null) { return; } ShipRepairing?.Invoke(t, ship, msg.InstantRepair); if (msg.InstantRepair) { ship.SetRepaired(); } var oldMaterials = Materials; var materials = oldMaterials; materials.Fuel -= ship.RepairingCost.Fuel; materials.Steel -= ship.RepairingCost.Steel; Materials = materials; MaterialsUpdating?.Invoke(t, oldMaterials, materials, MaterialsChangeReason.ShipRepair); questKnowledges.OnSingletonEvent(SingletonEvent.ShipRepair); }; listener.InstantRepaired += (t, msg) => { var dock = RepairingDocks[msg]; RepairingDockInstant?.Invoke(t, msg, dock.RepairingShip); dock.Instant(); }; listener.InstantBuilt += (t, msg) => { var dock = BuildingDocks[msg]; dock.Instant(); var oldMaterials = Materials; var materials = oldMaterials; materials.InstantBuild -= dock.IsLSC ? 10 : 1; Materials = materials; MaterialsUpdating?.Invoke(t, oldMaterials, materials, MaterialsChangeReason.InstantBuilt); }; listener.ShipCreated += (t, msg) => questKnowledges.OnSingletonEvent(SingletonEvent.ShipConstruct); listener.ShipBuildCompleted += (t, msg) => { _allEquipment.BatchUpdate(msg.Equipments, t, removal: false); _allShips.Add(msg.Ship, t); }; listener.EquipmentCreated += (t, msg) => { foreach (var e in msg.Equipment) { if (e is object) { _allEquipment.Add(e, t); } questKnowledges.OnSingletonEvent(SingletonEvent.EquipmentCreate); } }; listener.ShipDismantled += (t, msg) => { var removed = RemoveShips(msg.ShipIds, msg.DismantleEquipments); questKnowledges.OnShipDismantle(removed); ShipDismantling?.Invoke(t, removed, msg.DismantleEquipments); }; listener.EquipmentDismantled += (t, msg) => { var removed = RemoveEquipment(msg); questKnowledges.OnEquipmentDismantle(removed); EquipmentDismantling?.Invoke(t, removed); }; listener.EquipmentImproved += (t, msg) => { var consumed = msg.ConsumedEquipmentIds != null?RemoveEquipment(msg.ConsumedEquipmentIds) : null; var original = AllEquipment[msg.EquipmentId]; EquipmentImproving?.Invoke(t, original, msg.UpdatedTo, consumed, msg.IsSuccess); if (msg.IsSuccess) { original.Update(msg.UpdatedTo, t); } questKnowledges?.OnSingletonEvent(SingletonEvent.EquipmentImprove); }; listener.ShipPoweruped += (t, msg) => { var consumed = RemoveShips(msg.ConsumedShipIds, msg.DismantleEquipments); var original = AllShips[msg.ShipId]; questKnowledges.OnShipPowerup(original, consumed, msg.IsSuccess); ShipPoweruping?.Invoke(t, original, msg.UpdatedTo, consumed); original.Update(msg.UpdatedTo, t); }; listener.ExpeditionCompleted += (t, msg) => { var fleet = Fleets[msg.FleetId]; questKnowledges?.OnExpeditionComplete(fleet, fleet.Expedition, msg.Result); }; listener.MapsUpdated += (t, msg) => _maps.BatchUpdate(msg, t); listener.AirForceUpdated += (t, msg) => _airForce.BatchUpdate(msg, t); listener.AirForcePlaneSet += (t, msg) => AirForce[(msg.MapAreaId, msg.GroupId)].SetPlane(t, msg);
public Tokenizer() { /* White spaces */ _tokenMatchDefinitions.Add(new TokenMatchDefinition(@"^[ \f\r\t\v]+", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new NullToken() })); _tokenMatchDefinitions.Add(new TokenMatchDefinition(@"^\n", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial, RuleState.Comment), Value = _ => { _lineNumber += 1; return(new NullToken()); } })); /* Key words */ _tokenMatchDefinitions.Add(new TokenMatchDefinition("^(?i:class)", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.Class) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^(?i:else)", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.Else) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^(?i:if)", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.If) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^(?i:fi)", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.Fi) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^(?i:inherits)", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.Inherits) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^(?i:in)", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.In) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^(?i:let)", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.Let) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^(?i:loop)", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.Loop) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^(?i:pool)", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.Pool) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^(?i:then)", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.Then) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^(?i:while)", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.While) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^(?i:case)", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.Case) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^(?i:esac)", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.Esac) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^(?i:of)", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.Of) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^(?i:new)", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.New) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^t(?i:rue)", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.BoolConst, true) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^f(?i:alse)", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.BoolConst, false) })); /* Operations */ _tokenMatchDefinitions.Add(new TokenMatchDefinition(@"^\.", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.Dot) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^@", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.At) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^~", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.Tilde) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^isvoid", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.Isvoid) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition(@"^\*", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.Asterisk) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition(@"^\/", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.Slash) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition(@"^\+", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.Plus) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^-", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.Minus) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^=>", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.Darrow) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^<=", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.Le) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^<", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.LessThan) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^=", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.Equal) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^not", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.Not) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^<-", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.Assign) })); /* Braces */ _tokenMatchDefinitions.Add(new TokenMatchDefinition("^{", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.OpenBrace) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^}", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.CloseBrace) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition(@"^\(", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.OpenParenthesis) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition(@"^\)", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.CloseParenthesis) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^:", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.Colon) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^;", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.SemiColon) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^,", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.Comma) })); /* Integers */ _tokenMatchDefinitions.Add(new TokenMatchDefinition("^[0-9]+", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = (matchString) => { var intIndex = IntTable.addString(matchString); return(new Token(TokenType.IntConst, intIndex)); } })); /* Type identifiers */ _tokenMatchDefinitions.Add(new TokenMatchDefinition("^[A-Z][A-Za-z0-9_]*", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = (matchString) => { var idIndex = IdTable.addString(matchString); return(new Token(TokenType.TypeId, idIndex)); } })); /* Object identifiers */ _tokenMatchDefinitions.Add(new TokenMatchDefinition("^[a-z][A-Za-z0-9_]*", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = (matchString) => { var idIndex = IdTable.addString(matchString); return(new Token(TokenType.ObjectId, idIndex)); } })); /* Comments */ _tokenMatchDefinitions.Add(new TokenMatchDefinition(@"^--.*$", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new NullToken() })); _tokenMatchDefinitions.Add(new TokenMatchDefinition(@"^\(\*", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial, RuleState.Comment), Value = _ => { _commentDepth += 1; _ruleState = RuleState.Comment; return(new NullToken()); } })); _tokenMatchDefinitions.Add(new TokenMatchDefinition(@"^[^\*\n]+", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Comment), Value = _ => new NullToken() })); _tokenMatchDefinitions.Add(new TokenMatchDefinition(@"^\*", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Comment), Value = _ => new NullToken() })); _tokenMatchDefinitions.Add(new TokenMatchDefinition(@"^\*\)", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Comment), Value = _ => { _commentDepth -= 1; if (_commentDepth == 0) { _ruleState = RuleState.Initial; } return(new NullToken()); } })); _tokenMatchDefinitions.Add(new TokenMatchDefinition(@"^\z", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Comment), Value = _ => new Token(TokenType.Error, "Unexpected EOF in comment") })); _tokenMatchDefinitions.Add(new TokenMatchDefinition(@"^\*\)", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => new Token(TokenType.Error, "Unmatched *)") })); /* String constants */ _tokenMatchDefinitions.Add(new TokenMatchDefinition("^\"", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.Initial), Value = _ => { _ruleState = RuleState.String; return(new NullToken()); } })); _tokenMatchDefinitions.Add(new TokenMatchDefinition(@"^[^\\\n\0\" + "\"]+", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.String), Value = (matchString) => { _stringBuffer += matchString; if (IsStringTooLong()) { return(ProvokeStringLengthErrorToken()); } return(new NullToken()); } })); _tokenMatchDefinitions.Add(new TokenMatchDefinition(@"^\\\n", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.String), Value = _ => { _stringBuffer += "\n"; _lineNumber += 1; if (IsStringTooLong()) { return(ProvokeStringLengthErrorToken()); } return(new NullToken()); } })); _tokenMatchDefinitions.Add(new TokenMatchDefinition(@"^\\[ntbf]", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.String), Value = (matchString) => { switch (matchString) { case @"\n": _stringBuffer += "\n"; break; case @"\t": _stringBuffer += "\t"; break; case @"\b": _stringBuffer += "\t"; break; case @"\f": _stringBuffer += "\f"; break; } if (IsStringTooLong()) { return(ProvokeStringLengthErrorToken()); } return(new NullToken()); } })); _tokenMatchDefinitions.Add(new TokenMatchDefinition(@"^\\", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.String), Value = _ => { _stringBuffer += @"\"; if (IsStringTooLong()) { return(ProvokeStringLengthErrorToken()); } return(new NullToken()); } })); _tokenMatchDefinitions.Add(new TokenMatchDefinition(@"^\0", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.String), Value = _ => { _ruleState = RuleState.BrokenString; return(new Token(TokenType.Error, "String contains null character")); } })); _tokenMatchDefinitions.Add(new TokenMatchDefinition(@"^\n", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.String), Value = _ => { _ruleState = RuleState.BrokenString; return(new Token(TokenType.Error, "Unterminated string constant")); } })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^.*[\\\"\\n]", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.BrokenString), Value = _ => { _ruleState = RuleState.Initial; return(new Token(TokenType.Error, "String contains null character")); } })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^\\\"", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.String), Value = _ => { var stringIndex = StringTable.addString(_stringBuffer); _stringBuffer = string.Empty; _ruleState = RuleState.Initial; return(new Token(TokenType.StrConst, stringIndex)); } })); _tokenMatchDefinitions.Add(new TokenMatchDefinition(@"^\z", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.String), Value = _ => { _ruleState = RuleState.Initial; return(new Token(TokenType.Error, "EOF in string constant;")); } })); _tokenMatchDefinitions.Add(new TokenMatchDefinition("^.", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.String), Value = matchString => new Token(TokenType.Error, matchString) })); _tokenMatchDefinitions.Add(new TokenMatchDefinition(@"^\s+", new TokenMatchRule() { States = ImmutableList.Create <RuleState>(RuleState.String), Value = _ => new NullToken() })); }
public NavalBase(IGameProvider listener, ILocalizationService localization) { Localization = localization; MasterData = new MasterDataRoot(listener, localization); Quests = new QuestManager(listener, localization); _allEquipment = new IdTable<EquipmentId, Equipment, IRawEquipment, NavalBase>(this); _buildingDocks = new IdTable<BuildingDockId, BuildingDock, IRawBuildingDock, NavalBase>(this); _repairingDocks = new IdTable<RepairingDockId, RepairingDock, IRawRepairingDock, NavalBase>(this); _useItems = new IdTable<UseItemId, UseItemCount, IRawUseItemCount, NavalBase>(this); _allShips = new IdTable<ShipId, Ship, IRawShip, NavalBase>(this); _fleets = new IdTable<FleetId, Fleet, IRawFleet, NavalBase>(this); _maps = new IdTable<MapId, Map, IRawMap, NavalBase>(this); _airForce = new IdTable<(MapAreaId MapArea, AirForceGroupId GroupId), AirForceGroup, IRawAirForceGroup, NavalBase>(this); listener.AllEquipmentUpdated += (t, msg) => _allEquipment.BatchUpdate(msg, t); listener.BuildingDockUpdated += (t, msg) => _buildingDocks.BatchUpdate(msg, t); listener.UseItemUpdated += (t, msg) => _useItems.BatchUpdate(msg, t); listener.AdmiralUpdated += (t, msg) => { if (Admiral?.Id != msg.Id) { var @new = new Admiral(msg, this, t); AdmiralChanging?.Invoke(t, Admiral, @new); Admiral = @new; NotifyPropertyChanged(nameof(Admiral)); } else Admiral.Update(msg, t); }; listener.MaterialsUpdated += (t, msg) => { var materials = Materials; msg.Apply(ref materials); if (Materials != materials) { Materials = materials; MaterialsUpdating?.Invoke(t, Materials, materials, msg.Reason); } }; listener.HomeportReturned += (t, msg) => _allShips.BatchUpdate(msg.Ships, t); listener.CompositionChanged += (t, msg) => { var fleet = Fleets[msg.FleetId]; if (msg.ShipId is ShipId shipId) { var ship = AllShips[shipId]; fleet.ChangeComposition(msg.Index, ship, Fleets.FirstOrDefault(x => x.Ships.Contains(ship))); } else fleet.ChangeComposition(msg.Index, null, null); }; listener.FleetsUpdated += (t, msg) => _fleets.BatchUpdate(msg, t); listener.FleetPresetSelected += (t, msg) => Fleets[msg.Id].Update(msg, t); listener.ShipEquipmentUdated += (t, msg) => AllShips[msg.ShipId].UpdateEquipments(msg.EquipmentIds); listener.ShipExtraSlotOpened += (t, msg) => AllShips[msg].ExtraSlot = new Slot(); listener.PartialFleetsUpdated += (t, msg) => _fleets.BatchUpdate(msg, t, removal: false); listener.PartialShipsUpdated += (t, msg) => _allShips.BatchUpdate(msg, t, removal: false); listener.RepairingDockUpdated += (t, msg) => _repairingDocks.BatchUpdate(msg, t); listener.ShipSupplied += (t, msg) => { foreach (var raw in msg) AllShips[raw.ShipId]?.Supply(raw); }; listener.RepairStarted += (t, msg) => { if (msg.InstantRepair) AllShips[msg.ShipId]?.SetRepaired(); }; listener.InstantRepaired += (t, msg) => { var dock = RepairingDocks[msg]; dock.State = RepairingDockState.Empty; dock.RepairingShip = null; }; listener.InstantBuilt += (t, msg) => BuildingDocks[msg].State = BuildingDockState.BuildCompleted; listener.ShipBuildCompleted += (t, msg) => { _allEquipment.BatchUpdate(msg.Equipments, t, removal: false); _allShips.Add(msg.Ship, t); }; listener.EquipmentCreated += (t, msg) => { if (msg.IsSuccess) _allEquipment.Add(msg.Equipment, t); }; listener.ShipDismantled += (t, msg) => ShipDismantling?.Invoke(t, RemoveShips(msg.ShipIds, msg.DismantleEquipments, t), msg.DismantleEquipments); listener.EquipmentDismantled += (t, msg) => EquipmentDismantling?.Invoke(t, RemoveEquipments(msg, t)); listener.EquipmentImproved += (t, msg) => { var consumed = RemoveEquipments(msg.ConsumedEquipmentIds, t); var original = AllEquipment[msg.EquipmentId]; EquipmentImproving?.Invoke(t, original, msg.UpdatedTo, consumed, msg.IsSuccess); if (msg.IsSuccess) original.Update(msg.UpdatedTo, t); }; listener.ShipPoweruped += (t, msg) => { var consumed = RemoveShips(msg.ConsumedShipIds, true, t); var original = AllShips[msg.ShipId]; ShipPoweruping?.Invoke(t, original, msg.UpdatedTo, consumed); original.Update(msg.UpdatedTo, t); }; listener.MapsUpdated += (t, msg) => _maps.BatchUpdate(msg, t); listener.AirForceUpdated += (t, msg) => _airForce.BatchUpdate(msg, t); listener.AirForcePlaneSet += (t, msg) => { var group = AirForce[(msg.MapAreaId, msg.GroupId)]; group.Distance = msg.NewDistance; group.squadrons.BatchUpdate(msg.UpdatedSquadrons, t, removal: false); };
public Serializer() { IdTable = new IdTable(); Interval = 10000; Timestep = 1000; IsRunning = false; }
public void Write(object o, IdTable id) { Begin(o, id); End(o); }
public void Begin(object o, IdTable id) { var type = o.GetType(); WriteLine("<" + type.Name + " id=\"" + id[o] + "\">"); WriteProperties(o, id); }
public void Setup() { IdTable.Init(); }