Exemplo n.º 1
0
        private static string FormatQueue(BatonQueue queue)
        {
            if (queue == null || queue.Queue.Count() == 0)
            {
                return($"");
            }

            var sb = new StringBuilder();

            sb.Append($"{{\"type\" : \"Column\", \"width\" : \"stretch\", \"items\":");
            sb.Append("[");

            var queueArray = queue.Queue.ToArray();

            for (var i = 0; i < queue.Queue.Count; i++)
            {
                var personInQueue = queueArray[i];
                if (personInQueue != null)
                {
                    var comma = i != 0 ? "," : "";

                    sb.AppendLine(
                        personInQueue.DateReceived.HasValue
                            ? $"{comma}{{\"type\" : \"RichTextBlock\", \"horizontalAlignment\": \"Center\", \"separator\": true, \"inlines\" : [{{ \"type\" : \"TextRun\", \"text\" : \"{personInQueue.UserName} Received At:{personInQueue.DateReceived:dd MMM HH:mm}\"}}]}}"
                            : $"{comma}{{\"type\" : \"RichTextBlock\", \"horizontalAlignment\": \"Center\", \"separator\": true, \"inlines\" : [{{ \"type\" : \"TextRun\", \"text\" : \"{personInQueue.UserName} Requested:{personInQueue.DateRequested:dd MMM HH:mm}\"}}]}}");
                }
            }

            sb.Append("]");
            sb.Append("},");

            return(sb.ToString());
        }
Exemplo n.º 2
0
        private static string FormatHeader(BatonQueue queue)
        {
            if (queue == null || queue.Queue.Count() == 0)
            {
                return($"");
            }

            var hasComment = queue.Queue.Any(x => !string.IsNullOrEmpty(x.Comment));

            var sb = new StringBuilder();

            sb.Append($"{{\"type\" : \"Column\", \"width\" : \"stretch\", \"items\":");
            sb.Append("[");

            if (hasComment)
            {
                sb.AppendLine(
                    $"{{\"type\" : \"Image\", \"altText\": \"\", \"url\": \"https://infomational-bucket.s3.eu-west-2.amazonaws.com/olympic-flame.png\", \"size\" : \"small\", \"horizontalAlignment\": \"Center\" }}," +
                    $"{{\"type\" : \"RichTextBlock\", \"horizontalAlignment\": \"Center\", \"inlines\": [{{ \"type\" : \"TextRun\", \"text\" : \"{queue.Name}*\"}}]}},");
            }
            else
            {
                sb.AppendLine(
                    $"{{\"type\" : \"Image\", \"altText\": \"\", \"url\": \"https://infomational-bucket.s3.eu-west-2.amazonaws.com/olympic-flame.png\", \"size\" : \"small\", \"horizontalAlignment\": \"Center\" }}," +
                    $"{{\"type\" : \"RichTextBlock\", \"horizontalAlignment\": \"Center\", \"inlines\": [{{ \"type\" : \"TextRun\", \"text\" : \"{queue.Name}\"}}]}},");
            }

            sb.Append("]");
            sb.Append("},");

            return(sb.ToString());
        }
Exemplo n.º 3
0
        public async void SaveQueue(BatonQueue queue)
        {
            var auth  = new FirebaseAuthProvider(new FirebaseConfig(firebaseApiKey));
            var token = await auth.SignInWithEmailAndPasswordAsync(firebaseLogin, firebasePassword);

            var firebaseClient = new FirebaseClient(firebaseUrl, new FirebaseOptions
            {
                AuthTokenAsyncFactory = () => Task.FromResult(token.FirebaseToken)
            });

            await firebaseClient
            .Child("Users")
            .Child(firebaseUserId)
            .Child(this.queueId)
            .PostAsync(queue);
        }
Exemplo n.º 4
0
        private static string FormatComments(BatonQueue queue)
        {
            if (queue == null || queue.Queue.Count() == 0)
            {
                return($"");
            }

            var sb = new StringBuilder();

            var queueArray = queue.Queue.ToArray();

            var comments = queueArray.Where(x => x.Comment != string.Empty).ToArray();

            if (!comments.Any())
            {
                return($"");
            }

            sb.Append("{ \"type\": \"Container\",\"items\": [");

            sb.Append(
                $"{{\"type\": \"TextBlock\", \"text\": \"{queue.Name + " Baton"}\", \"spacing\": \"ExtraLarge\", \"height\": \"stretch\", \"size\": \"Medium\",\"fontType\": \"Default\"}}");

            sb.Append(",{\"type\": \"Container\",\"items\": [");


            for (var i = 0; i < comments.Length; i++)
            {
                var comma   = i != 0 ? "," : "";
                var comment = comments[i];

                sb.Append(
                    $"{comma}{{\"type\" : \"TextBlock\", \"text\" : \"* **{comment.UserName}** - {comment.Comment}\",\"isSubtle\": true, \"wrap\":true}}");
            }

            sb.Append("],\"separator\": true");
            sb.Append("}]},");

            return(sb.ToString());
        }
Exemplo n.º 5
0
        public async Task Handler(string type, string comment, int pullRequest, ITurnContext <IMessageActivity> turnContext,
                                  CancellationToken cancellationToken)
        {
            var batons = await service.GetQueues();

            var batonFireObject = batons?.FirstOrDefault(x => x.Object.Name.Equals(type));

            var conversationReference = turnContext.Activity.GetConversationReference();

            var name = turnContext.Activity.From.Name.Replace(" | Redington", "").Replace(" | Godel", "");

            if (batonFireObject == null)
            {
                var baton = new BatonQueue(type);

                baton.Queue.Enqueue(new BatonRequest()
                {
                    UserName          = name,
                    UserId            = conversationReference.User.Id,
                    DateRequested     = DateTime.Now.ToLocalTime(),
                    DateReceived      = DateTime.Now.ToLocalTime(),
                    Conversation      = conversationReference,
                    BatonName         = type,
                    Comment           = comment,
                    PullRequestNumber = pullRequest
                });

                service.SaveQueue(baton);

                SendItsAllYours(turnContext, cancellationToken);
            }
            else
            {
                if (batonFireObject.Object.Queue.Count == 0)
                {
                    var baton = new BatonRequest()
                    {
                        UserName          = name,
                        UserId            = conversationReference.User.Id,
                        BatonName         = type,
                        DateRequested     = DateTime.Now,
                        DateReceived      = DateTime.Now,
                        Conversation      = conversationReference,
                        Comment           = comment,
                        PullRequestNumber = pullRequest
                    };

                    batonFireObject.Object.Queue.Enqueue(baton);

                    await service.UpdateQueue(batonFireObject);

                    this.SendItsAllYours(turnContext, cancellationToken);
                    await this.releaseService.GotBaton(baton, string.Empty, false, turnContext, cancellationToken);
                }
                else
                {
                    batonFireObject.Object.Queue.Enqueue(new BatonRequest()
                    {
                        UserName = name, UserId = conversationReference.User.Id, BatonName = type, DateRequested = DateTime.Now, Conversation = conversationReference, Comment = comment, PullRequestNumber = pullRequest
                    });

                    await service.UpdateQueue(batonFireObject);

                    await this.SendAddedToTheQueue(turnContext, cancellationToken);

                    //TODO - just use the queue you have
                    await showBatonService.SendBatons(turnContext, cancellationToken);
                }
            }
        }