Beispiel #1
0
        public static string Show(
            string prompt,
            string title,
            string initialCid,
            MetaTable mt)
        {
            //if (Instance == null)
            Instance = new InputCompoundId();             // always allocate a new class

            new JupyterGuiConverter().ConvertFormOrUserControl(Instance);

            Instance.Text        = title;
            Instance.Prompt.Text = prompt;
            Instance.CidCtl.Text = initialCid;
            Instance.PreviousCid = "";
            Instance.QuickStructure.ClearMolecule();
            Instance.MetaTable = mt;

            if (mt != null && Lex.Eq(mt.Name, MetaTable.SmallWorldMetaTableName))
            {
                Instance.MetaTable = null;                 // don't use smallworld db directly since can't retrieve by CID
            }
            DialogResult dr = Instance.ShowDialog(SessionManager.ActiveForm);

            if (dr == DialogResult.OK)
            {
                return(Instance.CidCtl.Text);
            }
            else
            {
                return(null);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Get map of query table alias changes, return null if no alias changes
        /// </summary>
        /// <param name="q"></param>
        /// <returns></returns>

        public static Dictionary <string, string> GetAliasMap(
            Query q)
        {
            q.AssignUndefinedAliases();             // be sure everything has an alias

            bool aliasChanged = false;
            Dictionary <string, string> tAliasMap = new Dictionary <string, string>();

            for (int qti = 0; qti < q.Tables.Count; qti++)
            {             // build map from old table aliases to new
                QueryTable qt    = q.Tables[qti];
                string     alias = "T" + (qti + 1).ToString();
                if (qt.Alias != "")
                {
                    tAliasMap[qt.Alias.ToUpper()] = alias;
                }
                if (!Lex.Eq(qt.Alias, alias))
                {
                    aliasChanged = true;
                }
            }

            if (aliasChanged)
            {
                return(tAliasMap);
            }
            else
            {
                return(null);             // no map if no change
            }
        }
Beispiel #3
0
/// <summary>
/// Set privileges that are stored as privs in Mobius user parameters
/// </summary>
/// <param name="ui"></param>

        public static void SetUserParmPrivileges(UserInfo ui)
        {
            Dictionary <string, string> ups = UserObjectDao.GetUserParameters(ui.UserName);

            string prefix = "Privilege";

            foreach (string uoName in ups.Keys)             // store other non-ad privileges
            {
                if (!Lex.StartsWith(uoName, prefix) ||      // Privilege user parm?
                    Lex.Ne(ups[uoName], "True"))
                {
                    continue;                                                  // and granted?
                }
                string privName = uoName.Substring(prefix.Length);
                if (!PrivilegesMx.IsValidPrivilegeName(privName))
                {
                    continue;
                }
                if (Lex.Eq(privName, "Logon"))
                {
                    continue;                                            // ignore old Logon priv from database
                }
                ui.Privileges.SetPrivilege(privName, true);
            }

            if (!ups.ContainsKey("NAMEADDRESS"))             // store user name and address in Mobius db if not there already
            {
                Security.CreateUser(ui);
            }

            return;
        }
Beispiel #4
0
        /// <summary>
        /// Perform a full structure search of query molecule against target molecule
        /// </summary>
        /// <param name="query"></param>
        /// <param name="target"></param>
        /// <returns></returns>

        public bool IsFSSMatch(
            MoleculeMx query,
            MoleculeMx target)
        {
            if (query.IsBiopolymerFormat || target.IsBiopolymerFormat)
            {
                if (!query.IsBiopolymerFormat || !target.IsBiopolymerFormat)
                {
                    return(false);
                }

                if (Lex.Eq(query.PrimaryValue, target.PrimaryValue))
                {
                    return(true);
                }

                else
                {
                    return(false);
                }
            }

            SetFSSQueryMolecule(query);
            bool b = IsFSSMatch(target);

            return(b);
        }
Beispiel #5
0
/// <summary>
/// Set the initial browse page for the query based on the preferred view
/// </summary>
/// <param name="preferredView"></param>
/// <param name="q"></param>

        public static void  SetInitialBrowsePageToPreferredView(
            string preferredView,
            Query q)
        {
            string pv = preferredView;
            int    pi = 0;

            if (Lex.Eq(pv, "Table"))
            {
                pi = 0;
            }
            else if (Lex.Eq(pv, "Map"))
            {
                pi = 1;
            }
            else if (Lex.Eq(pv, "Heatmap"))
            {
                pi = 2;
            }
            else if (Lex.Eq(pv, "Network"))
            {
                pi = 3;
            }
            else if (Lex.Eq(pv, "WebPlayer"))
            {
            }                                                 // not currently supported

            if (pi < q.ResultsPages.Pages.Count)
            {
                q.InitialBrowsePage = pi;
            }

            return;
        }
Beispiel #6
0
        /// <summary>
        /// Get the specific broker, allocating as needed
        /// </summary>
        /// <param name="mt"></param>

        GenericMetaBroker GSP(
            MetaTable mt)
        {
            if (SpecificBroker == null)             // need to allocate?
            {
                string sbType = mt.TableMap;        // metatable map contains is of specific broker type

                if (Lex.Eq(sbType, "Mobius.Tools.SarLandscape"))
                {
                    SpecificBroker = new SasMapMetaBroker();
                }

                else if (Lex.StartsWith(sbType, "SmallWorld"))
                {
                    SpecificBroker = new GenericMetaBroker();
                }

                else
                {
                    throw new QueryException("Unrecognized NoSql data source type: " + sbType);
                }
            }

            return(SpecificBroker);            //  already allocated?
        }
Beispiel #7
0
        /// <summary>
        /// Set value for a Data field
        /// </summary>
        /// <param name="fList">Pointer to field list</param>
        /// <param name="field">Name of field to set</param>
        /// <param name="value">Field value</param>

        public static void SetSdFileField(         /*  */
            List <SdFileField> fList,
            string fieldName,
            string value)
        {
            // See if field exists

            foreach (SdFileField field2 in fList)
            {
                if (Lex.Eq(fieldName, field2.Header))
                {
                    field2.Data = value;
                    if (!field2.Data.EndsWith("\n"))
                    {
                        field2.Data += "\n";
                    }
                    return;
                }
            }

            // Allocate new field

            SdFileField field = new SdFileField();

            field.Header = fieldName;
            field.Data   = value;
            if (!field.Data.EndsWith("\n"))
            {
                field.Data += "\n";
            }

            return;
        }
Beispiel #8
0
        /// <summary>
        /// See if the supplied user name can write the user object the supplied object
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="uo"></param>
        /// <returns></returns>

        public static bool UserHasWriteAccess(
            string userName,
            UserObject uo)
        {
            if (uo == null)
            {
                return(false);
            }
            else if (Lex.Eq(uo.Owner, userName))
            {
                return(true);
            }
            else if (uo.AccessLevel == UserObjectAccess.Public)
            {
                return(false);
            }
            else if (uo.AccessLevel == UserObjectAccess.ACL)
            {
                AccessControlList acl = AccessControlList.Deserialize(uo.ACL);
                return(acl.UserHasWriteAccess(userName));
            }

            else
            {
                return(false);             // unexpected AccessLevel
            }
        }
Beispiel #9
0
/// <summary>
/// Deserialize
/// </summary>
/// <param name="serializedForm"></param>
/// <returns></returns>

        public static AccessControlList Deserialize(
            string serializedForm)
        {
            if (Lex.IsNullOrEmpty(serializedForm))
            {
                return(new AccessControlList());
            }

            XmlMemoryStreamTextReader mstr = new XmlMemoryStreamTextReader(serializedForm);

            XmlTextReader tr = mstr.Reader;

            tr.Read();             // get AccessControlList element
            tr.MoveToContent();
            if (!Lex.Eq(tr.Name, "AccessControlList"))
            {
                throw new Exception("\"AccessControlList\" element not found");
            }

            if (tr.IsEmptyElement)
            {
                return(new AccessControlList());                               // if nothing there return empty rule list
            }
            AccessControlList acl = Deserialize(mstr.Reader);

            mstr.Close();
            return(acl);
        }
Beispiel #10
0
        /// <summary>
        /// Pass the tree operation to the proper handler
        /// </summary>
        /// <param name="op"></param>
        /// <param name="args"></param>

        public static void TreeItemOperation(
            string op,
            string args)
        {
            if (Lex.Eq(op, "Open"))
            {
                MetaTreeNode mtn = MetaTreeNodeCollection.GetNode(args);
                if (mtn == null || !mtn.IsUserObjectType)
                {
                    return;
                }

                Instance.ObjectName.Text = mtn.Label;
                Instance.SelectedNode    = mtn;
                Instance.OK_Click(null, null);
                return;
            }

            else
            {
                Instance.ContentsTreeWithSearch.ContentsTreeCtl.FindInContents(args);
            }

            return;
        }
Beispiel #11
0
/// <summary>
/// Get dictionary of all groups that specified user belongs to keyed by internal group name
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>

        public static Dictionary <string, UserGroup> GetMemberGroups(string userName)
        {
            Dictionary <string, UserGroup> dict = new Dictionary <string, UserGroup>();

            for (int gi = 0; gi < UserGroups.Items.Count; gi++)
            {
                UserGroup group = UserGroups.Items[gi];
                if (group == null || group.ACL == null || group.ACL.Items == null)
                {
                    continue;
                }

                for (int ii = 0; ii < group.ACL.Items.Count; ii++)
                {
                    AclItem item = group.ACL.Items[ii];
                    if (Lex.Eq(item.AssignedTo, userName))
                    {
                        dict[group.InternalName] = group;
                        break;
                    }
                }
            }

            return(dict);
        }
Beispiel #12
0
        /// <summary>
        /// Convert an external user or group name to an internal name
        /// </summary>
        /// <param name="extName"></param>
        /// <returns></returns>
        string ExternalToInternalName(string extName)
        {
            if (Lex.IsNullOrEmpty(extName))
            {
                return("");
            }
            UserGroup g = LookupGroupItem(extName);             // see if group name first

            if (g != null)
            {
                return(g.InternalName);
            }

            DictionaryMx userDict = DictionaryMx.Get("UserName");

            if (userDict == null)
            {
                return(extName);
            }
            foreach (string userName in userDict.Words)
            {
                string   userInfoString = userDict.LookupDefinition(userName);
                UserInfo userInfo       = UserInfo.Deserialize(userInfoString);
                if (userInfo == null || Lex.IsNullOrEmpty(userInfo.FullName))
                {
                    continue;
                }
                if (Lex.Eq(userInfo.FullNameReversed, extName))
                {
                    return(userInfo.UserName);
                }
            }

            return(extName);            // shouldn't happen
        }
Beispiel #13
0
        /// <summary>
        /// Edit given a list name
        /// </summary>
        /// <returns></returns>

        public static CidList Edit(
            string inListName,
            MetaTable rootTable)
        {
            CidList cnList;

            if (Lex.Eq(inListName, "Current"))
            {
                inListName = CidList.CurrentListInternalName;
            }

            if (inListName == "")
            {
                cnList = new CidList();                 // new list
                cnList.UserObject.Name = "New List";
            }

            else
            {
                cnList = CidListCommand.Read(inListName, rootTable);
                if (cnList == null)
                {
                    return(null);                                // doesn't exist
                }
                if (!cnList.UserObject.IsTempObject && MainMenuControl != null)
                {
                    MainMenuControl.UpdateMruList(cnList.UserObject.InternalName);
                }
            }

            cnList = Edit(cnList, rootTable);
            return(cnList);
        }
Beispiel #14
0
        /// <summary>
        /// Hack to extract MASS= attributes from a V3000 file because CDK has an issue reading these
        /// </summary>
        /// <param name="molfile"></param>
        /// <returns></returns>
        static Dictionary <int, int> ExtractMassAttributes(ref string molfile)
        {
            Dictionary <int, int> map = new Dictionary <int, int>();

            string molfile2 = molfile.Replace("\r", "");

            molfile2 = molfile2.Replace("\n", " ");
            string[] sa = molfile2.Split(' ');
            for (int si = 0; si < sa.Length; si++)
            {
                if (Lex.Contains(sa[si], "MASS="))
                {
                    int mass = int.Parse(sa[si].Substring(5));
                    molfile = molfile.Replace(" " + sa[si], "");
                    for (int si2 = si - 1; si2 >= 0; si2--)
                    {
                        if (Lex.Eq(sa[si2], "V30"))
                        {
                            int ai = int.Parse(sa[si2 + 1]);
                            map[ai] = mass;
                            break;
                        }
                    }
                }
            }

            return(map);
        }
Beispiel #15
0
        public static int Write(
            CidList list,
            string parentFolder,
            string name,
            string description)
        {
            UserObject uo = new UserObject(UserObjectType.CnList);

            uo.Name         = name;
            uo.Description  = description;
            uo.ParentFolder = parentFolder;

            if (Lex.Eq(parentFolder, UserObject.TempFolderName))
            {
                uo.ParentFolderType = FolderTypeEnum.None;
            }

            else if (Lex.StartsWith(parentFolder, "FOLDER_"))
            {
                uo.ParentFolderType = FolderTypeEnum.User;
            }

            else
            {
                uo.ParentFolderType = FolderTypeEnum.System;
            }

            return(Write(list, uo));
        }
Beispiel #16
0
        /// <summary>
        /// Get the permissions that a user has
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>

        public PermissionEnum GetUserPermissions(string userName)
        {
            PermissionEnum permissions = PermissionEnum.None;

            foreach (AclItem item in Items)
            {
                if (item.IsUser)                 // user name
                {
                    if (Lex.Eq(item.AssignedTo, userName) || Lex.Eq(item.AssignedTo, "Public"))
                    {
                        permissions |= item.Permissions;                         // or permissions together
                    }
                }

                else                 // group name
                {
                    if (UserGroups.GroupContainsUser(item.AssignedTo, userName) || Lex.Eq(item.AssignedTo, "Public"))
                    {
                        permissions |= item.Permissions;                         // or permissions together
                    }
                }
            }

            return(permissions);
        }
Beispiel #17
0
        /// <summary>
        /// Calculate metatable statistics for each broker type
        /// </summary>
        /// <param name="factoryName"></param>
        /// <returns></returns>

        public static int UpdateStats(
            string factoryName)
        {
            int total = 0;

            if (Lex.Eq(factoryName, "Generic") || Lex.IsNullOrEmpty(factoryName))
            {
                if (Instance == null)
                {
                    Instance = new MetaTableFactory();
                }
                total += Instance.UpdateMetaTableStatistics();
            }

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

                if (!String.IsNullOrEmpty(factoryName) && Lex.Ne(mtfr.Name, factoryName))
                {
                    continue;                     // skip if name supplied and this isn't it
                }
                int cnt = mtfr.MetaTableFactory.UpdateMetaTableStatistics();
                total += cnt;
            }

            return(total);
        }
Beispiel #18
0
		/// <summary>
		/// Rename a Spotfire Column
		/// </summary>
		/// <param name="ri"></param>

		void RenameColumn(int ri)
		{
			DataRow dRow = FieldDataTable.Rows[ri];
			string currentName = dRow["SpotfireColNameField"] as string;

			string newName = InputBoxMx.Show("Name:", "Rename Column", currentName);
			if (Lex.IsUndefined(newName) || newName == currentName) return;

			for (int ri2 = 0; ri2 < FieldDataTable.Rows.Count; ri2++)
			{
				if (ri2 == ri) continue;
				string name = FieldDataTable.Rows[ri2]["SpotfireColNameField"] as string;
				if (Lex.Eq(name, newName))
				{
					MessageBoxMx.ShowError("Name already in use: " + newName);
					return;
				}
			}

			dRow["SpotfireColNameField"] = newName;

			CurrentMap.ColumnMapCollection[ri].SpotfireColumnName = newName;

			Api.RenameColumn(CurrentMap.SpotfireDataTable?.Name, currentName, newName);

			return;
		}
Beispiel #19
0
/// <summary>
/// Find any results column corresponding to a metacolumn
/// </summary>
/// <param name="mc"></param>
/// <returns></returns>

        public ResultsField GetResultsField(
            MetaColumn mc)
        {
            if (mc == null)
            {
                return(null);
            }

            foreach (ResultsTable rt in Tables)
            {
                if (Lex.Ne(mc.MetaTable.Name, rt.MetaTable.Name))
                {
                    continue;
                }

                foreach (ResultsField rfld in rt.Fields)
                {
                    if (Lex.Eq(mc.Name, rfld.MetaColumn.Name))
                    {
                        return(rfld);
                    }
                }
            }

            return(null);
        }
Beispiel #20
0
        /// <summary>
        /// Lookup a color set in a color set dict by name
        /// </summary>
        /// <param name="colorDict"></param>
        /// <param name="colorSetName"></param>
        /// <returns></returns>

        public static Color[] GetColorSetByName(
            Dictionary <string, Color[]> colorDict,
            string colorSetName)
        {
            if (Lex.IsUndefined(colorSetName))
            {
                return(null);
            }

            int i1 = colorSetName.IndexOf(".");             // remove any file extension

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

            foreach (string setName in colorDict.Keys)
            {
                if (Lex.Eq(setName, colorSetName))
                {
                    return(colorDict[setName]);
                }
            }

            return(null);
        }
Beispiel #21
0
/// <summary>
/// See if user can modify the supplied object
/// </summary>
/// <param name="uo"></param>
/// <returns></returns>

        public static bool UserHasWriteAccess(
            string userName,
            UserObject[] uoArray)
        {
            bool approved = false;

            foreach (var uo in uoArray)
            {
                if (uo == null || uo.Owner == null || uo.Owner == "")
                {
                    approved = true;                                                   // no current owner
                }
                if (Lex.Eq(uo.Owner, userName) ||
                    (Security.IsAdministrator(userName) && SS.I.AllowAdminFullObjectAccess) ||
                    Permissions.UserHasWriteAccess(userName, uo))
                {
                    approved = true;
                }

                else
                {
                    return(false);
                }
            }
            return(approved);
        }
Beispiel #22
0
        int MaxShapeEnumValue()
        {
            int max = -1, fixedShape;

            if (ShapeTypeMenu == null)
            {
                return(max);
            }

            foreach (ToolStripItem i in ShapeTypeMenu.Items)
            {
                if (Lex.Eq(i.Tag as string, "EndOfNormalShapes"))
                {
                    break;
                }

                ToolStripMenuItem mi = i as ToolStripMenuItem;
                if (mi == null || !int.TryParse(mi.Tag as string, out fixedShape))
                {
                    continue;
                }

                if (fixedShape > max)
                {
                    max = fixedShape;
                }
            }

            return(max);
        }
Beispiel #23
0
        /// <summary>
        /// Lookup a MetaTreeNode by label
        /// </summary>
        /// <param name="label"></param>
        /// <returns></returns>

        public static MetaTreeNode GetNodeByLabel(
            string label)
        {
            if (Nodes == null || label == null || label == "")
            {
                return(null);
            }

            foreach (MetaTreeNode mtn in Nodes.Values)             // look for exact match
            {
                if (Lex.Eq(mtn.Label, label))
                {
                    return(mtn);
                }
            }

            foreach (MetaTreeNode mtn in Nodes.Values)             // look for label with suffix match
            {
                if (Lex.StartsWith(mtn.Label, label))
                {
                    foreach (string suffix in MetaTable.NameSuffixes)
                    {
                        if (Lex.Eq(mtn.Label, label + suffix))
                        {
                            return(mtn);
                        }
                    }
                }
            }

            return(null);
        }
Beispiel #24
0
        /// <summary>
        /// Set the activity bin for the row (now set in SQL)
        /// </summary>

        public void SetActivityBin(
            QualifiedNumber resultValueQn,
            double resultNumericValue,
            out int activityBin)
        {
            UnpivotedAssayResult sRow = this;

            double val = 0;

            if (resultNumericValue > 0)             // use numeric value if we have it
            {
                val = resultNumericValue;
            }
            else if (resultValueQn != null && resultValueQn.NumberValue > 0)             // otherwise use any qualified number numeric value
            {
                val = resultValueQn.NumberValue;
            }

            if (val <= 0)
            {
                activityBin = 0;                       // no valid value
            }
            else if (Lex.Eq(sRow.ResultTypeConcType, "SP"))
            {             // calc SP activity bin
                double crc = ConvertSPToCRC(val, sRow.Conc);
                activityBin = CalcCRCActivityBin(crc);
            }

            else             // calc CRC activity bin
            {
                activityBin = CalcCRCActivityBin(val);
            }
        }
Beispiel #25
0
        /// <summary>
        /// Get the curren tool query and it's parameter string
        /// </summary>
        /// <returns></returns>

        public static void GetCurrentQueryAndParameterString(
            out Query q,
            out string parms)
        {
            parms = "";

            q = QueriesControl.Instance.CurrentQuery;
            if (q == null)
            {
                return;
            }

            foreach (QueryTable qt in q.Tables)
            {
                foreach (QueryColumn qc in qt.QueryColumns)
                {
                    if (Lex.Eq(qc.MetaColumn.ColumnMap, ToolUtil.ToolParametersColumnMapValue))
                    {
                        parms = qc.Criteria;
                        return;
                    }
                }
            }

            return;
        }
Beispiel #26
0
        public void ExecuteCommandLine()
        {
            string s = CommandLineControl.Text;

            if (s == "")
            {
                return;
            }

            HideQuickSearchPopup();

            DevExpress.XtraEditors.Controls.MRUEditItemCollection items = CommandLineControl.Properties.Items;
            if (items.Count > 0 && Lex.Eq(items[0].ToString(), s))
            {
            }                                                                      // don't insert same item again
            else
            {
                CommandLineControl.Properties.Items.Insert(0, s);              // insert in list manually since we clear it here
            }
            CommandLineControl.Text = "";
            PreviousInput           = "";   // avoid any additional QuickDisplays

            QbUtil.CallCurrentProcessTreeItemOperationMethod("CommandLine", s);
            //CommandExec.Execute("CommandLine " + s);
        }
Beispiel #27
0
/// <summary>
/// Get object type from plural of type name
/// </summary>
/// <param name="label"></param>
/// <returns></returns>

        public static UserObjectType GetTypeFromPlural(string label)
        {
            if (Lex.Eq(label, "Queries"))
            {
                return(UserObjectType.Query);
            }
            if (Lex.Eq(label, "Lists"))
            {
                return(UserObjectType.CnList);
            }
            if (Lex.Eq(label, "Calculated Fields"))
            {
                return(UserObjectType.CalcField);
            }
            if (Lex.Eq(label, "Spotfire Links"))
            {
                return(UserObjectType.SpotfireLink);
            }
            if (Lex.Eq(label, "Annotations"))
            {
                return(UserObjectType.Annotation);
            }
            if (Lex.Eq(label, "Conditional Formattings"))
            {
                return(UserObjectType.CondFormat);
            }
            if (Lex.Eq(label, "Folders"))
            {
                return(UserObjectType.Folder);
            }
            return(UserObjectType.Unknown);
        }
Beispiel #28
0
/// <summary>
/// Update collection of temp lists
/// </summary>
/// <param name="uo"></param>

        public static void UpdateTempListCollection(UserObject uo)
        {
            if (Lex.Ne(uo.ParentFolder, UserObject.TempFolderName))
            {
                return;                                                                 // update for lists in temp folder only
            }
            List <TempCidList> tLists = SS.I.TempCidLists;
            TempCidList        tl     = null;
            int tli;

            for (tli = 0; tli < tLists.Count; tli++)
            {
                tl = tLists[tli];
                if (Lex.Eq(tl.Name, uo.Name))
                {
                    break;
                }
            }

            if (tli >= tLists.Count)
            {
                tl = new TempCidList();
                tLists.Add(tl);
            }

            tl.Name  = uo.Name;
            tl.Count = uo.Count;
            tl.Id    = uo.Id;
            return;
        }
Beispiel #29
0
        /// <summary>
        /// Process a command line to grant a user a privilege
        /// </summary>
        /// <param name="commandLine"></param>et
        /// <returns></returns>

        public static string GrantPrivilege(
            string commandLine)
        {
            if (UserInfo == null || !IsAdministrator(UserInfo.UserName))
            {
                return("You must be an administrator to grant privileges");
            }

            Lex lex = new Lex();

            lex.OpenString(commandLine);
            string priv     = lex.Get();
            string userName = lex.Get();

            if (Lex.Eq(userName, "to"))
            {
                userName = lex.Get();
            }
            if (priv == "" || userName == "")
            {
                return("Syntax: GRANT privilege TO userid");
            }
            if (!PrivilegesMx.IsValidPrivilegeName(priv))
            {
                return(priv + " is not a valid privilege");
            }
            if (!UserExists(userName))
            {
                return("User " + userName + " doesn't exist");
            }
            GrantPrivilege(userName, priv);
            return("Privilege granted");
        }
Beispiel #30
0
        public static CondFormat Deserialize(
            XmlTextReader tr)
        {
            string txt;

            CondFormat cf = new CondFormat();

            txt = tr.GetAttribute("ColumnType");
            if (txt != null)
            {
                EnumUtil.TryParse(txt, out cf.ColumnType);
            }

            XmlUtil.GetStringAttribute(tr, "Name", ref cf.Name);
            XmlUtil.GetBoolAttribute(tr, "Option1", ref cf.Option1);
            XmlUtil.GetBoolAttribute(tr, "Option2", ref cf.Option2);
            //XmlUtil.GetBoolAttribute(tr, "ShowInHeaders", ref cf.ShowInHeaders);

            tr.Read();             // get CondFormatRules element
            tr.MoveToContent();
            if (!Lex.Eq(tr.Name, "CondFormatRules"))
            {
                throw new Exception("CondFormat.Deserialize - \"CondFormat\" end element not found");
            }

            if (!tr.IsEmptyElement)
            {
                cf.Rules = CondFormatRules.Deserialize(tr);
                cf.Rules.InitializeInternalMatchValues(cf.ColumnType);
            }

            else
            {
                cf.Rules = new CondFormatRules(); // no rules
            }
            tr.Read();                            // get CondFormat end element
            tr.MoveToContent();
            if (!Lex.Eq(tr.Name, "CondFormat") || tr.NodeType != XmlNodeType.EndElement)
            {
                throw new Exception("CondFormat.Deserialize - Expected CondFormat end element");
            }

            if (cf.ColumnType == MetaColumnType.Date && cf.Rules != null)
            {             // store normalized dates
                foreach (CondFormatRule rule in cf.Rules)
                {
                    if (!String.IsNullOrEmpty(rule.Value))
                    {
                        rule.ValueNormalized = DateTimeMx.Normalize(rule.Value);
                    }

                    if (!String.IsNullOrEmpty(rule.Value2))
                    {
                        rule.Value2Normalized = DateTimeMx.Normalize(rule.Value2);
                    }
                }
            }

            return(cf);
        }