private bool Move(Direction direction)
        {
            if (!EnsureInitialized())
            {
                return(false);
            }

            int position = _textView.Caret.Position.BufferPosition.Position;

            ParseItem item = _tree.StyleSheet.ItemBeforePosition(position);

            if (item == null)
            {
                return(false);
            }

            NumericalValue unit = item.FindType <NumericalValue>();

            if (unit != null)
            {
                return(HandleUnits(direction, unit));
            }

            HexColorValue hex = item.FindType <HexColorValue>();

            if (hex != null)
            {
                return(HandleHex(direction, hex));
            }

            return(false);
        }
Пример #2
0
        private static bool HandleUnits(Direction direction, NumericalValue item, ITextSnapshot snapshot)
        {
            float value;

            if (!float.TryParse(item.Number.Text, out value))
            {
                return(false);
            }

            if (!AreWithinLimits(direction, value, item))
            {
                return(true);
            }

            var    span   = new SnapshotSpan(snapshot, item.Number.Start, item.Number.Length);
            float  delta  = GetDelta(item.Number.Text);
            string format = item.Number.Text.Contains(".") ? "#.#0" : string.Empty;

            if (NumberDecimalPlaces(item.Number.Text) == 1)
            {
                format = "F1";
            }

            if (direction == Direction.Down)
            {
                UpdateSpan(span, (value - delta).ToString(format, CultureInfo.InvariantCulture), "Decrease value");
            }
            else
            {
                UpdateSpan(span, (value + delta).ToString(format, CultureInfo.InvariantCulture), "Increase value");
            }

            return(true);
        }
Пример #3
0
        public ItemCheckResult CheckItem(ParseItem item, ICssCheckerContext context)
        {
            if (!WESettings.Instance.Css.ValidateZeroUnit)
            {
                return(ItemCheckResult.Continue);
            }

            NumericalValue number = (NumericalValue)item;
            UnitValue      unit   = number as UnitValue;

            if (unit == null || context == null || item.FindType <Declaration>() == null)
            {
                return(ItemCheckResult.Continue);
            }

            // The 2nd and 3rd arguments to hsl() require units even when zero
            var function = unit.Parent.Parent as FunctionColor;

            if (function != null && function.FunctionName.Text.StartsWith("hsl", StringComparison.OrdinalIgnoreCase))
            {
                var arg = unit.Parent as FunctionArgument;
                if (arg != function.Arguments[0])
                {
                    return(ItemCheckResult.Continue);
                }
            }

            if (number.Number.Text == "0" && unit.UnitType != UnitType.Unknown && unit.UnitType != UnitType.Time)
            {
                string message = string.Format(System.Globalization.CultureInfo.CurrentCulture, Resources.BestPracticeZeroUnit, unit.UnitToken.Text);
                context.AddError(new SimpleErrorTag(number, message));
            }

            return(ItemCheckResult.Continue);
        }
Пример #4
0
        public void FunctionRgb_ParseTest1()
        {
            ITextProvider tp     = new StringTextProvider("rgb(25, 10%, 34)");
            TokenStream   tokens = Helpers.MakeTokenStream(tp);
            Function      f      = Function.ParseFunction(null, new ItemFactory(tp, null), tp, tokens);

            Assert.AreEqual(typeof(FunctionColor), f.GetType());
            Assert.AreEqual(3, f.Arguments.Count);

            Assert.IsInstanceOfType(f.Arguments[0], typeof(FunctionArgument));
            FunctionArgument fa = f.Arguments[0] as FunctionArgument;

            Assert.IsNotNull(fa.Comma);

            Assert.AreEqual(1, fa.ArgumentItems.Count);
            Assert.IsInstanceOfType(fa.ArgumentItems[0], typeof(NumericalValue));
            NumericalValue numericalValue = (NumericalValue)fa.ArgumentItems[0];

            Assert.IsInstanceOfType(numericalValue.Children[0], typeof(TokenItem));
            Assert.AreEqual(CssTokenType.Number, ((TokenItem)numericalValue.Children[0]).TokenType);

            Assert.IsInstanceOfType(f.Arguments[1], typeof(FunctionArgument));
            Assert.IsNotNull(fa.Comma);
            Assert.AreEqual(1, fa.ArgumentItems.Count);
            Assert.IsInstanceOfType(fa.ArgumentItems[0], typeof(NumericalValue));

            fa = f.Arguments[1] as FunctionArgument;
            Assert.IsInstanceOfType(fa.ArgumentItems[0], typeof(NumericalValue));
            numericalValue = (NumericalValue)fa.ArgumentItems[0];
            Assert.IsInstanceOfType(numericalValue.Children[1], typeof(TokenItem));
            Assert.IsInstanceOfType(numericalValue.Children[1], typeof(TokenItem));
            Assert.AreEqual(CssTokenType.Number, ((TokenItem)numericalValue.Children[0]).TokenType);
            Assert.AreEqual(CssTokenType.Units, ((TokenItem)numericalValue.Children[1]).TokenType);
        }
Пример #5
0
        private static bool AreWithinLimits(Direction direction, float number, NumericalValue item)
        {
            UnitType type = GetUnitType(item);

            switch (type)
            {
            case UnitType.Angle:
                return((direction == Direction.Up) ? number <360 : number> -360);

            //case UnitType.Percentage:
            //    return (direction == Direction.Up) ? number < 100 : number > 0;

            // Larger than zero
            case UnitType.Grid:
            case UnitType.Frequency:
            case UnitType.Resolution:
            case UnitType.Time:
                return((direction == Direction.Down) ? number > 0 : true);

            case UnitType.Percentage:
            case UnitType.Length:
            case UnitType.Viewport:
                return(true);
            }

            FunctionColor func = item.FindType <FunctionColor>();

            if (func != null)
            {
                if (func.FunctionName.Text.StartsWith("rgb", StringComparison.Ordinal))
                {
                    if (direction == Direction.Up)
                    {
                        return(number < 255);
                    }
                    else
                    {
                        return(number > 0);
                    }
                }

                if (func.FunctionName.Text.StartsWith("hsl", StringComparison.Ordinal))
                {
                    if (direction == Direction.Up)
                    {
                        return(number < 360);
                    }
                    else
                    {
                        return(number > 0);
                    }
                }
            }

            return(true);
        }
        private static bool HandleUnits(Direction direction, NumericalValue item, ITextSnapshot snapshot)
        {
            float value;
            if (!float.TryParse(item.Number.Text, out value))
                return false;

            if (!AreWithinLimits(direction, value, item))
                return true;

            var span = new SnapshotSpan(snapshot, item.Number.Start, item.Number.Length);
            float delta = GetDelta(item.Number.Text);
            string format = item.Number.Text.Contains(".") ? "#.#0" : string.Empty;
            if (NumberDecimalPlaces(item.Number.Text) == 1)
                format = "F1";

            if (direction == Direction.Down)
                UpdateSpan(span, (value - delta).ToString(format, CultureInfo.InvariantCulture), "Decrease value");
            else
                UpdateSpan(span, (value + delta).ToString(format, CultureInfo.InvariantCulture), "Increase value");

            return true;
        }
        public void NumericalValue_Parse()
        {
            string[] tests = new string[]
            {
                "100",
                "-100",
                "+100",
                "002.125",
                "-23.125",
                "+234.125",
            };

            foreach (string test in tests)
            {
                TokenStream    tokens = Helpers.MakeTokenStream(test);
                ITextProvider  tp     = new StringTextProvider(test);
                NumericalValue s      = new NumericalValue();
                Assert.IsTrue(s.Parse(new ItemFactory(tp, null), tp, tokens));
                Assert.IsNotNull(s.Number);
                Assert.AreEqual(test.Length, s.Number.Length);
            }
        }
Пример #8
0
        private static IRValueNode CreateConstant(ParseContext context)
        {
            var         tokens       = context.Tokens;
            var         currentToken = tokens.CurrentToken;
            IRValueNode term         = null;

            switch (currentToken.TokenType)
            {
            case RTokenType.NaN:
            case RTokenType.Infinity:
            case RTokenType.Number:
                term = new NumericalValue();
                break;

            case RTokenType.Complex:
                term = new ComplexValue();
                break;

            case RTokenType.Logical:
                term = new LogicalValue();
                break;

            case RTokenType.String:
                term = new StringValue();
                break;

            case RTokenType.Null:
                term = new NullValue();
                break;

            case RTokenType.Missing:
                term = new MissingValue();
                break;
            }

            Debug.Assert(term != null);
            term.Parse(context, null);
            return(term);
        }
Пример #9
0
        private bool Move(Direction direction)
        {
            if (WebEditor.Host == null)
            {
                return(false);
            }

            var point = _textView.BufferGraph.MapDownToInsertionPoint(_textView.Caret.Position.BufferPosition, PointTrackingMode.Positive, ts => ts.ContentType.IsOfType(CssContentTypeDefinition.CssContentType));

            if (point == null)
            {
                return(false);
            }

            var       tree = CssEditorDocument.FromTextBuffer(point.Value.Snapshot.TextBuffer);
            ParseItem item = tree.StyleSheet.ItemBeforePosition(point.Value.Position);

            if (item == null)
            {
                return(false);
            }

            NumericalValue unit = item.FindType <NumericalValue>();

            if (unit != null)
            {
                return(HandleUnits(direction, unit, point.Value.Snapshot));
            }

            HexColorValue hex = item.FindType <HexColorValue>();

            if (hex != null)
            {
                return(HandleHex(direction, hex, point.Value.Snapshot));
            }

            return(false);
        }
        public ItemCheckResult CheckItem(ParseItem item, ICssCheckerContext context)
        {
            if (!WESettings.GetBoolean(WESettings.Keys.ValidateZeroUnit))
            {
                return(ItemCheckResult.Continue);
            }

            NumericalValue number = (NumericalValue)item;
            UnitValue      unit   = number as UnitValue;

            if (unit == null || context == null)
            {
                return(ItemCheckResult.Continue);
            }

            if (number.Number.Text == "0" && unit.UnitType != UnitType.Unknown && unit.UnitType != UnitType.Time)
            {
                string message = string.Format(Resources.BestPracticeZeroUnit, unit.UnitToken.Text);
                context.AddError(new SimpleErrorTag(number, message));
            }

            return(ItemCheckResult.Continue);
        }
Пример #11
0
    public override Condition buildCondition()
    {
        if (op == "and")
        {
            return(new AndCondition(new Condition[] { left.buildCondition(), right.buildCondition() }));
        }
        else if (op == "or")
        {
            return(new OrCondition(new Condition[] { left.buildCondition(), right.buildCondition() }));
        }
        else if (op == ">=" || op == "<=" || op == ">" || op == "<")
        {
            NumericalValue leftValue  = left.buildNumberValue();
            NumericalValue rightValue = right.buildNumberValue();

            if (op == "<=")
            {
                return(new NotCondition(new LessThanCondition(rightValue, leftValue)));
            }
            else if (op == ">")
            {
                return(new LessThanCondition(rightValue, leftValue));
            }
            else if (op == ">=")
            {
                return(new NotCondition(new LessThanCondition(leftValue, rightValue)));
            }
            else
            {
                return(new LessThanCondition(leftValue, rightValue));
            }
        }
        else
        {
            throw new ParseError(op + " is not a valid boolean binary operator");
        }
    }
Пример #12
0
 public static int NumericalValueToCardSize(NumericalValue nv)
 {
     if (nv >= NumericalValue.NV_3 && nv <= NumericalValue.NV_KING)
     {
         return((int)nv);
     }
     else if (nv == NumericalValue.NV_ACE)
     {
         return(20);
     }
     else if (nv == NumericalValue.NV_2)
     {
         return(21);
     }
     else if (nv == NumericalValue.NV_SMALL_JOKER)
     {
         return(30);
     }
     else if (nv == NumericalValue.NV_BIG_JOKER)
     {
         return(31);
     }
     return(-1);
 }
Пример #13
0
 public override string ToString()
 {
     return(string.Format("({0},{1})", Suit.ToString(), NumericalValue.ToString()));
 }
        private static bool AreWithinLimits(Direction direction, float number, NumericalValue item)
        {
            UnitType type = GetUnitType(item);
            switch (type)
            {
                case UnitType.Angle:
                    return (direction == Direction.Up) ? number < 360 : number > -360;

                //case UnitType.Percentage:
                //    return (direction == Direction.Up) ? number < 100 : number > 0;

                // Larger than zero
                case UnitType.Grid:
                case UnitType.Frequency:
                case UnitType.Resolution:
                case UnitType.Time:
                    return (direction == Direction.Down) ? number > 0 : true;

                case UnitType.Percentage:
                case UnitType.Length:
                case UnitType.Viewport:
                    return true;
            }

            FunctionColor func = item.FindType<FunctionColor>();
            if (func != null)
            {
                if (func.FunctionName.Text.StartsWith("rgb", StringComparison.Ordinal))
                {
                    if (direction == Direction.Up)
                        return number < 255;
                    else
                        return number > 0;
                }

                if (func.FunctionName.Text.StartsWith("hsl", StringComparison.Ordinal))
                {
                    if (direction == Direction.Up)
                        return number < 360;
                    else
                        return number > 0;
                }
            }

            return true;
        }
Пример #15
0
        private static IRValueNode CreateConstant(ParseContext context) {
            TokenStream<RToken> tokens = context.Tokens;
            RToken currentToken = tokens.CurrentToken;
            IRValueNode term = null;

            switch (currentToken.TokenType) {
                case RTokenType.NaN:
                case RTokenType.Infinity:
                case RTokenType.Number:
                    term = new NumericalValue();
                    break;

                case RTokenType.Complex:
                    term = new ComplexValue();
                    break;

                case RTokenType.Logical:
                    term = new LogicalValue();
                    break;

                case RTokenType.String:
                    term = new StringValue();
                    break;

                case RTokenType.Null:
                    term = new NullValue();
                    break;

                case RTokenType.Missing:
                    term = new MissingValue();
                    break;
            }

            Debug.Assert(term != null);
            term.Parse(context, null);
            return term;
        }
Пример #16
0
 public AddNumberValue(NumericalValue left, NumericalValue right)
 {
     this.left  = left;
     this.right = right;
 }
Пример #17
0
 public override int GetHashCode()
 => NumericalValue.GetHashCode();
 public LessThanCondition(NumericalValue left, NumericalValue right)
 {
     this.left  = left;
     this.right = right;
 }
Пример #19
0
        // dataset service
        public bool LoadHDdDdata(int datasetId, int fileId /*, int referencFromHdId*/)
        {
            _observationRepository.DeleteMany(d => d.DatasetId == datasetId);
            var dataset  = GetActivityDataset(datasetId);
            var dataFile = _dataFileRepository.Get(fileId);
            var filePath = dataFile.Path + "\\" + dataFile.FileName;

            var dataTable = _fileService.ReadOriginalFile(filePath);

            var sampleList = _biosampleRepository.FindAll(s => s.DatasetId == datasetId).ToList();
            var scos       = sampleList.ToDictionary(co => co.BiosampleStudyId);

            var obsReadyToInsert = new List <Observation>();

            foreach (DataRow row in dataTable.Rows)
            {
                for (int index = 0; index < dataTable.Columns.Count; index++)
                {
                    if (index == 0)
                    {
                        continue;
                    }
                    else
                    {
                        var column = dataTable.Columns[index];
                        var obs    = new Observation();
                        // Fill an Observation
                        var value = new NumericalValue();
                        value.Value    = double.Parse(row[column.ColumnName].ToString());
                        value.Property = new PropertyDescriptor();
                        {
                            value.Property.Description = dataset.Template.Description;
                            value.Property.ObsClass    = dataset.Template.Class;
                            value.Property.Name        = dataset.TemplateId;
                        }
                        //   value.Unit = ??
                        obs.ObservedValue = value;                                                             // Observed Value which includes in it the VALUE and its PROPERTY

                        // ****** FOR NOW WE USE THE FOLLOWING TILL WE HAVE THE FEATURE referencFromHdId ******
                        obs.SubjectOfObservationName = column.ColumnName;                                      // sample name (HERE IS THE FILE NAME)
                        //obs.SubjectOfObservationId = column.ColumnName;                                    // sampleID     (here is the file name)
                        // ******

                        //   obs.SubjectOfObservationName = scos[column.ColumnName].BiosampleStudyId;      // sample Name
                        //   obs.SubjectOfObservationId = scos[column.ColumnName].Id.ToString();           // sample ID
                        //   obs.StudyId = scos[column.ColumnName].StudyId;                                // study ID
                        obs.FeatureName = row[0].ToString();                                                   // feature name
                        // obs.FeatureId =;  Not implemented yet                                           // feature ID
                        obs.DatafileId = dataFile.Id;
                        obs.DatasetId  = datasetId;
                        obs.ActivityId = dataset.ActivityId;
                        obs.ProjectId  = dataset.Activity.ProjectId;
                        obs.Id         = Guid.NewGuid();

                        obsReadyToInsert.Add(obs);
                        //   observationsTotal.Add(obs);

                        if (obsReadyToInsert.Count % ((dataTable.Columns.Count) - 1) == 0)
                        {
                            _observationRepository.InsertMany(obsReadyToInsert);
                            obsReadyToInsert.Clear();
                        }
                    }
                }
            }
            if (obsReadyToInsert.Count > 0)
            {
                Debug.WriteLine("Created Observations are NOT Equal to measured values in the file please check!!");
            }

            dataFile.State        = "LOADED";
            dataFile.IsLoadedToDB = true;
            _dataFileRepository.Update(dataFile);
            _dataContext.Save();
            return(true);
        }
Пример #20
0
 public CardInfo(Suit suit, NumericalValue numericalValue)
 {
     this.Suit           = suit;
     this.NumericalValue = numericalValue;
 }
Пример #21
0
 public SetNumberCommand(string name, NumericalValue value)
 {
     this.name  = name;
     this.value = value;
 }
 public NegateNumberValue(NumericalValue ofValue)
 {
     this.ofValue = ofValue;
 }