Exemple #1
0
        internal Status Compile(IDictionary <string, object> viewProps, string language)
        {
            language = language ?? "javascript";
            string mapSource = viewProps.Get("map") as string;

            if (mapSource == null)
            {
                return(new Status(StatusCode.NotFound));
            }

            MapDelegate mapDelegate = Compiler.CompileMap(mapSource, language);

            if (mapDelegate == null)
            {
                Log.To.View.W(TAG, "{0} could not compile {1} map fn: {2}", Name, language,
                              new SecureLogString(mapSource, LogMessageSensitivity.PotentiallyInsecure));
                return(new Status(StatusCode.CallbackError));
            }

            string         reduceSource   = viewProps.Get("reduce") as string;
            ReduceDelegate reduceDelegate = null;

            if (reduceSource != null)
            {
                reduceDelegate = Compiler.CompileReduce(reduceSource, language);
                if (reduceDelegate == null)
                {
                    Log.To.View.W(TAG, "{0} could not compile {1} reduce fn: {2}", Name, language,
                                  new SecureLogString(reduceSource, LogMessageSensitivity.PotentiallyInsecure));
                    return(new Status(StatusCode.CallbackError));
                }
            }

            string version = Misc.HexSHA1Digest(Manager.GetObjectMapper().WriteValueAsBytes(viewProps));

            SetMapReduce(mapDelegate, reduceDelegate, version);
            DocumentType = viewProps.GetCast <string>("documentType");

            var options = viewProps.Get("options").AsDictionary <string, object>();

            Collation = ViewCollation.Unicode;
            if (options != null && options.ContainsKey("collation"))
            {
                string collation = options["collation"] as string;
                if (collation.ToLower().Equals("raw"))
                {
                    Collation = ViewCollation.Raw;
                }
            }

            return(new Status(StatusCode.Ok));
        }
        internal Status Compile(IDictionary<string, object> viewProps, string language)
        {
            language = language ?? "javascript";
            string mapSource = viewProps.Get("map") as string;
            if (mapSource == null) {
                return new Status(StatusCode.NotFound);
            }

            MapDelegate mapDelegate = Compiler.CompileMap(mapSource, language);
            if (mapDelegate == null) {
                Log.W(TAG, "View {0} could not compile {1} map fn: {2}", Name, language, mapSource);
                return new Status(StatusCode.CallbackError);
            }

            string reduceSource = viewProps.Get("reduce") as string;
            ReduceDelegate reduceDelegate = null;
            if (reduceSource != null) {
                reduceDelegate = Compiler.CompileReduce(reduceSource, language);
                if (reduceDelegate == null) {
                    Log.W(TAG, "View {0} could not compile {1} reduce fn: {2}", Name, language, mapSource);
                    return new Status(StatusCode.CallbackError);
                }
            }
                
            string version = Misc.HexSHA1Digest(Manager.GetObjectMapper().WriteValueAsBytes(viewProps));
            SetMapReduce(mapDelegate, reduceDelegate, version);
            DocumentType = viewProps.GetCast<string>("documentType");

            var options = viewProps.Get("options").AsDictionary<string, object>();
            Collation = ViewCollation.Unicode;
            if (options != null && options.ContainsKey("collation")) {
                string collation = options["collation"] as string;
                if (collation.ToLower().Equals("raw")) {
                    Collation = ViewCollation.Raw;
                }
            }

            return new Status(StatusCode.Ok);
        }