public static String toString(this RecordSetMDEnums.eSchemaType self)
        {
            switch (self)
            {
            case RecordSetMDEnums.eSchemaType.XSD:
                return("XSD");

            case RecordSetMDEnums.eSchemaType.XML:
                return("XML Signature");

            case RecordSetMDEnums.eSchemaType.JSON:
                return("JSON");

            case RecordSetMDEnums.eSchemaType.HDF5:
                return("HDF5 Metadata");

            case RecordSetMDEnums.eSchemaType.DBB:
                return("DBB Layout");

            case RecordSetMDEnums.eSchemaType.XDataMap:
                return("Internally generated RecordSetMD");

            case RecordSetMDEnums.eSchemaType.SQL:
                return("SQL");

            case RecordSetMDEnums.eSchemaType.NamingConvention:
                return("NamingConvention");

            default:
                return("Unknown");
            }
        }
Example #2
0
        public RecordSetMD cAs(RecordSetMDEnums.eType arg, RecordSetMDEnums.eSchemaType schema)
        //throws com.WDataSci.WDS.WDSException
        {
            this.Type       = arg;
            this.SchemaType = schema;
            if (this.SchemaType.bIn(RecordSetMDEnums.eSchemaType.XSD, RecordSetMDEnums.eSchemaType.XML))
            {
                this.SchemaMatter = new __SchemaMatter();
            }
            if (this.ModeMatter == null && this.Mode.Equals(RecordSetMDEnums.eMode.Internal))
            {
                this.ModeMatter = new __ModeMatter();
                this.ModeMatter.bRepeatInputFields = false;
            }
            switch (this.Type)
            {
            //case DBB:
            case RecordSetMDEnums.eType.DBB:
                this.DBBMatter = new WranglerDBB();
                break;

            //case HDF5:
            case RecordSetMDEnums.eType.HDF5:
                if (this.SchemaType.bIn(RecordSetMDEnums.eSchemaType.Unknown))
                {
                    this.SchemaType = RecordSetMDEnums.eSchemaType.HDF5;
                }
                this.FileMatter = new WranglerFlatFile();
                this.DBBMatter  = new WranglerDBB();
                this.HDF5Matter = new WranglerHDF5();
                break;

            //case TXT:
            case RecordSetMDEnums.eType.TXT:
                this.FileMatter     = new WranglerFlatFile();
                this.FileMatter.Dlm = "\t";
                break;

            //case Dlm:
            case RecordSetMDEnums.eType.Dlm:
            //case CSV:
            case RecordSetMDEnums.eType.CSV:
                this.FileMatter     = new WranglerFlatFile();
                this.FileMatter.Dlm = ",";
                break;

            //case XML:
            case RecordSetMDEnums.eType.XML:
            //case JSON:
            case RecordSetMDEnums.eType.JSON:
            //case SQL:
            case RecordSetMDEnums.eType.SQL:
            default:
                throw new WDSException("Error RecordSetMD Type, %s, not implemented yet!");
            }
            return(this);
        }
 public static Boolean bIn(this RecordSetMDEnums.eSchemaType self, params String[] args)
 {
     foreach (String s in args)
     {
         if (self.Equals(eSchemaType_FromAlias(s)))
         {
             return(true);
         }
     }
     return(false);
 }
 public static Boolean bIn(this RecordSetMDEnums.eSchemaType self, params RecordSetMDEnums.eSchemaType[] args)
 {
     foreach (RecordSetMDEnums.eSchemaType arg in args)
     {
         if (self.Equals(arg))
         {
             return(true);
         }
     }
     return(false);
 }
Example #5
0
        public RecordSetMD cAs(RecordSetMDEnums.eType arg, RecordSetMDEnums.eSchemaType schema, Boolean isFileName, String schemadetails)
        //throws com.WDataSci.WDS.WDSException
        {
            this.cAs(arg, schema);
            if (isFileName || (schemadetails != null && schemadetails.Length > 0))
            {
                switch (this.SchemaType)
                {
                //case XSD:
                case RecordSetMDEnums.eSchemaType.XSD:
                    if (isFileName)
                    {
                        String s = com.WDataSci.WDS.Util.FetchFileAsString(schemadetails);
                        //Java this.SchemaMatter.InputSchema = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(s);
                        //C#
                        this.SchemaMatter.InputSchema = new XmlDocument();
                        //C#
                        this.SchemaMatter.InputSchema.LoadXml(s);
                        this.SchemaMatter.InputSchemaFileName = schemadetails;
                        this.SchemaMatter.InputSchemaString   = s;
                    }
                    else
                    {
                        //Java this.SchemaMatter.InputSchema = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(schemadetails);
                        //C#
                        this.SchemaMatter.InputSchema = new XmlDocument();
                        //C#
                        this.SchemaMatter.InputSchema.LoadXml(schemadetails);
                        this.SchemaMatter.InputSchemaString = schemadetails;
                    }
                    break;

                default:
                    break;
                }
            }
            return(this);
        }
        public static int AsInt(this RecordSetMDEnums.eSchemaType self)
        {
            switch (self)
            {
            case RecordSetMDEnums.eSchemaType.XSD: return(1);

            case RecordSetMDEnums.eSchemaType.XML: return(2);

            case RecordSetMDEnums.eSchemaType.JSON: return(3);

            case RecordSetMDEnums.eSchemaType.HDF5: return(4);

            case RecordSetMDEnums.eSchemaType.DBB: return(5);

            case RecordSetMDEnums.eSchemaType.XDataMap: return(6);

            case RecordSetMDEnums.eSchemaType.SQL: return(7);

            case RecordSetMDEnums.eSchemaType.NamingConvention: return(8);

            default: return(0);
            }
        }
Example #7
0
        public static void ImportCSVToXMLMappedList()
        {
            String         sFileName = "test.csv";
            ExcelReference selection;

            MOIE.Application tapp;
            MOIE.Range       trng;
            MOIE.Range       trng2;
            MOIE.Workbook    twb;
            MOIE.Sheets      twbSheets;
            MOIE.Worksheet   tws;
            MOIE.Range       tblr;
            MOIE.ListObject  tbl;
            MOIE.XmlMap      aXmlMap;
            tapp = (ExcelDnaUtil.Application as MOIE.Application);
            Boolean screenupdating_prior = tapp.ScreenUpdating;

            MOIE.XlCalculation calculation_prior = tapp.Calculation;
            RecordSetMD        aRecordSetMD;
            RecordSet          aRecordSet;

            //using isContinuing instead of throwing on last steps
            Boolean isContinuing = true;

            try {
                //tapp.ScreenUpdating = false;
                tapp.Calculation = MOIE.XlCalculation.xlCalculationManual;

                int i, iP1;

                using (OpenFileDialog aOpenFileDialog = new OpenFileDialog()) {
                    aOpenFileDialog.InitialDirectory = tapp.ActiveWorkbook.Path;
                    aOpenFileDialog.Filter           = "CSV Files (*.csv)|*.csv|All Files (*.*)|*.*";
                    aOpenFileDialog.FilterIndex      = 1;
                    aOpenFileDialog.RestoreDirectory = true;
                    aOpenFileDialog.CheckPathExists  = true;
                    aOpenFileDialog.CheckFileExists  = true;
                    aOpenFileDialog.FileName         = sFileName;
                    aOpenFileDialog.AddExtension     = true;
                    aOpenFileDialog.DefaultExt       = ".csv";
                    aOpenFileDialog.Title            = "Import compound data from CSV (*.csv) File....";

                    if (aOpenFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        sFileName = aOpenFileDialog.FileName;
                    }
                    else
                    {
                        isContinuing = false;
                    }
                }

                if (!isContinuing)
                {
                    throw new com.WDataSci.WDS.WDSException("Cancel");
                }

                String aXSDString = XSDUserInput();
                if (aXSDString.Equals("Cancel") || aXSDString.StartsWith("Err"))
                {
                    throw new com.WDataSci.WDS.WDSException(aXSDString);
                }
                Boolean isXSDProvided = aXSDString.StartsWith("<");


                RecordSetMDEnums.eSchemaType aSchemaType = RecordSetMDEnums.eSchemaType.XSD;
                if (!isXSDProvided)
                {
                    aSchemaType = RecordSetMDEnums.eSchemaType.NamingConvention;
                }

                aRecordSetMD = new RecordSetMD(RecordSetMDEnums.eMode.Input)
                               .cAs(RecordSetMDEnums.eType.CSV, aSchemaType, false, aXSDString)
                               .cAsDlmFile(sFileName)
                ;

                MessageBoxButtons msgboxbuttons = MessageBoxButtons.YesNoCancel;
                DialogResult      msgboxresponse;

                msgboxresponse = MessageBox.Show("Does file have a header row (Yes) or (No)?", "Confirm", msgboxbuttons);
                if (msgboxresponse == System.Windows.Forms.DialogResult.Cancel)
                {
                    throw new com.WDataSci.WDS.WDSException("Cancel");
                }
                if (msgboxresponse == System.Windows.Forms.DialogResult.Yes)
                {
                    aRecordSetMD.cWithHeaderRow();
                }

                aRecordSetMD.mReadMapFor(null, null, true);

                aRecordSet = new RecordSet()
                             .cAsInput()
                             .mReadRecordSet(aRecordSetMD)
                ;

                msgboxresponse = MessageBox.Show("Write to a new sheet (Yes) or point to cell for the upper left corder (No)?", "Confirm", msgboxbuttons);
                if (msgboxresponse == System.Windows.Forms.DialogResult.Cancel)
                {
                    throw new com.WDataSci.WDS.WDSException("Cancel");
                }
                if (msgboxresponse == System.Windows.Forms.DialogResult.No)
                {
                    try {
                        selection = (ExcelReference)XlCall.Excel(XlCall.xlfSelection);
                        trng      = tapp.Evaluate(XlCall.Excel(XlCall.xlfReftext, selection, true)) as MOIE.Range;
                        trng2     = tapp.InputBox("Enter cell address (navigable)", "Output Location", trng.Address.ToString(), 100, 100, "", 0, 8) as MOIE.Range;
                        trng      = null;
                        tws       = trng2.Parent;
                        twb       = tws.Parent;
                    }
                    catch {
                        throw new com.WDataSci.WDS.WDSException("Cancel");
                    }
                }
                else
                {
                    twb       = tapp.ActiveWorkbook;
                    twbSheets = twb.Sheets;
                    tws       = twbSheets.Add();
                    twbSheets = null;
                    trng2     = tws.Cells[1, 1];
                    try {
                        tws.Name = sFileName;
                    }
                    catch (Exception e) {
                        String s = tapp.InputBox("Cannot name sheet to " + sFileName, "New Sheet Name", "Leave-As-Is", 100, 100, "");
                        if (!s.Equals("Leave-As-Is"))
                        {
                            try {
                                tws.Name = s;
                            }
                            catch (Exception) {
                            }
                        }
                    }
                }

                //tapp.ScreenUpdating = false;

                int nRows    = aRecordSet.Records.Count;
                int nColumns = aRecordSetMD.nColumns();

                for (uint jj = 0; jj < nColumns; jj++)
                {
                    trng2.Offset[0, jj].Value2 = aRecordSetMD.Column[jj].Name;
                    for (i = 0, iP1 = 1; i < nRows; i++, iP1++)
                    {
                        trng2.Offset[iP1, jj].Value2 = aRecordSet.Records_Orig[i][jj];
                    }
                }

                tblr = tws.Range[trng2, trng2.Offset[nRows, nColumns - 1]];
                tbl  = (MOIE.ListObject)tws.ListObjects.AddEx(MOIE.XlListObjectSourceType.xlSrcRange, tblr, null, MOIE.XlYesNoGuess.xlYes);

                if (aRecordSetMD.SchemaType.bIn(RecordSetMDEnums.eSchemaType.XSD))
                {
                    aXmlMap = twb.XmlMaps.Add(aRecordSetMD.SchemaMatter.InputSchemaString);

                    for (int j = 0, jP1 = 1; j < nColumns; j++, jP1++)
                    {
                        tbl.ListColumns[jP1].XPath.SetValue(aXmlMap
                                                            , "/" + aRecordSetMD.SchemaMatter.RecordSetElementName
                                                            + "/" + aRecordSetMD.SchemaMatter.RecordElementName
                                                            + "/" + aRecordSetMD.Column[j].Name);
                    }
                }

                if (tapp.ScreenUpdating != screenupdating_prior)
                {
                    tapp.ScreenUpdating = screenupdating_prior;
                }
            }
            catch (com.WDataSci.WDS.WDSException e) {
                if (tapp.ScreenUpdating != screenupdating_prior)
                {
                    tapp.ScreenUpdating = screenupdating_prior;
                }
                MessageBox.Show(e.getMessage());
            }
            catch (Exception e) {
                if (tapp.ScreenUpdating != screenupdating_prior)
                {
                    tapp.ScreenUpdating = screenupdating_prior;
                }
                MessageBox.Show(e.Message);
            }
            finally {
                if (tapp.ScreenUpdating != screenupdating_prior)
                {
                    tapp.ScreenUpdating = screenupdating_prior;
                }
                if (tapp.Calculation != calculation_prior)
                {
                    tapp.Calculation = calculation_prior;
                }
                //Queuing up for GC
                aXmlMap      = null;
                aRecordSet   = null;
                aRecordSetMD = null;
                tapp         = null;
                twb          = null;
                twbSheets    = null;
                tws          = null;
                tblr         = null;
                tbl          = null;
                trng         = null;
                trng2        = null;
                selection    = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            return;
        }
 public static Boolean equals(this RecordSetMDEnums.eSchemaType self, RecordSetMDEnums.eSchemaType arg)
 {
     return(self.Equals(arg));
 }