public LabelDocumentFrame(DocumentDeserializationContext context, PropertyDictionary frameProperties)
            : base(context, frameProperties)
        {
            if (!frameProperties.HasDictionaryFor("callOutOffsetInDocument"))
            {
                throw new DocumentReadingException("A label frame is missing the required \"callOutOffsetInDocument\" field.");
            }

            _callOutOffsetInDocument = PropertyBuilders.ToSize(frameProperties.DictionaryFor("callOutOffsetInDocument"));
            _label = frameProperties.StringFor("label", "");
            _caption = frameProperties.StringFor("caption", "");
        }
        public void HandleRequest(ChatroomServerProtocol protocol, PropertyDictionary request)
        {
            if (!request.HasValueFor(ChatroomKeys.MessageType) || request.StringFor(ChatroomKeys.MessageType) != Key)
            {
                protocol.SendMalformedRequestResponse();
                return;
            }

            object connected = null;

            lock (_lockObject)
            {
                connected = protocol.Parent.RequestLogin(protocol, request);
                request.SetValueFor(ChatroomKeys.Message, connected);
            }

            if (connected.ToString() == ChatroomKeys.LoginSuccess)
            {
                protocol.Parent.BroadcastServerMessage("{0} has joined.", protocol.Username);
                protocol.SendWelcomeMessage();
            }

            protocol.SendTerm(Atom.From(request.PersistToString()));
        }
        public void HandleRequest(ChatroomServerProtocol protocol, PropertyDictionary request)
        {
            if (!request.HasValueFor(ChatroomKeys.MessageType) || !(request.StringFor(ChatroomKeys.MessageType) == Key))
            {
                protocol.SendMalformedRequestResponse();
                return;
            }

            lock (_lockObject)
            {
                string sender = protocol.Parent.ResolveSenderName(request);

                if (sender != null)
                {
                    request[ChatroomKeys.SenderName] = sender;

                    protocol.Parent.Broadcast(request);
                }
                else
                {
                    protocol.SendMalformedRequestResponse();
                }
            }
        }
        public Uri ResolveMasterReference(PropertyDictionary master, string manifestPath)
        {
            if (master == null || string.IsNullOrEmpty(master.StringFor("fileName")))
            {
                throw new AdornedReferenceResolutionException(string.Format(
                    "The manifest for reference \"{0}\" does not have a master section or the master " +
                    "section does not contain a \"fileName\" setting.",
                    manifestPath));
            }

            string imageFileName = Path.Combine(_referencesDirectory, master.StringFor("fileName"));

            if (!File.Exists(imageFileName))
            {
                throw new AdornedReferenceResolutionException(string.Format(
                    "A file (\"{0}\") referenced in the reference manifest \"{1}\" could not be found.",
                    imageFileName, manifestPath));
            }

            string newUrl = ResolveFormat(Path.GetFullPath(imageFileName), master);
            string newerUrl = ResolveFormat(newUrl.ToString(), master);
            string reallyNewUrl = ResolveFormat(newerUrl.ToString(), master);

            return new Uri(reallyNewUrl);
        }
Exemple #5
0
 public ImageLink(DocumentDeserializationContext context, PropertyDictionary dictionary)
 {
     _fileName = Path.Combine(context.AbsolutePath, dictionary.StringFor("fileName"));
     _physicalDimension = PropertyBuilders.ToSize(dictionary.DictionaryFor("physicalDimension"));
 }
        internal string ResolveSenderName(PropertyDictionary request)
        {
            if (request.HasValueFor(ChatroomKeys.SenderId))
            {
                ChatroomServerProtocol protocol = _clients[request.StringFor(ChatroomKeys.SenderId)];

                return protocol == null ? null : protocol.Username;
            }

            return null;
        }
        internal object RequestLogin(ChatroomServerProtocol protocol, PropertyDictionary request)
        {
            if (!CanAddClient) return ChatroomKeys.LoginFail_TooManyClients;
            if (!UsernameIsAvailable(request.StringFor(ChatroomKeys.SenderName))) return ChatroomKeys.LoginFail_UserNameInUse;

            protocol.Username = request.StringFor(ChatroomKeys.SenderName);
            protocol.Key = request.StringFor(ChatroomKeys.SenderId);

            _clients.AddClient(protocol);

            BroadcastLoggedInUsers();

            return ChatroomKeys.LoginSuccess;
        }
Exemple #8
0
        static DocumentFrame DeserializeFrame(DocumentDeserializationContext context, PropertyDictionary frameProperties)
        {
            string type = frameProperties.StringFor("type", "missing");

            switch (type)
            {
                case "label":
                    return new LabelDocumentFrame(context, frameProperties);

                case "rectangular":
                    return new RectangularDocumentFrame(context, frameProperties);

                default:
                    throw new DocumentReadingException(string.Format("The frame type \"{0}\" is not recognised by this version.",
                        type));
            }
        }
Exemple #9
0
        private void BroadcastMessageReceived(PropertyDictionary message)
        {
            if (!message.HasStringFor(ChatroomKeys.SenderName)) return;//Ignore potential hacked message
            if (!message.HasStringFor(ChatroomKeys.Message)) return;//Ignore potential hacked message

            string name = message.StringFor(ChatroomKeys.SenderName);
            string chat = message.StringFor(ChatroomKeys.Message);

            AddToChat(string.Format("{0}: {1}", name, chat));
        }
Exemple #10
0
        private void ServerMessageReceived(PropertyDictionary message)
        {
            if (!message.HasStringFor(ChatroomKeys.Message)) return;//Ignore potential hacked message

            string chat = message.StringFor(ChatroomKeys.Message);

            AddToChat(chat);
        }
Exemple #11
0
        private void LogInMessageReceived(PropertyDictionary message)
        {
            string dialogText = "Log in response received, however contained no message";

            if (message.HasStringFor(ChatroomKeys.Message))
            {
                switch (message.StringFor(ChatroomKeys.Message))
                {
                    case ChatroomKeys.LoginSuccess:

                        _messageInput.Focus();

                        return;//No message required. Start chatting.

                    case ChatroomKeys.LoginFail_UserNameInUse:

                        dialogText = "Requested username already being used";
                        break;
                    case ChatroomKeys.LoginFail_TooManyClients:

                        dialogText = "Sorry, chat room is full. Please try again later.";
                        break;

                    default:
                        break;
                }
            }

            MessageBox.Show(dialogText);
        }