Beispiel #1
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 #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> 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 #4
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 #5
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 #6
0
        public virtual DateTime?PreviousCheck()
        {
            var val = Di.GetInstance <IScheduledAutoTestApi>()
                      .Get(GetConstantsProvider().TriggerAllSurveillancesSchedulerName())
                      .LastRun;

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

            return(true);
        }
        private async Task <IDetails> GetDetails(IIndexEntity item, IDetails super)
        {
            if (super.CommentsEnabled)
            {
                super.SetComments(await Di.GetInstance <IJsonStorage <Comment> >().Get(item.CommonIdentifier));
            }

            return(super);
        }
        public virtual async Task <Comment> AddComment([FromBody] Comment comment)
        {
            comment.IsLegal();

            comment.RegisteredBy             = GetEmail();
            comment.RegisteredByFriendlyName = GetFriendlyName();
            comment.CreatedAt = DateTime.Now;
            comment.Key       = Guid.NewGuid().ToString();
            comment.SetProject(GetTeam());

            await Di.GetInstance <IJsonStorage <Comment> >().Post(comment);

            return(comment);
        }
        public async Task <bool> RemoveComment(string key, string commonIdentifier)
        {
            if (string.IsNullOrEmpty(key))
            {
                return(false);
            }

            var comment = await Di.GetInstance <IJsonStorage <Comment> >().Get(commonIdentifier, key);

            if (comment.RegisteredBy != GetEmail())
            {
                throw new Exception("Du kan ikke slette andres kommentarer");
            }

            return(await Di.GetInstance <IJsonStorage <Comment> >().Delete(comment));
        }
Beispiel #11
0
        public virtual async Task <IEnumerable <LatestSurveillanceResult> > GetLatestResults()
        {
            var latestResults = (await LatestSurveillanceResult.GetLatestSurveillanceResult(GetTeam(), Di.GetInstance <IJsonStorage <LatestSurveillanceResult> >())).ToList();
            var claimDb       = Di.GetInstance <ITableStorageDb <SurveilledItem> >();

            foreach (var possibleSurveillanceAction in Di.GetAllInstancesOf <ISurveillanceAction>())
            {
                foreach (var surveilanceItem in await SurveilledItem.GetAllForteam(possibleSurveillanceAction.GetKey(), GetTeam(), claimDb))
                {
                    var existing = latestResults.FirstOrDefault(result => result.ActionInstanceIdentifier == surveilanceItem.ActionInstanceIdentifier && result.ActionKey == surveilanceItem.ActionKey);

                    if (existing != null)
                    {
                        if (string.IsNullOrEmpty(existing.CommonIdentifier))
                        {
                            existing.CommonIdentifier = surveilanceItem.CommonIdentifier;
                        }

                        existing.Taken = true;
                        continue;
                    }

                    var lsr = new LatestSurveillanceResult
                    {
                        ActionKey = surveilanceItem.ActionKey,
                        ActionInstanceIdentifier = surveilanceItem.ActionInstanceIdentifier,
                        CommonIdentifier         = surveilanceItem.CommonIdentifier ?? surveilanceItem.ActionInstanceIdentifier,
                        RegisterEnvironmentInt   = surveilanceItem.RegisterEnvironmentInt,
                        RegisteredBy             = surveilanceItem.RegisteredByFriendlyName,
                        TeamProjectInt           = surveilanceItem.TeamProjectInt,
                        Success = true,
                        Taken   = true
                    };

                    latestResults.Add(lsr);
                }
            }

            return(latestResults.Where(x => x.Taken));
        }
Beispiel #12
0
 public async Task <IEnumerable <Tag> > GetAllTags()
 {
     return(await Di.GetInstance <IJsonStorage <Tag> >()
            .Get(Tag.PartitionKey));
 }
        public virtual async Task <IEnumerable <Comment> > LatestCommentsForProject()
        {
            var comment = await Di.GetInstance <IJsonStorage <Comment> >().Get();

            return(comment.Where(c => c.TeamProjectInt == GetTeam().Id).Take(10));
        }