public Empty Visit(DekiScriptAccess expr, StringBuilder state)
        {
            expr.Prefix.VisitWith(this, state);
            DekiScriptString index = expr.Index as DekiScriptString;

            if ((index != null) && DekiScriptParser.IsIdentifier(index.Value))
            {
                state.Append(".");
                state.Append(index.Value);
            }
            else
            {
                state.Append("[");
                expr.Index.VisitWith(this, state);
                state.Append("]");
            }
            return(Empty.Value);
        }
        public Empty Visit(DekiScriptMapConstructor expr, StringBuilder state)
        {
            state.Append("{");
            bool first = true;

            foreach (var field in expr.Fields)
            {
                if (!first)
                {
                    state.Append(", ");
                }
                else
                {
                    state.Append(" ");
                }
                first = false;

                // check if key is a string and a valid identifier
                if (field.Key is DekiScriptString)
                {
                    string key = ((DekiScriptString)field.Key).Value;
                    if (DekiScriptParser.IsIdentifier(key))
                    {
                        state.Append(key + " : " + field.Value);
                    }
                    else
                    {
                        state.Append(key.QuoteString() + " : " + field.Value);
                    }
                }
                else
                {
                    state.Append("(" + field.Key + ") : " + field.Value);
                }
            }
            if (expr.Generator != null)
            {
                state.Append(" foreach ");
                state.Append(expr.Generator.ToString());
            }
            state.Append(" }");
            return(Empty.Value);
        }
        public Empty Visit(DekiScriptMap expr, StringBuilder state)
        {
            state.Append("{");

            // convert values to an array so they can be sorted
            var values = new List <KeyValuePair <string, DekiScriptLiteral> >();

            foreach (KeyValuePair <string, DekiScriptLiteral> entry in expr.Value)
            {
                values.Add(entry);
            }
            values.Sort((left, right) => left.Key.CompareInvariantIgnoreCase(right.Key));

            // emit values
            bool first = true;

            foreach (KeyValuePair <string, DekiScriptLiteral> entry in values)
            {
                if (!first)
                {
                    state.Append(", ");
                }
                else
                {
                    state.Append(" ");
                }
                first = false;
                if (DekiScriptParser.IsIdentifier(entry.Key) || DekiScriptParser.IsNumber(entry.Key))
                {
                    state.Append(entry.Key);
                }
                else
                {
                    state.Append(entry.Key.QuoteString());
                }
                state.Append(" : ");
                entry.Value.VisitWith(this, state);
            }
            state.Append(" }");
            return(Empty.Value);
        }
예제 #4
0
        //--- Class Methods ---
        public static void StartExtensionService(DekiContext context, ServiceBE service, ServiceRepository.IServiceInfo serviceInfo, bool forceRefresh)
        {
            // retrieve document describing the extension functions
            XUri            uri       = new XUri(service.Uri);
            XDoc            manifest  = null;
            DekiWikiService deki      = context.Deki;
            var             extension = serviceInfo.Extension;

            if (!service.ServiceLocal)
            {
                lock (deki.RemoteExtensionLibraries) {
                    deki.RemoteExtensionLibraries.TryGetValue(uri, out manifest);
                }
            }
            if (manifest == null || forceRefresh)
            {
                manifest = Plug.New(uri).Get().ToDocument();

                // normalize the extension XML
                manifest = manifest.TransformAsXml(_extensionConverterXslt);

                // check if document describes a valid extension: either the extension has no functions, or the functions have end-points
                if (manifest.HasName("extension") && ((manifest["function"].ListLength == 0) || (manifest["function/uri"].ListLength > 0)))
                {
                    // add source uri for service
                    manifest.Attr("uri", uri);

                    // register service in extension list
                    lock (deki.RemoteExtensionLibraries) {
                        deki.RemoteExtensionLibraries[uri] = manifest;
                    }
                }
                else
                {
                    throw new ExtensionRemoveServiceInvalidOperationException(uri);
                }
            }
            extension.Manifest = manifest;

            // add function prefix if one is defined
            serviceInfo.Extension.SetPreference("namespace.custom", service.Preferences["namespace"]);
            string serviceNamespace = service.Preferences["namespace"] ?? manifest["namespace"].AsText;

            if (serviceNamespace != null)
            {
                serviceNamespace = serviceNamespace.Trim();
                if (string.IsNullOrEmpty(serviceInfo.Namespace))
                {
                    // Note (arnec): Namespace from preferences is assigned at service creation. If we do not have one at this
                    // point, it came from the extension manifest and needs to be registered as our default. Otherwise the
                    // preference override persists as the namespace.
                    context.Instance.RunningServices.RegisterNamespace(serviceInfo, serviceNamespace);
                }
                if (serviceNamespace.Length != 0)
                {
                    if (!DekiScriptParser.IsIdentifier(serviceNamespace))
                    {
                        throw new ExtensionNamespaceInvalidArgumentException(service.Preferences["namespace"] ?? manifest["namespace"].AsText);
                    }
                }
                else
                {
                    serviceNamespace = null;
                }
            }
            serviceNamespace = (serviceNamespace == null) ? string.Empty : (serviceNamespace + ".");

            // add custom library title

            extension.SetPreference("title.custom", service.Preferences["title"]);
            extension.SetPreference("label.custom", service.Preferences["label"]);
            extension.SetPreference("description.custom", service.Preferences["description"]);
            extension.SetPreference("uri.logo.custom", service.Preferences["uri.logo"]);
            extension.SetPreference("functions", service.Preferences["functions"]);
            extension.SetPreference("protected", service.Preferences["protected"]);

            // add each extension function
            bool.TryParse(service.Preferences["protected"], out extension.IsProtected);
            var functions = new List <ServiceRepository.ExtensionFunctionInfo>();

            foreach (XDoc function in manifest["function"])
            {
                XUri functionUri = function["uri"].AsUri;
                if (functionUri != null)
                {
                    functions.Add(new ServiceRepository.ExtensionFunctionInfo(serviceNamespace + function["name"].Contents, functionUri));
                }
            }
            extension.Functions = functions.ToArray();
        }