Ejemplo n.º 1
0
        /// <summary>
        /// Convert the specified object to the corresponding MobiusDataType
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>

        public static StringMx ConvertTo(
            object o)
        {
            StringMx sx;

            if (o is StringMx)
            {
                return((StringMx)o);
            }
            else if (NullValue.IsNull(o))
            {
                return(new StringMx());
            }
            else if (o is MobiusDataType)
            {
                MobiusDataType mdt = o as MobiusDataType;
                sx = new StringMx(mdt.ToString());
                mdt.MemberwiseCopy(sx);
                return(sx);
            }
            else
            {
                return(new StringMx(o.ToString()));
            }
        }
Ejemplo n.º 2
0
/// <summary>
/// Get a pair of MobiusDataType objects of the specified type that can be used
/// for comparison to the specified text value. This is useful for comparing
/// decimal numbers for equality.
/// </summary>
/// <param name="type"></param>
/// <param name="textValue"></param>
/// <param name="mdtLow"></param>
/// <param name="mdtHigh"></param>

        public static void GetFuzzyEqualityComparators(
            MetaColumnType type,
            string textValue,
            out MobiusDataType mdtLow,
            out MobiusDataType mdtHigh)
        {
            try
            {
                mdtLow  = MobiusDataType.New(type, textValue);
                mdtHigh = MobiusDataType.New(type, textValue);

                if (MetaColumn.IsDecimalMetaColumnType(type))
                {
                    double e = GetEpsilon(textValue);
                    mdtLow.NumericValue  -= e;
                    mdtHigh.NumericValue += e;
                }
            }
            catch (Exception ex)
            {
                mdtLow  = MobiusDataType.New(type);
                mdtHigh = MobiusDataType.New(type);
            }

            return;
        }
Ejemplo n.º 3
0
/// <summary>
/// Deserialize base of Mobius Data Type
/// </summary>
/// <param name="br"></param>
/// <param name="mdt"></param>

        public static void DeserializeBinary(BinaryReader br, MobiusDataType mdt)
        {
            int nonExistant = br.PeekChar();

            if (nonExistant == NonExistantValueFlag)
            {
                mdt.IsNonExistant = true;
                nonExistant       = br.ReadByte();
            }

            if (br.ReadBoolean())
            {
                mdt.BackColor = Color.FromArgb(br.ReadInt32());
            }
            if (br.ReadBoolean())
            {
                mdt.ForeColor = Color.FromArgb(br.ReadInt32());
            }
            if (br.ReadBoolean())
            {
                mdt.DbLink = br.ReadString();
            }
            if (br.ReadBoolean())
            {
                mdt.Hyperlink = br.ReadString();
            }
        }
Ejemplo n.º 4
0
/// <summary>
/// Binary Deserialize
/// </summary>
/// <param name="br"></param>
/// <returns></returns>

        public static NumberMx DeserializeBinary(BinaryReader br)
        {
            NumberMx nx = new NumberMx();

            MobiusDataType.DeserializeBinary(br, nx);
            nx.Value = br.ReadDouble();
            return(nx);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Binary Deserialize
        /// </summary>
        /// <param name="br"></param>
        /// <returns></returns>

        public static StringMx DeserializeBinary(BinaryReader br)
        {
            StringMx sx = new StringMx();

            MobiusDataType.DeserializeBinary(br, sx);
            sx.Value = br.ReadString();
            return(sx);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Binary Deserialize
        /// </summary>
        /// <param name="br"></param>
        /// <returns></returns>

        public static CompoundId DeserializeBinary(BinaryReader br)
        {
            CompoundId sx = new CompoundId();

            MobiusDataType.DeserializeBinary(br, sx);
            sx.Value = br.ReadString();
            return(sx);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Binary Deserialize
        /// </summary>
        /// <param name="br"></param>
        /// <returns></returns>

        public static DateTimeMx DeserializeBinary(BinaryReader br)
        {
            DateTimeMx dtx = new DateTimeMx();

            MobiusDataType.DeserializeBinary(br, dtx);
            long ticks = br.ReadInt64();

            dtx.Value = new DateTime(ticks);
            return(dtx);
        }
Ejemplo n.º 8
0
/// <summary>
/// Clone
/// </summary>
/// <returns></returns>

        public MobiusDataType Clone()
        {
            MobiusDataType mdt = (MobiusDataType)this.MemberwiseClone();

            if (mdt.MdtExAttr != null)
            {
                mdt.MdtExAttr = MdtExAttr.Clone();
            }
            return(mdt);
        }
Ejemplo n.º 9
0
/// <summary>
/// Convert a MobiusDataType object to the associated primitive type
/// </summary>
/// <param name="vo"></param>
/// <returns></returns>

        public static object ConvertToPrimitiveValue(object vo)
        {
            if (vo == null || vo is DBNull ||             // return as is if not MobiusDataType
                vo.GetType().IsPrimitive || vo is string || vo is DateTime ||
                !vo.GetType().IsSubclassOf(typeof(MobiusDataType)))
            {
                return(vo);
            }

            else             // return associated primitive type
            {
                MobiusDataType mdt = vo as MobiusDataType;
                return(mdt.ToPrimitiveType());
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Get epsilon value for fuzzy numeric comparisons = .5 * 10**(-decimals)
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>

        public double GetNumericValueEpsilon()
        {
            if (MetaColumn == null || !MetaColumn.IsDecimal)
            {
                return(0);
            }

            int decimals = MetaColumn.Decimals;             // default to metacolumn decimals

            if (Decimals >= 0)
            {
                decimals = Decimals;                            // use QC decimals if defined
            }
            double epsilon = MobiusDataType.GetEpsilon(decimals);

            return(epsilon);
        }
Ejemplo n.º 11
0
/// <summary>
/// Try to convert object to a MobiusDataType
/// </summary>
/// <param name="type"></param>
/// <param name="o"></param>
/// <param name="mdt"></param>
/// <returns></returns>

        public static bool TryConvertTo(
            MetaColumnType type,
            object o,
            out MobiusDataType mdt)
        {
            mdt = null;

            try
            {
                mdt = ConvertToMobiusDataType(type, o);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Ejemplo n.º 12
0
/// <summary>
/// Make a memberwise copy of this object onto another existing MobiusDataType
/// </summary>
/// <param name="dest"></param>

        public void MemberwiseCopy(MobiusDataType dest)
        {
            dest._flags    = _flags;          // copy all flags
            dest.DbLink    = DbLink;
            dest.BackColor = BackColor;

            if (MdtExAttr == null)
            {
                dest.MdtExAttr = null;
            }
            else
            {
                dest.MdtExAttr = new MdtExtendedAttributes();
                MdtExAttr.MemberwiseCopy(dest.MdtExAttr);
            }
            return;
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Binary serialize a single Mobius data type object
        /// </summary>
        /// <param name="mdtObject"></param>
        /// <returns></returns>

        public static MobiusDataType DeserializeBinarySingle(
            byte[] ba)
        {
            if (ba == null)
            {
                return(null);
            }

            MemoryStream ms = new MemoryStream(ba);
            BinaryReader br = new BinaryReader(ms);

            object         obj = VoArray.ReadBinaryItem(br);
            MobiusDataType mdt = obj as MobiusDataType;

            br.Close();
            return(mdt);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Binary Deserialize
        /// </summary>
        /// <param name="br"></param>
        /// <returns></returns>

        public static ImageMx DeserializeBinary(BinaryReader br)
        {
            ImageMx ix = new ImageMx();

            MobiusDataType.DeserializeBinary(br, ix);

            if (br.ReadBoolean())
            {
                int          len   = br.ReadInt32();
                byte[]       bytes = br.ReadBytes(len);
                MemoryStream ms    = new MemoryStream(bytes, 0, len);
                ix.Value = new Bitmap(ms);
            }

            ix.Caption = br.ReadString();

            return(ix);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Binary Deserialize
        /// </summary>
        /// <param name="br"></param>
        /// <returns></returns>

        public static QualifiedNumber DeserializeBinary(BinaryReader br)
        {
            QualifiedNumber qn = new QualifiedNumber();

            MobiusDataType.DeserializeBinary(br, qn);

            if (br.ReadBoolean())
            {
                qn.Qualifier = br.ReadString();
            }

            if (br.ReadBoolean())
            {
                qn.NumberValue = br.ReadDouble();
            }

            if (br.ReadBoolean())
            {
                qn.StandardDeviation = br.ReadDouble();
            }

            if (br.ReadBoolean())
            {
                qn.StandardError = br.ReadDouble();
            }

            if (br.ReadBoolean())
            {
                qn.NValue = br.ReadInt32();
            }

            if (br.ReadBoolean())
            {
                qn.NValueTested = br.ReadInt32();
            }

            if (br.ReadBoolean())
            {
                qn.TextValue = br.ReadString();
            }

            return(qn);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Initialize internal match values for a single rule
        /// </summary>
        /// <param name="columnType"></param>

        public void InitializeInternalMatchValues(MetaColumnType columnType)
        {
            OpCode = ConvertOpNameToCode(Op);

            bool calculateEpsilonFromCfValue = false;             // if true use cf value (note: may not be same number of decimals as output format)

            Epsilon = 0;

            if (MetaColumn.IsNumericMetaColumnType(columnType) && !String.IsNullOrEmpty(Value))
            {
                double.TryParse(Value, out ValueNumber);

                if (calculateEpsilonFromCfValue)
                {
                    Epsilon = MobiusDataType.GetEpsilon(Value);
                }

                else
                {
                    int decimals = 10;                     // use default epsilon value
                    Epsilon = MobiusDataType.GetEpsilon(decimals);
                }
            }

            else if (columnType == MetaColumnType.Date && !String.IsNullOrEmpty(Value))
            {
                ValueNormalized = DateTimeMx.Normalize(Value);
            }

            if (MetaColumn.IsNumericMetaColumnType(columnType) && !String.IsNullOrEmpty(Value2))
            {
                double.TryParse(Value2, out Value2Number);
                double e2 = MobiusDataType.GetEpsilon(Value2);
                if (e2 < Epsilon)
                {
                    Epsilon = e2;
                }
            }
            else if (columnType == MetaColumnType.Date && !String.IsNullOrEmpty(Value2))
            {
                Value2Normalized = DateTimeMx.Normalize(Value2);
            }
        }
Ejemplo n.º 17
0
/// <summary>
/// Binary serialize a single Mobius data type object
/// </summary>
/// <param name="mdtObject"></param>
/// <returns></returns>

        public static byte[] SerializeBinarySingle(
            MobiusDataType mdtObject)
        {
            if (mdtObject == null)
            {
                return(new byte[0]);
            }

            MemoryStream ms = new MemoryStream();
            BinaryWriter bw = new BinaryWriter(ms);

            VoArray.WriteBinaryItem(mdtObject, bw);

            bw.Flush();
            byte[] ba = new byte[ms.Length];
            ms.Seek(0, 0);
            ms.Read(ba, 0, (int)ms.Length);
            bw.Close();

            return(ba);
        }
Ejemplo n.º 18
0
/// <summary>
/// Try to create the specifed MobiusDataType from a text string
/// </summary>
/// <param name="type"></param>
/// <param name="textValue"></param>
/// <param name="mdt"></param>
/// <returns></returns>

        public static bool TryParse(
            MetaColumnType type,
            string textValue,
            out MobiusDataType mdt)
        {
            try
            {
                mdt = New(type, textValue);
                if (mdt != null)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                mdt = null;
                return(false);
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Custom compact Deserialization of MobiusDataType
        /// </summary>
        /// <returns></returns>

        public static MobiusDataType Deserialize(string[] sa)
        {
            int sai;

            MobiusDataType mdt  = null;
            char           type = sa[0][0];

            sai = 5;             // first array entry for specific subclass

            switch (type)
            {
            case 'M':                     // ChemicalStructure (Molecule)
                mdt = MoleculeMx.Deserialize(sa, sai);
                break;

            case 'C':                     // CompoundId
                mdt = CompoundId.Deserialize(sa, sai);
                break;

            case 'D':                     // DateTimeEx
                mdt = DateTimeMx.Deserialize(sa, sai);
                break;

            case 'I':                     // ImageEx
                mdt = ImageMx.Deserialize(sa, sai);
                break;

            case 'N':                     //NumberEx
                mdt = NumberMx.Deserialize(sa, sai);
                break;

            case 'Q':                     // QualifiedNumber
                mdt = QualifiedNumber.Deserialize(sa, sai);
                break;

            case 'S':                     // StringEx
                mdt = StringMx.Deserialize(sa, sai);
                break;

            default:
                throw new Exception("Unexpected MobiusDataType: " + type);
            }

            if (!Lex.IsNullOrEmpty(sa[1]))
            {
                mdt.BackColor = Color.FromArgb(int.Parse(sa[1]));
            }

            if (!Lex.IsNullOrEmpty(sa[2]))
            {
                mdt.ForeColor = Color.FromArgb(int.Parse(sa[2]));
            }

            if (!Lex.IsNullOrEmpty(sa[3]))
            {
                mdt.DbLink = sa[3];
            }

            if (!Lex.IsNullOrEmpty(sa[4]))
            {
                mdt.Hyperlink = sa[4];
            }

            return(mdt);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Write out the values for a data row
        /// </summary>
        /// <param name="dr"></param>
        /// <param name="qtMap"></param>
        /// <param name="tw"></param>
        /// <param name="ep"></param>
        /// <param name="outputNValues"></param>
        /// <param name="nValueMetaColumns"></param>
        /// <param name="noDataForTable"></param>
        /// <param name="ti"></param>
        /// <param name="keyValueForRow"></param>

        void WriteRowValues(
            object[] dr,
            QueryTableVoMap qtMap,
            SpotfireDataFileTableWriter tw,
            ExportParms ep,
            bool outputNValues,
            HashSet <MetaColumn> nValueMetaColumns,
            bool noDataForTable = false,
            int ti = 0,
            string keyValueForRow = "")
        {
            QueryColumn qc;
            MetaColumn  mc;
            SpotfireDataFileValueType sdfType;
            QualifiedNumber           qn;
            object vo, vo2;
            double dVal;
            string txt;

            for (int fi = 0; fi < qtMap.SelectedColumns.Count; fi++)
            {
                qc = qtMap.SelectedColumns[fi];
                mc = qc.MetaColumn;

                sdfType = (SpotfireDataFileValueType)qc.SpotfireExportType;

                if (noDataForTable && ti == 0 && qc.IsKey)                 // if this is the root table and no data then supply the row key value
                {
                    vo             = keyValueForRow;
                    noDataForTable = false;                     // now have data
                }

                if (noDataForTable)
                {
                    vo = null;
                }
                else
                {
                    vo = dr[qc.VoPosition];
                }

                bool isNull = NullValue.IsNull(vo);

                if (isNull && (mc.DataType != MetaColumnType.QualifiedNo))                 // write null value (unless QN which may require multiple value writes)
                {
                    WriteValue(tw, sdfType, null);
                }

                else if (mc.DataType == MetaColumnType.Structure)
                {
                    if (vo is MoleculeMx)
                    {
                        string molString = GetMoleculeString(vo, ep.ExportStructureFormat);
                        WriteValue(tw, sdfType, molString);
                    }

                    else
                    {
                        vo2 = MobiusDataType.ConvertToPrimitiveValue(vo, mc);
                        WriteValue(tw, sdfType, vo2);
                    }
                }


                else if (mc.DataType == MetaColumnType.QualifiedNo)                 // write 1-3 values for Qualified number
                {
                    // Output a split QN

                    if (QnSubcolumns.IsSplitFormat(ep.QualifiedNumberSplit))
                    {
                        if (vo is QualifiedNumber && !isNull)                         // regular QN
                        {
                            qn = (QualifiedNumber)vo;
                            WriteValue(tw, SpotfireDataFileValueType.String, qn.Qualifier);                             // qualifier
                            WriteValue(tw, SpotfireDataFileValueType.Double, qn.NumberValue);

                            if (outputNValues && nValueMetaColumns.Contains(mc))
                            {
                                if (NullValue.IsNull(qn.NValueTested))
                                {
                                    WriteValue(tw, SpotfireDataFileValueType.Int, null);                                     // number in calc
                                }
                                else
                                {
                                    WriteValue(tw, SpotfireDataFileValueType.Int, qn.NValueTested);
                                }
                            }
                        }

                        else if (!isNull)                                           // non-qn
                        {
                            WriteValue(tw, SpotfireDataFileValueType.String, null); // qualifier

                            if (QualifiedNumber.TryConvertToDouble(vo, out dVal))
                            {
                                WriteValue(tw, SpotfireDataFileValueType.Double, dVal);
                            }
                            else
                            {
                                WriteValue(tw, SpotfireDataFileValueType.Double, null);
                            }

                            if (outputNValues && nValueMetaColumns.Contains(mc))
                            {
                                WriteValue(tw, SpotfireDataFileValueType.Int, null);                                 // N value
                            }
                        }

                        else                                                        // null value
                        {
                            WriteValue(tw, SpotfireDataFileValueType.String, null); // qualifier
                            WriteValue(tw, SpotfireDataFileValueType.Double, null); // value

                            if (outputNValues && nValueMetaColumns.Contains(mc))
                            {
                                WriteValue(tw, SpotfireDataFileValueType.Int, null);                                 // N value
                            }
                        }
                    }

                    // Output a non-split (combined) QN

                    else                     // combined
                    {
                        if (isNull)
                        {
                            WriteValue(tw, SpotfireDataFileValueType.String, null);
                        }

                        else if (vo is QualifiedNumber && !isNull)                         // regular QN
                        {
                            qn  = (QualifiedNumber)vo;
                            txt = qn.Format(qc, false, mc.Format, mc.Decimals, ep.QualifiedNumberSplit, false);
                            WriteValue(tw, SpotfireDataFileValueType.String, txt);
                        }

                        else if (!isNull)                         // non-qn
                        {
                            txt = vo.ToString();
                            WriteValue(tw, SpotfireDataFileValueType.String, txt);
                        }

                        else                         // null value
                        {
                            WriteValue(tw, SpotfireDataFileValueType.String, null);
                        }
                    }
                }

                else                 // write other types as primitive value for now
                {
                    vo2 = MobiusDataType.ConvertToPrimitiveValue(vo, mc);
                    WriteValue(tw, sdfType, vo2);
                }
            }             // col loop

            return;
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Serialize a DataRow to a StringBuilder object
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>

        public static StringBuilder SerializeToText(
            object[] oa,
            int startPos,
            int length)
        {
            StringBuilder sb = new StringBuilder();

            ConvertMoleculesToChimeStrings(oa);

            for (int vi = startPos; vi < startPos + length; vi++)
            {
                object o = oa[vi];
                if (NullValue.IsNull(o))
                {
                    sb.Append("<>");
                }

                else if (o is MobiusDataType)
                {
                    MobiusDataType mdt = o as MobiusDataType;
                    sb.Append(mdt.Serialize());
                }

                else
                {
                    sb.Append("<");
                    if (o is string)
                    {
                        sb.Append('s');
                        o = MobiusDataType.NormalizeForSerialize(o.ToString());
                    }
                    else if (o is int)
                    {
                        sb.Append('i');
                    }
                    else if (o is float)
                    {
                        sb.Append('f');
                    }
                    else if (o is double)
                    {
                        sb.Append('f');
                    }
                    else if (o is decimal)
                    {
                        sb.Append('f');
                    }
                    else if (o is DateTime)
                    {                     // write datetime as number of ticks
                        sb.Append('d');
                        o = ((DateTime)o).Ticks;
                    }
                    else
                    {
                        throw new Exception("Invalid type: " + o.GetType());
                    }
                    sb.Append(',');
                    sb.Append(o);
                    sb.Append(">");
                }
            }

            return(sb);
        }
Ejemplo n.º 22
0
        }         // WriteMergedSpotfireDataFileForCombinedQueryTables

        /// <summary>
        /// Write results to individual Spotfire text data files
        /// Handles writing of both STDF and SBDF files
        /// </summary>
        /// <param name="query"></param>
        /// <param name="Rows"></param>
        /// <param name="ep"></param>
        /// <returns></returns>

        public string WriteIndividualSpotfireDataFilesForEachQueryTable(

            Query query,
            VoArrayList Rows,
            ExportParms ep)
        {
            QueryTable  qt;
            QueryColumn qc, qcKey;
            MetaTable   mt;
            MetaColumn  mc, mcKey;
            SpotfireDataFileValueType sdfType;
            object vo, vo2, voKey;
            string outputFile = "", colName = "", molString = "";
            int    gci       = 0;
            int    fileCount = 0;
            int    rowCount  = 0;

            Sff = SpotfireFileFormat.Text;
            if (ep.ExportFileFormat == ExportFileFormat.Sbdf)
            {
                Sff = SpotfireFileFormat.Binary;
            }

            string baseOutputFileName = ep.OutputFileName;
            bool   outputNValues      = QnSubcolumns.NValueIsSet(ep.QualifiedNumberSplit);
            HashSet <MetaColumn> nValueMetaColumns = new HashSet <MetaColumn>();

            string extraColNameSuffix = ColumnMapParms.SpotfireExportExtraColNameSuffix;

            QueryResultsVoMap voMap = QueryResultsVoMap.BuildFromQuery(query, includeKeyColsForAllTables: true);

            string baseStub = "";
            int    i1       = baseOutputFileName.IndexOf('.');

            if (i1 >= 0)
            {
                baseStub = baseOutputFileName.Substring(0, i1);
            }

            else
            {
                baseStub = baseOutputFileName;
            }

            // Process each table

            for (int ti = 0; ti < voMap.Tables.Count; ti++)
            {
                QueryTableVoMap qtMap = voMap.Tables[ti];
                qt    = qtMap.Table;
                mt    = qt.MetaTable;
                mcKey = mt.KeyMetaColumn;
                qcKey = qt.KeyQueryColumn;

                outputFile = Lex.Replace(baseOutputFileName, baseStub, baseStub + "_" + mt.Name);                 // append meta table name to stub to get name of file to output

                //if (TextFormat)
                //{
                //	if (!Lex.EndsWith(outputFile, ".txt")) outputFile += ".txt"; // needed for IIS use
                //}
                //else if (!Lex.EndsWith(outputFile, ".bin")) outputFile += ".bin"; // needed for IIS use

                SpotfireDataFileMetadataBuilder mdb = new SpotfireDataFileMetadataBuilder(Sff);

                for (int fi = 0; fi < qtMap.SelectedColumns.Count; fi++)
                {
                    qc = qtMap.SelectedColumns[fi];
                    mc = qc.MetaColumn;

                    sdfType = GetSpotfireDataFileType(mc);
                    qc.SpotfireExportType = sdfType;
                    colName = mt.Name + "." + mc.Name;                     // use internal mt.mc name

                    AddMetadataForColumn(qc, colName, extraColNameSuffix, mdb, ep, nValueMetaColumns);
                }

                SpotfireDataFileTableMetadata tableMetaData = mdb.Build();                 // do build of metadata

                // Write out the data for the table

                FileUtil.DeleteFile(outputFile);
                SpotfireDataFileTableWriter tw = new SpotfireDataFileTableWriter(outputFile, tableMetaData);

                for (int dri = 0; dri < Rows.TotalRowCount; dri++)
                {
                    object[] dr = Rows[dri];

                    int qcKeyValueVoPos = qcKey.VoPosition;

                    voKey = dr[qcKeyValueVoPos];                     // get key value for row for this QueryTable
                    if (voKey == null)
                    {
                        continue;
                    }
                    voKey = MobiusDataType.ConvertToPrimitiveValue(voKey, mcKey);
                    if (NullValue.IsNull(voKey))
                    {
                        continue;                                              // if key not defined then don't write anything for the row
                    }
                    WriteRowValues(dr, qtMap, tw, ep, outputNValues, nValueMetaColumns);

                    rowCount++;
                    WriteValue(tw, null, null); // write end of line as appropriate
                }                               // row loop

                tw.Close();

                fileCount++;
            }             // table loop

            string response;

            if (fileCount == 1)
            {
                response =
                    "Data exported to file: " + outputFile + "\r\n";
            }

            else
            {
                response =
                    "Data exported to folder: " + baseOutputFileName + "\r\n" +
                    "- DataTable files: " + fileCount + "\r\n";
            }

            response +=
                "- Data rows: " + rowCount;

            return(response);
        }         // WriteIndividualSpotfireDataFilesForEachQueryTable
Ejemplo n.º 23
0
        /// <summary>
        /// Deserialize a string format DataRow value object array
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>

        public static object[] DeserializeText(
            string content)
        {
            string[] sa;
            string   vos;
            int      voi = 0, sai = 0;

            int cnt = Lex.CountCharacter(content, '>');

            object[] oa = new object[cnt];
            int      ltbrk = 0, rtbrk = 0;

            try
            {
                for (voi = 0; voi < cnt; voi++)
                {
                    for (rtbrk = ltbrk + 1; rtbrk < content.Length; rtbrk++)
                    {
                        if (content[rtbrk] == '>')
                        {
                            break;
                        }
                    }

                    vos   = content.Substring(ltbrk + 1, rtbrk - ltbrk - 1);
                    ltbrk = rtbrk + 1;                     // move to next
                    if (vos.Length == 0)
                    {
                        continue;                                      // null
                    }
                    sa = vos.Split(',');

                    for (sai = 0; sai < sa.Length; sai++)                     // convert back to original form
                    {
                        sa[sai] = MobiusDataType.DenormalizeForDeserialize(sa[sai]);
                    }

                    char type = sa[0][0];
                    switch (type)
                    {
                    case 's':                             // string
                        oa[voi] = sa[1];
                        break;

                    case 'i':                             // integer
                        oa[voi] = int.Parse(sa[1]);
                        break;

                    case 'f':                             // double
                        oa[voi] = double.Parse(sa[1]);
                        break;

                    case 'd':                             // date time - stored as tick count
                        long ticks = long.Parse(sa[1]);
                        oa[voi] = new DateTime(ticks);
                        break;

                    default:
                        oa[voi] = MobiusDataType.Deserialize(sa);
                        break;
                    }
                }

                //if (oa[0] == "02507049") oa = oa; // debug
            }

            catch (Exception ex)
            {
                string msg = "Deserialization error at position: " + voi + ", " + sai + " for string:\n\n" +
                             content + "\n\n" + DebugLog.FormatExceptionMessage(ex);

                //ServicesLog.Message(msg);
                throw new Exception(msg, ex);
            }

            return(oa);
        }