public IChatModel Create(IChatModel model)
        {
            // Validate model
            BusinessWorkflowBase.ValidateIDIsNull(model.Id);
            //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name));
            // Search for an Existing Record (Don't allow Duplicates
            var results = Search(ChatMapper.MapToSearchModel(model));

            if (results.Any())
            {
                return(results.First());
            }                                              // Return the first that matches
            // Map model to a new entity
            var newEntity = ChatMapper.MapToEntity(model);

            newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
            newEntity.UpdatedDate = null;
            newEntity.Active      = true;
            // Add it
            ChatsRepository.Add(newEntity);
            // Try to Save Changes
            ChatsRepository.SaveChanges();
            // Return the new value
            return(Get(newEntity.Id));
        }
        public IChatModel Update(IChatModel model)
        {
            // Validate model
            BusinessWorkflowBase.ValidateRequiredNullableID(model.Id);
            //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name));
            // Find existing entity
            // ReSharper disable once PossibleInvalidOperationException
            var existingEntity = ChatsRepository.Get(model.Id.Value);

            // Check if we would be applying identical information, if we are, just return the original
            // ReSharper disable once SuspiciousTypeConversion.Global
            if (ChatMapper.AreEqual(model, existingEntity))
            {
                return(ChatMapper.MapToModel(existingEntity));
            }
            // Map model to an existing entity
            ChatMapper.MapToEntity(model, ref existingEntity);
            existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime;
            // Update it
            ChatsRepository.Update(ChatMapper.MapToEntity(model));
            // Try to Save Changes
            ChatsRepository.SaveChanges();
            // Return the new value
            return(Get(existingEntity.Id));
        }
 public override void Serialize(Stream stream)
 {
     using (var w = stream.ToBinaryWriter(true))
     {
         w.WriteEnum(ChatMapper.GetOpCode(GetType()));
         Serializer.Serialize(w, this);
     }
 }
Exemple #4
0
 /// <summary>
 /// Initializes a new Link copied from a Chat Mapper link.
 /// </summary>
 /// <param name='chatMapperLink'>
 /// The Chat Mapper link.
 /// </param>
 public Link(ChatMapper.Link chatMapperLink)
 {
     if (chatMapperLink != null) {
         //---Updated to handle pre-1.3 XML files. Was: originConversationID = chatMapperLink.OriginConvoID;
         originConversationID = ((chatMapperLink.OriginConvoID == 0) && (chatMapperLink.ConversationID > 0)) ? chatMapperLink.ConversationID : chatMapperLink.OriginConvoID;
         originDialogueID = chatMapperLink.OriginDialogID;
         //---Updated to handle pre-1.3 XML files. Was: destinationConversationID = chatMapperLink.DestinationConvoID;
         destinationConversationID = ((chatMapperLink.DestinationConvoID == 0) && (chatMapperLink.ConversationID > 0)) ? chatMapperLink.ConversationID : chatMapperLink.DestinationConvoID;
         destinationDialogueID = chatMapperLink.DestinationDialogID;
         isConnector = chatMapperLink.IsConnector;
     }
 }
Exemple #5
0
        public void Verify_AreEqual_WithDifferentObjects_ReturnsFalse()
        {
            // Arrange
            var mapper = new ChatMapper();
            var model  = ChatsMockingSetup.DoMockingSetupForChatModel(1);
            var entity = ChatsMockingSetup.DoMockingSetupForChat(2);
            // Act
            var result = mapper.AreEqual(model.Object, entity.Object);

            // Assert
            Assert.False(result);
        }
Exemple #6
0
        public void Verify_MapToModelLite_AssignsLiteOnlyChatProperties()
        {
            // Arrange
            var mapper = new ChatMapper();
            var entity = ChatsMockingSetup.DoMockingSetupForChat();
            // Act
            var model = mapper.MapToModelLite(entity.Object);

            // Assert
            Assert.Equal(entity.Object.ChannelName, model.ChannelName);
            Assert.Equal(entity.Object.PasswordHash, model.PasswordHash);
            // Related Objects
            Assert.Equal(entity.Object.ImageFileId, model.ImageFileId);
        }
Exemple #7
0
        public void Verify_MapToEntity_AssignsChatProperties()
        {
            // Arrange
            var mapper = new ChatMapper();
            var model  = ChatsMockingSetup.DoMockingSetupForChatModel();
            // Act
            var entity = mapper.MapToEntity(model.Object);

            // Assert
            Assert.Equal(model.Object.ChannelName, entity.ChannelName);
            Assert.Equal(model.Object.PasswordHash, entity.PasswordHash);
            // Related Objects
            Assert.Equal(model.Object.ImageFileId, entity.ImageFileId);
            // Associated Objects
            // <None>
        }
Exemple #8
0
        public void Verify_MapToSearchModel_AssignsChatSearchProperties()
        {
            // Arrange
            var mapper = new ChatMapper();
            var model  = ChatsMockingSetup.DoMockingSetupForChatModel();
            // Act
            var searchModel = mapper.MapToSearchModel(model.Object);

            // Assert
            Assert.Equal(model.Object.ImageFileId, searchModel.ImageFileId);
            Assert.Equal(model.Object.ImageFile?.CustomKey, searchModel.ImageFileCustomKey);
            Assert.Equal(model.Object.ImageFile?.ApiDetailUrl, searchModel.ImageFileApiDetailUrl);
            Assert.Equal(model.Object.ImageFile?.SiteDetailUrl, searchModel.ImageFileSiteDetailUrl);
            Assert.Equal(model.Object.ImageFile?.Name, searchModel.ImageFileName);
            Assert.Equal(model.Object.ImageFile?.ShortDescription, searchModel.ImageFileShortDescription);
            Assert.Equal(model.Object.ImageFile?.Description, searchModel.ImageFileDescription);
            Assert.Equal(model.Object.ChannelName, searchModel.ChannelName);
        }
 /// <summary>
 /// Initializes a new Conversation copied from a Chat Mapper conversation.
 /// </summary>
 /// <param name='chatMapperConversation'>
 /// The Chat Mapper conversation.
 /// </param>
 public Conversation(ChatMapper.Conversation chatMapperConversation)
 {
     Assign(chatMapperConversation);
 }
 public void Verify_MapToEntity_WithExistingEntity_AssignsChatProperties()
 {
     // Arrange
     var mapper = new ChatMapper();
     var model = ChatsMockingSetup.DoMockingSetupForChatModel();
     // Act
     IChat existingEntity = new Chat { Id = 1 };
     mapper.MapToEntity(model.Object, ref existingEntity);
     // Assert
     Assert.Equal(model.Object.ChannelName, existingEntity.ChannelName);
     Assert.Equal(model.Object.PasswordHash, existingEntity.PasswordHash);
     // Related Objects
     Assert.Equal(model.Object.ImageFileId, existingEntity.ImageFileId);
     // Associated Objects
     // <None>
 }
Exemple #11
0
 /// <summary>
 /// Initializes a new Field copied from a Chat Mapper field.
 /// </summary>
 /// <param name='chatMapperField'>
 /// The Chat Mapper field to copy.
 /// </param>
 public Field(ChatMapper.Field chatMapperField)
 {
     Assign(chatMapperField);
 }
Exemple #12
0
 /// <summary>
 /// Copies the contents of a Chat Mapper field.
 /// </summary>
 /// <param name='chatMapperField'>
 /// The Chat Mapper field to copy.
 /// </param>
 public void Assign(ChatMapper.Field chatMapperField)
 {
     if (chatMapperField != null) {
         title = chatMapperField.Title;
         value = (filenameFields.Contains(title) && (chatMapperField.Value != null)) ? chatMapperField.Value.Replace('\\', '/') : chatMapperField.Value;
         type = StringToFieldType(chatMapperField.Type);
     }
 }
Exemple #13
0
 /// <summary>
 /// Copies a Chat Mapper location asset.
 /// </summary>
 /// <param name='chatMapperLocation'>
 /// The Chat Mapper location.
 /// </param>
 public void Assign(ChatMapper.Location chatMapperLocation)
 {
     if (chatMapperLocation != null) Assign(chatMapperLocation.ID, chatMapperLocation.Fields);
 }
Exemple #14
0
        /// <summary>
        /// Copies a Chat Mapper user variable asset.
        /// </summary>
        /// <param name='chatMapperUserVariable'>
        /// The Chat Mapper user variable.
        /// </param>
        public void Assign(ChatMapper.UserVariable chatMapperUserVariable)
        {
            if (chatMapperUserVariable != null) {
                Assign(0, chatMapperUserVariable.Fields);

                // Chat Mapper 1.6 XML lists type of bools as "Number". This fixes it:
                Field initialValue = Field.Lookup(fields, "Initial Value");
                if ((initialValue != null) &&
                    (initialValue.type == FieldType.Number) &&
                    (string.Equals(initialValue.value, "True") || (string.Equals(initialValue.value, "False")))) {
                    initialValue.type = FieldType.Boolean;
                }
            }
        }
 /// <summary>
 /// Copies a Chat Mapper conversation.
 /// </summary>
 /// <param name='chatMapperConversation'>
 /// The Chat Mapper conversation.
 /// </param>
 public void Assign(ChatMapper.Conversation chatMapperConversation)
 {
     if (chatMapperConversation != null) {
         Assign(chatMapperConversation.ID, chatMapperConversation.Fields);
         nodeColor = chatMapperConversation.NodeColor;
         foreach (var chatMapperEntry in chatMapperConversation.DialogEntries) {
             AddConversationDialogueEntry(chatMapperEntry);
         }
         SplitPipesIntoEntries();
     }
 }
 public void Verify_MapToModel_AssignsChatProperties()
 {
     // Arrange
     var mapper = new ChatMapper();
     var entity = ChatsMockingSetup.DoMockingSetupForChat();
     // Act
     var model = mapper.MapToModel(entity.Object);
     // Assert
     Assert.Equal(entity.Object.ChannelName, model.ChannelName);
     Assert.Equal(entity.Object.PasswordHash, model.PasswordHash);
     // Related Objects
     Assert.Equal(entity.Object.ImageFileId, model.ImageFileId);
     // Associated Objects
     // <None>
 }
 public IChatModel Get(string key)
 {
     BusinessWorkflowBase.ValidateRequiredKey(key);
     return(ChatMapper.MapToModel(ChatsRepository.Get(key)));
 }
 public IChatModel Get(int id)
 {
     BusinessWorkflowBase.ValidateRequiredID(id);
     return(ChatMapper.MapToModel(ChatsRepository.Get(id)));
 }
Exemple #19
0
 /// <summary>
 /// Copies a Chat Mapper actor.
 /// </summary>
 /// <param name='chatMapperActor'>
 /// The Chat Mapper actor.
 /// </param>
 public void Assign(ChatMapper.Actor chatMapperActor)
 {
     if (chatMapperActor != null) Assign(chatMapperActor.ID, chatMapperActor.Fields);
 }
Exemple #20
0
 /// <summary>
 /// Initializes a new Actor copied from a Chat Mapper actor.
 /// </summary>
 /// <param name='chatMapperActor'>
 /// The Chat Mapper actor.
 /// </param>
 public Actor(ChatMapper.Actor chatMapperActor)
 {
     Assign(chatMapperActor);
 }
Exemple #21
0
 /// <summary>
 /// Initializes a new Variable copied from a Chat Mapper user variable.
 /// </summary>
 /// <param name='chatMapperUserVariable'>
 /// The Chat Mapper user variable.
 /// </param>
 public Variable(ChatMapper.UserVariable chatMapperUserVariable)
 {
     Assign(chatMapperUserVariable);
 }
Exemple #22
0
 /// <summary>
 /// Copies a Chat Mapper item.
 /// </summary>
 /// <param name='chatMapperItem'>
 /// The Chat Mapper item.
 /// </param>
 public void Assign(ChatMapper.Item chatMapperItem)
 {
     if (chatMapperItem != null) Assign(chatMapperItem.ID, chatMapperItem.Fields);
 }
 public void Verify_AreEqual_WithEqualObjects_ReturnsTrue()
 {
     // Arrange
     var mapper = new ChatMapper();
     var model = ChatsMockingSetup.DoMockingSetupForChatModel(1);
     var entity = ChatsMockingSetup.DoMockingSetupForChat(1);
     // Act
     var result = mapper.AreEqual(model.Object, entity.Object);
     // Assert
     Assert.True(result);
 }
 /// <summary>
 /// Adds the conversation dialogue entry. Starting in Chat Mapper 1.6, XML entries don't 
 /// include the conversation ID, so we set it manually here.
 /// </summary>
 /// <param name='chatMapperEntry'>
 /// Chat Mapper entry.
 /// </param>
 private void AddConversationDialogueEntry(ChatMapper.DialogEntry chatMapperEntry)
 {
     DialogueEntry entry = new DialogueEntry(chatMapperEntry);
     entry.conversationID = id;
     dialogueEntries.Add(entry);
 }
 public void Verify_MapToSearchModel_AssignsChatSearchProperties()
 {
     // Arrange
     var mapper = new ChatMapper();
     var model = ChatsMockingSetup.DoMockingSetupForChatModel();
     // Act
     var searchModel = mapper.MapToSearchModel(model.Object);
     // Assert
     Assert.Equal(model.Object.ImageFileId, searchModel.ImageFileId);
     Assert.Equal(model.Object.ImageFile?.CustomKey, searchModel.ImageFileCustomKey);
     Assert.Equal(model.Object.ImageFile?.ApiDetailUrl, searchModel.ImageFileApiDetailUrl);
     Assert.Equal(model.Object.ImageFile?.SiteDetailUrl, searchModel.ImageFileSiteDetailUrl);
     Assert.Equal(model.Object.ImageFile?.Name, searchModel.ImageFileName);
     Assert.Equal(model.Object.ImageFile?.ShortDescription, searchModel.ImageFileShortDescription);
     Assert.Equal(model.Object.ImageFile?.Description, searchModel.ImageFileDescription);
     Assert.Equal(model.Object.ChannelName, searchModel.ChannelName);
 }
Exemple #26
0
 /// <summary>
 /// Initializes a new Item copied from a Chat Mapper item.
 /// </summary>
 /// <param name='chatMapperItem'>
 /// The Chat Mapper item.
 /// </param>
 public Item(ChatMapper.Item chatMapperItem)
 {
     Assign(chatMapperItem);
 }
Exemple #27
0
 public ProudMessage GetMessage(ISession session, ushort opCode, BinaryReader r)
 {
     return(ChatMapper.GetMessage((ChatOpCode)opCode, r));
 }
Exemple #28
0
 /// <summary>
 /// Initializes a new Location copied from a Chat Mapper location asset.
 /// </summary>
 /// <param name='chatMapperLocation'>
 /// The Chat Mapper location.
 /// </param>
 public Location(ChatMapper.Location chatMapperLocation)
 {
     Assign(chatMapperLocation);
 }
 /// <summary>
 /// Initializes a new DialogueEntry copied from a Chat Mapper DialogEntry.
 /// </summary>
 /// <param name='chatMapperDialogEntry'>
 /// The Chat Mapper dialog entry to copy.
 /// </param>
 public DialogueEntry(ChatMapper.DialogEntry chatMapperDialogEntry)
 {
     if (chatMapperDialogEntry != null) {
         id = chatMapperDialogEntry.ID;
         fields = Field.CreateListFromChatMapperFields(chatMapperDialogEntry.Fields);
         //--- Removed in Chat Mapper 1.7: conversationID = chatMapperDialogEntry.ConversationID;
         isRoot = chatMapperDialogEntry.IsRoot;
         isGroup = chatMapperDialogEntry.IsGroup;
         if (isGroup) Sequence = "None()";
         nodeColor = chatMapperDialogEntry.NodeColor;
         delaySimStatus = chatMapperDialogEntry.DelaySimStatus;
         falseConditionAction = chatMapperDialogEntry.FalseCondtionAction;
         conditionPriority = ConditionPriorityTools.StringToConditionPriority(chatMapperDialogEntry.ConditionPriority);
         foreach (var chatMapperLink in chatMapperDialogEntry.OutgoingLinks) {
             outgoingLinks.Add(new Link(chatMapperLink));
         }
         conditionsString = chatMapperDialogEntry.ConditionsString;
         userScript = chatMapperDialogEntry.UserScript;
     }
 }