示例#1
0
        /// <summary>
        /// peek and return specified length of bytes from current position in Bytes
        /// array. If length exceeds remaining length then shorten the peek length.
        /// </summary>
        /// <param name="Length"></param>
        /// <returns></returns>
        public byte[] PeekBytesLenient(int Length)
        {
            int lx  = IntExt.Min(this.RemainingLength, Length);
            var buf = this.Bytes.SubArray(this.Index, lx);

            return(buf);
        }
示例#2
0
 protected override Expression VisitMethodCall(MethodCallExpression m)
 {
     if (m.Object != null && m.Object.NodeType == ExpressionType.Parameter)
     {
         var p = (ParameterExpression)m.Object;
         if (_paramWhere.Contains(p))
         {
             if (m.Method.Name != "get_Item" || m.Arguments[0].NodeType != ExpressionType.Constant)
             {
                 _nonConstant = true;
                 return(m);
             }
             var paramVar = _paramVar[p.Name];
             var index    = (int)((ConstantExpression)m.Arguments[0]).Value;
             if (index < 0 || index >= paramVar.ListCount)
             {
                 _indexOutOfLength = true;
                 return(m);
             }
             var kvp = IntExt.CreateLong(paramVar.Index, index);
             if (!_paramId.Contains(kvp))
             {
                 _paramId.Add(kvp);
             }
             return(makeListParam(_param, _methods, kvp, m.Type));
         }
     }
     return(base.VisitMethodCall(m));
 }
示例#3
0
        bool tryAppendAllDifferent(ReadOnlyCollection <Expression> exps)
        {
            var list = new HashSet <long>();

            foreach (var exp in exps)
            {
                switch (exp.NodeType)
                {
                case ExpressionType.Call:
                    var m = (MethodCallExpression)exp;
                    if (m.Method.Name == "get_Item" && m.Object.NodeType == ExpressionType.Parameter && m.Arguments[0].NodeType == ExpressionType.Constant)
                    {
                        list.Add(IntExt.CreateLong(_paramVar[((ParameterExpression)m.Object).Name].Index, (int)((ConstantExpression)m.Arguments[0]).Value));
                    }
                    else
                    {
                        return(false);
                    }
                    break;

                case ExpressionType.Parameter:
                    list.Add(IntExt.CreateLong(0, _paramVar[((ParameterExpression)exp).Name].Index));
                    break;

                default:
                    return(false);
                }
            }
            _exp = Expression.Call(_exp, "AppendAllDifferent", null, Expression.Constant(list));
            return(true);
        }
示例#4
0
        public int FillInExtractionWithCount(IPlantCollection Plants)
        {
            JXL.ReadExtractionTables();

            Plant CurrentPlant;

            //Loop the extractions
            foreach (var Ext in JXL.WRRCATCHMENT)
            {
                if (Plants.TryGetValue(Ext.PLANTID, out CurrentPlant))
                {
                    if (!Ext.IsAMOUNTNull())
                    {
                        CurrentPlant.Extractions.AddSiValue(Ext.STARTDATE, Ext.ENDDATE, Ext.AMOUNT);
                    }
                    if (!Ext.IsSURFACEWATERVOLUMENull())
                    {
                        CurrentPlant.SurfaceWaterExtrations.AddSiValue(Ext.STARTDATE, Ext.ENDDATE, Ext.SURFACEWATERVOLUME);
                    }
                }
            }


            //In ribe amt extractions are in another table

            foreach (var IntExt in JXL.INTAKECATCHMENT)
            {
                if (Plants.TryGetValue(IntExt.DRWPLANTINTAKERow.PLANTID, out CurrentPlant))
                {
                    //It would be possible to store this on the intake instead of the plant.
                    //We are throwing away information!

                    if (!IntExt.IsVOLUMENull())
                    {
                        CurrentPlant.Extractions.AddSiValue(IntExt.STARTDATE, IntExt.ENDDATE, IntExt.VOLUME);
                        //if (IntExt.ENDDATE.Year != IntExt.STARTDATE.Year)
                        //  throw new Exception("Volume cover period longer than 1 year)");

                        //var E = CurrentPlant.Extractions.Items.FirstOrDefault(var => var.StartTime.Year == IntExt.ENDDATE.Year);
                        //if (E == null)
                        //  CurrentPlant.Extractions.AddSiValue (new TimeSeriesEntry(IntExt.ENDDATE, IntExt.VOLUME));
                        //else
                        //  E.Value += IntExt.VOLUME;
                    }
                }
            }
            int toreturn = JXL.INTAKECATCHMENT.Count + JXL.WRRCATCHMENT.Count;

            JXL.INTAKECATCHMENT.Dispose();
            JXL.WRRCATCHMENT.Dispose();
            return(toreturn);
        }
示例#5
0
 protected override Expression VisitParameter(ParameterExpression p)
 {
     if (_paramWhere.Contains(p) && !_paramVar[p.Name].IsList)
     {
         var kvp = IntExt.CreateLong(0, _paramVar[p.Name].Index);
         if (!_paramId.Contains(kvp))
         {
             _paramId.Add(kvp);
         }
         return(makeVarParam(_param, _methods, kvp.GetLowInt(), p.Type));
     }
     return(p);
 }
示例#6
0
        private static void LogFile_WriteRawBytes(byte[] Buffer, string FilePath)
        {
            int ix = 0;

            while (ix < Buffer.Length)
            {
                int remLx = Buffer.Length - ix;
                int lx    = 1;

                if ((Buffer[ix] == 0x1b) && (remLx > 1))
                {
                    var fx = Buffer.IndexOf(ix + 1, new byte[] { 0x1b });
                    if (fx == -1)
                    {
                        lx = remLx;
                    }
                    else
                    {
                        lx = fx - ix;
                    }
                }
                else
                {
                    lx = IntExt.Min(remLx, 15);
                }

                {
                    var sb = new StringBuilder();
                    sb.Append(Buffer.ToHex(ix, lx, ' '));
                    System.IO.File.AppendAllText(
                        FilePath, sb.ToString() + Environment.NewLine);
                }

                {
                    var sb = new StringBuilder();
                    sb.Append(Buffer.ToAscii(ix, lx, "  "));
                    System.IO.File.AppendAllText(
                        FilePath, sb.ToString() + Environment.NewLine);
                }

                ix += lx;
            }
        }
        private static void LogFile_WriteRawBytes(byte[] Buffer, List <string> Lines)
        {
            int ix = 0;

            while (ix < Buffer.Length)
            {
                int remLx = Buffer.Length - ix;
                int lx    = 1;

                if ((Buffer[ix] == 0x1b) && (remLx > 1))
                {
                    var fx = Buffer.IndexOf(ix + 1, new byte[] { 0x1b });
                    if (fx == -1)
                    {
                        lx = remLx;
                    }
                    else
                    {
                        lx = fx - ix;
                    }
                }
                else
                {
                    lx = IntExt.Min(remLx, 15);
                }

                {
                    var sb = new StringBuilder();
                    sb.Append(Buffer.ToHex(ix, lx, ' '));
                    Lines.Add(sb.ToString());
                }

                {
                    var sb = new StringBuilder();
                    sb.Append(Buffer.ToAscii(ix, lx, "  "));
                    Lines.Add(sb.ToString());
                }

                ix += lx;
            }
        }
示例#8
0
        //public methods
        public virtual IEnumerable <List <ReadOnlyCollection <T> > > LookAhead()
        {
            if (_noSolution)
            {
                return(Enumerable.Empty <List <ReadOnlyCollection <T> > >());
            }

            var data = _variables.Select(a =>
                                         a.Select(b => b.ToList()).ToList()
                                         ).ToList();

            return(lookAhead(
                       data,
                       _variables.SelectMany((a, i) =>
                                             a.Select((b, j) => IntExt.CreateLong(i, j))
                                             ).ToArray(),
                       new HashSet <long>()
                       ).Select(s =>
                                s.GroupBy(a => a.Item1.GetHighInt()).OrderBy(a => a.Key).Select(a =>
                                                                                                a.OrderBy(b => b.Item1.GetLowInt()).Select(b => b.Item2).ToList().AsReadOnly()
                                                                                                ).ToList()
                                ));
        }
示例#9
0
        //local methods
        IEnumerable <IEnumerable <Tuple <long, T> > > lookAhead(List <List <List <T> > > data, long[] unsolved, HashSet <long> solved)
        {
            //all solved, return empty
            if (unsolved.Length == 0)
            {
                yield return(Tuple.Create(IntExt.CreateLong(0, _variables[0].Count), default(T)).ToEnumerable());

                yield break;
            }

            //do on first time
            if (solved.Count == 0)
            {
                var newData = data.Select(d => d.ToList()).ToList();
                foreach (var node in _nodeConstraints)
                {
                    filterData(newData, node.Key, node.Value.PredicateAll(), null);
                }
                unsolved = unsolved.OrderBy(x => getData(newData, x).Count).ToArray();
                data     = newData;
            }

            //pull out first unsolve
            var index      = unsolved[0];
            var candidate  = getData(data, index);
            var newUnsolve = new long[unsolved.Length - 1];

            Array.Copy(unsolved, 1, newUnsolve, 0, newUnsolve.Length);
            var newSolved = new HashSet <long>(solved)
            {
                index
            };

            //get predicate
            List <Tuple <HashSet <long>, Func <List <List <List <T> > >, bool> > > arc;

            _arcConstraints.TryGetValue(index, out arc);
            List <Tuple <HashSet <long>, Func <List <List <List <T> > >, bool> > > pair;

            _pairConstraints.TryGetValue(index, out pair);
            List <HashSet <long> > diff;

            _allDifferents.TryGetValue(index, out diff);

            foreach (var t in candidate)
            {
                //create new data set
                var newData = data.Select(d => d.ToList()).ToList();
                setData(newData, index, new List <T> {
                    t
                });

                //find minimum scope
                var minValue   = int.MaxValue;
                var minUnSolve = 0;

                //set occurrents
                List <Dictionary <T, int> > valueCheck = null;
                if (_occurrents.Count > 0)
                {
                    valueCheck = new List <Dictionary <T, int> >(_occurrents.Count);
                    for (var i = 0; i < _occurrents.Count; i++)
                    {
                        valueCheck.Add(new Dictionary <T, int>(tComparer));
                    }
                }

                //for each unsolve
                for (var j = 0; j < newUnsolve.Length; j++)
                {
                    var prediList = Enumerable.Empty <Func <List <List <List <T> > >, bool> >();
                    var k         = newUnsolve[j];

                    //apply predicate
                    if (diff != null)
                    {
                        prediList = diff.Where(a => a.Contains(k))
                                    .Take(1)
                                    .Select(a => new Func <List <List <List <T> > >, bool>(x => !tComparer.Equals(x[k.GetHighInt()][k.GetLowInt()][0], t)));
                    }
                    if (pair != null)
                    {
                        prediList = prediList.Concat(pair.Where(a => a.Item1.Contains(k))
                                                     .Take(1)
                                                     .Select(a => a.Item2));
                    }
                    if (arc != null)
                    {
                        prediList = prediList.Concat(arc.Where(a => a.Item1.All(b => b == k || newSolved.Contains(b)))
                                                     .Select(a => a.Item2));
                    }
                    var predicate = prediList.PredicateAll();

                    //if predicate is not empty
                    if (!Equals(predicate, emptyPredicate))
                    {
                        filterData(newData, k, predicate, val => setValueCheck(valueCheck, val, j, newUnsolve[j]));
                    }
                    else if (_occurrents.Count > 0)
                    {
                        var oldList = getData(newData, k);
                        foreach (var item in oldList)
                        {
                            setValueCheck(valueCheck, item, j, newUnsolve[j]);
                        }
                    }

                    //set minimum scope
                    if (j == 0 || getData(newData, k).Count < minValue)
                    {
                        minUnSolve = j;
                        minValue   = getData(newData, k).Count;
                    }
                }

                //apply occurents
                if (_occurrents.Count > 0)
                {
                    foreach (var c in valueCheck)
                    {
                        foreach (var kvp in c)
                        {
                            if (kvp.Value == -1)
                            {
                                continue;
                            }
                            var k = newUnsolve[kvp.Value];
                            setData(newData, k, new List <T> {
                                kvp.Key
                            });
                            if (minValue > 1)
                            {
                                minValue   = 1;
                                minUnSolve = kvp.Value;
                            }
                        }
                    }
                }

                //swop item based on minimum scope
                if (minUnSolve > 0)
                {
                    var tmp = newUnsolve[0];
                    newUnsolve[0]          = newUnsolve[minUnSolve];
                    newUnsolve[minUnSolve] = tmp;
                }

                //iterate next item
                foreach (var r in lookAhead(newData, newUnsolve, newSolved))
                {
                    yield return(Tuple.Create(index, t).ToEnumerable().Concat(r));
                }
            }
        }
示例#10
0
        private static TerminalVt100Statement Factory_FromStmtText(string StmtText)
        {
            Vt100Command?          cmd  = null;
            TerminalVt100Statement stmt = null;
            string text1  = "";
            string text2  = "";
            string text3  = "";
            string text4  = "";
            string text20 = "";
            int    rx     = 0;

            if (StmtText.Length >= 1)
            {
                text1 = StmtText.Substring(0, 1);
            }
            if (StmtText.Length >= 2)
            {
                text2 = StmtText.Substring(0, 2);
            }
            if (StmtText.Length >= 3)
            {
                text3 = StmtText.Substring(0, 3);
            }
            if (StmtText.Length >= 4)
            {
                text4 = StmtText.Substring(0, 4);
            }

            int lx = IntExt.Min(StmtText.Length, 20);

            text20 = StmtText.Substring(0, lx);

            if (text4 == "[?3l")
            {
                cmd  = Vt100Command.SetCol80;
                stmt = new TerminalVt100Statement(StmtText.Substring(0, 4), cmd);
            }
            else if (text4 == "[?7h")
            {
                cmd  = Vt100Command.SetAutoWrap;
                stmt = new TerminalVt100Statement(StmtText.Substring(0, 4), cmd);
            }

            else if (text3 == "[0m")
            {
                stmt = new TerminalVt100Statement(text3, Vt100Command.CharAttrOff);
            }

            else if (text3 == "[1m")
            {
                stmt = new TerminalVt100Statement(text3, Vt100Command.BoldModeOn);
            }

            else if (text3 == "[4m")
            {
                stmt = new TerminalVt100Statement(text3, Vt100Command.UnderlineModeOn);
            }

            else if (text3 == "[2J")
            {
                stmt = new TerminalVt100Statement(text3, Vt100Command.ClearScreen);
            }

            else if ((text1 == "[") && (StmtText.Length >= 5) &&
                     ((rx = StmtText.MatchRegExp(REGEXPCURSORPOSITION)) > 0))
            {
                stmt = new Vt100PosCursor(StmtText.Substring(0, rx));
            }

            else
            {
                stmt = new TerminalVt100Statement(StmtText, null);
            }


            return(stmt);
        }