public override string EvaluateExpressions(string url, string arg, bool bEncrypt, bool includeSession) { ConfigurationRecord rec = null; try { rec = this.GetRecord(); } catch (Exception) { // Do Nothing } if (rec == null && url.IndexOf("{") >= 0) { // Localization. throw new Exception(Page.GetResourceValue("Err:RecDataSrcNotInitialized", "OLR")); } if (includeSession) { return(EvaluateExpressions(url, arg, rec, bEncrypt)); } else { return(EvaluateExpressions(url, arg, rec, bEncrypt, includeSession)); } }
public void GetValueWithId_CacheExists_Returns() { var objectId = new MongoDB.Bson.ObjectId(); var configurationRecord = new ConfigurationRecord() { Value = "boyner.com.tr", Type = "String", GuId = objectId, Name = "site" }; List <ConfigurationRecord> configurationRecords = new List <ConfigurationRecord>() { new ConfigurationRecord() { Name = "site", Value = "boyner.com.tr", Type = "String" } }; _configurationStorage.Get(Arg.Any <string>(), applicationName).Returns(configurationRecord); _cacheManager.Get <IEnumerable <ConfigurationRecord> >("site").Returns(configurationRecords); var manager = new ConfigurationReader(applicationName, "hede", 10, _configurationStorageFactory, _cacheManagerFactory, _configurationStorage); var returnValue = manager.GetValueWithId("site"); Assert.AreEqual(configurationRecords[0].Value, returnValue.Value); }
public void GetValue_CacheExists_Returns() { string applicationName = "applicationA"; var configurationRecord = new ConfigurationRecord() { Value = "boyner.com.tr", Type = "String" }; List <ConfigurationRecord> configurationRecords = new List <ConfigurationRecord>() { new ConfigurationRecord() { Name = "site", Value = "boyner.com.tr", Type = "String" } }; _configurationStorage.GetWithKey("site", applicationName).Returns(configurationRecord); _cacheManager.Get <IEnumerable <ConfigurationRecord> >(Arg.Any <string>()).Returns(configurationRecords); var manager = new ConfigurationReader(applicationName, "hede", 10, _configurationStorageFactory, _cacheManagerFactory, _configurationStorage); var returnValue = manager.GetValue <string>("site"); Assert.AreEqual("boyner.com.tr", returnValue); }
//Audit Trail methods //Evaluates Initialize when->Reading record formulas specified at the data access layer protected virtual void ConfigurationRecord_ReadRecord(Object sender, System.EventArgs e) { //Apply Initialize->Reading record formula only if validation is successful. ConfigurationRecord ConfigurationRec = (ConfigurationRecord)sender; if (ConfigurationRec != null && !ConfigurationRec.IsReadOnly) { } }
//Evaluates Initialize when->Updating formulas specified at the data access layer protected virtual void ConfigurationRecord_UpdatingRecord(Object sender, System.ComponentModel.CancelEventArgs e) { //Apply Initialize->Updating formula only if validation is successful. ConfigurationRecord ConfigurationRec = (ConfigurationRecord)sender; Validate_Updating(); if (ConfigurationRec != null && !ConfigurationRec.IsReadOnly) { ConfigurationRec.Parse(EvaluateFormula("1", this, null), ConfigurationTable.EventId); } }
public void GetValue_CacheNotExistsTypeInvalid_ReturnsDefault() { var configurationRecord = new ConfigurationRecord() { Value = "boyner.com.tr", Type = "String" }; _configurationStorage.GetWithKey("site", applicationName).Returns(configurationRecord); _cacheManager.Get <IEnumerable <ConfigurationRecord> >("site").Returns((IEnumerable <ConfigurationRecord>)null); var manager = new ConfigurationReader(applicationName, "hede", 10, _configurationStorageFactory, _cacheManagerFactory, _configurationStorage); var returnValue = manager.GetValue <System.Int32>("site"); Assert.AreEqual(0, returnValue); }
public ActionResult IndexByVersion(int versionId) { MOE.Common.Models.Repositories.ISignalsRepository sr = MOE.Common.Models.Repositories.SignalsRepositoryFactory.Create(); var signal = sr.GetSignalVersionByVersionId(versionId); List <MOE.Common.Business.Helpers.ConfigurationRecord> records = new List <MOE.Common.Business.Helpers.ConfigurationRecord>(); foreach (MOE.Common.Models.Detector gd in signal.GetDetectorsForSignal()) { MOE.Common.Business.Helpers.ConfigurationRecord r = new ConfigurationRecord(gd); records.Add(r); } Models.SPMConfigurationTableViewModel model = new Models.SPMConfigurationTableViewModel(); model.Records = records; return(PartialView("ConfigurationTable", model)); }
public void Update(RecordDto recorDto) { ConfigurationRecord record = new ConfigurationRecord() { ApplicationName = _applicationName, IsActive = true, Name = recorDto.Name, Type = recorDto.Type, Value = recorDto.Value, GuId = recorDto.Guid }; _storage.Update(record); ICacheManager cacheManager = _cacheManagerFactory.GetCacheProvider(_refreshTimerIntervalInMs, cacheProvider); cacheManager.Remove(_applicationName); }
public static void Initialize(ICurrentEnvironment env) { Stream defaultConfigStream = Assembly.GetExecutingAssembly().LoadStream("Chrome.BookmarkSearch.default.json"); SetRecord defaultConfig = Converter.ReadJson(defaultConfigStream) as SetRecord; string configPath = env.ConfigDirectory + "\\bookmarksearch.json"; if (File.Exists(configPath)) { try { Stream userConfigStream = File.OpenRead(configPath); SetRecord userConfig = Converter.ReadJson(userConfigStream) as SetRecord; userConfigStream.Dispose(); defaultConfig.Combine(userConfig); } catch { } } else { try { defaultConfigStream.Seek(0, SeekOrigin.Begin); FileStream configStream = File.Create(configPath); defaultConfigStream.CopyTo(configStream); configStream.Flush(); configStream.Dispose(); } catch { } } defaultConfigStream.Dispose(); ConfigurationRecord = defaultConfig; Config = new SearchConfig() { SearchUrl = ConfigurationRecord.ReadAs <bool>("allow_url_search"), EnableSearch = ConfigurationRecord.ReadAs <bool>("enable") }; Bookmarks = BookmarkCollection.Retrive(); SearchPatternErrorAction = new ErrorAction(null, "搜索模式错误", "搜索模式错误"); }
public T GetValue <T>(string key) { ICacheManager cacheManager = _cacheManagerFactory.GetCacheProvider(_refreshTimerIntervalInMs, cacheProvider); IEnumerable <ConfigurationRecord> cacheRecordDto = cacheManager.Get <IEnumerable <ConfigurationRecord> >(_applicationName); var converter = new ConfigurationConverter <T>(); if (cacheRecordDto != null && cacheRecordDto.ToList() != null && cacheRecordDto.ToList().Count > 0) { var cacheRecord = cacheRecordDto.Where(p => p.Name == key).FirstOrDefault(); bool typeMatch = TypeHelper.HasTypeMatched <T>(cacheRecord.Type); if (typeMatch) { return(converter.GetValue(cacheRecord.Value)); } else { return(default(T)); } } else { ConfigurationRecord record = _storage.GetWithKey(key, _applicationName); if (record != null) { bool typeMatch = TypeHelper.HasTypeMatched <T>(record.Type); if (typeMatch) { AddToCache(cacheManager); return(converter.GetValue(record.Value)); } else { return(default(T)); } } else { return(default(T)); } } }
public RecordDto GetValueWithId(string guid) { if (!string.IsNullOrEmpty(guid)) { IEnumerable <ConfigurationRecord> cacheRecordDto = GetCachedRecords(); if (cacheRecordDto != null && cacheRecordDto.ToList() != null & cacheRecordDto.ToList().Count > 0) { return(cacheRecordDto.Where(q => q.GuId.ToString() == guid).Select(p => new RecordDto() { ApplicationName = p.ApplicationName, Guid = p.GuId, Name = p.Name, Value = p.Value, Type = p.Type }).FirstOrDefault()); } else { ConfigurationRecord record = _storage.Get(guid, _applicationName); if (record != null) { return(new RecordDto() { ApplicationName = _applicationName, Name = record.Name, Type = record.Type, Value = record.Value, Guid = record.GuId }); } else { return(null); } } } else { return(null); } }
/// <summary> /// This is a shared function that can be used to get a ConfigurationRecord record using a where and order by clause. /// </summary> public static ConfigurationRecord GetRecord(BaseFilter join, string where, OrderBy orderBy) { SqlFilter whereFilter = null; if (where != null && where.Trim() != "") { whereFilter = new SqlFilter(where); } ArrayList recList = ConfigurationTable.Instance.GetRecordList(join, whereFilter, null, orderBy, BaseTable.MIN_PAGE_NUMBER, BaseTable.MIN_BATCH_SIZE); ConfigurationRecord rec = null; if (recList.Count > 0) { rec = (ConfigurationRecord)recList[0]; } return(rec); }
public void Write(RecordDto recorDto) { if (!string.IsNullOrEmpty(recorDto.ApplicationName) && !string.IsNullOrEmpty(recorDto.Name) && !string.IsNullOrEmpty(recorDto.Value) && !string.IsNullOrEmpty(recorDto.Type)) { ConfigurationRecord record = new ConfigurationRecord() { ApplicationName = _applicationName, IsActive = true, Name = recorDto.Name, Type = recorDto.Type, Value = recorDto.Value }; _storage.Add(record); ICacheManager cacheManager = _cacheManagerFactory.GetCacheProvider(_refreshTimerIntervalInMs, cacheProvider); cacheManager.Remove(_applicationName); } }
public static void SetupProxyAndUserAgent(bool first_setting_of_proxy) { if (!have_initialised) { Logging.Warn("GeckoFX is not setting proxy and user agent until initialised."); return; } try { ConfigurationRecord configuration_record = ConfigurationManager.Instance.ConfigurationRecord; { Logging.Info("+Setting user agent"); string user_agent = configuration_record.Web_UserAgentOverride; if (String.IsNullOrEmpty(user_agent)) { user_agent = String.Format( "Mozilla/5.0 (Windows; {0}; rv:13.0) Gecko/13.0 Firefox/13.0.0", Environment.OSVersion ); } else { Logging.Info("Using overridden user agent: {0}", user_agent); } GeckoPreferences.User["general.useragent.override"] = user_agent; Logging.Info("-Setting user agent"); } if (configuration_record.Proxy_UseProxy) { Logging.Warn("Setting PROXY for GeckoFX"); GeckoPreferences.User["network.proxy.type"] = 1; GeckoPreferences.User["network.proxy.user"] = configuration_record.Proxy_Username ?? ""; GeckoPreferences.User["network.proxy.password"] = configuration_record.Proxy_Password ?? ""; GeckoPreferences.User["network.proxy.http"] = configuration_record.Proxy_Hostname ?? ""; GeckoPreferences.User["network.proxy.http_port"] = configuration_record.Proxy_Port; GeckoPreferences.User["network.proxy.socks"] = configuration_record.Proxy_Hostname ?? ""; GeckoPreferences.User["network.proxy.socks_port"] = configuration_record.Proxy_Port; GeckoPreferences.User["network.proxy.socks_remote_dns"] = true; GeckoPreferences.User["network.proxy.ssl"] = configuration_record.Proxy_Hostname ?? ""; GeckoPreferences.User["network.proxy.ssl_port"] = configuration_record.Proxy_Port; //0 – Direct connection, no proxy. (Default) //1 – Manual proxy configuration. //2 – Proxy auto-configuration (PAC). //4 – Auto-detect proxy settings. //5 – Use system proxy settings (Default in Linux). } else { // Only try to turn off the proxy if there is a chance that we turned it on previously if (!first_setting_of_proxy) { Logging.Info("Setting DEFAULT for GeckoFX"); GeckoPreferences.User["network.proxy.type"] = 5; } else { Logging.Info("Leaving DEFAULT for GeckoFX"); } } } catch (Exception ex) { FeatureTrackingManager.Instance.UseFeature(Features.Exception_GeckoProxy); Logging.Error(ex, "There was a problem setting the Gecko proxy and user agent."); } }