Beispiel #1
0
        private DocumentValue ConvertDocument(XmlDocument doc)
        {
            var result = new DocumentValue();

            ConvertElement(result, doc.DocumentElement);
            return(result);
        }
        //=============================

        public void Load(string filename)
        {
            Clear();
            //
            using (FileStream stream = File.Open(filename, FileMode.Open, FileAccess.Read))
                using (StreamReader reader = new StreamReader(stream, true)) {
                    double length = (double)stream.Length;
                    //
                    string        line;
                    double        p;
                    DocumentValue value;
                    while ((line = reader.ReadLine()) != null)
                    {
                        value = new DocumentValue();
                        value.FromString(line, ' ');
                        items.Add(value);
                        //
                        if (length > 0)
                        {
                            p = stream.Position / length;
                            invokeProgressChanged(p);
                        }
                    }
                }
        }
Beispiel #3
0
        //=============================

        public DocumentValue Clone()
        {
            DocumentValue item = new DocumentValue();

            item.Key   = Key;
            item.Value = Value;
            return(item);
        }
Beispiel #4
0
        private void ConvertElement(DocumentValue parent, XmlElement element)
        {
            var tagName = element.Name;

            // cater for repeated elements
            if (parent.HasMember(tagName))
            {
                ConvertListElement(parent, tagName, element);
            }
            else
            {
                parent.SetMember(tagName, ConvertElementValue(element));
            }
        }
Beispiel #5
0
        private static IValue ConvertDocument(Context context, Object value, Type type, IType returnType)
        {
            if ((returnType == DocumentType.Instance || returnType == AnyType.Instance) && value is IDictionary <string, object> )
            {
                IDictionary <string, object> dict = (IDictionary <string, object>)value;
                DocumentValue doc = new DocumentValue();
                foreach (KeyValuePair <string, object> kvp in dict)
                {
                    doc.SetMemberValue(context, kvp.Key, ConvertCSharpValueToPromptoValue(context, kvp.Value, null, AnyType.Instance));
                }
                return(doc);
            }

            return(null);
        }
Beispiel #6
0
        public override IValue ReadJSONValue(Context context, JToken value, Dictionary <String, byte[]> parts)
        {
            if (!(value is JObject))
            {
                throw new InvalidDataException("Expecting a JSON object!");
            }
            JObject       obj      = (JObject)value;
            DocumentValue instance = new DocumentValue();

            foreach (KeyValuePair <String, JToken> prop in obj)
            {
                IValue item = ReadJSONField(context, prop.Value, parts);
                instance.SetMemberValue(context, prop.Key, item);
            }
            return(instance);
        }
Beispiel #7
0
        public void testEmptyValue()
        {
            String csv = "\"id\",\"name\"\n,\"John\"\n2,\n";
            IEnumerator <DocumentValue> iter = CSVReader.iterator(csv, null, ',', '"');

            Assert.IsTrue(iter.MoveNext());
            DocumentValue doc = iter.Current;

            Assert.IsNotNull(doc);
            Assert.AreEqual(doc.GetMember("id", false), NullValue.Instance);
            Assert.AreEqual(doc.GetMember("name", false), "John");
            Assert.IsTrue(iter.MoveNext());
            doc = iter.Current;
            Assert.IsNotNull(doc);
            Assert.AreEqual(doc.GetMember("id", false), "2");
            Assert.AreEqual(doc.GetMember("name", false), NullValue.Instance);
        }
Beispiel #8
0
        public void testEscapeNoQuotes()
        {
            String csv = "id,name\n1,John\n2,Riou\\, Sylvie\n";
            IEnumerator <DocumentValue> iter = CSVReader.iterator(csv, null, ',', '"');

            Assert.IsTrue(iter.MoveNext());
            DocumentValue doc = iter.Current;

            Assert.IsNotNull(doc);
            Assert.AreEqual(doc.GetMember("id", false), "1");
            Assert.AreEqual(doc.GetMember("name", false), "John");
            Assert.IsTrue(iter.MoveNext());
            doc = iter.Current;
            Assert.IsNotNull(doc);
            Assert.AreEqual(doc.GetMember("id", false), "2");
            Assert.AreEqual(doc.GetMember("name", false), "Riou, Sylvie");
        }
Beispiel #9
0
        public void testQuotedInnerNewLine()
        {
            String csv = "id,name\n1,\"Jo\nhn\"\n2,Sylvie\n";
            IEnumerator <DocumentValue> iter = CSVReader.iterator(csv, null, ',', '"');

            Assert.IsTrue(iter.MoveNext());
            DocumentValue doc = iter.Current;

            Assert.IsNotNull(doc);
            Assert.AreEqual(doc.GetMember("id", false), "1");
            Assert.AreEqual(doc.GetMember("name", false), "Jo\nhn");
            Assert.IsTrue(iter.MoveNext());
            doc = iter.Current;
            Assert.IsNotNull(doc);
            Assert.AreEqual(doc.GetMember("id", false), "2");
            Assert.AreEqual(doc.GetMember("name", false), "Sylvie");
        }
Beispiel #10
0
        private void ConvertListElement(DocumentValue parent, String tagName, XmlElement element)
        {
            ListValue list    = null;
            var       current = parent.GetMember(tagName, false);

            if (current is ListValue)
            {
                list = (ListValue)current;
            }
            else
            {
                list = new ListValue(AnyType.Instance);
                list.Add(current);
                parent.SetMember(tagName, list);
            }
            list.Add(ConvertElementValue(element));
        }
Beispiel #11
0
        public override IValue interpret(Context context)
        {
            List <object> toDelete = null;

            if (deletables != null)
            {
                toDelete = new List <object>();
                deletables.ForEach((exp) => CollectDeletables(context, exp, toDelete));
            }
            List <IStorable> toStore = null;

            if (storables != null)
            {
                toStore = new List <IStorable>();
                storables.ForEach((exp) => CollectStorables(context, exp, toStore));
            }
            if (deletables != null || storables != null)
            {
                IAuditMetadata withMeta = null;
                if (metadata != null)
                {
                    IValue value = metadata.interpret(context);
                    if (value is DocumentValue)
                    {
                        DocumentValue doc = (DocumentValue)value;
                        withMeta = DataStore.Instance.NewAuditMetadata();
                        foreach (String name in doc.GetMemberNames())
                        {
                            value          = doc.GetMemberValue(context, name, false);
                            withMeta[name] = value.GetStorableData();
                        }
                    }
                }
                DataStore.Instance.DeleteAndStore(toDelete, toStore, withMeta);
            }
            if (andThen != null)
            {
                andThen.interpret(context);
            }
            return(null);
        }
Beispiel #12
0
        private void ProcessDecimalValues(string versionHistoryXmlValue, object coupledDataColumnValue)
        {
            var documentValue = (decimal)coupledDataColumnValue;

            DocumentValue = documentValue.ToString();

            var decimalSeparator = NumberFormatInfo.CurrentInfo.CurrencyDecimalSeparator;
            var position         = DocumentValue.IndexOf(decimalSeparator);
            var precision        = (position == -1) ? 0 : DocumentValue.Length - position - 1;

            var versionHistoryValue = decimal.Parse(versionHistoryXmlValue);

            var formatting = "0.";

            for (int i = 0; i < precision; i++)
            {
                formatting += "0";
            }

            VersionHistoryValue = versionHistoryValue.ToString(formatting);
        }
Beispiel #13
0
        private IValue ConvertElementValue(XmlElement element)
        {
            var hasAttributes = keepAttributes && element.Attributes.Count > 0;
            var hasChildren   = ElementHasChildren(element);

            if (hasAttributes || hasChildren)
            {
                DocumentValue result = new DocumentValue();
                if (keepAttributes)
                {
                    foreach (XmlAttribute a in element.Attributes)
                    {
                        result.SetMember("@" + a.Name, new TextValue(a.InnerText));
                    }
                }
                if (hasChildren)
                {
                    foreach (var node in element.ChildNodes)
                    {
                        if (node is XmlElement)
                        {
                            ConvertElement(result, (XmlElement)node);
                        }
                    }
                }
                else
                {
                    result.SetMember("$value", new TextValue(element.InnerText));
                }
                return(result);
            }
            else
            {
                return(new TextValue(element.InnerText));
            }
        }
Beispiel #14
0
        private static IDictionary <object, object> convertDocument(DocumentValue value)
        {
            IDictionary <string, IValue> dict = (IDictionary <string, IValue>)value.GetStorableData();

            return(dict.ToDictionary(x => (object)x.Key, x => convert(x.Value)));
        }
Beispiel #15
0
        public override IValue interpret(Context context)
        {
            CategoryDeclaration cd = context.getRegisteredDeclaration <CategoryDeclaration>(this.type.GetTypeName());

            if (cd == null)
            {
                throw new SyntaxError("Unknown category " + this.type.GetTypeName());
            }
            checkFirstHomonym(context, cd);
            IInstance instance = type.newInstance(context);

            instance.setMutable(true);
            try
            {
                if (copyFrom != null)
                {
                    Object copyObj = copyFrom.interpret(context);
                    if (copyObj is IInstance)
                    {
                        IInstance copyInstance = (IInstance)copyObj;
                        foreach (String name in copyInstance.GetMemberNames())
                        {
                            if (name == "dbId")
                            {
                                continue;
                            }
                            else if (cd.hasAttribute(context, name))
                            {
                                IValue value = copyInstance.GetMemberValue(context, name, false);
                                if (value != null && value.IsMutable() && !this.type.Mutable)
                                {
                                    throw new NotMutableError();
                                }
                                instance.SetMemberValue(context, name, value);
                            }
                        }
                    }
                    else if (copyObj is DocumentValue)
                    {
                        DocumentValue copyDoc = (DocumentValue)copyObj;
                        foreach (String name in copyDoc.GetMemberNames())
                        {
                            if (name == "dbId")
                            {
                                continue;
                            }
                            else if (cd.hasAttribute(context, name))
                            {
                                IValue value = copyDoc.GetMemberValue(context, name, false);
                                if (value != null && value.IsMutable() && !this.type.Mutable)
                                {
                                    throw new NotMutableError();
                                }
                                // TODO convert to attribute type, see Java version
                                instance.SetMemberValue(context, name, value);
                            }
                        }
                    }
                }
                if (arguments != null)
                {
                    foreach (Argument argument in arguments)
                    {
                        IValue value = argument.getExpression().interpret(context);
                        if (value != null && value.IsMutable() && !this.type.Mutable)
                        {
                            throw new NotMutableError();
                        }
                        instance.SetMemberValue(context, argument.GetName(), value);
                    }
                }
            }
            finally
            {
                instance.setMutable(this.type.Mutable);
            }
            return(instance);
        }
Beispiel #16
0
 internal DocumentContext(DocumentValue document)
 {
     this.document = document;
 }
Beispiel #17
0
 public Context newDocumentContext(DocumentValue document, bool isChild)
 {
     return(initInstanceContext(new DocumentContext(document), isChild));
 }
        /// <summary>
        /// Creats the section of document with diagram
        /// </summary>
        /// <param name="title">Title of the diagram</param>
        /// <param name="resultsInPoints"> Result in point collection</param>
        /// <param name="resultTypes">The type of results that will be displayed in the diagram.</param>
        /// <param name="document">Active Revit document</param>
        /// <param name="elementType">Structural element type</param>
        /// <param name="reversedAxis">Sets the direction of the Y axis on the graph</param>
        /// <returns>Returns section of document with diagram</returns>
        private DocumentDiagram CreateResultDiagramForLinearElements(String title, IEnumerable <ResultInPointLinear> resultsInPoints, List <ResultTypeLinear> resultTypes, Autodesk.Revit.DB.Document document, ElementType elementType, bool reversedAxis)
        {
            Units           units = document.GetUnits();
            DocumentDiagram chart = new DocumentDiagram();

            if (resultTypes != null)
            {
                if (resultTypes.Count() > 0)
                {
                    if (title.Length != 0)
                    {
                        chart.Title = title;
                    }
                    chart.Height = 200;
                    chart.Width  = 4 * chart.Height;

                    UnitType        unitTypeX                = ResultTypeLinear.X.GetUnitType();
                    FormatOptions   formatOptions            = units.GetFormatOptions(unitTypeX);
                    DisplayUnitType displayUnitTypeX         = formatOptions.DisplayUnits;
                    DisplayUnitType internalDisplayUnitTypeX = UnitsConverter.GetInternalUnit(unitTypeX);
                    UnitSymbolType  unitSymbolTypeX          = formatOptions.UnitSymbol;
                    String          axisTitle                = "";
                    if (ElementType.Column == elementType)
                    {
                        axisTitle = Resources.ResourceManager.GetString("AxisHeight");
                    }
                    else
                    {
                        axisTitle = Resources.ResourceManager.GetString("AxisLength");
                    }
                    if (UnitSymbolType.UST_NONE != unitSymbolTypeX)
                    {
                        axisTitle += " " + LabelUtils.GetLabelFor(unitSymbolTypeX);
                    }
                    chart.AxisX.Title    = axisTitle;
                    chart.AxisY.Reversed = reversedAxis;
                    UnitType unitTypeY = resultTypes.First().GetUnitType();
                    formatOptions = units.GetFormatOptions(unitTypeY);
                    DisplayUnitType displayUnitTypeY         = formatOptions.DisplayUnits;
                    DisplayUnitType internalDisplayUnitTypeY = UnitsConverter.GetInternalUnit(unitTypeY);
                    UnitSymbolType  unitSymbolTypeY          = formatOptions.UnitSymbol;
                    switch (unitTypeY)
                    {
                    case UnitType.UT_Reinforcement_Area:
                        axisTitle = Resources.ResourceManager.GetString("AxisArea");
                        break;

                    case UnitType.UT_Force:
                        axisTitle = Resources.ResourceManager.GetString("AxisForce");
                        break;

                    case UnitType.UT_Moment:
                        axisTitle = Resources.ResourceManager.GetString("AxisMoment");
                        break;

                    case UnitType.UT_Displacement_Deflection:
                        axisTitle = Resources.ResourceManager.GetString("AxisDisplacmentDeflection");
                        break;

                    case UnitType.UT_Section_Dimension:
                        axisTitle = Resources.ResourceManager.GetString("AxisSpacing");
                        break;

                    case UnitType.UT_Reinforcement_Area_per_Unit_Length:
                        axisTitle = Resources.ResourceManager.GetString("AxisDencity");
                        break;

                    default:
                        break;
                    }
                    axisTitle += " ";
                    if (UnitSymbolType.UST_NONE == unitSymbolTypeY)
                    {
                        if (DisplayUnitType.DUT_FEET_FRACTIONAL_INCHES == displayUnitTypeY)
                        {
                            axisTitle += LabelUtils.GetLabelFor(UnitSymbolType.UST_FT);
                        }
                        else if (DisplayUnitType.DUT_FRACTIONAL_INCHES == displayUnitTypeY)
                        {
                            axisTitle += LabelUtils.GetLabelFor(UnitSymbolType.UST_IN);
                        }
                    }
                    else
                    {
                        axisTitle += LabelUtils.GetLabelFor(unitSymbolTypeY);
                    }
                    chart.AxisY.Title = axisTitle;
                    double valX = 0;
                    double valY = 0;
                    foreach (ResultTypeLinear resultType in resultTypes)
                    {
                        DocumentDiagramSeries series = new DocumentDiagramSeries(resultType.ToString());
                        chart.Legend = true;
                        chart.Series.Add(series);
                        series.Color = ResultTypeLinearToColorDictionary[resultType];
                        series.Name  = Resources.ResourceManager.GetString(resultType.ToString());
                        int lblNbr  = 5;
                        int lblN    = 0;
                        int lblStep = resultsInPoints.Count <ResultInPointLinear>() / lblNbr;
                        // Labels on the X axis will be formatted according to Revit preferences
                        //formatOptions = units.GetFormatOptions(unitTypeX);
                        //string accuracy = formatOptions.Accuracy.ToString();
                        //accuracy = accuracy.Replace("1", "0");
                        string valXAsString = "";
                        foreach (ResultInPointLinear resultInPoint in resultsInPoints)
                        {
                            valX = Autodesk.Revit.DB.UnitUtils.Convert(resultInPoint[ResultTypeLinear.X], internalDisplayUnitTypeX, displayUnitTypeX);
                            valY = Autodesk.Revit.DB.UnitUtils.Convert(resultInPoint[resultType], internalDisplayUnitTypeY, displayUnitTypeY);
                            series.AddXY(valX, valY);
                            if (lblStep == 0 || lblN % lblStep == 0)
                            {
                                //DocumentValue docVal = new DocumentValue(resultInPoint[ResultTypeLinear.X], displayUnitTypeX, unitTypeX, units);
                                DocumentValue docVal = new DocumentValue(valX, displayUnitTypeX, unitTypeX, units);
                                valXAsString = (string)docVal.Value;
                                chart.AxisX.Labels.Add(new DocumentDiagramAxisLabel(valX, valXAsString));
                            }
                            lblN++;
                        }
                    }
                }
            }
            return(chart);
        }