public void ModelTrackerCollection_ExistingCollection_AddRemoveModel_RemoveReturnsTrue() { var m = new TestModel(); Existing.Add(m); Assert.IsTrue(Existing.Remove(m)); }
private bool FindMissingUsersInDatabase(out List <UserPrincipal> _UsersToBePut, List <UserPrincipal> _Users, Action <string> _ErrorMessageAction) { _UsersToBePut = null; var TmpDictionary = new Dictionary <string, UserPrincipal>(); foreach (var AzureUser in _Users) { TmpDictionary.Add(AzureUser.Email + Controller_SSOAccessToken.EMAIL_USER_NAME_POSTFIX, AzureUser); } if (!DatabaseService.ScanTable( UniqueUserFieldsDBEntry.DBSERVICE_UNIQUEUSERFIELDS_TABLE(), out List <JObject> Result, _ErrorMessageAction)) { _ErrorMessageAction?.Invoke("Scan unique-users-fields operation has failed."); return(false); } foreach (var Existing in Result) { if (Existing.TryGetValue(UniqueUserFieldsDBEntry.KEY_NAME_USER_EMAIL, out JToken ExistingEmailToken) && ExistingEmailToken.Type == JTokenType.String) { TmpDictionary.Remove((string)ExistingEmailToken); //TryRemove } } _UsersToBePut = TmpDictionary.Values.ToList(); return(true); }
public async Task Execute() { //process adds if (Add != null) { foreach (var e in Changed) { if (!Existing.Any(y => Compare(y, e))) { await Add(e); } } } foreach (var e in Existing) { if (Changed.Any(x => Compare(e, x))) { if (Update != null) { await Update(e, Changed.Single(x => Compare(e, x))); } } else { if (Remove != null) { await Remove(e); } } } }
public void ModelTrackerCollection_ExistingCollection_UpdateModel_ModelUpdated() { var ex = Existing.First(); ex.Data = "new data"; Existing.Update(ex.Id, ex); }
//利用该函数,静态地从仍何存在的IControllable建立控制器 static public Controller From <T>(Existing <T> obj) where T : class, IControllable { return(new Controller( new Existing <IControllable>((IControllable)obj.Unwrap()) )); }
/// <summary> /// Deserializes a document represented by the provided stream and assigns any values into the provided instance /// context, using the provided reader settings. /// </summary> /// <param name="settings">The xml reader settings to apply during document processing.</param> /// <param name="stream">The stream representing the source document.</param> /// <returns>The initial provided target instance, assigned with values discovered in the provided document.</returns> public T Deserialize(XmlReaderSettings settings, Stream stream) { var reader = new XmlReaderFactory(settings, settings.NameTable.Context()).Get(stream); var existing = new Existing(reader, _existing); var result = (T)_reader.Get(existing); return(result); }
/// <summary> /// This method was generated by Visual Studio. /// </summary> public override int GetHashCode() { var hashCode = -699697695; hashCode = hashCode * -1521134295 + Existing.GetHashCode(); hashCode = hashCode * -1521134295 + Added.GetHashCode(); return(hashCode); }
public void Watch(Existing <Bird> some_bird) { if (this.birdUnderWatch == null) { this.birdUnderWatch = some_bird.Unwrap(); Debug.Log("Watch bird"); } }
public void ModelTrackerCollection_ExistingCollection_AddModel_IndexReturnsModel() { var m = new TestModel(); Existing.Add(m); Assert.IsNotNull(Existing[m.Id]); Assert.AreEqual(m, Existing[m.Id]); }
public void ModelTrackerCollection_ExistingCollection_AddRemoveModel_ContainsModel_ReturnsFalse() { var m = new TestModel(); Existing.Add(m); Existing.Remove(m); Assert.IsFalse(Existing.Contains(m)); }
public void ModelTrackerCollection_ExistingCollection_AddRmoveModel_CountUnchanged() { var m = new TestModel(); var c = Existing.Count; Existing.Add(m); Existing.Remove(m); Assert.AreEqual(Existing.Count, c); }
//U cannot watch a bird that does not exist public void Watch(Existing <Bird> some_bird) { if (!birdWatcher.BirdWithinScene().HasValue) { birdWatcher.Watch(some_bird); shooter.GetComponent <Collider2D>().enabled = false; Debug.Log("Watch bird"); } }
public void ModelTrackerCollection_ExistingCollection_AddModel_CountIncreased() { var m = new TestModel(); int c = Existing.Count; Existing.Add(m); Assert.IsTrue(Existing.Count > c); }
public bool Equals(CollectionItemsThatMayHaveChanged <TExisting, TUpdated> other) { if (Object.ReferenceEquals(null, other)) { return(false); } return (Existing.Equals(other.Existing) && Updated.Equals(other.Updated)); }
//load when mouse clicked private void OnMouseDown() { var next_bird = this.GetBird(); if (next_bird != null) { var temp = new Existing <Bird>(next_bird); this.Load(temp); } }
public void ModelTrackerCollection_ExistingCollection_CopyToArray_ArrayContainsModels() { TestModel[] arr = new TestModel[Existing.Count]; Existing.CopyTo(arr, 0); foreach (var m in Existing) { Assert.IsTrue(arr.Contains(m)); } }
public override int GetHashCode() { unchecked { var result = 0; result = (result * 397) ^ Existing.GetHashCode(); result = (result * 397) ^ Updated.GetHashCode(); return(result); } }
private async Task WriteExisting(Existing state, RawSession session, DateTime expirationDate) { if (session.IsEmpty()) { await RemoveSession(state.Id); } else { await WriteSessionData(session, expirationDate); } }
public void ModelTrackerCollection_ExistingCollection_AddModel_IdAssigned() { var m = new TestModel(); var m2 = new TestModel(); m.Id = 1000000; Existing.Add(m); Existing.Add(m2); Assert.IsTrue(m.Id != 1000000); Assert.IsTrue(m2.Id != 1000000); Assert.IsTrue(m.Id != m2.Id); }
//load the bird onto SlingShot. The slingshot's bullet cannot be NULL!!! //The existence simplify the implemantation. It ensures the load to change states. public void Load(Existing <Bird> bullet) { //since the bullet reflects the state, this ensures call only works under unloaded state if (!this.IsLoaded) { this.bullet = bullet.Unwrap(); this.bullet.physicsLock = true; this.bullet.transform.position = new Vector3( positioner.position.x, positioner.position.y, this.bullet.transform.position.z ); } }
public void ModelTrackerCollection_ExistingCollection_RemoveModel_EventInvoked() { var m = Existing.Skip(1).First(); bool removed = false; Existing.ModelRemovedEvent += (s, e) => { Assert.AreEqual(m.Data, e.Model.Data); Assert.AreEqual(m.Id, e.Model.Id); removed = true; }; Existing.Remove(m.Id); Assert.IsTrue(removed); }
async Task <int> FetchNewMessages(IChatMessageOptions options, CancellationToken token) { IEnumerable <IChatMessage> messages = null; int count = 0; if (!token.IsCancellationRequested) { await ssFetch.WaitAsync(token); try { messages = await GitterApi.GetChatMessages(ChatRoom.Id, options); if (messages is object) { count = messages.Count(); if (!string.IsNullOrWhiteSpace(options.BeforeId)) { Messages.InsertRange(0, RemoveDuplicates(Messages, messages)); } else { Messages.AddRange(RemoveDuplicates(Messages, messages)); } await Invoke(StateHasChanged); await Task.Delay(1); } } catch (Exception e) { Console.WriteLine($"RoomMessages.FetchNewMessages: {e.GetBaseException().Message}"); } finally { ssFetch.Release(); } } return(count); IEnumerable <IChatMessage> RemoveDuplicates(IEnumerable <IChatMessage> Existing, IEnumerable <IChatMessage> Merging) { IEnumerable <string> ExistingIds = Existing.Select(m => m.Id); return(Merging.Where(m => !ExistingIds.Contains(m.Id))); } }
public virtual void AddMultipleStockEntries(IEnumerable <StockEntry> stockentries) { //TODO:Add Validation var existingAndNewEntries = stockentries.Select(st => (Existing: GetByNfCode(st.NfNumber), Given: st)); var newEntries = existingAndNewEntries.Where(st => st.Existing is null) .Select(st => st.Given); var existingEntries = existingAndNewEntries.Where(st => !(st.Existing is null)); foreach (var(Existing, Given) in existingEntries) { Given.Items.ToList().ForEach(given => Existing.AddEntry(given)); } _stockEntryRepository.AddRange(newEntries); _stockEntryRepository.AddRange(existingEntries.Select(st => st.Existing)); _stockEntryRepository.SaveChanges(); }
/// <summary> /// Compute and set the new <see cref="WordEntry.Origin"/> of the <see cref="Candidate"/> entry, so this entry intersects in the common letter /// </summary> /// <exception cref="InvalidOperationException">If both entries do not intersect or do not have common letters</exception> public WordEntry RepositionEntry() { if (!Intersects) { throw new InvalidOperationException("Can't reposition an entry that do not intersects with others"); } if (!GetCommonLetters()) { Logger.LogWarning($"Words {Existing} and {Candidate} intersect but don't have common letters"); return(null); } bool reposition = false; WordEntry repositionedWord = null; if (Overlaps) { Logger.LogInformation($"Words {Existing} and {Candidate} overlap {Count} common letters"); Point target = Existing.Coordinate(ExistingRange.Init); int increment = Candidate.Direction.IsReverse() ? 1 : 0; Point delta = target.Delta(Candidate.Coordinate(CandidateRange.Init + increment)); repositionedWord = Candidate.Translate(delta); bool insideBoundaries = CheckBoundaries(repositionedWord.Origin); reposition = insideBoundaries && !IntersectsWithOthers(repositionedWord, Soup.UsedWords.Values); } else { int i = 0; bool insideBoundaries = false; Logger.LogInformation($"Candidate intersects at ({this[0]}) with ({Existing})"); do { Point target = Existing.Coordinate(CommonLetters[i].ExistingPos); Point delta = target.Delta(Candidate.Coordinate(CommonLetters[i].CandidatePos)); repositionedWord = Candidate.Translate(delta); Logger.LogDebug($"Try to reposition to: {repositionedWord}"); insideBoundaries = CheckBoundaries(repositionedWord.Origin); i++; } while (!insideBoundaries && i < CommonLetters.Count); reposition = insideBoundaries && !IntersectsWithOthers(repositionedWord, Soup.UsedWords.Values); } if (reposition) { Logger.LogWarning($"Candidate repositioned: {repositionedWord}"); return(repositionedWord); } return(null); }
/// <summary> /// Returns a list of coordinates where both entries intersects /// </summary> /// <returns></returns> public IEnumerable <Point> GetIntersection() { Clear(); CommonLetters.Clear(); ExistingRange = new Range(); CandidateRange = new Range(); for (int i = 0; i < Existing.Name.Length; i++) { for (int j = 0; j < Candidate.Name.Length; j++) { if (Existing.Coordinate(i) == Candidate.Coordinate(j)) { Add(Existing.Coordinate(i)); Logger.LogTrace($" {Existing.Coordinate(i)}"); } } } Logger.LogDebug($"Comparing ({Existing}) with candidate ({Candidate}): {Count} intersection(s) found"); return(this); }
public void ModelTrackerCollection_ExistingCollection_UpdateModel_EventInvoked() { var m = Existing.Skip(1).First(); var oldData = m.Data; var oldId = m.Id; m = new TestModel(); m.Id = oldId; m.Data = Guid.NewGuid().ToString(); bool updated = false; Existing.ModelUpdatedEvent += (s, e) => { Assert.AreEqual(e.UpdatedModel.Data, m.Data); Assert.AreEqual(e.UpdatedModel.Id, m.Id); Assert.AreEqual(e.OldModel.Data, oldData); Assert.AreEqual(e.OldModel.Id, oldId); updated = true; }; Existing.Update(m.Id, m); Assert.IsTrue(updated); }
public void Transfer(IMainLoop ignored) { if (Existing.IsDead()) { return; } var entity = Existing.Get(); var net = entity.GetNetwork(); if (net == null) { return; } if (!net.TryReinitializeUsing(NewConnection, SignlinkUid)) { Log.Normal(this, $"Attempted but failed to reconnected entity {Existing} Disposed?"); return; } Log.Normal(this, $"Reconnected entity {Existing}."); }
private void Kill(Existing <Bird> bird) { bird.Unwrap().isDead = true; }
Controller(Existing <IControllable> control) { this.control = control.Unwrap(); }
//为控制器绑定新的可控制对象 public void BindsTo <T>(Existing <T> obj) where T : class, IControllable { this.control = (IControllable)obj.Unwrap(); }