public string this[string name]
        {
            get
            {
                ValueLine vl = this.attributes.Find(delegate(ValueLine l) { return(l.Name == name); });
                if (vl == null)
                {
                    return(null);
                }

                return(vl.Value);
            }
            set
            {
                ValueLine vl = this.attributes.Find(delegate(ValueLine l) { return(l.Name == name); });
                if (vl == null)
                {
                    vl = new ValueLine(name, value);

                    this.attributes.Add(vl);
                }

                vl.Value = value;
            }
        }
Ejemplo n.º 2
0
        public static void SetupParameter(ValueLine vl, ChartParameterEmbedded parameter)
        {
            var scriptParameter = parameter.ScriptParameter;

            vl.LabelColumns = new BsColumn(6);
            vl.LabelText    = scriptParameter.Name;

            if (scriptParameter.Type == ChartParameterType.Number || scriptParameter.Type == ChartParameterType.String)
            {
                vl.ValueLineType = ValueLineType.TextBox;
            }
            else if (scriptParameter.Type == ChartParameterType.Enum)
            {
                vl.ValueLineType = ValueLineType.Enum;

                var token = scriptParameter.GetToken(parameter.ParentChart);

                var compatible = scriptParameter.GetEnumValues().Where(a => a.CompatibleWith(token)).ToList();
                vl.ReadOnly       = compatible.Count <= 1;
                vl.EnumComboItems = compatible.Select(ev => new SelectListItem
                {
                    Value    = ev.Name,
                    Text     = ev.Name,
                    Selected = ((string)vl.UntypedValue) == ev.Name
                }).ToList();

                if (!vl.ValueHtmlProps.IsNullOrEmpty())
                {
                    vl.ValueHtmlProps.Clear();
                }
            }


            vl.ValueHtmlProps["class"] = "sf-chart-redraw-onchange";
        }
Ejemplo n.º 3
0
        public void Construct()
        {
            const string defaultValue = "A";

            var valueLine = new ValueLine <string>(defaultValue);

            CollectionAssert.IsEmpty(valueLine, "Value line contains changes.");
            Assert.AreEqual(defaultValue, valueLine.GetValueAtTime(0), "Invalid value at the start.");
            Assert.AreEqual(defaultValue, valueLine.GetValueAtTime(100), "Invalid value at the middle.");
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a new <see cref="IIniDocument"/> using data from a <see cref="TextReader"/>.
        /// </summary>
        /// <param name='reader'>
        /// A <see cref="TextReader"/> that will supply the input data.
        /// </param>
        public static IIniDocument Read(TextReader reader)
        {
            IIniDocument output         = new IniDocument();
            IIniSection  currentSection = output;
            bool         endOfStream    = false;
            int          lineNumber     = 0;

            while (!endOfStream)
            {
                string currentLine = reader.ReadLine();
                Match  currentMatch;

                lineNumber++;

                // If we get a null response then we are at the end of the stream and can exit
                if (currentLine == null)
                {
                    endOfStream = true;
                    continue;
                }

                // We silently skip over empty lines
                if (EmptyLine.Match(currentLine).Success || CommentLine.Match(currentLine).Success)
                {
                    continue;
                }

                // If we find a 'new section' line then we create a new section and begin dealing with it
                currentMatch = SectionLine.Match(currentLine);
                if (currentMatch.Success)
                {
                    string sectionName = currentMatch.Groups[1].Value.Trim();
                    currentSection = new IniSection();
                    output.Sections.Add(sectionName, currentSection);
                    continue;
                }

                // If we find a value line then we store it within the current section.
                currentMatch = ValueLine.Match(currentLine);
                if (currentMatch.Success)
                {
                    string key   = currentMatch.Groups[1].Value.Trim();
                    string value = currentMatch.Groups[2].Value.Trim();
                    currentSection[key] = value;
                    continue;
                }

                throw new FormatException(String.Format("Invalid INI data at line {0}.", lineNumber));
            }

            return(output);
        }
Ejemplo n.º 5
0
        public void SetValue_NonDefault_AtStart()
        {
            const string defaultValue    = "A";
            const string nonDefaultValue = "B";

            var valueLine = new ValueLine <string>(defaultValue);

            valueLine.SetValue(0, nonDefaultValue);

            CollectionAssert.AreEqual(new[] { new ValueChange <string>(0, nonDefaultValue) }, valueLine, "Invalid value changes.");
            Assert.AreEqual(nonDefaultValue, valueLine.GetValueAtTime(0), "Invalid value at the start.");
            Assert.AreEqual(nonDefaultValue, valueLine.GetValueAtTime(100), "Invalid value at the middle.");
        }
Ejemplo n.º 6
0
        public void SetValue_Default_AtMiddle()
        {
            const string defaultValue    = "A";
            const long   valueChangeTime = 100;

            var valueLine = new ValueLine <string>(defaultValue);

            valueLine.SetValue(valueChangeTime, defaultValue);

            CollectionAssert.IsEmpty(valueLine, "Value line contains changes.");
            Assert.AreEqual(defaultValue, valueLine.GetValueAtTime(0), "Invalid value at the start.");
            Assert.AreEqual(defaultValue, valueLine.GetValueAtTime(valueChangeTime), "Invalid value at the value change time.");
            Assert.AreEqual(defaultValue, valueLine.GetValueAtTime(valueChangeTime + 1), "Invalid value after the value change time.");
        }
Ejemplo n.º 7
0
        public void SetValue_NonDefault_AtMiddle()
        {
            const string defaultValue    = "A";
            const string nonDefaultValue = "B";
            const long   valueChangeTime = 100;

            var valueLine = new ValueLine <string>(defaultValue);

            valueLine.SetValue(valueChangeTime, nonDefaultValue);

            CollectionAssert.AreEqual(new[] { new ValueChange <string>(valueChangeTime, nonDefaultValue) }, valueLine, "Invalid value changes.");
            Assert.AreEqual(defaultValue, valueLine.GetValueAtTime(0), "Invalid value at the start.");
            Assert.AreEqual(nonDefaultValue, valueLine.GetValueAtTime(valueChangeTime), "Invalid value at the value change time.");
            Assert.AreEqual(nonDefaultValue, valueLine.GetValueAtTime(valueChangeTime + 1), "Invalid value after the value change time.");
        }
Ejemplo n.º 8
0
        private void InitializeControlData(ControlChangeEvent controlChangeEvent, long time)
        {
            if (controlChangeEvent == null)
            {
                return;
            }

            var controlsLines = _controlsLines[controlChangeEvent.Channel];

            ValueLine <SevenBitNumber> controlValueLine;

            if (!controlsLines.TryGetValue(controlChangeEvent.ControlNumber, out controlValueLine))
            {
                controlsLines.Add(controlChangeEvent.ControlNumber, controlValueLine = new ValueLine <SevenBitNumber>(SevenBitNumber.MinValue));
            }

            controlValueLine.SetValue(time, controlChangeEvent.ControlValue);
        }
Ejemplo n.º 9
0
        private void SetValue_TwoChanges <TValue>(
            TValue defaultValue,
            TValue value1,
            long valueChangeTime1,
            TValue value2,
            long valueChangeTime2,
            IEnumerable <ValueChange <TValue> > expectedValueChanges,
            TValue expectedValueAtStart,
            TValue expectedValueBeforeFirstChange,
            TValue expectedValueAtFirstChange,
            TValue expectedValueAfterFirstChange,
            TValue expectedValueBeforeSecondChange,
            TValue expectedValueAtSecondChange,
            TValue expectedValueAfterSecondChange,
            bool checkValueChangesFirst)
        {
            var valueLine = new ValueLine <TValue>(defaultValue);

            valueLine.SetValue(valueChangeTime1, value1);
            valueLine.SetValue(valueChangeTime2, value2);

            if (checkValueChangesFirst)
            {
                CollectionAssert.AreEqual(expectedValueChanges, valueLine, "Invalid value changes.");
            }

            Assert.AreEqual(expectedValueAtStart, valueLine.GetValueAtTime(0), "Invalid value at start.");
            if (valueChangeTime1 > 0)
            {
                Assert.AreEqual(expectedValueBeforeFirstChange, valueLine.GetValueAtTime(valueChangeTime1 - 1), "Invalid value before first change.");
            }
            Assert.AreEqual(expectedValueAtFirstChange, valueLine.GetValueAtTime(valueChangeTime1), "Invalid value at first change.");
            Assert.AreEqual(expectedValueAfterFirstChange, valueLine.GetValueAtTime(valueChangeTime1 + 1), "Invalid value after first change.");
            if (valueChangeTime2 > 0)
            {
                Assert.AreEqual(expectedValueBeforeSecondChange, valueLine.GetValueAtTime(valueChangeTime2 - 1), "Invalid value before second change.");
            }
            Assert.AreEqual(expectedValueAtSecondChange, valueLine.GetValueAtTime(valueChangeTime2), "Invalid value at second change.");
            Assert.AreEqual(expectedValueAfterSecondChange, valueLine.GetValueAtTime(valueChangeTime2 + 1), "Invalid value after second change.");

            CollectionAssert.AreEqual(expectedValueChanges, valueLine, "Invalid value changes.");
        }
Ejemplo n.º 10
0
        public void Read(TextReader reader)
        {
            string line;

            while ((line = reader.ReadLine()) != null)
            {
                if (line.StartsWith("##", StringComparison.OrdinalIgnoreCase))
                {
                    Match m = Regex.Match(line, @"^##\s+(?'NAME'[^:]+)\s*:\s*(?'VALUE'.*)$", RegexOptions.Compiled);
                    if (m.Success)
                    {
                        ValueLine vl = new ValueLine(m.Groups["NAME"].Value, m.Groups["VALUE"].Value);
                        this.attributes.Add(vl);

                        continue;
                    }
                }

                this.files.Add(line);
            }
        }
Ejemplo n.º 11
0
        public string this[string name]
        {
            get
            {
                ValueLine vl = this.attributes.Find(delegate(ValueLine l) { return l.Name == name; });
                if (vl == null)
                    return null;

                return vl.Value;
            }
            set
            {
                ValueLine vl = this.attributes.Find(delegate(ValueLine l) { return l.Name == name; });
                if (vl == null)
                {
                    vl = new ValueLine(name, value);

                    this.attributes.Add(vl);
                }

                vl.Value = value;
            }
        }
Ejemplo n.º 12
0
 private void BindParameter(ValueLine vl)
 {
     vl.Bind(ValueLine.ItemSourceProperty, "", EnumValues);
     vl.Bind(ValueLine.ValueLineTypeProperty, "ScriptParameter.Type", ParameterType);
 }
Ejemplo n.º 13
0
 public void SetValue(object value, string format = null)
 {
     ValueLine.SetValue(value, format);
 }
Ejemplo n.º 14
0
 public T GetValue <T>()
 {
     return(ValueLine.GetValue <T>());
 }
Ejemplo n.º 15
0
        public void Read(TextReader reader)
        {
            string line;

            while ((line = reader.ReadLine()) != null)
            {
                if (line.StartsWith("##", StringComparison.OrdinalIgnoreCase))
                {
                    Match m = Regex.Match(line, @"^##\s+(?'NAME'[^:]+)\s*:\s*(?'VALUE'.*)$", RegexOptions.Compiled);
                    if (m.Success)
                    {
                        ValueLine vl = new ValueLine(m.Groups["NAME"].Value, m.Groups["VALUE"].Value);
                        this.attributes.Add(vl);

                        continue;
                    }
                }

                this.files.Add(line);
            }
        }