コード例 #1
0
        public void ModelTrackerCollection_ExistingCollection_AddRemoveModel_RemoveReturnsTrue()
        {
            var m = new TestModel();

            Existing.Add(m);
            Assert.IsTrue(Existing.Remove(m));
        }
コード例 #2
0
            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);
            }
コード例 #3
0
 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);
             }
         }
     }
 }
コード例 #4
0
        public void ModelTrackerCollection_ExistingCollection_UpdateModel_ModelUpdated()
        {
            var ex = Existing.First();

            ex.Data = "new data";
            Existing.Update(ex.Id, ex);
        }
コード例 #5
0
 //利用该函数,静态地从仍何存在的IControllable建立控制器
 static public Controller From <T>(Existing <T> obj)
     where T : class, IControllable
 {
     return(new Controller(
                new Existing <IControllable>((IControllable)obj.Unwrap())
                ));
 }
コード例 #6
0
        /// <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);
        }
コード例 #7
0
            /// <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);
            }
コード例 #8
0
 public void Watch(Existing <Bird> some_bird)
 {
     if (this.birdUnderWatch == null)
     {
         this.birdUnderWatch = some_bird.Unwrap();
         Debug.Log("Watch bird");
     }
 }
コード例 #9
0
        public void ModelTrackerCollection_ExistingCollection_AddModel_IndexReturnsModel()
        {
            var m = new TestModel();

            Existing.Add(m);
            Assert.IsNotNull(Existing[m.Id]);
            Assert.AreEqual(m, Existing[m.Id]);
        }
コード例 #10
0
        public void ModelTrackerCollection_ExistingCollection_AddRemoveModel_ContainsModel_ReturnsFalse()
        {
            var m = new TestModel();

            Existing.Add(m);
            Existing.Remove(m);
            Assert.IsFalse(Existing.Contains(m));
        }
コード例 #11
0
        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);
        }
コード例 #12
0
ファイル: CentralControl.cs プロジェクト: cre-chan/AngryBird
 //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");
     }
 }
コード例 #13
0
        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));
 }
コード例 #15
0
ファイル: ReleaseControl.cs プロジェクト: cre-chan/AngryBird
    //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);
        }
    }
コード例 #16
0
        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);
     }
 }
コード例 #18
0
 private async Task WriteExisting(Existing state, RawSession session, DateTime expirationDate)
 {
     if (session.IsEmpty())
     {
         await RemoveSession(state.Id);
     }
     else
     {
         await WriteSessionData(session, expirationDate);
     }
 }
コード例 #19
0
        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);
        }
コード例 #20
0
 //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
             );
     }
 }
コード例 #21
0
        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);
        }
コード例 #22
0
        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)));
            }
        }
コード例 #23
0
ファイル: StockService.cs プロジェクト: adnanioricce/DHsys
        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();
        }
コード例 #24
0
        /// <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);
        }
コード例 #25
0
 /// <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);
 }
コード例 #26
0
        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);
        }
コード例 #27
0
        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}.");
        }
コード例 #28
0
ファイル: CentralControl.cs プロジェクト: cre-chan/AngryBird
 private void Kill(Existing <Bird> bird)
 {
     bird.Unwrap().isDead = true;
 }
コード例 #29
0
 Controller(Existing <IControllable> control)
 {
     this.control = control.Unwrap();
 }
コード例 #30
0
 //为控制器绑定新的可控制对象
 public void BindsTo <T>(Existing <T> obj)
     where T : class, IControllable
 {
     this.control = (IControllable)obj.Unwrap();
 }