private static IdMap ReadIdMap(string mapFileLocation) { var @default = new Dictionary <int, string>(); var map = new IdMap(@default); if (!File.Exists(mapFileLocation)) { Log.Information("ID mapping file {file} doesn't exist. Skipping.", mapFileLocation); return(map); } foreach (var format in new[] { MapFormat.RoE, MapFormat.AB, MapFormat.SoD, MapFormat.HotA, MapFormat.WoG }) { var file = Path.ChangeExtension(mapFileLocation, $"{format}.txt"); if (File.Exists(file)) { var values = new Dictionary <int, string>(); ReadFileValues(file, values); map.AddFormatMapping(format, values); } else { Log.Debug("ID mapping file {file} doesn't exist. Skipping.", file); } } ReadFileValues(mapFileLocation, @default); return(map); }
/// <summary> /// Parse the caller from the specified caller string. /// </summary> /// <param name="clientId">client id string</param> private void ParseClientId(string clientId) { string str; IdMap.TryGetValue(clientId.ToUpperInvariant(), out str); Id = str; }
getColumnTypeName(int column) { String type = null; if (trace.enabled()) { trace.log(title + ".getColumnTypeName( " + column + " )"); } column = columnMap(column); switch (desc[column].dbms_type) { case DBMS_TYPE_INT: type = IdMap.get(desc[column].length, intMap); break; case DBMS_TYPE_FLOAT: type = IdMap.get(desc[column].length, floatMap); break; default: type = IdMap.get(desc[column].dbms_type, typeMap); break; } if (trace.enabled()) { trace.log(title + ".getColumnTypeName: " + type); } return(type); } // getColumnTypeName
private async Task InsertMissingApisAsync(IdMap <Guid> apis, SqliteTransaction transaction) { var existingApis = await ReadApisAsync(); await using var command = new SqliteCommand(@" INSERT INTO Apis (ApiId, Guid) VALUES (@ApiId, @Guid) ", _connection, transaction); var apiIdParameter = command.Parameters.Add("ApiId", SqliteType.Integer); var guidParameter = command.Parameters.Add("Guid", SqliteType.Text); foreach (var(apiId, guid) in apis) { if (existingApis.Contains(guid)) { continue; } apiIdParameter.Value = apiId; guidParameter.Value = guid; await command.ExecuteNonQueryAsync(); } }
/// <summary> /// Generates an id for the specified entity. /// </summary> /// <param name="entity">The entity.</param> /// <param name="idMap">The id map.</param> /// <returns></returns> /// <remarks> /// This code was taken from NHibernate. /// </remarks> public object Generate(object entity, IdMap idMap) { var guidArray = Guid.NewGuid().ToByteArray(); var baseDate = new DateTime(1900, 1, 1); var now = DateTime.Now; // Get the days and milliseconds which will be used to build the byte string var days = new TimeSpan(now.Ticks - baseDate.Ticks); var msecs = now.TimeOfDay; // Convert to a byte array // Note that SQL Server is accurate to 1/300th of a millisecond so we divide by 3.333333 var daysArray = BitConverter.GetBytes(days.Days); var msecsArray = BitConverter.GetBytes((long)(msecs.TotalMilliseconds / 3.333333)); // Reverse the bytes to match SQL Servers ordering Array.Reverse(daysArray); Array.Reverse(msecsArray); // Copy the bytes into the guid Array.Copy(daysArray, daysArray.Length - 2, guidArray, guidArray.Length - 6, 2); Array.Copy(msecsArray, msecsArray.Length - 4, guidArray, guidArray.Length - 4, 4); return(new Guid(guidArray)); }
public async Task InsertMissingApisAsync(IdMap <Guid> apis) { await using var transaction = _connection.BeginTransaction(); await InsertMissingApisAsync(apis, transaction); await transaction.CommitAsync(); }
public override void Visit(IdMap idMap) { var id = idMap.MemberGetter(this.currentEntity); if(!Object.Equals(id, idMap.UnsavedValue)) return; id = idMap.Generate(this.currentEntity, this.mongoSession); idMap.MemberSetter(this.currentEntity, id); }
public LanguageFirstModel(IEnumerable <Language> languages, IReadOnlyDictionary <string, uint> translationIds) { Languages = languages.ToDictionary(l => l.Index); LanguageIds = new IdMap <ushort>(languages.ToDictionary(l => l.TextId, l => l.Index) , x => (ushort)(x + 1), (x, y) => x == y); TranslationIds = new IdMap <uint>(translationIds, x => (uint)(x + 1), (x, y) => x == y); }
public void TestPostIdMap_MissingRequiredName() { var d = new IdMap { }; var r = api.PostIdMap(d); //payload is {"Id":"00000000-0000-0000-0000-000000000000"}, while RequiredName is with IsRequired=true; Assert.Null(r); // The service binding will fail to deserialize sicne RequiredName has to be presented in payload, }
public bool TryGetPacketId(Type type, out TType id) { if (IdMap.TryGetValue(type, out id)) { return(true); } id = default(TType); return(false); }
public LanguageFirstModel(IEnumerable <ProtoLanguage> languages, IReadOnlyDictionary <string, uint> translationIds) { Languages = languages.Select(l => new Language(l.Index, l.TextId, this, l.Translations, l.Name0, l.Name1)) .ToDictionary(l => l.Index); LanguageIds = new IdMap <ushort>(languages.ToDictionary(l => l.TextId, l => l.Index) , x => (ushort)(x + 1), (x, y) => x == y); TranslationIds = new IdMap <uint>(translationIds, x => (uint)(x + 1), (x, y) => x == y); }
public void InitListInfo() { knownGuids.Clear(); idMap = new IdMap(); if (Manager.Character.Instance != null) { Manager.Character.Instance.chaListCtrl = new ChaListControl(); Manager.Character.Instance.chaListCtrl.LoadListInfoAll(); } }
public void Should_throw_id_generation_exception_when_id_has_not_been_assigned() { var generator = new AssignedGenerator(); var idMap = new IdMap("Id", x => null, (x, y) => { }, generator, new Mock<IValueConverter>().Object, null); var mockClassMap = new Mock<ClassMap>(typeof(int)); var mockMongoSession = new Mock<IMongoSessionImplementor>(); mockMongoSession.Setup(x => x.MappingStore.GetClassMapFor(It.IsAny<Type>())).Returns(mockClassMap.Object); mockClassMap.SetupGet(x => x.IdMap).Returns(idMap); generator.Generate("setat", mockMongoSession.Object); }
/// <summary> /// Generates an id for the specified entity. /// </summary> /// <param name="entity">The entity.</param> /// <param name="idMap">The id map.</param> /// <returns></returns> public object Generate(object entity, IdMap idMap) { var id = idMap.GetValue(entity); if (Equals(id, idMap.UnsavedValue)) { throw new IdGenerationException(string.Format("Ids for {0} must be manually assigned before saving.", entity.GetType())); } return(id); }
public void TestPostIdMap() { var d = new IdMap { RequiredName = "Hey" }; var r = api.PostIdMap(d); //payload is {"Id":"00000000-0000-0000-0000-000000000000"}, while RequiredName is with IsRequired=true; Assert.Equal(Guid.Empty, r.Id); Assert.Equal(Guid.Empty, r.IdNotEmitDefaultValue); }
public void Should_return_entity_id_when_set() { var generator = new AssignedGenerator(); var idMap = new IdMap("Id", x => 42, (x, y) => { }, generator, new Mock<IValueConverter>().Object, null); var mockClassMap = new Mock<ClassMap>(typeof(int)); var mockMongoSession = new Mock<IMongoSessionImplementor>(); mockMongoSession.Setup(x => x.MappingStore.GetClassMapFor(It.IsAny<Type>())).Returns(mockClassMap.Object); mockClassMap.SetupGet(x => x.IdMap).Returns(idMap); var id = (int)generator.Generate("setat", mockMongoSession.Object); Assert.AreEqual(42, id); }
protected virtual async Task ToCache(TEntity entity) { if (entity == null) { return; } string key = $"{entity.GetType().FullName}:{entity.Id}"; await ToCache(key, entity); IdMap.Set(entity.GlobalId, entity.Id); }
public void Register(TType packetId, Func <TPacket> createPacket) { lock (_addLock) { if (Packets.ContainsKey(packetId)) { throw new DuplicatePacketIdException <TType>(packetId); } Packets.Add(packetId, createPacket); IdMap.Add(createPacket().GetType(), packetId); } }
public async Task <IdMap <Guid> > ReadApisAsync() { var result = new IdMap <Guid>(); var rows = await _connection.QueryAsync <(int Id, string GuidText)>(@" SELECT ApiId, Guid FROM Apis "); foreach (var(id, guidText) in rows) { var guid = Guid.Parse(guidText); result.Add(id, guid); } return(result); }
private LanguageFirstModel(JObject json) { var transIds = json["TranslationIds"] .ToDictionary(j => ((JProperty)j).Name, j => ((JValue)j.First).Value <uint>()); var jLangs = json["Languages"]; Languages = jLangs.Cast <JProperty>() .Select(j => j.Value) .Cast <JObject>() .Select(j => new Language(j.Value <ushort>("Index"), j.Value <string>("TextId"), this, Parse(j["Translations"]), j.Value <string>("Name0"), j.Value <string>("Name1"))) .ToDictionary(l => l.Index); LanguageIds = new IdMap <ushort>(Languages.Values.ToDictionary(l => l.TextId, l => l.Index) , x => (ushort)(x + 1), (x, y) => x == y); TranslationIds = new IdMap <uint>(transIds, x => (uint)(x + 1), (x, y) => x == y); }
public async Task <IdMap <PackageIdentity> > ReadPackagesAsync() { var result = new IdMap <PackageIdentity>(); var rows = await _connection.QueryAsync <(int Id, string Name, string Version)>(@" SELECT PackageId, Name, Version FROM Packages "); foreach (var(id, name, versionText) in rows) { var version = NuGetVersion.Parse(versionText); var identity = new PackageIdentity(name, version); result.Add(id, identity); } return(result); }
public virtual async Task <TEntity> Load(string id, Func <IQueryable <TEntity>, IQueryable <TEntity> > includes) { if (string.IsNullOrEmpty(id)) { return(null); } if (IdMap.TryGetValue(id, out int i)) { return(await Load(i, includes)); } int actualId = await DbContext.Set <TEntity>() .Where(e => e.GlobalId == id) .Select(e => e.Id) .SingleOrDefaultAsync(); return(await Load(actualId, includes)); }
} // InBuff /* ** Name: receive ** ** Description: ** Read the next message. Any data remaining in the current ** message is discarded. A server abort (TL disconnect request) ** is processed here and results in an exception being raised. ** ** Input: ** None. ** ** Output: ** None. ** ** Returns: ** short TL Message type. ** ** History: ** 16-Jun-99 (gordy) ** Created. ** 10-Sep-99 (gordy) ** Check for TL disconnect request. ** 28-Jan-00 (gordy) ** Added TL msg ID tracing. ** 20-Dec-02 (gordy) ** Header ID now protocol level dependent. Moved TL DR ** processing to MSG classes where it is more appropriatte. */ /// <summary> /// Read the next message. Any data remaining in the current /// message is discarded. /// </summary> /// <returns>TL Message type.</returns> public virtual short receive() { int hdr_id; short msg_id; /* ** Get the next segment in the input buffer. ** If buffer is empty, receive next buffer. */ base.next(); /* ** Read and validate packet header: ID and type. */ hdr_id = readInt(); if ( (proto_lvl <= DAM_TL_PROTO_1 && hdr_id != DAM_TL_ID_1) || (proto_lvl >= DAM_TL_PROTO_2 && hdr_id != DAM_TL_ID_2) ) { if (trace.enabled(1)) { trace.write(title + ": invalid TL header ID"); } close(); throw SqlEx.get(ERR_GC4002_PROTOCOL_ERR); } /* ** Determine type of message. A disconnect request is only ** issued by the server when aborting the connection. Handle ** this exceptional case directly. */ msg_id = readShort(); if (trace.enabled(3)) { trace.write(title + ": recv TL packet " + IdMap.map(msg_id, tlMap) + " length " + avail()); } return(msg_id); } // receive
} // OutBuff /* ** Name: begin ** ** Description: ** Start a new message of the requested type. ** ** Input: ** type Message type. ** size Minimum buffer space required for message. ** ** Output: ** None. ** ** Returns: ** void ** ** History: ** 16-Jun-99 (gordy) ** Created. ** 28-Jan-00 (gordy) ** Added TL msg ID tracing. ** 20-Dec-02 (gordy) ** Header ID protocol level dependent. */ /// <summary> /// Start a new message of the requested type /// with the minimum buffer space required for the message. /// </summary> /// <param name="type">Message type.</param> /// <param name="size">Minimum buffer space required for message.</param> public virtual void begin(short type, int size) { size += 6; // Include TL header if (trace.enabled(3)) { trace.write(title + ": begin TL packet " + IdMap.map(type, tlMap)); if (trace.enabled(5)) { trace.write(title + ": reserving " + size); } } base.begin(size); // write TL header write((int)((proto_lvl == DAM_TL_PROTO_1) ? DAM_TL_ID_1 : DAM_TL_ID_2)); write((short)type); return; } // begin
static async Task OutputWorker(UsageDatabase database, IdMap <Guid> apiMap, IdMap <PackageIdentity> packageMap, BlockingCollection <PackageResults> queue) { try { using var usageWriter = database.CreateUsageWriter(); foreach (var(packageIdentity, logLines, apis) in queue.GetConsumingEnumerable()) { foreach (var line in logLines) { Console.WriteLine($"[Crawler] {line}"); } foreach (var api in apis) { if (!apiMap.Contains(api)) { continue; } var packageId = packageMap.GetId(packageIdentity); var apiId = apiMap.GetId(api); await usageWriter.WriteAsync(packageId, apiId); } } await usageWriter.SaveAsync(); Console.WriteLine("Output Worker has finished."); } catch (Exception ex) { Console.WriteLine("[Fatal] Output Worker crashed: " + ex); Environment.Exit(1); } }
internal void Initialize(bool doGarbageCollectAfterAwake) { Dictionary <int, UnityObject> idMap = new Dictionary <int, UnityObject>(); AfterLoad(idMap); // Remove placeholder references and replace them with live ones Queue <IdMap> idMaps = new Queue <IdMap>(); int count = components.Count; for (int i = 0; i < count; i++) { Component cmp = components.Dequeue(); cmp.FixReferences(idMap); if (cmp is IdMap) { idMaps.Enqueue(cmp as IdMap); } components.Enqueue(cmp); } idMap.Clear(); // Issue new ids to all objects from a scene now that references have been fixed count = gameObjects.Count; for (int i = 0; i < count; i++) { gameObjects[i].SetNewId(idMap); } while (idMaps.Count > 0) { IdMap map = idMaps.Dequeue(); map.UpdateIdReferences(idMap); } // Register and awake all components Application.RegisterComponents(components); Application.AwakeNewComponents(); if (doGarbageCollectAfterAwake) { GC.Collect(); } }
static void Main(string[] args) { using (TcpClient tcpc = new TcpClient(Host, 993)) using (SslStream ssl = new SslStream(tcpc.GetStream())) { ssl.AuthenticateAsClient(Host); Console.Write("user: "******"password: "******"$ LOGIN {user} {password}"); string folder = "Test2"; string cfg = File.ReadAllText(Program.CfgFile); Dictionary <int, string> map = JsonConvert.DeserializeObject <Dictionary <int, string> >(cfg); IdMap <int, string> idMap = new IdMap <int, string>(map); var imapStore = new ImapStore(ssl, folder); var fileStore = new FileStore(folder); Util.Integrate(imapStore, fileStore, idMap); var idMap2 = idMap.Invert(); Util.Integrate(fileStore, imapStore, idMap2); cfg = JsonConvert.SerializeObject(idMap2.Invert().Map); File.WriteAllText(Program.CfgFile, cfg); // check uivalidity // TODO skip invalid filenames (subject not content) // TODO check if folder is empty, dangerous actions // TODO MS Outlook Plugin var messages = Imap.Send(ssl, $"$ STATUS {folder} (MESSAGES)"); int count = Convert.ToInt32(Regex.Match(messages, @".*MESSAGES (\d+).*").Groups[1].Value); Imap.Send(ssl, "$ LOGOUT"); } }
private void IDTableIncludesEverythingHelper <T>(IdMap <T> idMap) { Assert.IsTrue(idMap.IsAllIncluded()); }
public IdMap PostIdMap([FromBody] IdMap idMap) { return(idMap); }
private void loadFromDump(string dump) { IdMap map = new IdMap(); // clear takmicenje = new Takmicenje(); klubovi = new List <KlubUcesnik>(); drzave = new List <DrzavaUcesnik>(); gimnasticari = new List <GimnasticarUcesnik>(); ocene = new List <Ocena>(); rasporediNastupa = new List <RasporedNastupa>(); sudije = new List <SudijaUcesnik>(); rasporediSudija = new List <RasporedSudija>(); rezTakmicenja = new List <RezultatskoTakmicenje>(); using (StringReader reader = new StringReader(dump)) { if (reader.ReadLine() != BILTEN_TAKMICENJE_DUMP) { throw new Exception("Neuspesno ucitavanje takmicenja."); } if (int.Parse(reader.ReadLine()) != Program.VERZIJA_PROGRAMA) { throw new Exception("Neuspesno uvozenje takmicenja.\n\nTakmicenje je izvezeno koristeci verziju " + "programa razlicitu od trenutne, i nije ga moguce uvesti."); } int prvoKoloId, drugoKoloId, treceKoloId, cetvrtoKoloId; int vrhovniSudijaId; // load takmicenje string id = reader.ReadLine(); map.takmicenjeMap.Add(int.Parse(id), takmicenje); takmicenje.loadFromDump(reader, map, out prvoKoloId, out drugoKoloId, out treceKoloId, out cetvrtoKoloId, out vrhovniSudijaId); // TODO4: Ovde moze da se desi da ID koji je postojao u biltenu iz koga se takmicenje izvozilo ne postoji // u biltenu u koji se takmicenje uvozi. takmicenje.PrvoKolo = prvoKoloId == -1 ? null : DAOFactoryFactory.DAOFactory.GetTakmicenjeDAO().FindById(prvoKoloId); takmicenje.DrugoKolo = drugoKoloId == -1 ? null : DAOFactoryFactory.DAOFactory.GetTakmicenjeDAO().FindById(drugoKoloId); takmicenje.TreceKolo = treceKoloId == -1 ? null : DAOFactoryFactory.DAOFactory.GetTakmicenjeDAO().FindById(treceKoloId); takmicenje.CetvrtoKolo = cetvrtoKoloId == -1 ? null : DAOFactoryFactory.DAOFactory.GetTakmicenjeDAO().FindById(cetvrtoKoloId); // Vrhovnog sudiju ucitavam dole (nakon sto ucitam sve sudije ucesnike). // load klubovi int count = int.Parse(reader.ReadLine()); for (int i = 0; i < count; ++i) { id = reader.ReadLine(); KlubUcesnik k = new KlubUcesnik(); map.kluboviMap.Add(int.Parse(id), k); k.loadFromDump(reader, map); klubovi.Add(k); } // load drzave count = int.Parse(reader.ReadLine()); for (int i = 0; i < count; ++i) { id = reader.ReadLine(); DrzavaUcesnik d = new DrzavaUcesnik(); map.drzaveMap.Add(int.Parse(id), d); d.loadFromDump(reader, map); drzave.Add(d); } // load gimnasticari count = int.Parse(reader.ReadLine()); for (int i = 0; i < count; ++i) { id = reader.ReadLine(); GimnasticarUcesnik g = new GimnasticarUcesnik(); map.gimnasticariMap.Add(int.Parse(id), g); g.loadFromDump(reader, map); gimnasticari.Add(g); } // load ocene count = int.Parse(reader.ReadLine()); for (int i = 0; i < count; ++i) { id = reader.ReadLine(); Ocena o = new Ocena(); o.loadFromDump(reader, map); ocene.Add(o); } // load rasporedi nastupa count = int.Parse(reader.ReadLine()); for (int i = 0; i < count; ++i) { id = reader.ReadLine(); RasporedNastupa r = new RasporedNastupa(); r.loadFromDump(reader, map); rasporediNastupa.Add(r); } // load sudije count = int.Parse(reader.ReadLine()); for (int i = 0; i < count; ++i) { id = reader.ReadLine(); SudijaUcesnik s = new SudijaUcesnik(); map.sudijeMap.Add(int.Parse(id), s); s.loadFromDump(reader, map); sudije.Add(s); } takmicenje.VrhovniSudija = vrhovniSudijaId == -1 ? null : map.sudijeMap[vrhovniSudijaId]; // load rasporedi sudija count = int.Parse(reader.ReadLine()); for (int i = 0; i < count; ++i) { id = reader.ReadLine(); RasporedSudija r = new RasporedSudija(); r.loadFromDump(reader, map); rasporediSudija.Add(r); } // load rezultatska takmicenja count = int.Parse(reader.ReadLine()); for (int i = 0; i < count; ++i) { id = reader.ReadLine(); RezultatskoTakmicenje rt = new RezultatskoTakmicenje(); rt.loadFromDump(reader, map); rezTakmicenja.Add(rt); } } }
public virtual void Visit(IdMap idMap) { }
/// <summary> /// Translates id map to xml /// </summary> /// <returns>map xml</returns> public static XElement IdMapToXml() { return(new XElement("ClientIdMap", IdMap.Select(_ => new XElement("Client", new XAttribute("Value", _.Key), new XAttribute("Id", _.Value))))); }
/// <summary> /// Generates an id for the specified entity. /// </summary> /// <param name="entity">The entity.</param> /// <param name="idMap">The id map.</param> /// <returns></returns> public object Generate(object entity, IdMap idMap) { return(Oid.NewOid()); }
public override void Visit(IdMap idMap) { this.value = idMap.ValueConverter.ToDocument(value); }
public async Task ExportUsagesAsync(IdMap <Guid> apiMap, IEnumerable <(Guid Api, Guid Ancestor)> ancestors, string outputPath)
public override void Visit(IdMap idMap) { var value = idMap.MemberGetter(this.entity); value = idMap.ValueConverter.ToDocument(value); this.document[idMap.Key] = value; }