Example #1
0
 public int Reduce(GlobalTableKey gkey, int state)
 {
     try
     {
         Reduce reduce = ReduceWaitLater(gkey, state);
         if (null != reduce)
         {
             reduce.Future.Task.Wait();
             // 如果rpc返回错误的值,外面能处理。
             return(reduce.Result.State);
         }
         return(GlobalCacheManager.StateReduceNetError);
     }
     catch (RpcTimeoutException timeoutex)
     {
         // 等待超时,应该报告错误。
         logger.Error(timeoutex, "Reduce RpcTimeoutException {0} target={1}", state, SessionId);
         return(GlobalCacheManager.StateReduceRpcTimeout);
     }
     catch (Exception ex)
     {
         logger.Error(ex, "Reduce Exception {0} target={1}", state, SessionId);
         return(GlobalCacheManager.StateReduceException);
     }
 }
Example #2
0
 /// <summary>
 /// 返回null表示发生了网络错误,或者应用服务器已经关闭。
 /// </summary>
 /// <param name="gkey"></param>
 /// <param name="state"></param>
 /// <returns></returns>
 public Reduce ReduceWaitLater(GlobalTableKey gkey, int state)
 {
     try
     {
         lock (this)
         {
             if (global::Zeze.Util.Time.NowUnixMillis - LastErrorTime < ForbitPeriod)
             {
                 return(null);
             }
         }
         AsyncSocket peer = GlobalCacheManager.Instance.Server.GetSocket(SessionId);
         if (null != peer)
         {
             Reduce reduce = new Reduce(gkey, state);
             reduce.SendForWait(peer, 10000);
             return(reduce);
         }
     }
     catch (Exception ex)
     {
         // 这里的异常只应该是网络发送异常。
         logger.Error(ex, "ReduceWaitLater Exception {0}", gkey);
     }
     SetError();
     return(null);
 }
Example #3
0
        public static IEnumerable <KeyValuePair <TOK, TOV> > Run <TIK, TIV, TTK, TTV, TOK, TOV>(
            Map <TIK, TIV, TTK, TTV> map,
            Reduce <TTK, TTV, TOK, TOV> reduce,
            IEnumerable <KeyValuePair <TIK, TIV> > input)
        {
            //
            // Map and group all at once
            //
            var tempStorage = new Dictionary <TTK, List <TTV> >();

            foreach (var inputPair in input)
            {
                foreach (var tempPair in map(inputPair.Key, inputPair.Value))
                {
                    List <TTV> vals;
                    if (!tempStorage.TryGetValue(tempPair.Key, out vals))
                    {
                        vals = new List <TTV>();
                        tempStorage.Add(tempPair.Key, vals);
                    }
                    vals.Add(tempPair.Value);
                }
            }

            //
            // Reduce
            //
            foreach (var tempPair in tempStorage)
            {
                foreach (var outPair in reduce(tempPair.Key, tempPair.Value))
                {
                    yield return(outPair);
                }
            }
        }
Example #4
0
        public void ReduceTestCase()
        {
            var parameters = new List <string>();
            var partition1 = "[[\"a\", 1],[\"word\", 1],[\"and\", 1],[\"another\", 1],[\"word\", 1],[\"in\", 1],[\"a\", 1],[\"sentence\", 1]]";
            var partition2 = "[[\"a\", 1],[\"word\", 1],[\"and\", 1],[\"another\", 1],[\"in\", 1],[\"a\", 1],[\"sentence\", 1]]";

            parameters.Add(partition1);
            parameters.Add(partition2);

            var reduce = new Reduce();

            reduce.SetInParameters(parameters);
            reduce.pHandler = null;             // Disable the persistence handler

            reduce.Execute();

            var result = reduce.Result as Dictionary <string, int>;

            Assert.True(result.ContainsKey("a"));
            Assert.AreEqual(4, result["a"]);
            Assert.True(result.ContainsKey("word"));
            Assert.AreEqual(3, result["word"]);
            Assert.True(result.ContainsKey("and"));
            Assert.AreEqual(2, result["and"]);
            Assert.True(result.ContainsKey("another"));
            Assert.AreEqual(2, result["another"]);
            Assert.True(result.ContainsKey("in"));
            Assert.AreEqual(2, result["in"]);
            Assert.True(result.ContainsKey("sentence"));
            Assert.AreEqual(2, result["sentence"]);

            // Something that doesn occurr
            Assert.False(result.ContainsKey("jesus"));
        }
Example #5
0
        private void ReducesSum()
        {
            var interceptor = new Reduce<int>("ValueMethod", SumFunc);
            var test = GetComposable(interceptor);

            Assert.Equal(15, test.ValueMethod());
        }
Example #6
0
        public static Continuation ETag(this ICacheSteps _,
            Reduce<string> etagReducer)
        {
            return step => ctx =>
              {
            var etag = etagReducer(ctx);

            // always sends the etag regardless wether the validator works or not
            if (!string.IsNullOrEmpty(etag))
              step = fu.Http.Header("ETag", "\"" + etag + "\"")(step);

            // if the validator validates, send back a 304 Not Modified
            var ifNoneMatchHeader = ctx.Request.Headers["If-None-Match"];

            if (!string.IsNullOrEmpty(ifNoneMatchHeader)) {
              // note that the Select part is lazy-evaluated
              var existingETags = ifNoneMatchHeader
            .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
            .Select(h => h.Trim())
            .Where(h => !string.IsNullOrEmpty(h) && h.Length > 2)
            .Select(h => h.Substring(1, h.Length - 2));

              // check wether there's meat (!= null) to match a wildcard
              // or that wether the client have a representation with the same etag
              if ((ifNoneMatchHeader == "*" && !string.IsNullOrEmpty(etag)) ||
            existingETags.Contains(etag)) {

            step = fu.Http.NotModified()(fu.EndAct);
              }
            }

            step(ctx);
              };
        }
Example #7
0
 public Job(Map map, Reduce reduce, Failure failure, string logName)
 {
     _map = map;
     _reduce = reduce;
     _failure = failure;
     LOGNAME = logName;
 }
Example #8
0
        public void ShouldConvertToStringWithBullet()
        {
            Reduce predicate;

            predicate = new Reduce();

            Assert.AreEqual("•;", predicate.ToString(predicate));
        }
Example #9
0
        public void ShouldNotEquals()
        {
            Reduce <char> a, b;

            a = new Reduce <char>("A", true, new MockedReduceInput(), null);
            b = new Reduce <char>("B", true, new MockedReduceInput(), null);
            Assert.IsFalse(a.Equals(b));
            Assert.IsFalse(b.Equals(a));
        }
Example #10
0
        public static Continuation Custom(this IMapSteps _,
            ContDict mappings, Reduce<string> pathReducer, Continuation on404)
        {
            var dict = mappings.ToDictionary(
            kv => new Regex(kv.Key),
            kv => kv.Value);

              return _.Custom(dict, pathReducer, on404);
        }
Example #11
0
        public static Continuation Results(Reduce<IResult> resultReducer)
        {
            return step => ctx =>
              {
            var result = resultReducer(ctx);
            var newCtx = new ResultContext(ctx, result);

            step(newCtx);
              };
        }
Example #12
0
 public static Continuation If(Reduce<bool> predicate,
     Continuation trueCont, Continuation falseCont)
 {
     return step => ctx =>
       {
     if (predicate(ctx))
       trueCont(step)(ctx);
     else
       falseCont(step)(ctx);
       };
 }
Example #13
0
 public override int GetHashCode()
 {
     unchecked
     {
         int result = (Map != null ? Map.GetHashCode() : 0);
         result = (result * 397) ^ (Reduce != null ? Reduce.GetHashCode() : 0);
         result = (result * 397) ^ (Stores != null ? Stores.GetHashCode() : 0);
         result = (result * 397) ^ (Indexes != null ? Indexes.GetHashCode() : 0);
         return(result);
     }
 }
        protected internal override IEnumerable <object> ApplyReduceFunctionIfExists(IndexQuery indexQuery, IEnumerable <object> enumerable)
        {
            if (Reduce == null)
            {
                return(enumerable.Take(indexQuery.PageSize));
            }

            var compile = Reduce.Compile();

            return(compile(enumerable.Cast <TReduceResult>()).Cast <object>().Take(indexQuery.PageSize));
        }
Example #15
0
        public void ShouldNotEquals()
        {
            Reduce a;


            a = new Reduce();

            Assert.IsFalse(a.Equals(null));
            Assert.IsFalse(a.Equals(new Terminal(new Token("C", "a"))));
            Assert.IsFalse(a.Equals(new AnyTerminal()));
        }
Example #16
0
        private void AddReductionsToState(State <T> State, ISituationCollection <T> Situations)
        {
            Reduce <T> reduce;

            foreach (Situation <T> situation in Situations.GetReductionSituations())
            {
                reduce = new Reduce <T>(situation.Rule.Name, situation.Rule.IsAxiom, situation.Input, situation.Rule.Attributes);

                State.Add(reduce);
            }
        }
Example #17
0
        public void Itest()
        {
            var a     = new add();
            var text1 = a.Result(20, 10);

            var b     = new Reduce();
            var text2 = b.Result(20, 10);

            var c     = new Ride();
            var text3 = c.Result(20, 10);
        }
Example #18
0
        public static Continuation File(this IStaticSteps _,
            Reduce<string> filenameReducer, Filter<string> contentTypeFilter)
        {
            return step => ctx =>
              {
            var filename = filenameReducer(ctx);
            var contentType = contentTypeFilter(ctx, filename);

            step(FileResult.From(ctx, filename, contentType));
              };
        }
Example #19
0
        public void ShouldEquals()
        {
            Reduce a, b;


            a = new Reduce();
            b = new Reduce();

            Assert.IsTrue(a.Equals(b));
            Assert.IsTrue(b.Equals(a));
        }
Example #20
0
 /// <summary>
 /// Returns a hash code for this instance.
 /// </summary>
 /// <returns>
 /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
 /// </returns>
 public override int GetHashCode()
 {
     unchecked
     {
         int result = Maps.Where(x => x != null).Aggregate(0, (acc, val) => acc * 397 ^ val.GetHashCode());
         result = (result * 397) ^ Maps.Count;
         result = (result * 397) ^ (Reduce?.GetHashCode() ?? 0);
         result = (result * 397) ^ DictionaryHashCode(Fields);
         return(result);
     }
 }
Example #21
0
        public void ShoudAddReduce()
        {
            State <char>  state;
            Reduce <char> action;

            action = new Reduce <char>("A", true, new MockedTerminalInput('a'), null);
            state  = new State <char>();
            state.Add(action);
            Assert.AreEqual(1, state.ReduceActionCount);
            Assert.IsTrue(state.ReduceActions.Contains(action));
        }
Example #22
0
        public void ShoudNotGetReduceUsingTerminalInput()
        {
            State <char>   state;
            IReduce <char> action;

            action = new Reduce <char>("A", true, new MockedTerminalInput('a'), null);
            state  = new State <char>();
            state.Add(action);

            action = state.GetReduce(new MockedTerminalInput('b'));
            Assert.IsNull(action);
        }
Example #23
0
        public void ShouldGetInputs()
        {
            Reduce predicate;

            IInput <Token>[] inputs;

            predicate = new Reduce();
            inputs    = predicate.GetInputs().ToArray();
            Assert.IsNotNull(inputs);
            Assert.AreEqual(1, inputs.Length);
            Assert.IsInstanceOfType(inputs[0], typeof(EOSInput <Token>));
        }
Example #24
0
        public void DirReduc_WithValidArray_ShouldReductToWest(params string[] instructions)
        {
            // Arrange
            var expected = "WEST";
            var reduct   = new Reduce(instructions);

            // Act
            var result = reduct.DirReduc();

            // Assert
            Assert.Equal(expected, result);
        }
Example #25
0
        public void DirReduc_WithValidArray_ShouldNotBeReducible(params string[] instructions)
        {
            // Arrange
            var expected = string.Join(", ", instructions);
            var reduct   = new Reduce(instructions);

            // Act
            var result = reduct.DirReduc();

            // Assert
            Assert.Equal(expected, result);
        }
Example #26
0
            public IReduce <int> some_method_6(int arg1, int arg2, int arg3, IScatter <int> arg4, IScatter <int> arg5, IScatter <int> arg6)
            {
                MPI.RequestList reqList = new MPI.RequestList();

                sendArguments(OPERATION_6, arg1, arg2, arg3, arg4, arg5, arg6, ref reqList);
                receiveResult <int> (ref reqList, OPERATION_6);

                IList <MPI.Request> reqList_complete = reqList.WaitAll();

                int[] result_values = takeResults(reqList_complete);

                return(Reduce <int> .create(channel, result_values, sum, 0));
            }
Example #27
0
        public void DirReduc_WithValidCaseSensitiveArray_ShouldReduct()
        {
            // Arrange
            var instructions = new[] { "north", "south", "east", "west", "west" };
            var expected     = "WEST";
            var reduct       = new Reduce(instructions);

            // Act
            var result = reduct.DirReduc();

            // Assert
            Assert.Equal(expected, result);
        }
Example #28
0
        public void DirReduc_WithValidCaseSensitiveString_ShouldReduct()
        {
            // Arrange
            var instructions = "[North, South, South, East, West, North, West]";
            var expected     = "WEST";
            var reduct       = new Reduce(instructions);

            // Act
            var result = reduct.DirReduc();

            // Assert
            Assert.Equal(expected, result);
        }
Example #29
0
        public void DirReduc_WithValidScapedString_ShouldReduct()
        {
            // Arrange
            var instructions = "[\"NORTH\", \"SOUTH\", \"SOUTH\", \"EAST\", \"WEST\", \"NORTH\", \"WEST\"]";
            var expected     = "WEST";
            var reduct       = new Reduce(instructions);

            // Act
            var result = reduct.DirReduc();

            // Assert
            Assert.Equal(expected, result);
        }
Example #30
0
 /// <summary>
 /// Returns a hash code for this instance.
 /// </summary>
 /// <returns>
 /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
 /// </returns>
 public override int GetHashCode()
 {
     unchecked
     {
         int result = (Map != null ? Map.GetHashCode() : 0);
         result = (result * 397) ^ (Reduce != null ? Reduce.GetHashCode() : 0);
         result = (result * 397) ^ DictionaryHashCode(Stores);
         result = (result * 397) ^ DictionaryHashCode(Indexes);
         result = (result * 397) ^ DictionaryHashCode(Analyzers);
         result = (result * 397) ^ DictionaryHashCode(SortOptions);
         return(result);
     }
 }
        public IEnumerable IndexingFunction(IEnumerable <dynamic> items)
        {
            try
            {
                EnsureGroupItemCreated();
                foreach (DynamicBlittableJson item in items)
                {
                    if (_groupedItems.TryGetValue(item.BlittableJson, out var list) == false)
                    {
                        list = new List <BlittableJsonReaderObject>();
                        _groupedItems[item.BlittableJson] = list;
                    }
                    list.Add(item.BlittableJson);
                }
                foreach (var item in _groupedItems.Values)
                {
                    Engine.ResetCallStack();
                    Engine.ResetStatementsCount();
                    Engine.ResetTimeoutTicks();

                    _oneItemArray[0] = ConstructValues(item);
                    JsValue jsItem = null;
                    try
                    {
                        jsItem = Reduce.Call(JsValue.Null, _oneItemArray).AsObject();
                    }
                    catch (JavaScriptException jse)
                    {
                        var(message, success) = JavaScriptIndexFuncException.PrepareErrorMessageForJavaScriptIndexFuncException(ReduceString, jse);
                        if (success == false)
                        {
                            throw new JavaScriptIndexFuncException($"Failed to execute {ReduceString}", jse);
                        }
                        throw new JavaScriptIndexFuncException($"Failed to execute reduce script, {message}", jse);
                    }
                    catch (Exception e)
                    {
                        throw new JavaScriptIndexFuncException($"Failed to execute {ReduceString}", e);
                    }
                    yield return(jsItem);

                    _resolver.ExplodeArgsOn(null, null);
                }
            }
            finally
            {
                _oneItemArray[0] = null;
                _groupedItems.Clear();
            }
        }
Example #32
0
 /// <summary>
 /// Returns a hash code for this instance.
 /// </summary>
 /// <returns>
 /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
 /// </returns>
 public override int GetHashCode()
 {
     unchecked
     {
         int result = Maps.Where(x => x != null).Aggregate(0, (acc, val) => acc * 397 ^ val.GetHashCode());
         result = (result * 397) ^ Maps.Count;
         result = (result * 397) ^ (Reduce != null ? Reduce.GetHashCode() : 0);
         result = (result * 397) ^ DictionaryHashCode(Stores);
         result = (result * 397) ^ DictionaryHashCode(Indexes);
         result = (result * 397) ^ DictionaryHashCode(Analyzers);
         result = (result * 397) ^ DictionaryHashCode(SortOptions);
         return(result);
     }
 }
Example #33
0
        private static void _Main(string[] args)
        {
            // input "x = 2*(3+3)"

            ICharStream input;

            if (args.Length > 0)
            {
                if (args[0].Equals("-i"))
                {
                    if (args.Length > 1)
                    {
                        input = new ANTLRFileStream(args[1]);
                    }
                    else
                    {
                        throw new Exception("No input file specified.");
                    }
                }
                else
                {
                    input = new ANTLRStringStream(args[0]);
                }
            }
            else
            {
                input = new ANTLRInputStream(Console.OpenStandardInput());
            }

            var lex    = new VecMathLexer(input);
            var tokens = new CommonTokenStream(lex);
            var g      = new VecMathParser(tokens);
            IAstRuleReturnScope <CommonTree> r = g.prog();
            CommonTree t = r.Tree;

            Console.WriteLine("Original tree:   " + t.ToStringTree());

            var simplify = new Simplify(new CommonTreeNodeStream(t));

            t = (CommonTree)simplify.Downup(t);

            var reduce = new Reduce(new CommonTreeNodeStream(t));

            t = (CommonTree)reduce.Downup(t);

            Console.WriteLine("Simplified tree: " + t.ToStringTree());
            Console.ReadKey();
        }
Example #34
0
        protected override void workProcessing()
        {
            Reduce = (Reduce)loadClientAssembly(AssemblyMetaData.ReduceClassName);

            var filesToProcess = WorkerConfig.WorkConfig.FilesToProcess;

            foreach (KeyValuePair <string, List <S3ObjectMetadata> > entry in filesToProcess)
            {
                LineReader lineReader = new LineReader(entry.Value);
                Reduce.setKey(entry.Key);

                Reduce.reduce(entry.Key, lineReader);

                lineReader.dispose();
            }
        }
Example #35
0
        public override IBatch End()
        {
            IBatch batch = new MysqlBatch();
            Tuple <List <String>, List <String> > tuple = ConvertHeader(Reduce.GetHeader());
            Type                         t            = typeof(T);
            StringBuilder                sb           = new StringBuilder();
            TableRelevanceMapper         table        = Reduce.GetTable();
            List <ColumnRelevanceMapper> wherecolumns = Reduce.GetWhere();

            sb.Append(table.TableOperatorEnum.GetOperator());
            sb.Append($" {EntityTableMapper.GetTableName(t)} ");
            switch (table.TableOperatorEnum)
            {
            case TableOperatorEnum.Insert:
                sb.Append(GetInsertSql(tuple));
                break;

            case TableOperatorEnum.Update:
                sb.Append(" set ");
                sb.Append(GetUpdateSql(tuple));
                if (wherecolumns.Count == 0)
                {
                    SetNoneWhere(t);
                }
                break;

            case TableOperatorEnum.Delete:
                if (wherecolumns.Count == 0)
                {
                    SetNoneWhere(t);
                }
                break;

            default:
                throw new Exception("请先选择操作种类");
            }
            String where = ConvertToWhere(wherecolumns);
            if (!String.IsNullOrEmpty(where))
            {
                sb.Append($" where {where}");
            }
            batch.SqlBuilder        = sb.ToString();
            batch.DynamicParameters = Reduce.Parameters;
            return(batch);
        }
Example #36
0
        void handleOperation4(IList <MPI.Request> reqList_complete)
        {
            int[] arg1_values = new int[channel.RemoteSize];
            int[] arg2_values = new int[channel.RemoteSize];
            int[] arg3_values = new int[channel.RemoteSize];
            int[] arg4_values = new int[channel.RemoteSize];
            int[] arg5_values = new int[channel.RemoteSize];
            int[] arg6_values = new int[channel.RemoteSize];

            foreach (MPI.Request req in reqList_complete)
            {
                MPI.ReceiveRequest  recv_req = (MPI.ReceiveRequest)req;
                MPI.CompletedStatus status   = recv_req.Test();
                Tuple <int, int, int, int, int, int> value = (Tuple <int, int, int, int, int, int>)recv_req.GetValue();
                arg1_values [status.Source] = value.Item1;
                arg2_values [status.Source] = value.Item2;
                arg3_values [status.Source] = value.Item3;
                arg4_values [status.Source] = value.Item4;
                arg5_values [status.Source] = value.Item5;
                arg6_values [status.Source] = value.Item6;
            }

            IGather <int> arg1 = Gather <int> .create(channel, arg1_values);

            IReduce <int> arg2 = Reduce <int> .create(channel, arg2_values, sum, 0);

            IScan <int> arg3 = Scan <int> .create(channel, arg3_values, sum, 0);

            IGather <int> arg4 = Gather <int> .create(channel, arg4_values);

            IReduce <int> arg5 = Reduce <int> .create(channel, arg5_values, sum, 0);

            IScan <int> arg6 = Scan <int> .create(channel, arg6_values, sum, 0);

            int result = service.some_method_4(arg1, arg2, arg3, arg4, arg5, arg6);

            int[] broadcast_result = new int[channel.RemoteSize];
            for (int i = 0; i < broadcast_result.Length; i++)
            {
                broadcast_result [i] = result;
            }

            returnResult(broadcast_result, OPERATION_4);
        }
Example #37
0
        private static void _Main(string[] args)
        {
            // input "x = 2*(3+3)"

            ICharStream input;
            if (args.Length > 0)
            {
                if (args[0].Equals("-i"))
                {
                    if (args.Length > 1)
                    {
                        input = new ANTLRFileStream(args[1]);
                    }
                    else
                    {
                        throw new Exception("No input file specified.");
                    }
                }
                else
                {
                    input = new ANTLRStringStream(args[0]);
                }
            }
            else
            {
                input = new ANTLRInputStream(Console.OpenStandardInput());
            }

            var lex = new VecMathLexer(input);
            var tokens = new CommonTokenStream(lex);
            var g = new VecMathParser(tokens);
            IAstRuleReturnScope<CommonTree> r = g.prog();
            CommonTree t = r.Tree;
            Console.WriteLine("Original tree:   " + t.ToStringTree());

            var simplify = new Simplify(new CommonTreeNodeStream(t));
            t = (CommonTree)simplify.Downup(t);

            var reduce = new Reduce(new CommonTreeNodeStream(t));
            t = (CommonTree)reduce.Downup(t);

            Console.WriteLine("Simplified tree: " + t.ToStringTree());
            Console.ReadKey();
        }
Example #38
0
        /// <summary>
        /// Equals the specified other.
        /// </summary>
        /// <param name="other">The other.</param>
        /// <param name="compareIndexIds">allow caller to choose whether to include the index Id in the comparison</param>
        /// <returns></returns>
        public bool Equals(IndexDefinition other, bool compareIndexIds = true, bool ignoreFormatting = false, bool ignoreMaxIndexOutput = false)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            if (compareIndexIds && !Equals(other.IndexId, IndexId))
            {
                return(false);
            }

            bool mapsReduceEquals;

            if (ignoreFormatting)
            {
#if !DNXCORE50
                var comparer = new IndexPrettyPrinterEqualityComparer();
                mapsReduceEquals = Maps.SequenceEqual(other.Maps, comparer) && comparer.Equals(Reduce, other.Reduce);
#else
                mapsReduceEquals = Maps.SequenceEqual(other.Maps) && Reduce.Equals(other.Reduce);
#endif
            }
            else
            {
                mapsReduceEquals = Maps.SequenceEqual(other.Maps) && Equals(other.Reduce, Reduce);
            }

            return(mapsReduceEquals &&
                   (ignoreMaxIndexOutput || other.MaxIndexOutputsPerDocument == MaxIndexOutputsPerDocument) &&
                   DictionaryExtensions.ContentEquals(other.Stores, Stores) &&
                   DictionaryExtensions.ContentEquals(other.Indexes, Indexes) &&
                   DictionaryExtensions.ContentEquals(other.Analyzers, Analyzers) &&
                   DictionaryExtensions.ContentEquals(other.SortOptions, SortOptions) &&
                   DictionaryExtensions.ContentEquals(other.Suggestions, Suggestions) &&
                   DictionaryExtensions.ContentEquals(other.TermVectors, TermVectors) &&
                   DictionaryExtensions.ContentEquals(other.SpatialIndexes, SpatialIndexes));
        }
Example #39
0
        public static Continuation Custom(this IMapSteps _,
            ContRegexDict mappings,
            Reduce<string> pathReducer, Continuation on404)
        {
            on404 = on404 ?? fu.Http.NotFound();

              return step => ctx =>
              {
            var path = pathReducer(ctx);
            var result = mappings
              .Select(kv => new { Match = kv.Key.Match(path), Cont = kv.Value })
              .FirstOrDefault(m => m.Match.Success);

            if (result == null)
              on404(step)(ctx);
            else
              result.Cont(step)(new UrlMappedContext(ctx, result.Match));
              };
        }
Example #40
0
 private void BuildMap()
 {
     for(int index=0;index<states.Count;index++){
         Set currentSet = (Set)states[index];
         if (currentSet.IsFinalState){
             actionMap[index][new End()] = new Accept();
         }
         if (currentSet.ReduceStateId<=0)
             continue;
         foreach(ISymbol grammerSymbol in this.grammer.SymbolsInGrammer){
             if (!grammerSymbol.IsNonTerminal()){
                 if (!actionMap[index].ContainsKey(grammerSymbol))
                     actionMap[index][grammerSymbol] = new Reduce(currentSet.ReduceStateId,grammer,this);
             }
         }
     }
 }
Example #41
0
 public static Continuation If(Reduce<bool> predicate, Continuation trueStep)
 {
     return fu.If(predicate, trueStep, fu.Identity);
 }
Example #42
0
 public static Continuation Expires(this ICacheSteps _, Reduce<DateTime> dateReducer)
 {
     return fu.Http.Header("Expires", ctx => dateReducer(ctx).ToString("R"));
 }
Example #43
0
 public static Continuation LastModified(this ICacheSteps _, Reduce<DateTime> lastModifiedReducer)
 {
     return _.LastModified((c, d) => lastModifiedReducer(c));
 }
Example #44
0
 /// <summary>
 /// Remove empty rows from the given <see cref="Trie"/> and return the newly reduced <see cref="Trie"/>.
 /// </summary>
 /// <param name="by">the <see cref="Trie"/> to reduce</param>
 /// <returns>newly reduced <see cref="Trie"/></returns>
 public virtual Trie Reduce(Reduce by)
 {
     return by.Optimize(this);
 }
Example #45
0
 public static ResultContext From(IFuContext input,
     Reduce<object> jsonStep)
 {
     return new ResultContext(input, new JsonResult(jsonStep(input)));
 }
Example #46
0
 public static Continuation Text(this IStaticSteps _, Reduce<string> textReducer)
 {
     return step => ctx => step(StringResult.From(ctx, textReducer(ctx)));
 }
Example #47
0
 public static Continuation Json(this IStaticSteps _, Reduce<object> objReducer)
 {
     return step => ctx => step(JsonResult.From(ctx, objReducer(ctx)));
 }
Example #48
0
        /// <summary>
        /// Remove empty rows from the given <see cref="Trie"/> and return the newly reduced <see cref="Trie"/>.
        /// </summary>
        /// <param name="by">the <see cref="Trie"/> to reduce</param>
        /// <returns>the newly reduced Trie</returns>
        public override Trie Reduce(Reduce by)
        {
            List<Trie> h = new List<Trie>();
            foreach (Trie trie in tries)
                h.Add(trie.Reduce(by));

            MultiTrie m = new MultiTrie(forward);
            m.tries = h;
            return m;
        }
Example #49
0
 public void Get(string url, Reduce<Continuation> contReducer)
 {
     mapBranch(url, fu.Map.Get, contReducer);
       mapBranch(url, fu.Map.Head, contReducer);
 }
Example #50
0
 public void Put(string url, Reduce<Continuation> contReducer)
 {
     mapBranch(url, fu.Map.Put, contReducer);
 }
Example #51
0
 public static Continuation File(this IStaticSteps _,
     Reduce<string> filenameReducer, string contentType)
 {
     return _.File(filenameReducer, (c, filename) => contentType);
 }
Example #52
0
 public static Continuation Custom(this IMapSteps _,
     ContRegexDict mappings, Reduce<string> pathReducer)
 {
     return _.Custom(mappings, pathReducer, null);
 }
Example #53
0
 public static Continuation Branch(Reduce<Continuation> nextCont)
 {
     // nextCont supplies the continuation to execute here by reducing from the context
       return step => ctx => nextCont(ctx)(step)(ctx);
 }
Example #54
0
 public static Continuation To(this IRedirectSteps _, Reduce<string> urlReducer)
 {
     return _.To((c, s) => urlReducer(c));
 }
Example #55
0
 public static Continuation Header(this IHttpSteps _,
     string header, Reduce<string> valueReducer)
 {
     return _.Header(header, (ctx, s) => valueReducer(ctx));
 }
Example #56
0
 private void mapBranch(string url,
     Func<Continuation, Continuation, Continuation> wrapper,
     Reduce<Continuation> branchReducer)
 {
     Map(url, wrapper, fu.Branch(branchReducer));
 }
Example #57
0
 public void Delete(string url, Reduce<Continuation> contReducer)
 {
     mapBranch(url, fu.Map.Delete, contReducer);
 }
Example #58
0
 public static Continuation File(this IStaticSteps _,
     Reduce<string> filenameReducer)
 {
     return _.File(filenameReducer, (c, filename) => Mime.FromFilename(filename));
 }