Пример #1
0
        /// <summary>
        /// Open an Excel file
        /// </summary>
        /// <param name="fileName"></param>

        public static void Open(string fileName)
        {
            if (LogCalls)
            {
                DebugLog.Message("ExcelOp Open " + fileName);
            }

            if (!File.Exists(fileName))
            {
                throw new Exception("File doesn't exist: " + fileName);
            }

            ReleaseObject(XlBook);
            XlBook = XlBooks.Open(Filename: fileName);
            //XlBook = XlBooks.Add(); // start new WorkBook rather than opening existing file

            if (XlBook == null)
            {
                throw new Exception("Error opening workBook: " + fileName);
            }

            ReleaseObject(XlSheet);
            XlSheet = (_Worksheet)XlApp.ActiveSheet;
            if (XlSheet == null)
            {
                throw new Exception("Error getting active sheet");
            }

            if (Lex.EndsWith(fileName, ".csv"))
            {
                XlSheet.Name = "Sheet1";                                             // set normal sheet name if opening .csv file
            }
            return;
        }
Пример #2
0
        /// <summary>
        /// Create MetaTable from template
        /// </summary>

        public MetaTable GetMetaTable(
            string mtName)
        {
            if (!Lex.StartsWith(mtName, UnpivotedAssayView.UnsummarizedMetaTableName))
            {
                return(null);
            }

            MetaTable mt0 = MetaTableCollection.Get(UnpivotedAssayView.UnsummarizedMetaTableName + "_TEMPLATE");             // get template metatable

            if (mt0 == null)
            {
                return(null);
            }

            MetaTable mt = mt0.Clone();

            string labelSuffix = "";             // default to integrated view of these

            mt.Label += labelSuffix;

            List <MetaColumn> mcList = new List <MetaColumn>();

// Build summarized version of table

            if (Lex.EndsWith(mtName, MetaTable.SummarySuffix))             // summarized version
            {
                mt.Name              = mtName;
                mt.Label            += " Summary";
                mt.UseSummarizedData = true;

                foreach (MetaColumn mc in mt.MetaColumns)
                {
                    if (mc.SummarizedExists)
                    {
                        mcList.Add(mc);
                    }
                }

                mt.MetaColumns = mcList;
                return(mt);
            }

            // Build unsummarized version of table

            else
            {
                mt.Name = mtName;
                foreach (MetaColumn mc in mt.MetaColumns)
                {
                    if (mc.UnsummarizedExists)
                    {
                        mcList.Add(mc);
                    }
                }

                mt.MetaColumns = mcList;
                return(mt);
            }
        }
Пример #3
0
/// <summary>
/// Export to csv or text file
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>

        private void ExportTextFileMenuItem_Click(object sender, EventArgs e)
        {
            CsvExportOptions ceo;           // Can specify separator
            TextExportMode   tem;           // Value or Text
            PdfExportOptions peo;

            if (Lex.IsNullOrEmpty(TextFileName))
            {
                TextFileName = ClientDirs.DefaultMobiusUserDocumentsFolder;
            }

            string filter =
                "CSV (Comma delimited)(*.csv)|*.csv|" +
                "Text (Tab delimited)(*.txt)|*.txt";
            string fileName = UIMisc.GetSaveAsFilename("CSV / Text File Name", TextFileName, filter, ".csv");

            if (Lex.IsNullOrEmpty(fileName))
            {
                return;
            }
            TextFileName = fileName;

            if (Lex.EndsWith(fileName, ".csv"))
            {
                PivotGridPanel.PivotGrid.ExportToCsv(TextFileName);
            }

            else
            {
                PivotGridPanel.PivotGrid.ExportToText(TextFileName);
            }

            return;
        }
Пример #4
0
        /// <summary>
        /// Return true if unpivoted summarized MultiDb table name
        /// </summary>
        /// <param name="mtName"></param>
        /// <returns></returns>

        public static bool IsUnpivotedSummarizedMdbAssayTable(string mtName)
        {
            if (Lex.EndsWith(mtName, "_NZ"))
            {
                mtName = mtName.Substring(0, mtName.Length - 3);                                          // Netezza fix
            }
            return(Lex.Eq(mtName, MultiDbAssayDataNames.BaseTableName) || Lex.Eq(mtName, MultiDbAssayDataNames.CombinedTableName));
        }
Пример #5
0
        /// <summary>
        /// IsRnaString
        /// </summary>
        /// <param name="seq"></param>
        /// <returns></returns>

        public static bool IsRnaString(string seq)
        {
            if (Lex.StartsWith(seq, "RNA1") && Lex.EndsWith(seq, "$"))             // Helm form?
            {
                return(true);
            }

            else
            {
                return(false);             // todo: check for sequence & fasta form
            }
        }
Пример #6
0
        /// <summary>
        /// Lookup a MetaTable by name throwing any exceptions from underlying factories
        /// </summary>
        /// <param name="name"></param>
        /// <returns>MetaTable or null if not found</returns>
        ///

        public MetaTable GetMetaTable(
            String name)
        {
            MetaTable mt;

            if (RestrictedMetaTables.MetatableIsRestricted(name))
            {
                return(null);
            }

            if (RestrictedMetatable.MetatableIsGenerallyRestricted(name))
            {
                return(null);
            }

            name = name.Trim().ToUpper();

            if (MetaTableCollection.TableMap.ContainsKey(name))
            {             // see if in collection already
                mt = MetaTableCollection.TableMap[name];
                return(mt);
            }

            for (int i1 = 0; i1 < MetaFactories.Count; i1++)
            {
                MetaTableFactoryRef mtfr = MetaFactories[i1];
                mt = mtfr.MetaTableFactory.GetMetaTable(name);

                if (mt != null)
                {
                    NormalizeMetaTable(mt);
                    return(mt);
                }
            }

            // Check to see if this is a summary table that can be created from an unsummarized version of itself

            if (!Lex.EndsWith(name, MetaTable.SummarySuffix))
            {
                return(null);                                                          // see if named as summary table
            }
            string    name2 = name.Substring(0, name.Length - MetaTable.SummarySuffix.Length);
            MetaTable mt2   = MetaTableCollection.Get(name2);

            if (mt2 == null || !mt2.SummarizedExists)
            {
                return(null);
            }
            mt = mt2.Clone();
            AdjustForSummarization(mt, true);
            return(mt);
        }
Пример #7
0
        /// <summary>
        /// Adjust metatable to contain proper summarized or unsummarized columns
        /// </summary>
        /// <param name="mt"></param>
        /// <param name="summarized"></param>

        public static void AdjustForSummarization(
            MetaTable mt,
            bool summary)
        {
            mt.UseSummarizedData = summary;

            if (summary)
            {
                if (!Lex.EndsWith(mt.Name, MetaTable.SummarySuffix))
                {
                    mt.Name += MetaTable.SummarySuffix;                     // be sure name indicates summary
                }
                if (!Lex.EndsWith(mt.Label, " Summary"))
                {
                    mt.Label += " Summary";                     // be sure label indicates summary
                }
            }

            int mci = 0;

            while (mci < mt.MetaColumns.Count)
            {
                MetaColumn mc = mt.MetaColumns[mci];
                //if (mc.ResultCode == "103468") mc = mc; // debug

                if (summary)
                {
                    if (mc.SummarizedExists)
                    {
                        mci++;
                    }
                    else
                    {
                        mt.MetaColumns.RemoveAt(mci);
                    }
                }

                else
                {
                    if (mc.UnsummarizedExists)
                    {
                        mci++;
                    }
                    else
                    {
                        mt.MetaColumns.RemoveAt(mci);
                    }
                }
            }

            return;
        }
Пример #8
0
/// <summary>
/// Normalize a temp list name to a form: TEMP_FOLDER.listName
/// </summary>
/// <param name="tempListName"></param>
/// <returns></returns>

        public static string GetInternalTempListName(
            string tempListName)
        {
            tempListName = Lex.RemoveAllQuotes(tempListName);
            if (Lex.EndsWith(tempListName, "Current List"))
            {
                tempListName = Lex.Replace(tempListName, "Current List", "Current");
            }
            if (!Lex.StartsWith(tempListName, UserObject.TempFolderNameQualified))
            {
                tempListName = UserObject.TempFolderNameQualified + tempListName;
            }

            return(tempListName);
        }
Пример #9
0
        static void CheckReferencedAssemblies(
            Assembly assembly,
            HashSet <Assembly> aDict,
            HashSet <string> aNamesTriedDict)
        {
            Assembly a2 = null;

            string dir = Path.GetDirectoryName(assembly.Location) + @"\";

            AssemblyName[] referencedAssemblies = assembly.GetReferencedAssemblies();

            foreach (AssemblyName aName in referencedAssemblies)
            {
                //if (Lex.Contains(aName.FullName, "SimSearchMx")) aNamesTriedDict = aNamesTriedDict; // debug

                if (aNamesTriedDict.Contains(aName.FullName))
                {
                    continue;
                }
                aNamesTriedDict.Add(aName.FullName);

                string aFileName = dir + aName.Name;
                if (!Lex.EndsWith(aFileName, ".dll"))
                {
                    aFileName += ".dll";
                }
                if (!File.Exists(aFileName))
                {
                    continue;
                }

                try { a2 = Assembly.LoadFrom(aFileName); }
                catch (Exception ex) { continue; }

                if (!IsMobiusAssembly(assembly))
                {
                    continue;
                }

                aDict.Add(assembly);

                CheckReferencedAssemblies(a2, aDict, aNamesTriedDict);                 // recur
            }
        }
Пример #10
0
/// <summary>
/// Export to Excel
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>

        private void ExportExcelMenuItem_Click(object sender, EventArgs e)
        {
            XlsxExportOptions xeo;

            if (Lex.IsNullOrEmpty(TextFileName))
            {
                XlsFileName = ClientDirs.DefaultMobiusUserDocumentsFolder;
            }

            string filter =
                "Excel Workbook (*.xlsx)|*.xlsx|" +
                "Excel 97-2003 Workbook (*.xls)|*.xls";
            string fileName = UIMisc.GetSaveAsFilename("Excel File Name", XlsFileName, filter, ".xlsx");

            if (Lex.IsNullOrEmpty(fileName))
            {
                return;
            }
            XlsFileName = fileName;

            if (Lex.EndsWith(fileName, ".xls"))
            {
                PivotGridPanel.PivotGrid.ExportToXls(XlsFileName);
            }

            else
            {
                PivotGridPanel.PivotGrid.ExportToXlsx(XlsFileName);
            }

            string msg =
                "Export to Excel complete.\n" +
                "Do you want to open " + fileName;
            DialogResult dr = MessageBoxMx.Show(msg, UmlautMobius.String,
                                                MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (dr == DialogResult.Yes)
            {
                SystemUtil.StartProcess(fileName);
            }

            return;
        }
Пример #11
0
        /// <summary>
        /// Deserialize the QualifiedNumberSplit settings
        /// </summary>
        /// <param name="txt"></param>
        /// <returns></returns>

        public static QnfEnum DeserializeQualifiedNumberSplit(string txt)
        {
            QnfEnum qnf;

            if (txt == null || txt.Trim().Length == 0)
            {
                return(QnfEnum.Combined);    // not split
            }
            qnf = QnfEnum.Split;             // values should be split

            if (Lex.Contains(txt, "Qualifier"))
            {
                qnf |= QnfEnum.Qualifier;
            }
            if (Lex.Contains(txt, "Number"))
            {
                qnf |= QnfEnum.NumericValue;
            }
            if (Lex.Contains(txt, "SD"))
            {
                qnf |= QnfEnum.StdDev;
            }
            if (Lex.Contains(txt, "SE"))
            {
                qnf |= QnfEnum.StdErr;
            }
            if (Lex.Contains(txt, "N,") || Lex.EndsWith(txt, "N"))
            {
                qnf |= QnfEnum.NValue;
            }
            if (Lex.Contains(txt, "NT"))
            {
                qnf |= QnfEnum.NValueTested;
            }
            if (Lex.Contains(txt, "Text"))
            {
                qnf |= QnfEnum.TextValue;
            }

            return(qnf);
        }
Пример #12
0
/// <summary>
/// Try to parse a user object id from the object name (i.e. ANNOTATION_123)
/// </summary>
/// <param name="internalName"></param>
/// <param name="id"></param>
/// <returns></returns>

        public static bool TryParseObjectIdFromInternalName(
            string internalName,
            out int id)
        {
            id = -1;
            if (Lex.EndsWith(internalName, MetaTable.SummarySuffix))             // remove any summary suffix
            {
                internalName = Lex.Replace(internalName, MetaTable.SummarySuffix, "");
            }
            int i1 = internalName.LastIndexOf("_");             // parse the <Type>_<ObjectId> string

            if (i1 < 0)
            {
                return(false);
            }
            string idString = internalName.Substring(i1 + 1);

            if (!Int32.TryParse(idString, out id))
            {
                return(false);
            }
            return(true);
        }
Пример #13
0
/// <summary>
/// Get primary or secondary key result (Obsolete)
/// </summary>
/// <param name="assayMetadataAssay"></param>
/// <param name="rti"></param>
/// <returns></returns>

        static MetaColumn GetKeyResult(
            AssayDbMetadata assayMetadataAssay,
            MetaTable mt,
            int rti,
            MetaColumn primary)
        {
            Dictionary <string, string> keyTypeDict = new Dictionary <string, string>
            {
                { "Inh", "SP" },
                { "% Inh", "SP" },
                { "Inhibition", "SP" },
                { "% Inhibition", "SP" },
                { "Stim", "SP" },
                { "% Stim", "SP" },
                { "Stimulation", "SP" },
                { "% Stimulation", "SP" },
                { "Pot", "SP" },
                { "Potentiation", "SP" },
                { "IC50", "CRC" },
                { "EC50", "CRC" },
                { "LC50", "CRC" },
                { "Ki", "CRC" },
                { "Kb", "CRC" },
                { "Ka", "CRC" }
            };

            MetaColumn mc      = null;
            bool       isAssay = (assayMetadataAssay != null);

            if (rti == 1)
            {
                mc = mt.PrimaryResult;
            }
            else
            {
                mc = mt.SecondaryResult;
            }

            if (mc != null)             // defined in metatable
            {
                mc = mc.Clone();
                return(mc);
            }

            if (rti == 2)
            {
                return(null);                      // if secondary then dont' try to second-guess the metatable
            }
            // See if CRC or SP in assay label

            string[] concTypes = { "CRC", "SP" };
            string   concType  = "";
            string   n         = mt.Label;

            foreach (string ct0 in concTypes)
            {
                if (Lex.StartsWith(n, ct0 + " ") || Lex.Contains(n, " " + ct0 + " ") || Lex.EndsWith(n, " " + ct0))
                {
                    concType = ct0;
                    break;
                }
            }

            //if (Lex.IsUndefined(type) && assay.CRC) // undefined in assay name but marked as CRC in AssayMetadata?
            //  type = "CRC";

            foreach (MetaColumn mc0 in mt.MetaColumns)             // pick first col with result code (could also check summarization method)
            {
                if (Lex.IsUndefined(mc0.ResultCode))
                {
                    continue;
                }

                mc = mc0;
                break;
            }
            if (mc == null)
            {
                return(null);
            }

            mc = mc.Clone();             // make copy

            if (isAssay)
            {
                Dictionary <int, AssayDbResultType> resultTypeDict = AssayMetadataDao.GetResultTypeDict();

                if (resultTypeDict.ContainsKey(mc.Id) &&                 // if mc is summarized as Log Normal assume CRC
                    Lex.Eq(resultTypeDict[mc.Id].SumMdTxt, "Log Normal"))
                {
                    concType = "CRC";
                }


                else if (Lex.IsUndefined(concType) && assayMetadataAssay.CRC)                 // undefined in assay name but marked as CRC in AssayMetadata?
                {
                    concType = "CRC";
                }
            }

            if (Lex.IsUndefined(concType))             // check exact match with key column names
            {
                foreach (string ktn0 in keyTypeDict.Keys)
                {
                    if (Lex.Eq(mc.Label, ktn0))
                    {
                        concType = keyTypeDict[ktn0];
                        break;
                    }
                }
            }

            if (Lex.IsUndefined(concType))             // check substring match with key column names
            {
                foreach (string ktn0 in keyTypeDict.Keys)
                {
                    if (Lex.StartsWith(mc.Label, ktn0 + " ") || Lex.Contains(mc.Label, " " + ktn0 + " ") || Lex.EndsWith(mc.Label, " " + ktn0))
                    {
                        concType = keyTypeDict[ktn0];
                        break;
                    }
                }
            }

            mc.PrimaryResult   = true;
            mc.SecondaryResult = false;
            mc.SinglePoint     = (concType == "SP");
            mc.MultiPoint      = (concType == "CRC");

            return(mc);
        }
Пример #14
0
        /// <summary>
        /// Load metadata describing dictionaries
        /// </summary>
        /// <param name="dictFileName"></param>
        /// <returns></returns>

        public Dictionary <string, DictionaryMx> LoadDictionaries()
        {
            XmlAttributeCollection atts;

            Dictionaries = new Dictionary <string, DictionaryMx>();

            //UalUtil is assumed to have been initialized
            // and UalUtil.MetaDataDir set
            string       dictFileName = ServicesDirs.MetaDataDir + @"\" + "Dictionaries.xml";
            StreamReader sr           = new StreamReader(dictFileName);
            XmlDocument  doc          = new XmlDocument();

            doc.Load(sr);
            XmlNode dictsNode = doc.FirstChild;

            while (dictsNode != null)
            {
                if (dictsNode.NodeType == XmlNodeType.Element)
                {
                    break;
                }
                dictsNode = dictsNode.NextSibling;
                if (dictsNode == null)
                {
                    throw new Exception("No initial element found");
                }
            }

            if (!Lex.Eq(dictsNode.Name, "Dictionaries"))
            {
                throw new Exception("Expected Dictionaries node: " + dictsNode.Name);
            }

            XmlNode dictNode = dictsNode.FirstChild;

            while (dictNode != null)             // loop through dictionaries
            {
                if (dictNode.NodeType != XmlNodeType.Element)
                {
                    ;                                                         // ignore non-elements
                }
                else if (Lex.Eq(dictNode.Name, "Dictionary"))                 // dictionary element
                {
                    DictionaryMx dict = new DictionaryMx();

                    atts = dictNode.Attributes;
                    for (int i = 0; i < atts.Count; i++)
                    {
                        XmlNode att = atts.Item(i);

                        if (Lex.Eq(att.Name, "Name"))
                        {
                            dict.Name = att.Value.ToLower();
                        }

                        else if (Lex.Eq(att.Name, "Sql"))
                        {
                            dict.Sql = att.Value;
                        }

                        else if (Lex.Eq(att.Name, "Cache"))
                        {
                            bool.TryParse(att.Value, out dict.Cache);
                        }

                        else
                        {
                            DebugLog.Message("Unexpected Dictionary (" + dict.Name + ") attribute: " + att.Name);
                        }
                    }

                    if (dict.Name == "")
                    {
                        throw new Exception("Connection is missing name");
                    }
                    if (Lex.EndsWith(dict.Name, "_cache"))
                    {
                        dict.Cache = true;                                                        // alternate way to indicate cached dictionary (avoid unexpected attribute exception in older clients)
                    }
                    Dictionaries[dict.Name] = dict;

                    XmlNode entryNode = dictNode.FirstChild;
                    while (entryNode != null)                     // loop through dict entries
                    {
                        if (entryNode.NodeType != XmlNodeType.Element)
                        {
                            ;                                                             // ignore non-elements
                        }
                        else if (Lex.Eq(entryNode.Name, "Entry"))                         // word entry
                        {
                            string word = "";
                            string def  = "";
                            atts = entryNode.Attributes;
                            for (int i = 0; i < atts.Count; i++)
                            {
                                XmlNode att = atts.Item(i);

                                if (Lex.Eq(att.Name, "Word"))
                                {
                                    word = att.Value.Trim();
                                }

                                else if (Lex.Eq(att.Name, "Def") ||
                                         Lex.Eq(att.Name, "Definition"))
                                {
                                    def = att.Value.Trim();
                                }

                                else
                                {
                                    DebugLog.Message("Unexpected Dictionary (" + dict.Name + ") entry attribute: " + att.Name);
                                }
                            }

                            if (word == "")
                            {
                                throw new Exception("Dictionary entry is missing Word attribute");
                            }
                            dict.Add(word, def);
                        }

                        else
                        {
                            throw new Exception("Expected Entry element but saw " +
                                                dictNode.Name);
                        }

                        entryNode = entryNode.NextSibling;
                    }                     // end of entry loop
                }

                else
                {
                    throw new Exception("Expected Dictionary element but saw " +
                                        dictNode.Name);
                }

                dictNode = dictNode.NextSibling;
            }             // end of dictionary loop

            sr.Close();

            return(Dictionaries);
        }
Пример #15
0
        /// <summary>
        /// Fill the grid of col defs
        /// </summary>
        /// <param name="mt"></param>
        /// <returns></returns>

        void FillItemDataTable()
        {
            MetaTreeNode mtn;
            string       txt = "", tok, name, label;

            ItemGridDataTable.Rows.Clear();

            List <string>        vList = new List <string>();
            ParsedSingleCriteria psc   = MqlUtil.ParseSingleCriteria(Qc.Criteria);

            if (psc != null)
            {
                if (psc.ValueList != null)
                {
                    vList = psc.ValueList;
                }
                else if (!Lex.IsNullOrEmpty(psc.Value))
                {
                    vList.Add(psc.Value);
                }
            }

            MetaTable  mt          = Qc.MetaColumn.MetaTable;
            MetaColumn mc          = Qc.MetaColumn;
            string     mcDict      = mc.Dictionary;
            bool       searchId    = Lex.EndsWith(mcDict, ".Id");
            bool       searchLabel = Lex.EndsWith(mcDict, ".Label");

            for (int si = 0; si < vList.Count; si++)
            {
                string s = vList[si];
                if (Lex.IsUndefined(s))
                {
                    continue;
                }

                name = label = "";
                if (searchId)                 // assume numeric ASSAY code for metatable for now
                {
                    name = "ASSAY_" + s;
                    mtn  = MetaTree.GetNode(name);                    // try to look up by internal name
                }

                else
                {
                    label = s;
                    mtn   = MetaTree.GetNodeByLabel(label);
                }

                if (mtn != null)
                {
                    name  = mtn.Target;
                    label = mtn.Label;
                }

                DataRow dr = ItemGridDataTable.NewRow();
                dr["LabelColumn"]        = label;
                dr["InternalNameColumn"] = name;

                ItemGridDataTable.Rows.Add(dr);
            }

            return;
        }
Пример #16
0
/// <summary>
/// Look at metatable title for possible CRC / SP assay type
/// </summary>
/// <param name="mt"></param>
/// <returns></returns>

        static string GetAssayConcType(MetaTable mt)
        {
            string[] concTypes = { "CRC", "SP" };
            string   concType  = "";
            string   n         = mt.Label;

            foreach (string ct0 in concTypes)
            {
                if (Lex.StartsWith(n, ct0 + " ") || Lex.Contains(n, " " + ct0 + " ") || Lex.EndsWith(n, " " + ct0))
                {
                    concType = ct0;
                    break;
                }
            }

            return(concType);
        }
Пример #17
0
/// <summary>
/// Get values from form and update criteria in associated QueryColumn
/// </summary>
/// <returns></returns>

        bool UpdateCriteria()
        {
            MetaTable mt;
            string    label, name, listString;
            bool      summary;
            int       tableId;

            DataRowCollection rows = ItemGridDataTable.Rows;
            string            s    = "";
            List <string>     sl2  = new List <string>(new string[] { "", "" });

            foreach (DataRow dr in rows)
            {
                label = sl2[0] = dr["LabelColumn"] as string;
                name  = sl2[1] = dr["InternalNameColumn"] as string;

                if (Lex.IsUndefined(label) && Lex.IsUndefined(name))
                {
                    continue;
                }

                string txt = Csv.JoinCsvString(sl2);
                s += txt + "\r\n";
            }

            List <MetaTableItem> list = MetaTableItem.ParseList(s, true, true);
            string valueList          = "";    // list of values to match in criteria
            string displayList        = "";

            string mcDict      = Qc.MetaColumn.Dictionary;
            bool   searchId    = Lex.EndsWith(mcDict, ".Id");
            bool   searchLabel = Lex.EndsWith(mcDict, ".Label");

            foreach (MetaTableItem mti in list)
            {
                mt = MetaTableCollection.Get(mti.InternalName);
                if (mt == null)
                {
                    continue;
                }

                MetaTable.ParseMetaTableName(mt.Name, out tableId, out summary);

                label = MetaTable.RemoveSuffixesFromName(mt.Label);

                //mtn = MetaTree.GetNode(mti.InternalName); // need to check node name vs target?

                // Append to value list

                if (valueList.Length > 0)
                {
                    valueList += ", ";
                }

                if (searchId)                 // extract numeric id for table if matching against numeric column
                {
                    valueList += tableId.ToString();
                }

                else
                {
                    valueList += Lex.AddSingleQuotes(label);
                }

                // Append to label list

                if (displayList.Length == 0)                 // include first item label only in CriteriaDisplay
                {
                    displayList = label + " - ASSAY: ";
                }
                else
                {
                    displayList += ", ";
                }

                displayList += tableId.ToString();
            }

            if (valueList == "")
            {
                Qc.Criteria = Qc.CriteriaDisplay = "";
            }
            else
            {
                Qc.Criteria        = Qc.MetaColumn.Name + " in (" + valueList + ")";
                Qc.CriteriaDisplay = displayList;
            }

            return(true);
        }
Пример #18
0
        /// <summary>
        /// Build click function and field value text string for output
        /// ClickFunction arguments may be defined in the clickfunction definition including col values
        /// indicated by fieldName.Value in the metacolumn clickfunction definition.
        /// If no args are defined in the clickfunction definition then a field value
        /// argument will be added by default, the keyValue if [keyvalue] or
        /// [rowcol] as a grid row and column to be returned if these appear in the
        /// ClickFunction definition.
        /// </summary>
        /// <param name="rf">Results field to display link for</param>
        /// <param name="vo">Vo contain tuple values</param>
        /// <param name="displayValue">Formatted display value for field</param>
        /// <returns></returns>

        public static string BuildClickFunctionText(
            ResultsField rf,
            DataRowMx dr,
            int dri,
            string displayValue)
        {
            ResultsTable rt;
            MetaColumn   mc, mc2;
            MetaTable    mt;
            string       arg, arg2, argsString;
            int          ai, rfi, voi;

            if (rf == null || dr == null || dri < 0)
            {
                return("");
            }

            rt = rf.ResultsTable;
            mc = rf.MetaColumn;
            mt = mc.MetaTable;
            object[] vo = dr.ItemArray;

            if (String.IsNullOrEmpty(mc.ClickFunction))
            {
                return("");
            }

            List <string> args     = Lex.ParseAllExcludingDelimiters(mc.ClickFunction, "( , )", false);
            string        funcName = args[0];      // click function name

            int fieldRefs = 0;

            for (ai = 1; ai < args.Count; ai++)
            {             // see how many mcName.Value references there are
                arg = args[ai];
                string suffix = ".Value";
                if (!Lex.EndsWith(arg, suffix))
                {
                    continue;
                }

                arg = arg.Substring(0, arg.Length - suffix.Length);
                if (mt.GetMetaColumnByName(arg) != null)
                {
                    fieldRefs++;
                }
            }

            if (fieldRefs == 0)             // if no field references add either the field value, key value or grid row and column
            {
                if (Lex.Eq(funcName, "RunHtmlQuery") || Lex.Eq(funcName, "RunGridQuery") ||
                    Lex.Eq(funcName, "DisplayWebPage"))                     // fixups for old functions
                {
                    args.Add(Lex.AddSingleQuotes(mt.Name));                 // add metatable name
                    args.Add(Lex.AddSingleQuotes(mc.Name));                 // add metacolumn name
                }

                if (Lex.Contains(mc.ClickFunction, "[TableColumnValue]")) // convert to metatable, metacolumns, &value refDataTable row & col
                {
                    args.RemoveAt(1);                                     // remove [TableColumnValue] arg
                    args.Add(Lex.AddSingleQuotes(mt.Name));
                    args.Add(Lex.AddSingleQuotes(mc.Name));
                    args.Add(mc.Name + ".Value");
                }

                else if (Lex.Contains(mc.ClickFunction, "[keyvalue]"))
                {
                    args.Add(mt.KeyMetaColumn.Name + ".value");                     // pass key value rather than this col value
                }
                else
                {
                    args.Add(mc.Name + ".value");                  // pass column value
                }
            }

            argsString = "";
            for (ai = 1; ai < args.Count; ai++)
            {
                arg = args[ai];

                string suffix = ".Value";
                if (!arg.EndsWith(suffix, StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                arg2 = arg.Substring(0, arg.Length - suffix.Length);
                mc2  = mt.GetMetaColumnByName(arg2);

                if (mc2 == null)
                {
                    continue;                              // assume unquoted string constant & pass as is
                }
                else if (mc2.IsKey && rt.Fields[0].MetaColumn.Name != mc2.Name)
                {                                      // see if undisplayed key value
                    voi = rt.Fields[0].VoPosition - 1; // position in vo
                }

                else                 // find the field name in the list of report fields
                {
                    for (rfi = 0; rfi < rt.Fields.Count; rfi++)
                    {
                        if (Lex.Eq(mc2.Name, rt.Fields[rfi].MetaColumn.Name))
                        {
                            break;
                        }
                    }

                    if (rfi >= rt.Fields.Count)
                    {
                        throw new Exception("Column name not selected in query: " + mc2.Name);
                    }
                    voi = rt.Fields[rfi].VoPosition;
                }

                if (vo[voi] == null)
                {
                    args[ai] = "";
                }
                else
                {
                    arg = vo[voi].ToString();
                    if (vo[voi] is MobiusDataType)
                    {                     // use dblink if defined
                        MobiusDataType mdt = vo[voi] as MobiusDataType;
                        if (!String.IsNullOrEmpty(mdt.DbLink))
                        {
                            arg = mdt.DbLink;
                        }
                    }

                    args[ai] = arg;
                }
            }

            for (ai = 1; ai < args.Count; ai++)
            {
                arg = args[ai];
                if (!Lex.IsDouble(arg) && !arg.StartsWith("'") && !arg.StartsWith("["))                 // quote if string
                {
                    arg = Lex.AddSingleQuotes(arg);
                }
                if (argsString != "")
                {
                    argsString += ",";
                }
                argsString += arg;
            }

            string txt =             // build full string including link & display value
                         "<a href=\"http:////Mobius/command?ClickFunction " +
                         funcName + "(" + argsString + ")\">" + displayValue + "</a>";

            return(txt);
        }
Пример #19
0
        /// <summary>
        /// Save file in .xlsx format
        /// </summary>
        /// <param name="?"></param>

        public static void SaveAs(string fileName)
        {
            XlFileFormat ff = new XlFileFormat();

            if (DebugFileSaveOperation)
            {
                return;                                     // debug
            }
            //if (DebugMx.True) // debug
            //{
            //	Save();
            //	return;
            //}

            if (LogCalls)
            {
                DebugLog.Message("ExcelOp SaveAs " + fileName);
            }

            try
            {
                ShowExcelApp(true);                      // make visible before save so visible when reopened later

                if (Lex.EndsWith(fileName, ".xlsx"))     // Excel 2007+ (version 12+) Workbook (.xlsx) open XML format
                {
                    ff = XlFileFormat.xlOpenXMLWorkbook; // 51 = xlsx

                    //fileName = Lex.Replace(fileName, ".xlsx", ".xlsm"); // debug
                    //ff = XlFileFormat.xlOpenXMLWorkbookMacroEnabled; // debug
                }

                else if (Lex.EndsWith(fileName, ".xlsm"))                 // Excel Macro-Enabled Workbook (.xlsm) open XML format
                {
                    ff = XlFileFormat.xlOpenXMLWorkbookMacroEnabled;
                }

                else if (Lex.EndsWith(fileName, ".xlsb"))                 // Excel Binary Workbook (.xlsx) (Excel 2007, version 12) binary format
                {
                    ff = XlFileFormat.xlExcel12;
                }

                else if (Lex.EndsWith(fileName, ".xls"))                 // Excel 97-2003 (version 8-11) Workbook (*.xls) proprietary binary format
                {
                    ff = XlFileFormat.xlExcel8;
                }

                else
                {
                    ff = XlFileFormat.xlWorkbookDefault;                  // use default for others
                }
                XlBook.SaveAs(
                    Filename: fileName,
                    FileFormat: ff,
                    AccessMode: XlSaveAsAccessMode.xlNoChange);
            }
            catch (Exception ex)
            {
                throw new Exception("File: " + fileName + "\n\n" + ex.Message);
            }

            return;
        }
Пример #20
0
        /// <summary>
        /// Prompt user for structure file name and read in structure
        /// </summary>
        /// <returns></returns>

        public static bool ReadMoleculeFileDialog(
            out MoleculeMx mol,
            out string fileName)
        {
            while (true)
            {
                mol = null;

                string filter = "Molecule Files (*.mol; *.sdf; *.smi; *.helm; *.txt)|*.mol; *.sdf; *.smi; *.helm; *.hlm; *.txt;|All files (*.*)|*.*";
                fileName = UIMisc.GetOpenFilename(
                    "Retrieve Model Structure from File", "", filter, "MOL");

                if (String.IsNullOrEmpty(fileName))
                {
                    return(false);
                }

                try
                {
                    if (Lex.EndsWith(fileName, ".mol") || Lex.EndsWith(fileName, ".sdf"))
                    {
                        mol = MoleculeMx.ReadMolfile(fileName);
                    }

                    if (Lex.EndsWith(fileName, ".smi"))
                    {
                        mol = MoleculeMx.ReadSmilesFile(fileName);
                    }

                    else if (Lex.EndsWith(fileName, ".skc"))
                    {
                        mol = MoleculeMx.ReadSketchFile(fileName);
                    }

                    else if (Lex.EndsWith(fileName, ".helm"))
                    {
                        mol = MoleculeMx.ReadHelmFile(fileName);
                    }

                    else if (Lex.EndsWith(fileName, ".fasta"))
                    {
                        mol = MoleculeMx.ReadFastaFile(fileName);
                    }

                    else if (Lex.EndsWith(fileName, ".seq"))
                    {
                        mol = MoleculeMx.ReadBiopolymerSequenceFile(fileName);
                    }

                    else                     // something else, look at the contents
                    {
                        string txt = FileUtil.ReadFile(fileName);
                        mol = new MoleculeMx(txt);
                    }
                }

                catch (Exception ex)                 // if error clear mol and try again
                {
                    mol = null;
                }

                if (NullValue.IsNull(mol))
                {
                    MessageBoxMx.ShowError("Unable to read molecule file: " + fileName);
                    continue;                     // try again
                }

                return(true);
            }
        }
Пример #21
0
/// <summary>
/// Setup
/// </summary>
/// <param name="prompt"></param>
/// <param name="caption"></param>
/// <param name="mc"></param>
/// <param name="checkmarkDefaultColumn"></param>

        void Setup(
            string prompt,
            string caption,
            MetaColumn mc,
            bool selectSummarizedDataByDefault,
            bool checkmarkDefaultColumn)
        {
            MetaTable   mt, mt2;
            QueryTable  qt = null;
            QueryColumn qc = null;
            string      selectedNodeTarget = "", topNodeTarget = "";
            int         i1;

            SelectSummarizedDataByDefault = selectSummarizedDataByDefault;
            CheckmarkDefaultColumn        = checkmarkDefaultColumn;

            if (mc != null)
            {
                mt = mc.MetaTable;                         // specify starting table/field
            }
            else if (SelectedQt != null)
            {
                mt = SelectedQt.MetaTable;                                      // use any last table
            }
            else
            {
                mt = null;
            }

            if (mt != null)
            {
                selectedNodeTarget = mt.Name;

                MetaTreeNode mtn = MetaTree.GetNodeByTarget(selectedNodeTarget);
                if (mtn == null && Lex.EndsWith(selectedNodeTarget, MetaTable.SummarySuffix))
                {
                    selectedNodeTarget = Lex.Replace(selectedNodeTarget, MetaTable.SummarySuffix, "");
                    mtn = MetaTree.GetNodeByTarget(selectedNodeTarget);
                }

                if (mtn != null)
                {
                    topNodeTarget = selectedNodeTarget;
                }
            }

            if (String.IsNullOrEmpty(topNodeTarget))
            {
                topNodeTarget = SS.I.PreferredProjectId;
            }

            ContentsTreeWithSearch.ContentsTreeCtl.FillTree(
                "root",
                MetaTreeNodeType.DataTableTypes,
                selectedNodeTarget,
                topNodeTarget,
                null,
                true,
                false);

            RenderTable(mt, mc);

            if (String.IsNullOrEmpty(caption))
            {
                caption = "Select Data Field";
            }
            Text = caption;

            if (String.IsNullOrEmpty(prompt))
            {
                prompt = "Select a data table/assay from Database Contents and a Data Field";
            }
            Prompt.Text = prompt;
        }
Пример #22
0
        /// <summary>
        /// Run Query & return any error message
        /// </summary>
        /// <param name="query"></param>
        /// <param name="rf"></param>
        /// <param name="browseExistingResults">If true browse existing results</param>
        /// <returns>Command command or an error message</command></returns>

        public static string RunQuery2(
            Query query,
            ResultsFormat rf,
            bool browseExistingResults = false)
        {
            QueryManager     qm = null;
            DataTableMx      dt;
            QueryTable       qt = null;
            QueryColumn      qc;
            MetaTable        mt;
            MetaColumn       mc;
            QueryExec        qex;
            ResultsFormatter rfmtr;
            Query            modifiedQuery = null;
            DialogResult     dr;
            bool             success;
            int ti, ci, count;

            if (query == null)
            {
                throw new Exception("Null Query");
            }


            qm = query.QueryManager as QueryManager;

            if (qm == null || !qm.ContainsRenderedResults())
            {
                browseExistingResults = false;
            }

            if (ToolHelper.IsOldToolQuery(query) && !browseExistingResults)
            {
                return(ToolHelper.RunOldToolQuery(query));
            }

            //if (query.FirstView == null)
            //{
            ResultsViewType tableViewType = ResultsViewType.Table;

            if (rf.OutputDestination == OutputDest.Html)
            {
                tableViewType = ResultsViewType.HtmlTable;
            }

            //}

            //CheckForConnectionLeaks(); // do routine check for connection leaks (disabled for now)

// Build/update the QueryManager as needed (including the QueryExec) if running the query rather than just browsing existing results

            if (!browseExistingResults)                       // initialize QueryManager
            {
                query.SetupQueryPagesAndViews(tableViewType); // adjust views as necessary to match query
                qm = BuildQueryManager(query, rf);
            }

// Attempt to display already retrieved data in memory or in cached results file

            else
            {
                if (qm != null)
                {
                    if (qm.QueryExec == null)                     // create QueryExec if not defined
                    {
                        qex = new QueryExec(qm);
                    }

                    if (qm.ResultsFormatter == null)                     // create ResultsFormatter if not defined
                    {
                        rfmtr = new ResultsFormatter(qm);
                    }
                }

                else
                {
                    qm = BuildQueryManager(query, rf);
                }

                if (Lex.IsDefined(query.ResultsDataTableFileName))                 // get data from file
                {
                    DataTableManager.LoadDataTableFromFile(query);
                }

                else                 // should have data in DataTable already
                {
                    DataTableManager.ValidateExistingDataTable(query);
                }

                if (qm.DataTableManager != null && qm.QueryExec != null)
                {
                    qm.QueryExec.ResultsKeys = qm.DataTableManager.ResultsKeys;                     // have data in memory already
                }
            }

            if (rf.OutputDestination == OutputDest.WinForms && rf.SessionOutputFormContext)
            {                                                       // save qm and query if this is a runquery from the main window
                QueriesControl.Instance.CurrentBrowseQuery = query; // save ref to the query being browsed
            }

            if (rf.SessionOutputFormContext)             // if not a popup then update main status bar
            {
                qm.StatusBarManager = SessionManager.Instance.StatusBarManager;
            }

            LastQEx = qm.QueryExec;             // keep track of last QueryExec

SetupRunQuery:

            bool saveHitList = (rf.SessionOutputFormContext && !browseExistingResults);             // if popup or browsing existing results don't change hitlist

            qex = qm.QueryExec;
            string response = qex.RunQuery3(rf, saveHitList, browseExistingResults); // run the query

            if (qex.ResultsKeys != null && qex.ResultsKeys.Count > 0 &&              // save in history list if normal query that resulted in hits
                !query.Preview && !MqlUtil.SingleStepExecution(query) && !browseExistingResults &&
                rf.OutputDestination == OutputDest.WinForms)
            {
                CidList keyList = new CidList(qex.ResultsKeys);
                AddToHistoryList(query, keyList);                 // use original query
            }

            if (response != "" && !response.ToLower().StartsWith("command"))
            {
                return(response);
            }

            else if (Lex.EndsWith(response, "refetch")) // data to be retrieved has changed, redo fetch part of query
            {
                if (!query.Preview)                     // use current keys if not preview
                {
                    query.ResultKeys = qex.QueryEngine.GetKeys();
                }
                goto SetupRunQuery;
            }

            //else if (response == "") response = "Command EditQuery";

            //if (rf.OutputDestination == OutputDest.Grid)
            //{
            //  QbUtil.SetMode(QueryMode.Build); // back to build mode
            //  QbUtil.RenderQuery(QbUtil.Qt);
            //}

            return(response);
        }
Пример #23
0
/// <summary>
/// Load plugin definitions
/// </summary>
/// <param name="pluginRootDir"></param>
/// <returns></returns>

        public static int LoadDefinitions(string pluginRootDir)
        {
            if (PluginList != null)
            {
                return(PluginList.Count);
            }
            PluginList = new List <Plugin>();

            string[] dirs = Directory.GetDirectories(pluginRootDir);
            foreach (string dir in dirs)
            {
                if (Lex.EndsWith(dir, @"\TargetResultsViewerNetwork") || // obsolete
                    Lex.EndsWith(dir, @"\RgroupMatrix"))                 // disabled
                {
                    continue;                                            // ignore
                }
                string fileName = dir + @"\plugin.xml";
//				ClientLog.Message("Loading Plugin: " + fileName); // debug
                if (!File.Exists(fileName))
                {
                    continue;
                }
                try
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(fileName);
                    XmlNodeList nodes = doc.GetElementsByTagName("plugin");                     // get all plugins in file
                    if (nodes == null || nodes.Count == 0)
                    {
                        return(0);
                    }

                    foreach (XmlNode node in nodes)
                    {
                        Plugin p = new Plugin();
                        p.Directory = dir;


                        foreach (XmlAttribute attr in node.Attributes)
                        {
                            if (Lex.Eq(attr.Name, "Id"))
                            {
                                p.Id = attr.Value;
                            }

                            else if (Lex.Eq(attr.Name, "Name"))
                            {
                                p.Name = attr.Value;
                            }

                            else if (Lex.Eq(attr.Name, "Class"))
                            {
                                p.Class = attr.Value;
                            }

                            else if (Lex.Eq(attr.Name, "Provider-Name"))
                            {
                                p.ProviderName = attr.Value;
                            }

                            else if (Lex.Eq(attr.Name, "Version"))
                            {
                                p.Version = attr.Value;

                                if (Lex.Eq(attr.Value, "Hidden"))
                                {
                                    p.Visible = false;                                                               // temp workaround to hide a plugin
                                }
                            }

                            else if (Lex.Eq(attr.Name, "Enabled"))
                            {
                                bool.TryParse(attr.Value, out p.Enabled);
                            }

                            else if (Lex.Eq(attr.Name, "Visible"))
                            {
                                bool.TryParse(attr.Value, out p.Visible);
                            }

                            else
                            {
                                throw new Exception("Unrecognized attribute: " + attr.Name);
                            }
                        }

                        if (p.Id == "")
                        {
                            throw new Exception("Id missing");
                        }

                        if (p.Class == "")
                        {
                            throw new Exception("Class name missing");
                        }

                        XmlNodeList libraryNodes = node.SelectNodes(".//library");                         // get library nodes (case sensitive)
                        if (libraryNodes.Count == 0)
                        {
                            libraryNodes = node.SelectNodes(".//Library");
                        }
                        if (libraryNodes.Count == 0)
                        {
                            libraryNodes = node.SelectNodes(".//LIBRARY");
                        }

                        foreach (XmlNode node2 in libraryNodes)
                        {
                            if (node2.Attributes == null || node2.Attributes.Count < 1 ||
                                !Lex.Eq(node2.Attributes[0].Name, "Name"))
                            {
                                throw new Exception("Runtime Library Name missing");
                            }
                            p.RunTimeLibraries.Add(node2.Attributes[0].Value);
                        }

                        if (p.RunTimeLibraries.Count == 0)
                        {
                            throw new Exception("Runtime library missing");
                        }

                        XmlNodeList eNodes = node.SelectNodes(".//extension");                         // get extension point nodes
                        if (eNodes == null || eNodes.Count == 0)
                        {
                            throw new Exception("Extension points missing");
                        }

                        foreach (XmlNode eNode in eNodes)
                        {
                            ExtensionPoint ep = new ExtensionPoint();
                            ep.Plugin = p;

                            foreach (XmlAttribute attr in eNode.Attributes)
                            {
                                if (Lex.Eq(attr.Name, "Point"))
                                {
                                    if (Lex.Ne(attr.Value, "Mobius.Action") && Lex.Ne(attr.Value, "Mobius.ClientDialog") &&
                                        Lex.Ne(attr.Value, "Mobius.Method"))
                                    {
                                        throw new Exception("Invalid extension point type " + attr.Value);
                                    }
                                    ep.Type = attr.Value;
                                }

                                else if (Lex.Eq(attr.Name, "Id"))
                                {
                                    ep.Id = attr.Value;
                                }

                                else if (Lex.Eq(attr.Name, "Class"))
                                {
                                    ep.Class = attr.Value;
                                }

                                else if (Lex.Eq(attr.Name, "MenuBarPath"))
                                {
                                    if (Lex.Ne(attr.Value, "Tools"))
                                    {
                                        throw new Exception("Unsupported MenubarPath " + attr.Value);
                                    }
                                    ep.MenuBarPath = attr.Value;
                                }

                                else if (Lex.Eq(attr.Name, "CommandLineCommand"))
                                {
                                    ep.CommandName = attr.Value;
                                }

                                else if (Lex.Eq(attr.Name, "MethodName"))
                                {
                                    ep.MethodName = attr.Value;
                                }

                                else if (Lex.Eq(attr.Name, "Label"))
                                {
                                    ep.Label = attr.Value;
                                }

                                else
                                {
                                    throw new Exception("Unrecognized extension point attribute: " + attr.Name);
                                }
                            }

                            if (ep.Id == "")
                            {
                                throw new Exception("Extension point Id missing");
                            }
                            if (ep.Type == "")
                            {
                                throw new Exception("Extension point type missing");
                            }
                            if (ep.Class == "")
                            {
                                if (p.Class != "")
                                {
                                    ep.Class = p.Class;                                                // use plugin class if defined
                                }
                                else
                                {
                                    throw new Exception("Extension point class name missing");
                                }
                            }

                            fileName = dir + @"\" + ep.Id + ".bmp";
                            if (File.Exists(fileName))
                            {
                                try { ep.Image = Bitmap.FromFile(fileName); }
                                catch (Exception ex) { ex = ex; }
                            }

                            p.ExtensionPoints.Add(ep);                             // add extension point to plugin
                        }

                        PluginList.Add(p);                         // add plugin to list
                    }
                }
                catch (Exception ex)
                {
                    ServicesLog.Message(DebugLog.FormatExceptionMessage(ex));
                    string msg = "Error in file \"" + fileName + "\"\r\n" + ex.Message;
                    throw new Exception(msg, ex);
                }
            }

            PluginCaller.CallRef =             // alloc PluginDao to call up to us
                                   new PluginCaller.CallMethodDelegate(CallStringExtensionPointMethod);

            return(PluginList.Count);
        }