Пример #1
0
Файл: Prefs.cs Проект: mnisl/OD
		///<summary></summary>
		public static void FillCache(DataTable table){
			//No need to check RemotingRole; no call to db.
			Dictionary<string,Pref> dictPrefs=new Dictionary<string,Pref>();
			Pref pref;
			//PrefName enumpn;
			//Can't use Crud.PrefCrud.TableToList(table) because it will fail the first time someone runs 7.6 before conversion.
			List<string> listDuplicatePrefs=new List<string>();
			for(int i=0;i<table.Rows.Count;i++) {
				pref=new Pref();
				if(table.Columns.Contains("PrefNum")) {
					pref.PrefNum=PIn.Long(table.Rows[i]["PrefNum"].ToString());
				}
				pref.PrefName=PIn.String(table.Rows[i]["PrefName"].ToString());
				pref.ValueString=PIn.String(table.Rows[i]["ValueString"].ToString());
				//no need to load up the comments.  Especially since this will fail when user first runs version 5.8.
				if(dictPrefs.ContainsKey(pref.PrefName)) {
					listDuplicatePrefs.Add(pref.PrefName);//The current preference is a duplicate preference.
				}
				else {
					dictPrefs.Add(pref.PrefName,pref);
				}
			}
			if(listDuplicatePrefs.Count>0 &&																				//Duplicate preferences found, and
				dictPrefs.ContainsKey(PrefName.CorruptedDatabase.ToString()) &&				//CorruptedDatabase preference exists (only v3.4+), and
				dictPrefs[PrefName.CorruptedDatabase.ToString()].ValueString!="0")		//The CorruptedDatabase flag is set.
			{
				throw new ApplicationException(Lans.g("Prefs","Your database is corrupted because an update failed.  Please contact us.  This database is unusable and you will need to restore from a backup."));
			}
			else if(listDuplicatePrefs.Count>0) {//Duplicate preferences, but the CorruptedDatabase flag is not set.
				throw new ApplicationException(Lans.g("Prefs","Duplicate preferences found in database")+": "+String.Join(",",listDuplicatePrefs));
			}
			PrefC.Dict=dictPrefs;
		}
Пример #2
0
        ///<summary>Returns true if a change was required, or false if no change needed.</summary>
        public static bool UpdateDateT(PrefName prefName, DateTime newValue)
        {
            //Very unusual.  Involves cache, so Meth is used further down instead of here at the top.
            DateTime curValue = PrefC.GetDateT(prefName);

            if (curValue == newValue)
            {
                return(false);               //no change needed
            }
            string command = "UPDATE preference SET "
                             + "ValueString = '" + POut.DateT(newValue, false) + "' "
                             + "WHERE PrefName = '" + POut.String(prefName.ToString()) + "'";
            bool retVal = true;

            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                retVal = Meth.GetBool(MethodBase.GetCurrentMethod(), prefName, newValue);
            }
            else
            {
                Db.NonQ(command);
            }
            Pref pref = new Pref();

            pref.PrefName    = prefName.ToString();
            pref.ValueString = POut.DateT(newValue, false);
            Prefs.UpdateValueForKey(pref);
            return(retVal);
        }
Пример #3
0
        ///<summary>Updates a pref of type long.  Returns true if a change was required, or false if no change needed.</summary>
        public static bool UpdateLong(PrefName prefName, long newValue)
        {
            //Very unusual.  Involves cache, so Meth is used further down instead of here at the top.
            if (!PrefC.Dict.ContainsKey(prefName.ToString()))
            {
                throw new ApplicationException(prefName + " is an invalid pref name.");
            }
            if (PrefC.GetLong(prefName) == newValue)
            {
                return(false);               //no change needed
            }
            string command = "UPDATE preference SET "
                             + "ValueString = '" + POut.Long(newValue) + "' "
                             + "WHERE PrefName = '" + POut.String(prefName.ToString()) + "'";
            bool retVal = true;

            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                retVal = Meth.GetBool(MethodBase.GetCurrentMethod(), prefName, newValue);
            }
            else
            {
                Db.NonQ(command);
            }
            Pref pref = new Pref();

            pref.PrefName    = prefName.ToString();
            pref.ValueString = newValue.ToString();
            PrefC.Dict[prefName.ToString()] = pref;          //in some cases, we just want to change the pref in local memory instead of doing a refresh afterwards.
            return(retVal);
        }
Пример #4
0
        ///<summary>Used for prefs that are non-standard.  Especially by outside programmers. Returns true if a change was required, or false if no change needed.</summary>
        public static bool UpdateRaw(string prefName, string newValue)
        {
            //Very unusual.  Involves cache, so Meth is used further down instead of here at the top.
            if (!PrefC.Dict.ContainsKey(prefName))
            {
                throw new ApplicationException(prefName + " is an invalid pref name.");
            }
            if (PrefC.GetRaw(prefName) == newValue)
            {
                return(false);               //no change needed
            }
            string command = "UPDATE preference SET "
                             + "ValueString = '" + POut.String(newValue) + "' "
                             + "WHERE PrefName = '" + POut.String(prefName) + "'";
            bool retVal = true;

            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                retVal = Meth.GetBool(MethodBase.GetCurrentMethod(), prefName, newValue);
            }
            else
            {
                Db.NonQ(command);
            }
            Pref pref = new Pref();

            pref.PrefName        = prefName;
            pref.ValueString     = newValue;
            PrefC.Dict[prefName] = pref;
            return(retVal);
        }
Пример #5
0
		///<summary></summary>
		public static void Update(Pref pref) {
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
				Meth.GetVoid(MethodBase.GetCurrentMethod(),pref);
				return;
			}
			//Don't use CRUD here because we want to update based on PrefName instead of PrefNum.  Otherwise, it might fail the first time someone runs 7.6.
			string command= "UPDATE preference SET "
				+"ValueString = '"+POut.String(pref.ValueString)+"' "
				+" WHERE PrefName = '"+POut.String(pref.PrefName)+"'";
			Db.NonQ(command);
		}
Пример #6
0
		///<summary></summary>
		public static void Update(Pref pref) {
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
				Meth.GetVoid(MethodBase.GetCurrentMethod(),pref);
				return;
			}
			//Don't use CRUD here because we want to update based on PrefName instead of PrefNum.  Otherwise, it might fail the first time someone runs 7.6.
			string command= "UPDATE preference SET "
				+"ValueString = '"+POut.String(pref.ValueString)+"' "
				+" WHERE PrefName = '"+POut.String(pref.PrefName)+"'";
			Db.NonQ(command);
		}
Пример #7
0
        ///<Summary>Gets a pref of type bool, but will not throw an exception if null or not found.  Indicate whether the silent default is true or false.</Summary>
        public static bool GetBoolSilent(PrefName prefName, bool silentDefault)
        {
            if (Prefs.DictIsNull())
            {
                return(silentDefault);
            }
            Pref pref = null;

            ODException.SwallowAnyException(() => {
                pref = Prefs.GetOne(prefName);
            });
            return(pref == null ? silentDefault : PIn.Bool(pref.ValueString));
        }
Пример #8
0
        ///<summary></summary>
        public static void FillHList(DataTable table)
        {
            HList = new Hashtable();
            Pref pref;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                pref             = new Pref();
                pref.PrefName    = PIn.PString(table.Rows[i][0].ToString());
                pref.ValueString = PIn.PString(table.Rows[i][1].ToString());
                HList.Add(pref.PrefName, pref);
            }
        }
Пример #9
0
        ///<summary>Gets culture info from DB if possible, if not returns current culture.</summary>
        public static CultureInfo GetLanguageAndRegion()
        {
            CultureInfo cultureInfo = CultureInfo.CurrentCulture;

            ODException.SwallowAnyException(() => {
                Pref pref = Prefs.GetOne("LanguageAndRegion");
                if (!string.IsNullOrEmpty(pref.ValueString))
                {
                    cultureInfo = CultureInfo.GetCultureInfo(pref.ValueString);
                }
            });
            return(cultureInfo);
        }
Пример #10
0
        ///<summary>Gets a pref of type string.  Will not throw an exception if null or not found.</summary>
        public static string GetStringSilent(PrefName prefName)
        {
            if (Prefs.DictIsNull())
            {
                return("");
            }
            Pref pref = null;

            ODException.SwallowAnyException(() => {
                pref = Prefs.GetOne(prefName);
            });
            return(pref == null ? "" : pref.ValueString);
        }
Пример #11
0
		///<summary></summary>
		public static void FillCache(DataTable table){
			//No need to check RemotingRole; no call to db.
			PrefC.Dict=new Dictionary<string,Pref>();
			Pref pref;
			//PrefName enumpn;
			//Can't use Crud.PrefCrud.TableToList(table) because it will fail the first time someone runs 7.6 before conversion.
			for(int i=0;i<table.Rows.Count;i++) {
				pref=new Pref();
				if(table.Columns.Contains("PrefNum")) {
					pref.PrefNum=PIn.Long(table.Rows[i]["PrefNum"].ToString());
				}
				pref.PrefName=PIn.String(table.Rows[i]["PrefName"].ToString());
				pref.ValueString=PIn.String(table.Rows[i]["ValueString"].ToString());
				//no need to load up the comments.  Especially since this will fail when user first runs version 5.8.
				PrefC.Dict.Add(pref.PrefName,pref);
			}
		}
Пример #12
0
        ///<summary></summary>
        public static void FillCache(DataTable table)
        {
            //No need to check RemotingRole; no call to db.
            PrefC.Dict = new Dictionary <string, Pref>();
            Pref pref;

            //PrefName enumpn;
            //Can't use Crud.PrefCrud.TableToList(table) because it will fail the first time someone runs 7.6 before conversion.
            for (int i = 0; i < table.Rows.Count; i++)
            {
                pref = new Pref();
                if (table.Columns.Contains("PrefNum"))
                {
                    pref.PrefNum = PIn.Long(table.Rows[i]["PrefNum"].ToString());
                }
                pref.PrefName    = PIn.String(table.Rows[i]["PrefName"].ToString());
                pref.ValueString = PIn.String(table.Rows[i]["ValueString"].ToString());
                //no need to load up the comments.  Especially since this will fail when user first runs version 5.8.
                PrefC.Dict.Add(pref.PrefName, pref);
            }
        }
Пример #13
0
		///<summary>Updates a pref of type long.  Returns true if a change was required, or false if no change needed.</summary>
		public static bool UpdateLong(PrefName prefName,long newValue) {
			//Very unusual.  Involves cache, so Meth is used further down instead of here at the top.
			if(!PrefC.Dict.ContainsKey(prefName.ToString())) {
				throw new ApplicationException(prefName+" is an invalid pref name.");
			}
			if(PrefC.GetLong(prefName)==newValue) {
				return false;//no change needed
			}
			string command= "UPDATE preference SET "
				+"ValueString = '"+POut.Long(newValue)+"' "
				+"WHERE PrefName = '"+POut.String(prefName.ToString())+"'";
			bool retVal=true;
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
				retVal=Meth.GetBool(MethodBase.GetCurrentMethod(),prefName,newValue);
			}
			else{
				Db.NonQ(command);
			}
			Pref pref=new Pref();
			pref.PrefName=prefName.ToString();
			pref.ValueString=newValue.ToString();
			PrefC.Dict[prefName.ToString()]=pref;//in some cases, we just want to change the pref in local memory instead of doing a refresh afterwards.
			return retVal;
		}
Пример #14
0
        ///<summary>Gets a Pref object when the PrefName is provided</summary>
        public static Pref GetPref(String PrefName)
        {
            Pref pref = PrefC.Dict[PrefName];

            return(pref);
        }
Пример #15
0
		///<summary>Used for prefs that are non-standard.  Especially by outside programmers. Returns true if a change was required, or false if no change needed.</summary>
		public static bool UpdateRaw(string prefName,string newValue) {
			//Very unusual.  Involves cache, so Meth is used further down instead of here at the top.
			if(!PrefC.Dict.ContainsKey(prefName)) {
				throw new ApplicationException(prefName+" is an invalid pref name.");
			}
			if(PrefC.GetRaw(prefName)==newValue) {
				return false;//no change needed
			}
			string command = "UPDATE preference SET "
				+"ValueString = '"+POut.String(newValue)+"' "
				+"WHERE PrefName = '"+POut.String(prefName)+"'";
			bool retVal=true;
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
				retVal=Meth.GetBool(MethodBase.GetCurrentMethod(),prefName,newValue);
			}
			else {
				Db.NonQ(command);
			}
			Pref pref=new Pref();
			pref.PrefName=prefName;
			pref.ValueString=newValue;
			PrefC.Dict[prefName]=pref;
			return retVal;
		}
Пример #16
0
Файл: Prefs.cs Проект: mnisl/OD
		///<summary>Returns true if a change was required, or false if no change needed.</summary>
		public static bool UpdateBool(PrefName prefName,bool newValue,bool isForced) {
			//Very unusual.  Involves cache, so Meth is used further down instead of here at the top.
			Dictionary<string,Pref> dictPrefs=PrefC.GetDict();
			if(!dictPrefs.ContainsKey(prefName.ToString())) {
				throw new ApplicationException(prefName+" is an invalid pref name.");
			}
			if(!isForced && PrefC.GetBool(prefName)==newValue) {
				return false;//no change needed
			}
			string command="UPDATE preference SET "
				+"ValueString = '"+POut.Bool(newValue)+"' "
				+"WHERE PrefName = '"+POut.String(prefName.ToString())+"'";
			bool retVal=true;
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
				retVal=Meth.GetBool(MethodBase.GetCurrentMethod(),prefName,newValue,isForced);
			}
			else{			
				Db.NonQ(command);
			}
			Pref pref=new Pref();
			pref.PrefName=prefName.ToString();
			pref.ValueString=POut.Bool(newValue);
			Dictionary<string,Pref> dictPrefsUpdated=PrefC.GetDict();
			dictPrefsUpdated[prefName.ToString()]=pref;
			PrefC.Dict=dictPrefsUpdated;
			return retVal;
		}
Пример #17
0
 public static void UpdateValueForKey(Pref pref)
 {
     _prefCache.SetValueForKey(pref.PrefName, pref);
 }