예제 #1
0
        /// <summary>
        /// Handles the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public override Reply Handle(Message message)
        {
            Reply reply = new Reply();

            reply.Add("The current time is: " + DateTime.Now.ToShortTimeString());
            reply.Add("The current date is: " + DateTime.Now.ToShortDateString());
            return(reply);
        }
예제 #2
0
        public override Reply Handle(Message message)
        {
            Reply reply = new Reply();

            reply.Add("Those are some of the things I can fully understand, " + message.SenderDisplayName.GetFirstName() + ":");
            reply.Add(Emoticons.QuestionMark + " hello");
            reply.Add(Emoticons.QuestionMark + " add");
            reply.Add(Emoticons.QuestionMark + " translate <term> from <lang1> to <lang2>");
            return(reply);
        }
예제 #3
0
        public override Reply Handle(BuildABot.Core.MessageHandlers.Message message)
        {
            Reply reply = new Reply();

            if (message.Content.Equals("hello", StringComparison.InvariantCultureIgnoreCase))
            {
                reply.Add("hi there!");
            }
            else
            {
                // "how are you" case
                reply.Add("I'm great, thanks!");
            }

            return(reply);
        }
예제 #4
0
        /// <summary>
        /// Gets the alternative solution feedback.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public Reply GetAlternativeSolutionFeedback(Message message)
        {
            Reply reply = new Reply();

            if (message.Content.Contains("yes"))
            {
                reply.Add("Great, good to know");
            }
            else
            {
                reply.Add("Sorry, I'll escalate this for you.");
                // escalation code...
            }
            this.Done = true;
            return(reply);
        }
예제 #5
0
        internal Reply HandleSecondNumber(Message message)
        {
            Reply reply = new Reply();
            int   secondNumber;

            if (int.TryParse(message.Content, out secondNumber))
            {
                totalSum += secondNumber;
                reply.Add("The total is: " + totalSum);
            }
            else
            {
                reply.Add("Error: number not valid. Aborting.");
            }
            this.Done = true;
            return(reply);
        }
예제 #6
0
        /// <summary>
        /// Gets the solution feedback.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public Reply GetSolutionFeedback(Message message)
        {
            Reply reply = new Reply();

            if (message.Content.Contains("yes"))
            {
                reply.Add("Great, good to know");
                this.Done = true;
            }
            else
            {
                string solution = this.GetAlternativeSolution(problemDescription);
                reply.Add("Sorry to hear that. What about this, will this work: " + solution);
                this.nextStateHandler = this.GetAlternativeSolutionFeedback;
            }
            return(reply);
        }
예제 #7
0
        internal Reply HandleFirstNumber(Message message)
        {
            Reply reply = new Reply();
            int   firstNumber;

            if (int.TryParse(message.Content, out firstNumber))
            {
                totalSum += firstNumber;
                reply.Add("Enter second number");
                this.nextStateHandler = HandleSecondNumber;
            }
            else
            {
                reply.Add("Error: number not valid. Aborting.");
                this.Done = true;
            }
            return(reply);
        }
예제 #8
0
        /// <summary>
        /// Handles the ticket status.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public Reply HandleTicketStatus(Message message)
        {
            Reply reply = new Reply();

            if (message.Content.Contains("new"))
            {
                this.ticketNumber = this.CreateNewTicket();
                reply.Add("This is your new ticket number: " + this.ticketNumber);
                reply.Add("What's your problem?");
                this.nextStateHandler = this.GetUserIssue;
            }
            else
            {
                reply.Add("What's the ticket number?");
                this.nextStateHandler = this.GetTicketNumber;
            }
            return(reply);
        }
예제 #9
0
        public override Reply Handle(Message message)
        {
            Reply reply = new Reply();

            reply.Add("Hello world!");

            string boldWorld = "world".EncloseRtfBold();

            reply.AddRtfMessage("This is a beautiful rich text " + boldWorld);
            return(reply);
        }
예제 #10
0
        public override Reply Handle(Message message)
        {
            Reply  reply        = new Reply();
            string term         = this["term"];
            string fromLanguage = this["from"];
            string toLanguage   = this["to"];

            reply.Add(string.Format("You want me to translate the term '{0}' from '{1}' to '{2}'. Got it, but won't!", term, fromLanguage, toLanguage));

            return(reply);
        }
예제 #11
0
파일: Program.cs 프로젝트: mujiansu/Lync
        static Reply FeedbackEngine_FeedbackCollected(object sender, FeedbackCollectedEventArgs e)
        {
            Reply reply = new Reply();

            switch (e.FeedbackType)
            {
            case FeedbackType.Positive:
                reply.Add("Great, good to know!");
                // store positive feedback
                break;

            case FeedbackType.Negative:
                reply.Add("Sorry for that...");
                // store negative feedback
                break;

            case FeedbackType.NotProvided:
                // probably don't do anything in this case.
                break;
            }

            return(reply);
        }
예제 #12
0
        public override Reply Handle(Message message)
        {
            Logger.Debug("Handle function");
            Reply reply = new Reply();

            try
            {
                reply.Add("user said : " + message.Content);
                Logger.Debug("bot message = " + message.Content);
            }
            catch (Exception e)
            {
                Logger.Debug("error :" + e);
            }
            return(reply);
        }
예제 #13
0
            public override int Execute(DocumentsOperationContext context)
            {
                if (IsClusterTransaction)
                {
                    Debug.Assert(false, "Shouldn't happen - cluster tx run via normal means");
                    return(0);// should never happened
                }

                _disposables.Clear();

                DocumentsStorage.PutOperationResults?lastPutResult = null;

                for (int i = ParsedCommands.Offset; i < ParsedCommands.Count; i++)
                {
                    var cmd = ParsedCommands.Array[ParsedCommands.Offset + i];

                    switch (cmd.Type)
                    {
                    case CommandType.PUT:

                        DocumentsStorage.PutOperationResults putResult;
                        try
                        {
                            putResult = Database.DocumentsStorage.Put(context, cmd.Id, cmd.ChangeVector, cmd.Document);
                        }
                        catch (Voron.Exceptions.VoronConcurrencyErrorException)
                        {
                            // RavenDB-10581 - If we have a concurrency error on "doc-id/"
                            // this means that we have existing values under the current etag
                            // we'll generate a new (random) id for them.

                            // The TransactionMerger will re-run us when we ask it to as a
                            // separate transaction
                            for (; i < ParsedCommands.Count; i++)
                            {
                                cmd = ParsedCommands.Array[ParsedCommands.Offset + i];
                                if (cmd.Type == CommandType.PUT && cmd.Id?.EndsWith('/') == true)
                                {
                                    cmd.Id       = MergedPutCommand.GenerateNonConflictingId(Database, cmd.Id);
                                    RetryOnError = true;
                                }
                            }
                            throw;
                        }
                        catch (ConcurrencyException e) when(CanAvoidThrowingToMerger(e, i))
                        {
                            return(0);
                        }
                        context.DocumentDatabase.HugeDocuments.AddIfDocIsHuge(cmd.Id, cmd.Document.Size);
                        AddPutResult(putResult);
                        lastPutResult = putResult;
                        break;

                    case CommandType.PATCH:
                        try
                        {
                            cmd.PatchCommand.Execute(context);
                        }
                        catch (ConcurrencyException e) when(CanAvoidThrowingToMerger(e, i))
                        {
                            return(0);
                        }

                        var patchResult = cmd.PatchCommand.PatchResult;
                        if (patchResult.ModifiedDocument != null)
                        {
                            context.DocumentDatabase.HugeDocuments.AddIfDocIsHuge(cmd.Id, patchResult.ModifiedDocument.Size);
                        }

                        if (patchResult.ChangeVector != null)
                        {
                            LastChangeVector = patchResult.ChangeVector;
                        }

                        if (patchResult.Collection != null)
                        {
                            ModifiedCollections?.Add(patchResult.Collection);
                        }

                        var patchReply = new DynamicJsonValue
                        {
                            [nameof(BatchRequestParser.CommandData.Id)]           = cmd.Id,
                            [nameof(BatchRequestParser.CommandData.ChangeVector)] = patchResult.ChangeVector,
                            [nameof(Constants.Documents.Metadata.LastModified)]   = patchResult.LastModified,
                            [nameof(BatchRequestParser.CommandData.Type)]         = nameof(CommandType.PATCH),
                            [nameof(PatchStatus)]       = patchResult.Status,
                            [nameof(PatchResult.Debug)] = patchResult.Debug
                        };

                        if (cmd.ReturnDocument)
                        {
                            patchReply[nameof(PatchResult.ModifiedDocument)] = patchResult.ModifiedDocument;
                        }

                        Reply.Add(patchReply);
                        break;

                    case CommandType.DELETE:
                        if (cmd.IdPrefixed == false)
                        {
                            DocumentsStorage.DeleteOperationResult?deleted;
                            try
                            {
                                deleted = Database.DocumentsStorage.Delete(context, cmd.Id, cmd.ChangeVector);
                            }
                            catch (ConcurrencyException e) when(CanAvoidThrowingToMerger(e, i))
                            {
                                return(0);
                            }
                            AddDeleteResult(deleted, cmd.Id);
                        }
                        else
                        {
                            DeleteWithPrefix(context, cmd.Id);
                        }
                        break;

                    case CommandType.AttachmentPUT:
                        var attachmentStream = AttachmentStreams.Dequeue();
                        var stream           = attachmentStream.Stream;
                        _disposables.Add(stream);

                        var docId = cmd.Id;

                        if (docId[docId.Length - 1] == '/')
                        {
                            // attachment sent by Raven ETL, only prefix is defined

                            if (lastPutResult == null)
                            {
                                ThrowUnexpectedOrderOfRavenEtlCommands();
                            }

                            Debug.Assert(lastPutResult.Value.Id.StartsWith(docId));

                            docId = lastPutResult.Value.Id;
                        }

                        var attachmentPutResult = Database.DocumentsStorage.AttachmentsStorage.PutAttachment(context, docId, cmd.Name,
                                                                                                             cmd.ContentType, attachmentStream.Hash, cmd.ChangeVector, stream, updateDocument: false);
                        LastChangeVector = attachmentPutResult.ChangeVector;

                        if (_documentsToUpdateAfterAttachmentChange == null)
                        {
                            _documentsToUpdateAfterAttachmentChange = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                        }
                        _documentsToUpdateAfterAttachmentChange.Add(docId);

                        Reply.Add(new DynamicJsonValue
                        {
                            [nameof(BatchRequestParser.CommandData.Id)]           = attachmentPutResult.DocumentId,
                            [nameof(BatchRequestParser.CommandData.Type)]         = nameof(CommandType.AttachmentPUT),
                            [nameof(BatchRequestParser.CommandData.Name)]         = attachmentPutResult.Name,
                            [nameof(BatchRequestParser.CommandData.ChangeVector)] = attachmentPutResult.ChangeVector,
                            [nameof(AttachmentDetails.Hash)] = attachmentPutResult.Hash,
                            [nameof(BatchRequestParser.CommandData.ContentType)] = attachmentPutResult.ContentType,
                            [nameof(AttachmentDetails.Size)] = attachmentPutResult.Size
                        });

                        break;

                    case CommandType.AttachmentDELETE:
                        Database.DocumentsStorage.AttachmentsStorage.DeleteAttachment(context, cmd.Id, cmd.Name, cmd.ChangeVector, updateDocument: false);

                        if (_documentsToUpdateAfterAttachmentChange == null)
                        {
                            _documentsToUpdateAfterAttachmentChange = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                        }
                        _documentsToUpdateAfterAttachmentChange.Add(cmd.Id);

                        Reply.Add(new DynamicJsonValue
                        {
                            ["Type"] = nameof(CommandType.AttachmentDELETE),
                            [Constants.Documents.Metadata.Id] = cmd.Id,
                            ["Name"] = cmd.Name
                        });

                        break;

                    case CommandType.AttachmentMOVE:
                        var attachmentMoveResult = Database.DocumentsStorage.AttachmentsStorage.MoveAttachment(context, cmd.Id, cmd.Name, cmd.DestinationId, cmd.DestinationName, cmd.ChangeVector);

                        LastChangeVector = attachmentMoveResult.ChangeVector;

                        if (_documentsToUpdateAfterAttachmentChange == null)
                        {
                            _documentsToUpdateAfterAttachmentChange = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                        }
                        _documentsToUpdateAfterAttachmentChange.Add(cmd.Id);
                        _documentsToUpdateAfterAttachmentChange.Add(cmd.DestinationId);

                        Reply.Add(new DynamicJsonValue
                        {
                            [nameof(BatchRequestParser.CommandData.Id)]              = cmd.Id,
                            [nameof(BatchRequestParser.CommandData.Type)]            = nameof(CommandType.AttachmentMOVE),
                            [nameof(BatchRequestParser.CommandData.Name)]            = cmd.Name,
                            [nameof(BatchRequestParser.CommandData.DestinationId)]   = attachmentMoveResult.DocumentId,
                            [nameof(BatchRequestParser.CommandData.DestinationName)] = attachmentMoveResult.Name,
                            [nameof(BatchRequestParser.CommandData.ChangeVector)]    = attachmentMoveResult.ChangeVector,
                            [nameof(AttachmentDetails.Hash)] = attachmentMoveResult.Hash,
                            [nameof(BatchRequestParser.CommandData.ContentType)] = attachmentMoveResult.ContentType,
                            [nameof(AttachmentDetails.Size)] = attachmentMoveResult.Size
                        });
                        break;

                    case CommandType.AttachmentCOPY:
                        var attachmentCopyResult = Database.DocumentsStorage.AttachmentsStorage.CopyAttachment(context, cmd.Id, cmd.Name, cmd.DestinationId, cmd.DestinationName, cmd.ChangeVector);

                        LastChangeVector = attachmentCopyResult.ChangeVector;

                        if (_documentsToUpdateAfterAttachmentChange == null)
                        {
                            _documentsToUpdateAfterAttachmentChange = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                        }
                        _documentsToUpdateAfterAttachmentChange.Add(cmd.DestinationId);

                        Reply.Add(new DynamicJsonValue
                        {
                            [nameof(BatchRequestParser.CommandData.Id)]           = attachmentCopyResult.DocumentId,
                            [nameof(BatchRequestParser.CommandData.Type)]         = nameof(CommandType.AttachmentCOPY),
                            [nameof(BatchRequestParser.CommandData.Name)]         = attachmentCopyResult.Name,
                            [nameof(BatchRequestParser.CommandData.ChangeVector)] = attachmentCopyResult.ChangeVector,
                            [nameof(AttachmentDetails.Hash)] = attachmentCopyResult.Hash,
                            [nameof(BatchRequestParser.CommandData.ContentType)] = attachmentCopyResult.ContentType,
                            [nameof(AttachmentDetails.Size)] = attachmentCopyResult.Size
                        });
                        break;

                    case CommandType.Counters:

                        var counterDocId = cmd.Counters.DocumentId;

                        if (cmd.FromEtl && counterDocId[counterDocId.Length - 1] == '/')
                        {
                            // counter sent by Raven ETL, only prefix is defined

                            if (lastPutResult == null)
                            {
                                ThrowUnexpectedOrderOfRavenEtlCommands();
                            }

                            Debug.Assert(lastPutResult.Value.Id.StartsWith(counterDocId));

                            cmd.Counters.DocumentId = lastPutResult.Value.Id;
                        }

                        var counterBatchCmd = new CountersHandler.ExecuteCounterBatchCommand(Database, new CounterBatch
                        {
                            Documents = new List <DocumentCountersOperation> {
                                cmd.Counters
                            },
                            FromEtl = cmd.FromEtl
                        });
                        try
                        {
                            counterBatchCmd.Execute(context);
                        }
                        catch (DocumentDoesNotExistException e) when(CanAvoidThrowingToMerger(e, i))
                        {
                            return(0);
                        }

                        LastChangeVector = counterBatchCmd.LastChangeVector;
                        Reply.Add(new DynamicJsonValue
                        {
                            [nameof(BatchRequestParser.CommandData.Id)]           = cmd.Id,
                            [nameof(BatchRequestParser.CommandData.ChangeVector)] = counterBatchCmd.LastChangeVector,
                            [nameof(BatchRequestParser.CommandData.Type)]         = nameof(CommandType.Counters),
                            [nameof(CountersDetail)] = counterBatchCmd.CountersDetail.ToJson(),
                        });
                        break;
                    }
                }

                if (_documentsToUpdateAfterAttachmentChange != null)
                {
                    foreach (var documentId in _documentsToUpdateAfterAttachmentChange)
                    {
                        var changeVector = Database.DocumentsStorage.AttachmentsStorage.UpdateDocumentAfterAttachmentChange(context, documentId);
                        if (changeVector != null)
                        {
                            LastChangeVector = changeVector;
                        }
                    }
                }
                return(Reply.Count);
            }