Beispiel #1
0
        public virtual async Task <Tag> AddTag(string commonIdentifier, string tag, string index)
        {
            var dbtag = new Tag
            {
                Name         = tag,
                Key          = GetHash(tag),
                RegisteredBy = GetFriendlyName()
            };

            dbtag.SetProject(GetTeam());

            if (!dbtag.IsLegal())
            {
                throw new Exception("Tag var ugyldig");
            }

            await Di.GetInstance <IJsonStorage <Tag> >().Put(dbtag);

            if (String.Equals(index, IndexTypeName.Person.ToString(), StringComparison.CurrentCultureIgnoreCase))
            {
                await _personIndex.AddToPropertyList(commonIdentifier, "Tags", dbtag.Key);
            }
            else
            {
                await _busIndex.AddToPropertyList(commonIdentifier, "Tags", dbtag.Key);
            }

            return(dbtag);
        }
Beispiel #2
0
        public virtual async Task <bool> AcceptChanges(string commonidentifier, string actionKey, string actionInstanceId, int registerEnvironment, [FromBody] string content)
        {
            if (string.IsNullOrEmpty(content))
            {
                throw new ArgumentException("Content was null");
            }

            var surveillanceAction = Di.GetInstance <ISurveillanceAction>(actionKey);

            if (!surveillanceAction.ValidJson(content))
            {
                throw new ArgumentException("Content was not in the right format given actionkey: " + actionKey);
            }

            var latestResultDb = Di.GetInstance <IJsonStorage <LatestSurveillanceResult> >();
            var latestResult   = await LatestSurveillanceResult.GetLatestSurveillanceResult(actionKey, actionInstanceId,
                                                                                            GetTeam(), latestResultDb);

            if (latestResult != null)
            {
                await latestResultDb.Delete(latestResult);
            }

            var claimDb = Di.GetInstance <ITableStorageDb <SurveilledItem> >();

            var surveillance = await SurveilledItem.Get(actionKey, actionInstanceId, GetTeam(), claimDb);

            surveillance.ContentAsJson = content;
            surveillance.ClaimedWhen   = DateTime.Now;

            await claimDb.InsertAsync(surveillance, true, true);

            return(true);
        }
Beispiel #3
0
        public virtual async Task <bool> Off(string commonidentifier, string actionKey, string actionInstanceId, int registerEnvironment)
        {
            var claimDb = Di.GetInstance <ITableStorageDb <SurveilledItem> >();

            var element = await SurveilledItem.Get(actionKey, actionInstanceId, GetTeam(), claimDb);

            if (element == null)
            {
                return(false);
            }

            claimDb.DeleteMany(new [] { element });

            var latestResultDb = Di.GetInstance <IJsonStorage <LatestSurveillanceResult> >();
            var latestResult   = await LatestSurveillanceResult.GetLatestSurveillanceResult(actionKey, actionInstanceId, GetTeam(), latestResultDb);

            if (latestResult != null)
            {
                await latestResultDb.Delete(latestResult);
            }

            var team = GetTeam().Id;
            var anyOtherSurveillanceItems = TriggerAllSurveillanceItems <RegisterPersonModel> .GetAllSurveillanceItems(Di)
                                            .Any(item => !string.IsNullOrEmpty(item.CommonIdentifier) && item.CommonIdentifier == commonidentifier && item.TeamProjectInt == team);

            if (!anyOtherSurveillanceItems)
            {
                await _personIndex.RemoveFromPropertyList(commonidentifier, "Teams", team.ToString());
            }

            return(true);
        }
Beispiel #4
0
        GivenDiWithTwoRootContainers_WhenGettingAllRegisteredObjects_ThenReturnsAllObjectsFromBothRootContainers()
        {
            // Arrange
            var objects1 = new List <Object>
            {
                NewGameObject().AddComponent <Rigidbody>(),
                NewGameObject().AddComponent <SphereCollider>(),
                NewGameObject().AddComponent <BoxCollider>(),
            };

            var objects2 = new List <Object>
            {
                NewGameObject().AddComponent <BoxCollider2D>(),
                NewGameObject().AddComponent <CharacterController>(),
            };

            var listDependencyContainer1 = CreateContainerWith <ListDependencyContainer>();
            var listDependencyContainer2 = CreateContainerWith <ListDependencyContainer>();

            objects1.ForEach(o => listDependencyContainer1.Add(o));
            objects2.ForEach(o => listDependencyContainer2.Add(o));

            // Act
            var allRegisteredObjects = Di.GetAllRegisteredObjects();

            // Assert
            var allObjects = objects1.Concat(objects2).Distinct().ToArray();

            Assert.That(allRegisteredObjects, Is.EquivalentTo(allObjects));
        }
Beispiel #5
0
        public void Setup()
        {
            Di.Bind <IDebug>().AsSingleton(typeof(DiDebug));



            Di.Bind <GameObject>().AsConversion <IGameObject>((o) =>
            {
                var go = (IGameObject)o;
                return(go.GameObject);
            });

            Di.Bind <IGameObject>().AsConversion <GameObject>((o) =>
            {
                return(new DiGameObject()
                {
                    GameObject = (GameObject)o
                });
            });

            Di.Bind <IMaterial>().AsConversion <Material>((o) =>
            {
                return(new DiMaterial()
                {
                    Material = (Material)o
                });
            });

            Di.Bind <Material>().AsConversion <IMaterial>((o) =>
            {
                var m = (IMaterial)o;
                return(m.Material);
            });
        }
Beispiel #6
0
        private void btnEqual_Click(object sender, EventArgs e)
        {
            second = double.Parse(tbxScreen.Text);

            double Su;
            double Mi;
            double Mu;
            double Di;

            switch (operation)
            {
            case "+":
                Su             = obj.Sum((first), (second));
                tbxScreen.Text = Su.ToString();
                break;

            case "-":
                Mi             = obj2.Minus((first), (second));
                tbxScreen.Text = Mi.ToString();
                break;

            case "*":
                Mu             = obj3.Multiply((first), (second));
                tbxScreen.Text = Mu.ToString();
                break;

            case "/":
                Di             = obj4.Divide((first), (second));
                tbxScreen.Text = Di.ToString();
                break;
            }
        }
Beispiel #7
0
        void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                var        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                var        didHit = Physics.Raycast(ray, out hit);

                if (didHit)
                {
                    var ball = hit.collider.gameObject.GetComponent <IBall>();
                    if (ball == null)
                    {
                        return;
                    }

                    if (Controller == null)
                    {
                        Controller = Di.Get <IMouseManagerController>();
                    }

                    Controller.BallClicked(ball);
                }
            }
        }
Beispiel #8
0
        public virtual async Task <bool> DeleteTag(string tag)
        {
            var hash = GetHash(tag);
            await Di.GetInstance <IJsonStorage <Tag> >().Delete(Tag.PartitionKey, hash);

            await _personIndex.RemoveFromPropertyList(string.Empty, $"tags/any(f: f eq '{hash}' )", "Tags", hash);

            await _busIndex.RemoveFromPropertyList(string.Empty, $"tags/any(f: f eq '{hash}' )", "Tags", hash);

            var searches = await Di.GetInstance <IJsonStorage <SearchQuery> >().Get();

            var searchesWithTags = searches.Where(s => s.SelectedFilters.Any(f => f.Value == hash)).ToList();

            if (!searchesWithTags.Any())
            {
                return(true);
            }

            searchesWithTags.ForEach(s => s.SelectedFilters.RemoveAt(s.SelectedFilters.FindIndex(f => f.Value == hash)));
            await Di.GetInstance <IJsonStorage <SearchQuery> >().Put(searchesWithTags);

            var empty = searchesWithTags.Where(s => s.SearchTerm.IsEmpty() && !s.SelectedFilters.Any());

            if (empty.Any())
            {
                await Di.GetInstance <IJsonStorage <SearchQuery> >().Delete(empty);
            }

            return(false);
        }
Beispiel #9
0
        public virtual async Task <bool> On(string commonidentifier, string actionKey, string actionInstanceId, int registerEnvironment, [FromBody] string content)
        {
            if (string.IsNullOrEmpty(content))
            {
                throw new ArgumentException("Content was null");
            }

            var surveillanceAction = Di.GetInstance <ISurveillanceAction>(actionKey);

            if (!surveillanceAction.ValidJson(content))
            {
                throw new ArgumentException("Content was not in the right format given actionkey: " + actionKey);
            }

            var claimDb = Di.GetInstance <ITableStorageDb <SurveilledItem> >();
            await claimDb.InsertAsync(new SurveilledItem(actionKey, actionInstanceId, GetTeam())
            {
                RegisteredByFriendlyName = GetFriendlyName(),
                RegisteredByUsername     = GetEmail(),
                ClaimedWhen            = DateTime.Now,
                ContentAsJson          = content,
                RegisterEnvironmentInt = registerEnvironment,
                CommonIdentifier       = commonidentifier
            }, true, true);

            var team = GetTeam().Id;
            await _personIndex.AddToPropertyList(commonidentifier, "Teams", team.ToString());

            return(true);
        }
Beispiel #10
0
        public virtual async Task <bool> Run()
        {
            await
            Di.GetInstance <IQueue>()
            .SendAsync(new SimpleQueueItem(QueueItemType.HodorTriggerAllSurveillance, string.Empty));

            return(true);
        }
Beispiel #11
0
 private bool OpenBinaryFile()
 {
     if (Di.Exists == false)
     {
         Di.Create();
     }
     return(Di.Exists && BinaryOpenWrite(Di.FullName + "\\" + header + "_" + PingID.ToString() + "." + ext));
 }
Beispiel #12
0
        public virtual DateTime?PreviousCheck()
        {
            var val = Di.GetInstance <IScheduledAutoTestApi>()
                      .Get(GetConstantsProvider().TriggerAllSurveillancesSchedulerName())
                      .LastRun;

            return(val);
        }
Beispiel #13
0
        public IMaterial GetMaterial()
        {
            var index = Random.Range(
                0,
                materials.Length);

            return(Di.Convert <IMaterial>(materials[index]));
        }
Beispiel #14
0
        public IGameObject GetBallPrefab()
        {
            var index = Random.Range(
                0,
                ballPrefabs.Length);

            return(Di.Convert <IGameObject>(ballPrefabs[index]));
        }
Beispiel #15
0
 private bool OpenStreamFile()
 {
     if (Di.Exists == false)
     {
         Di.Create();
     }
     return(Di.Exists && OpenForWrite(CreateFullFileName()));
 }
Beispiel #16
0
 private bool OpenBinaryFile()
 {
     if (Di.Exists == false)
     {
         Di.Create();
     }
     return(Di.Exists && BinaryOpenWrite(CreateFullFileName()));
 }
Beispiel #17
0
        public void StartReaction(IBall original)
        {
            var config      = Di.Get <IGameConfig>();
            var all         = new List <IBall>(GameController.BallCollection.Where(x => x.MaterialName == original.MaterialName));
            var consumables = new List <IBall>();
            var consumed    = new List <IBall>();

            consumables.Add(original);
            all.Remove(original);

            while (consumables.Count > 0)
            {
                var tester = consumables[0];
                consumables.RemoveAt(0);
                consumed.Add(tester);
                for (int i = all.Count - 1; i > -1; i--)
                {
                    var b        = all[i];
                    var distance = Vector3.Distance(tester.TransformPosition, b.TransformPosition);
                    if (distance > config.BallTouchRange)
                    {
                        continue;
                    }

                    consumables.Add(b);
                    all.Remove(b);
                }
            }

            var      score         = 0f;
            var      triggerIn     = 0f;
            var      reactorChoice = config.GetReactor();
            IReactor reactor       = null;

            foreach (var b in consumed)
            {
                if (reactorChoice == ReactorTypes.Fade)
                {
                    reactor = b.GetComponent <IFadeReactor>();
                }
                if (reactorChoice == ReactorTypes.Shrink)
                {
                    reactor = b.GetComponent <IShrinkReactor>();
                }
                if (reactorChoice == ReactorTypes.Slip)
                {
                    reactor = b.GetComponent <ISlipReactor>();
                }

                reactor.ActivateDestructionIn(triggerIn);
                triggerIn += config.TimeBetweenReactions;

                score += config.ScorePerBall;
                score *= config.CountMultiplier;
            }

            Di.Get <IScore>().TotalScore += (int)score;
        }
        private async Task <IDetails> GetDetails(IIndexEntity item, IDetails super)
        {
            if (super.CommentsEnabled)
            {
                super.SetComments(await Di.GetInstance <IJsonStorage <Comment> >().Get(item.CommonIdentifier));
            }

            return(super);
        }
Beispiel #19
0
        public void GivenDi_WhenCheckingWhetherCanResolveGloballySafeNullType_ThenThrowsArgumentNullException()
        {
            // Arrange

            // Act

            // Assert
            Assert.That(() => Di.CanBeResolvedGloballySafe(null), Throws.ArgumentNullException);
        }
Beispiel #20
0
        public void GivenDi_WhenTryingToResolveGloballyNullType_ThenThrowsArgumentNullException()
        {
            // Arrange

            // Act

            // Assert
            Assert.That(() => Di.TryResolveGlobally(null, out _), Throws.ArgumentNullException);
        }
Beispiel #21
0
 public void Setup()
 {
     Di.Bind <IBallController>()
     .AsSingleton <BallController>();
     Di.Bind <IGameController>()
     .AsSingleton <GameController>();
     Di.Bind <IMouseManagerController>()
     .AsSingleton <MouseManagerController>();
 }
Beispiel #22
0
        public void GivenDiWithNoRootContainers_WhenGettingAllRegisteredObjects_ThenItIsEmpty()
        {
            // Arrange

            // Act
            var allRegisteredObjects = Di.GetAllRegisteredObjects();

            // Assert
            Assert.That(allRegisteredObjects, Is.Empty);
        }
Beispiel #23
0
        public void GivenDi_WhenGettingAllRegisteredObjects_ThenItIsNotNull()
        {
            // Arrange

            // Act
            var allRegisteredObjects = Di.GetAllRegisteredObjects();

            // Assert
            Assert.That(allRegisteredObjects, Is.Not.Null);
        }
Beispiel #24
0
        public void GivenDi_WhenCreatingInstanceWithoutExplicitConstructors_ThenItIsNotNull()
        {
            // Arrange

            // Act
            var instance = Di.Create <PocoDep2>();

            // Assert
            Assert.That(instance, Is.Not.Null);
        }
Beispiel #25
0
        public void GivenRegisterIfNotNull_WhenNotNullUnityObj_ThenRegistered()
        {
            // Arrange
            CreateContainerWith <ContainerRegisteringNotNullUnityObj>();

            // Act
            var resolved = Di.TryResolveGlobally <Collider>(out _);

            // Assert
            Assert.IsTrue(resolved);
        }
Beispiel #26
0
        public void GivenTryResolveGloballyAndRegister_WhenNotResolved_ThenNotRegistered()
        {
            // Arrange
            CreateContainerWith <ContainerResolvingAndRegisteringString>();

            // Act
            var resolved = Di.TryResolveGlobally <string>(out _);

            // Assert
            Assert.IsFalse(resolved);
        }
Beispiel #27
0
        public void GivenRegisterIfNotNull_WhenNull_ThenNoExceptions()
        {
            // Arrange
            CreateContainerWith <ContainerRegisteringNull>();

            // Act
            var resolved = Di.TryResolveGlobally <object>(out _);

            // Assert
            Assert.IsFalse(resolved);
        }
Beispiel #28
0
        public void GivenDiAndNoComponents_WhenInjecting_ThenThrowsDependencyNotResolvedException()
        {
            // Arrange
            var gameObject = NewGameObject();

            gameObject.AddComponent <RigidbodyComponent>();

            // Act

            // Assert
            Assert.That(() => Di.Inject(gameObject), Throws.InstanceOf <DependencyNotResolvedException>());
        }
Beispiel #29
0
        public void GivenDiAndLocalComponent_WhenInjecting_ThenValueIsSet()
        {
            // Arrange
            var gameObject         = NewGameObject();
            var rigidbodyComponent = gameObject.AddComponent <RigidbodyComponent>();
            var rigidbody          = gameObject.AddComponent <Rigidbody>();

            // Act
            Di.Inject(gameObject);

            // Assert
            Assert.That(rigidbodyComponent.Rigidbody, Is.EqualTo(rigidbody));
        }
Beispiel #30
0
        public void GivenDi_WhenCreatingInstanceAndCanResolveDependency_ThenInstanceIsCreatedAndDependencyIsInjected()
        {
            // Arrange
            CreateContainerWith <SingleInstanceContainer_PocoDep2>();

            // Act
            var instance         = Di.Create <PocoDep1>();
            var resolvedPocoDep2 = Di.TryResolveGlobally <PocoDep2>(out var pocoDep2);

            // Assert
            Assert.That(instance, Is.Not.Null);
            Assert.That(resolvedPocoDep2);
            Assert.That(instance.Dep, Is.EqualTo(pocoDep2));
        }
Beispiel #31
0
 public Confuse(APro apro, Di di)
     : base(apro, di)
 {
 }
Beispiel #32
0
Datei: Main.cs Projekt: cpdean/di
 public Window FindOrCreateWindow(Di.Model.File file)
 {
     var window = FindWindow(file);
     return window == null ? CreateWindow(file) : window;
 }
Beispiel #33
0
 public Wrapper(APro apro, Di di)
     : base(apro, di)
 {
 }
Beispiel #34
0
 public Scrypto(APro apro, Di di)
     : base(apro, di)
 {
 }
Beispiel #35
0
Datei: Main.cs Projekt: cpdean/di
 public Window FindWindow(Di.Model.File file)
 {
     foreach (var window in Windows)
     {
         if (window.Model.Value.File == file)
         {
             return window;
         }
     }
     return null;
 }
Beispiel #36
0
 public Digest(APro asec, Di di)
     : base(asec, di)
 {
 }
Beispiel #37
0
 public Txt2Img(APro apro, Di di)
     : base(apro, di)
 {
 }
Beispiel #38
0
 public SstreamDef(APro apro, Di di)
     : base(apro, di)
 {
 }
Beispiel #39
0
 public RandKey(APro apro, Di di)
     : base(apro, di)
 {
 }
Beispiel #40
0
 public Default(APro apro, Di di)
     : base(apro, di)
 {
 }
Beispiel #41
0
 public SstreamEnc(APro apro, Di di)
     : base(apro, di)
 {
 }
Beispiel #42
0
Datei: Main.cs Projekt: cpdean/di
 private Window CreateWindow(Di.Model.File file)
 {
     var window = new Window(this, Model.FindOrCreateBuffer(file));
     Windows.Add(window);
     return window;
 }