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()));
        }
        private PropertyDictionary GenerateImpliedManifest(string manifestPath)
        {
            // Search for image files to fake a manifest from; return in the loop if one is found:
            foreach (string extension in _imageFileExtensions)
            {
                Debug.Assert(extension.StartsWith("."));

                string candidateName = Path.ChangeExtension(manifestPath, extension);

                if (File.Exists(candidateName))
                {
                    PropertyDictionary fileDictionary = new PropertyDictionary();
                    PropertyDictionary masterDictionary = new PropertyDictionary();

                    fileDictionary.SetValueFor("master", masterDictionary);

                    masterDictionary.SetValueFor("fileName", Path.GetFileName(candidateName));

                    return fileDictionary;
                }
            }

            // Nothing was found; complain:
            throw new AdornedReferenceResolutionException(string.Format(
                "The manifest file expected to be at \"{0}\" could not be found, and no images with " +
                "the same name were found.",
                manifestPath));
        }
        public Uri ResolveInline(string contentType, string content)
        {
            if (contentType != "latex")
            {
                throw new AdornedReferenceResolutionException(string.Format(
                    "The inline block content type \"{0}\" is unknown or not supported.", contentType));
            }

            string newFilePath = _temporaryFileManager.CreateAnonymousFilePath(".tex");

            using (StreamWriter writer = new StreamWriter(newFilePath))
            {
                writer.WriteLine(@"\batchmode");
                writer.WriteLine(@"\documentclass[fleqn]{article}");
                writer.WriteLine(@"\mathindent=0em");
                writer.WriteLine(@"\usepackage[a4paper,landscape]{geometry}");
                writer.WriteLine(@"\usepackage[fleqn]{amsmath}");
                writer.WriteLine(@"\usepackage[active,delayed,pdftex,tightpage]{preview}");
                writer.WriteLine(@"\setlength\PreviewBorder{5pt}");
                writer.WriteLine(@"\begin{document}");
                writer.WriteLine(@"\begin{preview}");

                writer.WriteLine(content.Trim());

                writer.WriteLine(@"\end{preview}");
                writer.WriteLine(@"\end{document}");

                writer.Close();
            }

            PropertyDictionary properties = new PropertyDictionary();
            properties.SetValueFor("resolution", 120);

            string newUrl = ResolveFormat(newFilePath, properties);
            string newerUrl = ResolveFormat(newUrl.ToString(), properties);

            return new Uri(newerUrl);
        }
Exemple #4
0
        private static object ParseDictionary(Lexer lexer)
        {
            PropertyDictionary dictionary = new PropertyDictionary();

            while (true)
            {
                Token token = lexer.Next();

                if (token.Kind == TokenKind.DictionaryClose) break;

                object key = ParseObject(lexer, token);

                Token equals = lexer.Next();
                if (equals.Kind != TokenKind.Equals) ThrowBecauseOfAnUnexpectedToken(lexer, equals);

                object value = ParseObject(lexer, Token.None);

                dictionary.SetValueFor(key, value);

                Token terminator = lexer.Next();

                if (terminator.Kind == TokenKind.DictionaryClose) break;
                if (terminator.Kind == TokenKind.Separator) continue;

                ThrowBecauseOfAnUnexpectedToken(lexer, terminator);
            }

            return dictionary;
        }