コード例 #1
0
        public IHttpActionResult UpdateCharacterById([FromUri] int characterId, CharacterUpdateModel characterToUpdate)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateCharacterService();

            service.UpdateCharacterById(characterId, characterToUpdate);
            return(Ok());
        }
コード例 #2
0
ファイル: JoinCommand.cs プロジェクト: tecknojock/slimCat
        private void JoinChannelCommand(IDictionary <string, object> command)
        {
            var title = command.Get(Constants.Arguments.Title);
            var id    = command.Get(Constants.Arguments.Channel);

            var characterDict = command.Get <IDictionary <string, object> >(Constants.Arguments.Character);
            var character     = characterDict.Get(Constants.Arguments.Identity);

            // JCH is used in a few situations. It is used when others join a channel and when we join a channel

            // if this is a situation where we are joining a channel...
            lock (chatStateLocker)
            {
                var channel = ChatModel.CurrentChannels.FirstByIdOrNull(id);
                if (channel == null)
                {
                    var kind = ChannelType.Public;
                    if (id.Contains("ADH-"))
                    {
                        kind = ChannelType.Private;
                    }

                    channels.JoinChannel(kind, id, title);
                }
                else
                {
                    var toAdd = CharacterManager.Find(character);
                    if (!channel.CharacterManager.SignOn(toAdd))
                    {
                        return;
                    }

                    var update = new CharacterUpdateModel(
                        toAdd,
                        new JoinLeaveEventArgs
                    {
                        Joined          = true,
                        TargetChannel   = channel.Title,
                        TargetChannelId = channel.Id
                    });

                    Events.NewUpdate(update);
                }
            }
        }
コード例 #3
0
        public void UpdateCharacterById(int characterId, CharacterUpdateModel characterToUpdate)
        {
            var entity = _ctx.Characters.Single(e => e.CharacterId == characterId);

            if (entity != null)
            {
                if (characterToUpdate.UpdatedFirstName != null)
                {
                    entity.FirstName = characterToUpdate.UpdatedFirstName;
                }
                if (characterToUpdate.UpdatedLastName != null)
                {
                    entity.LastName = characterToUpdate.UpdatedLastName;
                }
                if (characterToUpdate.UpdatedSpecies != null)
                {
                    entity.Species = characterToUpdate.UpdatedSpecies;
                }
                if (characterToUpdate.UpdatedPrice != null)
                {
                    entity.Price = (int)characterToUpdate.UpdatedPrice;
                }
                if (characterToUpdate.UpdatedAffiliation != null)
                {
                    entity.Affiliation = characterToUpdate.UpdatedAffiliation;
                }
                if (characterToUpdate.UpdatedDefaultWeaponId != null)
                {
                    entity.DefaultWeaponId = (int)characterToUpdate.UpdatedDefaultWeaponId;
                }
                if (characterToUpdate.UpdatedDefaultShipId != null)
                {
                    entity.DefaultShipId = (int)characterToUpdate.UpdatedDefaultShipId;
                }
                _ctx.SaveChanges();
            }
        }
コード例 #4
0
        private void RealTimeBridgeCommand(IDictionary <string, object> command)
        {
            var type = command.Get(Constants.Arguments.Type);

            if (type == null)
            {
                return;
            }

            var doListAction = new Action <string, ListKind, bool, bool>((name, list, isAdd, giveUpdate) =>
                                                                         Dispatcher.Invoke(() =>
            {
                var result = isAdd
                        ? CharacterManager.Add(name, list)
                        : CharacterManager.Remove(name, list);

                var character = CharacterManager.Find(name);
                if (isAdd && character.Status == StatusType.Offline)
                {
                    CharacterManager.SignOff(name);
                }
                character.IsInteresting = CharacterManager.IsOfInterest(name);

                if (!giveUpdate || !result)
                {
                    return;
                }

                var eventargs = new CharacterListChangedEventArgs
                {
                    IsAdded      = isAdd,
                    ListArgument = list
                };

                Events.NewCharacterUpdate(character, eventargs);
            }));

            if (type.Equals("note"))
            {
                var senderName = command.Get(Constants.Arguments.Sender);
                var subject    = command.Get("subject");

                var update = new CharacterUpdateModel(
                    CharacterManager.Find(senderName),
                    new NoteEventArgs
                {
                    Subject = subject,
                    Target  = senderName + "/notes"
                });

                notes.UpdateNotesAsync(senderName);
                Events.NewUpdate(update);
            }
            else if (type.Equals("comment"))
            {
                var name = command.Get(Constants.Arguments.Name);

                // sometimes ID is sent as a string. Sometimes it is sent as a number.
                // so even though it's THE SAME COMMAND we have to treat *each* number differently
                var commentId = long.Parse(command.Get("id"));
                var parentId  = (long)command["parent_id"];
                var targetId  = long.Parse(command.Get("target_id"));

                var title = HttpUtility.HtmlDecode(command.Get("target"));

                var commentType =
                    command.Get("target_type").ToEnum <CommentEventArgs.CommentTypes>();

                var update = new CharacterUpdateModel(
                    CharacterManager.Find(name),
                    new CommentEventArgs
                {
                    CommentId   = commentId,
                    CommentType = commentType,
                    ParentId    = parentId,
                    TargetId    = targetId,
                    Title       = title
                });

                Events.NewUpdate(update);
            }
            else if (type.Equals("trackadd"))
            {
                var name = command.Get(Constants.Arguments.Name);
                doListAction(name, ListKind.Bookmark, true, true);
            }
            else if (type.Equals("trackrem"))
            {
                var name = command.Get(Constants.Arguments.Name);
                doListAction(name, ListKind.Bookmark, false, true);
            }
            else if (type.Equals("friendadd"))
            {
                var name = command.Get(Constants.Arguments.Name);
                doListAction(name, ListKind.Friend, true, true);
                friendRequestService.UpdatePendingRequests();
                friendRequestService.UpdateOutgoingRequests();
            }
            else if (type.Equals("friendrequest"))
            {
                var name = command.Get(Constants.Arguments.Name);
                doListAction(name, ListKind.FriendRequestReceived, true, true);
                friendRequestService.UpdatePendingRequests();
            }
            else if (type.Equals("friendremove"))
            {
                var name = command.Get(Constants.Arguments.Name);
                doListAction(name, ListKind.Friend, false, false);
            }
        }
コード例 #5
0
ファイル: JoinCommand.cs プロジェクト: WreckedAvent/slimCat
        private void JoinChannelCommand(IDictionary<string, object> command)
        {
            var title = command.Get(Constants.Arguments.Title);
            var id = command.Get(Constants.Arguments.Channel);

            var characterDict = command.Get<IDictionary<string, object>>(Constants.Arguments.Character);
            var character = characterDict.Get(Constants.Arguments.Identity);

            // JCH is used in a few situations. It is used when others join a channel and when we join a channel

            // if this is a situation where we are joining a channel...
            lock (chatStateLocker)
            {
                var channel = ChatModel.CurrentChannels.FirstByIdOrNull(id);
                if (channel == null)
                {
                    var kind = ChannelType.Public;
                    if (id.Contains("ADH-"))
                        kind = ChannelType.Private;

                    channels.JoinChannel(kind, id, title);
                }
                else
                {
                    var toAdd = CharacterManager.Find(character);
                    if (!channel.CharacterManager.SignOn(toAdd)) return;

                    var update = new CharacterUpdateModel(
                        toAdd,
                        new JoinLeaveEventArgs
                        {
                            Joined = true,
                            TargetChannel = channel.Title,
                            TargetChannelId = channel.Id
                        });

                    Events.NewUpdate(update);
                }
            }
        }
コード例 #6
0
        private void HandleNewChannelMessage(IDictionary <string, object> update)
        {
            var channel = update.Get <GeneralChannelModel>("channel");
            var message = update.Get <IMessage>("message");

            if (message == null || channel == null)
            {
                return;
            }

            if (message.Poster.NameEquals(cm.CurrentCharacter.Name))
            {
                return;
            }

            var isFocusedAndSelected = (channel.IsSelected && WindowIsFocused);

            var cleanMessageText = HttpUtility.HtmlDecode(message.Message);

            var temp = new List <string>(channel.Settings.EnumerableTerms);

            temp.AddRange(ApplicationSettings.GlobalNotifyTermsList);
            if (ApplicationSettings.CheckForOwnName)
            {
                temp.Add(cm.CurrentCharacter.Name.ToLower());
            }

            var checkAgainst = temp.Distinct(StringComparer.OrdinalIgnoreCase).Select(x => x.Trim());

            // if any of these conditions hold true we have no reason to evaluate further
            if (characters.IsOnList(message.Poster.Name, ListKind.NotInterested) && message.Type == MessageType.Ad)
            {
                return;
            }

            var notifyLevel = message.Type == MessageType.Ad
                ? channel.Settings.AdNotifyLevel
                : channel.Settings.MessageNotifyLevel;

            // now we check to see if we should notify because of settings
            if (notifyLevel > (int)ChannelSettingsModel.NotifyLevel.NotificationOnly && !isFocusedAndSelected)
            {
                if (!channel.Settings.MessageNotifyOnlyForInteresting || IsOfInterest(message.Poster.Name))
                {
                    if (notifyLevel > (int)ChannelSettingsModel.NotifyLevel.NotificationAndToast)
                    {
                        ToastManager.PlaySound();
                        ToastManager.FlashWindow();
                    }

                    toast.TargetCharacter = message.Poster;
                    toast.Title           =
                        $"{(ApplicationSettings.ShowNamesInToasts ? message.Poster.Name : "A user")} #{channel.Title}";
                    toast.Content = ApplicationSettings.ShowMessagesInToasts ? cleanMessageText : "Has a new message";
                    toast.ShowNotifications();
                    toast.Navigator = new SimpleNavigator(chatState =>
                    {
                        chatState.EventAggregator.GetEvent <RequestChangeTabEvent>().Publish(channel.Id);

                        ShowWindow();
                    });
                    toast.TargetCharacter = message.Poster;
                    if (ApplicationSettings.ShowAvatarsInToasts)
                    {
                        message.Poster.GetAvatar();
                    }
                }
            }

            #region Ding Word evaluation

            // We have something to check for

            // Tokenized List is the list of terms the message has
            // Check against is a combined set of terms that the user has identified as ding words
            // Is Matching String uses Check against to see if any terms are a match
            var wordList = checkAgainst as IList <string> ?? checkAgainst.ToList();
            if (channel.Settings.NotifyIncludesCharacterNames)
            {
                // if the poster's name contains a ding word
                var match = wordList
                            .Select(dingword => message.Poster.Name.FirstMatch(dingword))
                            .FirstOrDefault(attemptedMatch => !string.IsNullOrWhiteSpace(attemptedMatch.Item1));

                if (match != null)
                {
                    var newUpdate = new CharacterUpdateModel(message.Poster, new ChannelMentionUpdateEventArgs
                    {
                        Channel       = channel,
                        Context       = match.Item2,
                        TriggeredWord = match.Item1,
                        IsNameMention = true
                    });
                    events.NewUpdate(newUpdate);

                    if (!isFocusedAndSelected)
                    {
                        channel.FlashTab();
                    }

                    message.IsOfInterest = true;
                    return;
                }
            }

            {
                // check the message content
                var match = wordList.Select(cleanMessageText.FirstMatch)
                            .FirstOrDefault(attemptedMatch => !string.IsNullOrWhiteSpace(attemptedMatch.Item1));

                if (match == null)
                {
                    return;
                }
                var newUpdate = new CharacterUpdateModel(message.Poster, new ChannelMentionUpdateEventArgs
                {
                    Channel       = channel,
                    Context       = match.Item2,
                    TriggeredWord = match.Item1,
                    IsNameMention = false
                });
                events.NewUpdate(newUpdate);

                if (!isFocusedAndSelected)
                {
                    channel.FlashTab();
                }

                message.IsOfInterest = true;
            }

            #endregion
        }
コード例 #7
0
        private void RealTimeBridgeCommand(IDictionary<string, object> command)
        {
            var type = command.Get(Constants.Arguments.Type);

            if (type == null) return;

            var doListAction = new Action<string, ListKind, bool, bool>((name, list, isAdd, giveUpdate) =>
                Dispatcher.Invoke(() =>
                {
                    var result = isAdd
                        ? CharacterManager.Add(name, list)
                        : CharacterManager.Remove(name, list);

                    var character = CharacterManager.Find(name);
                    if (isAdd && character.Status == StatusType.Offline)
                    {
                        CharacterManager.SignOff(name);
                    }
                    character.IsInteresting = CharacterManager.IsOfInterest(name);

                    if (!giveUpdate || !result) return;

                    var eventargs = new CharacterListChangedEventArgs
                    {
                        IsAdded = isAdd,
                        ListArgument = list
                    };

                    Events.NewCharacterUpdate(character, eventargs);
                }));

            if (type.Equals("note"))
            {
                var senderName = command.Get(Constants.Arguments.Sender);
                var subject = command.Get("subject");

                var update = new CharacterUpdateModel(
                    CharacterManager.Find(senderName),
                    new NoteEventArgs
                    {
                        Subject = subject,
                        Target = senderName + "/notes"
                    });

                notes.UpdateNotesAsync(senderName);
                Events.NewUpdate(update);
            }
            else if (type.Equals("comment"))
            {
                var name = command.Get(Constants.Arguments.Name);

                // sometimes ID is sent as a string. Sometimes it is sent as a number.
                // so even though it's THE SAME COMMAND we have to treat *each* number differently
                var commentId = long.Parse(command.Get("id"));
                var parentId = (long) command["parent_id"];
                var targetId = long.Parse(command.Get("target_id"));

                var title = HttpUtility.HtmlDecode(command.Get("target"));

                var commentType =
                    command.Get("target_type").ToEnum<CommentEventArgs.CommentTypes>();

                var update = new CharacterUpdateModel(
                    CharacterManager.Find(name),
                    new CommentEventArgs
                    {
                        CommentId = commentId,
                        CommentType = commentType,
                        ParentId = parentId,
                        TargetId = targetId,
                        Title = title
                    });

                Events.NewUpdate(update);
            }
            else if (type.Equals("trackadd"))
            {
                var name = command.Get(Constants.Arguments.Name);
                doListAction(name, ListKind.Bookmark, true, true);
            }
            else if (type.Equals("trackrem"))
            {
                var name = command.Get(Constants.Arguments.Name);
                doListAction(name, ListKind.Bookmark, false, true);
            }
            else if (type.Equals("friendadd"))
            {
                var name = command.Get(Constants.Arguments.Name);
                doListAction(name, ListKind.Friend, true, true);
                friendRequestService.UpdatePendingRequests();
                friendRequestService.UpdateOutgoingRequests();
            }
            else if (type.Equals("friendrequest"))
            {
                var name = command.Get(Constants.Arguments.Name);
                doListAction(name, ListKind.FriendRequestReceived, true, true);
                friendRequestService.UpdatePendingRequests();
            }
            else if (type.Equals("friendremove"))
            {
                var name = command.Get(Constants.Arguments.Name);
                doListAction(name, ListKind.Friend, false, false);
            }
        }
コード例 #8
0
        private void HandleNewChannelMessage(IDictionary<string, object> update)
        {
            var channel = update.Get<GeneralChannelModel>("channel");
            var message = update.Get<IMessage>("message");

            if (message == null || channel == null) return;

            if (message.Poster.NameEquals(cm.CurrentCharacter.Name))
                return;

            var isFocusedAndSelected = (channel.IsSelected && WindowIsFocused);

            var cleanMessageText = HttpUtility.HtmlDecode(message.Message);

            var temp = new List<string>(channel.Settings.EnumerableTerms);
            temp.AddRange(ApplicationSettings.GlobalNotifyTermsList);
            if (ApplicationSettings.CheckForOwnName)
                temp.Add(cm.CurrentCharacter.Name.ToLower());

            var checkAgainst = temp.Distinct(StringComparer.OrdinalIgnoreCase).Select(x => x.Trim());

            // if any of these conditions hold true we have no reason to evaluate further
            if (characters.IsOnList(message.Poster.Name, ListKind.NotInterested) && message.Type == MessageType.Ad)
                return;

            var notifyLevel = message.Type == MessageType.Ad
                ? channel.Settings.AdNotifyLevel
                : channel.Settings.MessageNotifyLevel;

            // now we check to see if we should notify because of settings
            if (notifyLevel > (int) ChannelSettingsModel.NotifyLevel.NotificationOnly && !isFocusedAndSelected)
            {
                if (!channel.Settings.MessageNotifyOnlyForInteresting || IsOfInterest(message.Poster.Name))
                {
                    if (notifyLevel > (int) ChannelSettingsModel.NotifyLevel.NotificationAndToast)
                    {
                        ToastManager.PlaySound();
                        ToastManager.FlashWindow();
                    }

                    toast.TargetCharacter = message.Poster;
                    toast.Title =
                        $"{(ApplicationSettings.ShowNamesInToasts ? message.Poster.Name : "A user")} #{channel.Title}";
                    toast.Content = ApplicationSettings.ShowMessagesInToasts ? cleanMessageText : "Has a new message";
                    toast.ShowNotifications();
                    toast.Navigator = new SimpleNavigator(chatState =>
                    {
                        chatState.EventAggregator.GetEvent<RequestChangeTabEvent>().Publish(channel.Id);

                        ShowWindow();
                    });
                    toast.TargetCharacter = message.Poster;
                    if (ApplicationSettings.ShowAvatarsInToasts) message.Poster.GetAvatar();
                }
            }

            #region Ding Word evaluation

            // We have something to check for

            // Tokenized List is the list of terms the message has
            // Check against is a combined set of terms that the user has identified as ding words
            // Is Matching String uses Check against to see if any terms are a match
            var wordList = checkAgainst as IList<string> ?? checkAgainst.ToList();
            if (channel.Settings.NotifyIncludesCharacterNames)
            {
                // if the poster's name contains a ding word
                var match = wordList
                    .Select(dingword => message.Poster.Name.FirstMatch(dingword))
                    .FirstOrDefault(attemptedMatch => !string.IsNullOrWhiteSpace(attemptedMatch.Item1));

                if (match != null)
                {
                    var newUpdate = new CharacterUpdateModel(message.Poster, new ChannelMentionUpdateEventArgs
                    {
                        Channel = channel,
                        Context = match.Item2,
                        TriggeredWord = match.Item1,
                        IsNameMention = true
                    });
                    events.NewUpdate(newUpdate);

                    if (!isFocusedAndSelected)
                        channel.FlashTab();

                    message.IsOfInterest = true;
                    return;
                }
            }

            {
                // check the message content
                var match = wordList.Select(cleanMessageText.FirstMatch)
                    .FirstOrDefault(attemptedMatch => !string.IsNullOrWhiteSpace(attemptedMatch.Item1));

                if (match == null) return;
                var newUpdate = new CharacterUpdateModel(message.Poster, new ChannelMentionUpdateEventArgs
                {
                    Channel = channel,
                    Context = match.Item2,
                    TriggeredWord = match.Item1,
                    IsNameMention = false
                });
                events.NewUpdate(newUpdate);

                if (!isFocusedAndSelected)
                    channel.FlashTab();

                message.IsOfInterest = true;
            }

            #endregion
        }