public RecordStream(CacheRecord record) { this.record = record; lock (record) { var isEmpty = record.length == 0; canWrite = record.locks++ == 0 && isEmpty; try { var path = record.Path; if (canWrite) { stream = File.Open(path, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete); } else { if (isEmpty) { inUse = true; record.Released += record_Released; } stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete); } } catch (Exception e) { Util.Logging.Log(e); } } }
public override object Do(PanelContext data) { string tag = data.Objects["tag"] as string; List <DataKey> dataKeys = data.State as List <DataKey>; if (!String.IsNullOrEmpty(tag) && dataKeys != null) { foreach (DataKey key in dataKeys) { string id = key["ID"] as string; Article a = ArticleHelper.GetArticle(id, null); if (a != null) { a.Tags += String.Format("'{0}'", tag); if (!String.IsNullOrEmpty(a.ModelXml)) { DataSet ds = BaseDataProvider.CreateDataSet(data.Model); BaseDataProvider.ReadXml(ds, a.ModelXml); if (ds.Tables[data.Table.Name].Rows.Count > 0 && ds.Tables[data.Table.Name].Columns.Contains("Tags")) { ds.Tables[data.Table.Name].Rows[0]["Tags"] = a.Tags; a.ModelXml = BaseDataProvider.GetXml(ds); } } AddTagToSingleTable(data, id, a.Tags); ArticleHelper.UpdateArticle(a, new string[] { "Tags", "ModelXml" }); } } } UIHelper.SendMessage("添加标签成功"); CacheRecord.Create(data.ModelName).Release(); return(false); }
public object Do(PanelContext data) { ModelDBHelper subHelper = ModelDBHelper.Create(data.ModelName); DataTable db = subHelper.Query(new Criteria(CriteriaType.Equals, "ID", data.DataKey.Value), new List <Order> { new Order("ID") }); DbProvider.Instance(data.Model.Type).Delete(data); foreach (We7Control ctrl in ModelHelper.GetPanelContext(data.ModelName, "edit").Panel.EditInfo.Controls) { if (!string.IsNullOrEmpty(ctrl.Params["count"])) { Dictionary <string, object> dic = new Dictionary <string, object>(); dic.Add(string.Format("{0}_Count", data.Model.Name), subHelper.Count(new Criteria(CriteriaType.Equals, ctrl.Name, db.Rows[0][ctrl.Name]))); ModelDBHelper helper = ModelDBHelper.Create(ctrl.Params["model"]); helper.Update(dic, new Criteria(CriteriaType.Equals, ctrl.Params["valuefield"], db.Rows[0][ctrl.Name])); } string fileurl = HttpContext.Current.Server.MapPath(db.Rows[0][ctrl.Name].ToString()); if (ctrl.Type == "MultiUploadify" && File.Exists(fileurl)) { File.Delete(fileurl); File.Delete(fileurl.Insert(fileurl.LastIndexOf('.'), "_thumb")); } } CacheRecord.Create(data.ModelName).Release(); return(null); }
protected void DeleteDepartmentButton_Click(object sender, EventArgs e) { try { if (DemoSiteMessage) { return; //是否是演示站点 } string dptID = IDTextBox.Text; string dptName = NameTextBox.Text; Department dpt = AccountHelper.GetDepartment(dptID, new string[] { "ParentID" }); AccountHelper.DeleteDepartment(dptID); CacheRecord.Create(typeof(AccountLocalHelper)).Release(); string content = string.Format("删除部门“{0}”", dptName); AddLog("删除部门", content); Response.Redirect(String.Format("Departments.aspx?id={0}", dpt.ParentID)); } catch (Exception ex) { Messages.ShowMessage("删除部门出错!出错原因:" + ex.Message); } }
private void AddToCacheRecordsThread(object cacheRecordObject) { CacheRecord cacheRecord = cacheRecordObject as CacheRecord; if (cacheRecord != null) { lock (this.cacheRecordsSynchronizer) { if (this.cacheRecords.ContainsKey(cacheRecord.FileName)) { this.RemoveFromCacheRecords(cacheRecord.FileName); } this.cacheRecords.Add(cacheRecord.FileName, cacheRecord); this.cacheRecordsSize += cacheRecord.FileLength; this.cacheRecordsOrder.Add(cacheRecord.FileName); while (this.memoryMaxSize > 0 && this.cacheRecordsSize > this.memoryMaxSize && this.cacheRecordsOrder.Count > 0) { this.RemoveFromCacheRecords(this.cacheRecordsOrder[0]); } } } }
object ICommand.Do(PanelContext data) { string oid = data.Objects["oid"] as string; if (We7Helper.IsEmptyID(oid)) { throw new Exception("不能添加到根栏目"); } Channel targetChannel = HelperFactory.Instance.GetHelper <ChannelHelper>().GetChannel(oid); if (targetChannel != null && !String.IsNullOrEmpty(targetChannel.ModelName)) { ModelInfo modelInfo = ModelHelper.GetModelInfo(targetChannel.ModelName); We7DataTable dt = modelInfo.DataSet.Tables[0]; List <DataKey> dataKeys = data.State as List <DataKey>; foreach (DataKey dk in dataKeys) { string id = dk["ID"].ToString(); SingleTableLinkTo(data, dt, id); } } UIHelper.SendMessage("引用成功"); CacheRecord.Create(data.ModelName).Release(); return(null); }
public override object Do(PanelContext data) { List <DataKey> dataKeys = data.State as List <DataKey>; if (dataKeys != null) { foreach (DataKey key in dataKeys) { string id = key["ID"] as string; if (ChannelProcess(id)) { Article a = ArticleHelper.GetArticle(id); Processing ap = ArticleProcessHelper.GetArticleProcess(a); if (ap.ArticleState != ArticleStates.Checking) { string accName = AccountHelper.GetAccount(AccountID, new string[] { "LastName" }).LastName; ap.ProcessState = ProcessStates.FirstAudit; ap.ProcessDirection = ((int)ProcessAction.Next).ToString(); ap.ProcessAccountID = AccountID; ap.ApproveName = accName; ArticleProcessHelper.SaveFlowInfoToDB(a, ap); } } } } CacheRecord.Create(data.ModelName).Release(); return(null); }
public object Do(PanelContext data) { string oid = data.Objects["oid"] as string; if (We7Helper.IsEmptyID(oid)) { UIHelper.Message.AppendInfo(MessageType.ERROR, "不能移动到根栏目"); } ChannelHelper chHelper = HelperFactory.Instance.GetHelper <ChannelHelper>(); Channel channel = chHelper.GetChannel(oid, null); if (channel == null) { throw new Exception("当前栏目不存在"); } if (channel.ModelName != data.ModelName) { throw new Exception("移动到的栏目类型与当前栏目类型不一致"); } List <DataKey> dataKeys = data.State as List <DataKey>; foreach (DataKey key in dataKeys) { string id = key["ID"] as string; if (DbHelper.CheckTableExits(data.Table.Name)) { DbHelper.ExecuteSql(String.Format("UPDATE [{0}] SET [OwnerID]='{2}' WHERE [ID]='{1}'", data.Table.Name, id, oid)); } } UIHelper.SendMessage("移动成功"); CacheRecord.Create(data.ModelName).Release(); return(null); }
public void Can_Store_with_Prefix() { var expected = new CacheRecord() {Id = "123"}; RedisTyped.Store(expected); var current = Redis.Get<CacheRecord>("RedisTypedClientTests:urn:cacherecord:123"); Assert.AreEqual(expected.Id, current.Id); }
private IEnumerable <string> GetFilesOfSubTree(string subPath, string fileFormat) { CacheKey key = new CacheKey { SubDirectory = subPath, FileFormat = fileFormat }; if (_cache.ContainsKey(key) && (DateTime.Now - _cache[key].TimeStamp) < TimeSpan.FromMinutes(5)) { return(_cache[key].Files); } else { List <string> result = new List <string>(); var files = System.IO.Directory.GetFiles(subPath, "*" + fileFormat); result.AddRange(files); var directories = System.IO.Directory.GetDirectories(subPath); foreach (string directory in directories) { result.AddRange(GetFilesOfSubTree(directory, fileFormat)); } _cache[key] = new CacheRecord() { Files = result, TimeStamp = DateTime.Now }; return(result); } }
/// <summary> /// 取得栏目树列表对象 /// </summary> /// <returns>栏目列表</returns> protected List <Channel> GetChannelTree() { if (DesignHelper.IsDesigning) { return(DesignRecords); } StringBuilder sb = new StringBuilder(); sb.Append("ChannelDataProvider$GetChannelTree$"); sb.AppendFormat("ID:{0}$Url:{1}$", ID, We7Helper.GetChannelUrlFromUrl(Request.RawUrl)); return(CacheRecord.Create("channel").GetInstance <List <Channel> >(sb.ToString(), delegate() { channelFlag = false; List <Channel> mainMenu = GetChannels(); if (MaxTreeClass > 1) { foreach (Channel ch in mainMenu) { ch.SubChannels = GetSubChannels(ch.ID, 2); ch.HaveSon = ch.SubChannels != null && ch.SubChannels.Count > 0; ch.MenuIsSelected = We7Helper.GetChannelUrlFromUrl(Request.RawUrl).ToLower().StartsWith(ch.FullUrl.ToLower()); } } channelFlag = true; return mainMenu; })); }
private void SaveFile(CacheRecord cacheRecord) { ICacheRecordMetadata metadata = new CacheRecordMetadata(cacheRecord.FileName, cacheRecord.Expires, cacheRecord.FileStorageLength, cacheRecord.LastAccess); if (this.cacheMetadataDictionary.ContainsKey(cacheRecord.FileName)) { this.cacheSize += cacheRecord.FileStorageLength - metadata.FileStorageLength; this.cacheMetadata[this.cacheMetadata.IndexOf(this.cacheMetadataDictionary[cacheRecord.FileName])] = metadata; this.cacheMetadataDictionary[cacheRecord.FileName] = metadata; } else { this.AddMetadata(metadata); } using (ManualResetEvent complete = new ManualResetEvent(false)) { cacheRecord.CompeleEvent = complete; this.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action <CacheRecord>(this.SaveCacheFile), cacheRecord); complete.WaitOne(); } this.CheckCacheSize(); }
/// <summary> /// Loaded file from a cache to event arguments. /// </summary> /// <param name="fileName">File name.</param> /// <param name="callback">Callback which should be called to return tile if it is available or null.</param> public override void LoadAsync(string fileName, Action <byte[]> callback) { CacheRecord record = this.GetCacheRecord(fileName); byte[] tile = null; if (record == null) { ICacheRecordMetadata metaData = this.LoadFileMetadata(fileName); if (metaData != null && metaData.Expires >= DateTime.Now) { Stream stream = this.OpenCacheStream(fileName); if (stream.Length == 0) { stream.Dispose(); } else { AsyncStreamOperations.LoadAsync(stream, callback); return; } } } else { tile = record.TileBody; } callback(tile); }
/// <summary> /// 执行操作 /// </summary> /// <param name="data"></param> /// <returns></returns> public object Do(PanelContext data) { ModelDBHelper subHelper = ModelDBHelper.Create(data.ModelName); List <DataKey> dataKeys = data.State as List <DataKey>; if (dataKeys.Count == 0) { return(null); } DataTable db = subHelper.Query(new Criteria(CriteriaType.Equals, "ID", dataKeys[0].Value), new List <Order> { new Order("ID") }); ModelDBHelper temhelper = null; string columnMapping = string.Empty; if (dataKeys != null) { foreach (We7DataColumn column in data.DataSet.Tables[0].Columns) { if (column.Name.Contains("_Count")) { temhelper = ModelDBHelper.Create(data.Model.GroupName + "." + column.Name.Remove(column.Name.IndexOf("_Count"))); columnMapping = column.Mapping; } } foreach (DataKey key in dataKeys) { if (temhelper != null) { DataTable dt = subHelper.Query(new Criteria(CriteriaType.Equals, "ID", key.Value), new List <Order> { new Order("ID") }); temhelper.Delete(new Criteria(CriteriaType.Equals, columnMapping.Split('|')[0], dt.Rows[0][columnMapping.Split('|')[1]])); } data.DataKey = key; DbProvider.Instance(data.Model.Type).Delete(data); } data.DataKey = null; } foreach (We7Control ctrl in ModelHelper.GetPanelContext(data.ModelName, "edit").Panel.EditInfo.Controls) { if (!string.IsNullOrEmpty(ctrl.Params["count"])) { Dictionary <string, object> dic = new Dictionary <string, object>(); dic.Add(string.Format("{0}_Count", data.Model.Name), subHelper.Count(new Criteria(CriteriaType.Equals, ctrl.Name, db.Rows[0][ctrl.Name]))); ModelDBHelper helper = ModelDBHelper.Create(ctrl.Params["model"]); helper.Update(dic, new Criteria(CriteriaType.Equals, ctrl.Params["valuefield"], db.Rows[0][ctrl.Name])); } string fileurl = HttpContext.Current.Server.MapPath(db.Rows[0][ctrl.Name].ToString()); if (ctrl.Type == "MultiUploadify" && File.Exists(fileurl)) { File.Delete(fileurl); File.Delete(fileurl.Insert(fileurl.LastIndexOf('.'), "_thumb")); } } CacheRecord.Create(data.ModelName).Release(); return(null); }
public void Store(string fileName, RunStatistics stats) { var fileInfo = new FileInfo(fileName); _cache[fileName] = new CacheRecord { LastModified = fileInfo.LastWriteTimeUtc, Statistics = stats }; }
private void RemoveFromCacheRecords(string fileName) { CacheRecord removedCacheRecord = this.cacheRecords[fileName]; this.cacheRecordsSize -= removedCacheRecord.FileLength; this.cacheRecords.Remove(fileName); this.cacheRecordsOrder.Remove(fileName); }
protected void bttnGenerate_Click(object sender, EventArgs e) { foreach (ListItem item in chkItem.Items) { CacheRecord.Create(item.Value).Release(); } Messages.ShowMessage("缓存更新成功"); }
/// <summary> /// 取得类别关键字 /// </summary> /// <param name="arg"></param> /// <returns></returns> public static string GetCatName(object arg) { string keyword = arg as string; return(!String.IsNullOrEmpty(keyword) ? CacheRecord.Create(typeof(CategoryHelper)).GetInstance <string>("Name$" + keyword, () => { Category category = HelperFactory.Instance.GetHelper <CategoryHelper>().GetCategoryByKeyword(keyword); return category != null ? category.Name : String.Empty; }) : String.Empty); }
/// <summary> /// 根据部门ID取得部门名称 /// </summary> /// <param name="arg"></param> /// <returns></returns> public static string GetDepartName(object arg) { string departId = arg as string; return(!String.IsNullOrEmpty(departId) ? CacheRecord.Create(typeof(AccountLocalHelper)).GetInstance <string>("Name$" + departId, () => { Department depart = AccountFactory.CreateInstance().GetDepartment(departId, null); return depart != null ? depart.Name : String.Empty; }) : String.Empty); }
private void SaveFileMetadataCallback(object userState) { CacheRecord cacheRecord = userState as CacheRecord; if (cacheRecord != null) { this.SaveFileMetadata(cacheRecord); cacheRecord.CompeleEvent.Set(); } }
public void Can_Store_with_Prefix() { var expected = new CacheRecord { Id = "123" }; this._redisTyped.Store(expected); var current = this.Redis.Get <CacheRecord>(this.PrefixedKey("urn:cacherecord:123")); Assert.AreEqual(expected.Id, current.Id); }
public virtual void Invalidate(IData key) { try { CacheRecord record = null; cache.TryRemove(key, out record); } catch (ArgumentNullException e) { } }
/// <summary> /// Reads buffer. /// </summary> /// <param name="fileName">File name.</param> /// <returns>Byte array of file image.</returns> protected byte[] GetBuffer(string fileName) { CacheRecord record = this.GetCacheRecord(fileName); if (record != null) { return(record.TileBody); } return(null); }
public void Store(string source, string translator, string language, string result) { CacheRecord rec; if (!dict.TryGetValue(source, out rec)) { rec = new CacheRecord(); dict.Add(source, rec); } rec[new CacheKey(translator, language)] = result; }
public static void Add(string key, object val, Type elemType, object factory) { lock (s_cache) { if (!s_cache.ContainsKey(key)) { CacheRecord rec = CacheRecord.Create(val, elemType, factory); s_cache.Add(key, rec); } } }
public int GetLastReadIndex(string sensorName) { CacheRecord record = null; if (this.DataMap.TryGetValue(sensorName, out record)) { return(record.CsvRecords.Count - 1); } return(-1); }
public CacheRecord GetAllSensorRecords(string sensorName) { CacheRecord sensorRecord = null; if (this.DataMap.TryGetValue(sensorName, out sensorRecord)) { return(sensorRecord); } return(null); }
public async Task Can_Store_with_Prefix() { var expected = new CacheRecord() { Id = "123" }; await RedisTyped.StoreAsync(expected); var current = await RedisAsync.GetAsync <CacheRecord>("RedisTypedClientTests:urn:cacherecord:123"); Assert.AreEqual(expected.Id, current.Id); }
public void Can_Store_with_Prefix() { var expected = new CacheRecord() { Id = "123" }; RedisTyped.Store(expected); var current = Redis.Get <CacheRecord>("RedisTypedClientTests:urn:cacherecord:123"); Assert.AreEqual(expected.Id, current.Id); }
/// <summary> /// Saves the file to the storage. /// </summary> /// <param name="fileName">File name.</param> /// <param name="expirationDate">Expiration date.</param> /// <param name="tile">Byte array which is saved to the file.</param> public override void Save(string fileName, DateTime expirationDate, byte[] tile) { base.Save(fileName, expirationDate, tile); expirationDate = this.CoerceExpirationDate(expirationDate); CacheRecord cacheRecord = new CacheRecord(fileName, tile, expirationDate, this is IsolatedStorageCache); lock (this.queueSynchronizer) { this.queue.Enqueue(cacheRecord); this.processRequest.Set(); } }
protected void SaveButton_Click(object sender, EventArgs e) { try { SaveDepartment(); CacheRecord.Create(typeof(AccountLocalHelper)).Release(); } catch (CDException ce) { ContentPanel.Visible = false; Messages.ShowError(ce.Message); } }
public void Can_Expire() { var cachedRecord = new CacheRecord { Id = "key", Children = { new CacheRecordChild { Id = "childKey", Data = "data" } } }; RedisTyped.Store(cachedRecord); RedisTyped.ExpireIn("key", TimeSpan.FromSeconds(1)); Assert.That(RedisTyped.GetById("key"), Is.Not.Null); Thread.Sleep(2000); Assert.That(RedisTyped.GetById("key"), Is.Null); }
public void Can_ExpireAt() { var cachedRecord = new CacheRecord { Id = "key", Children = { new CacheRecordChild { Id = "childKey", Data = "data" } } }; RedisTyped.Store(cachedRecord); var in1Sec = DateTime.Now.AddSeconds(1); RedisTyped.ExpireAt("key", in1Sec); Assert.That(RedisTyped.GetById("key"), Is.Not.Null); Thread.Sleep(2000); Assert.That(RedisTyped.GetById("key"), Is.Null); }
private IEnumerator wwwLoad(string fileName, ObjectLoaderCallback callback) { if (_loaders.Count >= MAX_THREADS) { Callback waitingRec; waitingRec.callback = callback; waitingRec.url = fileName; _waiting.Add(waitingRec); return true; } WWW www = new WWW(fileName); _loaders.Add(www); yield return www; _loaders.Remove(www); AssetBundle assetData = null; if (www.error != null) { Debug.LogWarning("AssetLoader: " + www.error); } else { assetData = www.assetBundle; CacheRecord cacheRec = new CacheRecord(); cacheRec.url = www.url; cacheRec.obj = assetData; _cache.Add(cacheRec); } if (callback != null) { try { callback(assetData); } catch { Debug.Log("AssetLoader: callback error for file " + fileName); } } for (int i = 0; i < _callback.Count; i++) { if (_callback[i].url == fileName) { try { _callback[i].callback(assetData); } catch { Debug.Log("AssetLoader: callback error for file " + fileName); } _callback.RemoveAt(i); i--; } } if (_waiting.Count > 0) { Callback waitingRec = _waiting[0]; _waiting.RemoveAt(0); StartCoroutine(wwwLoad(waitingRec.url, waitingRec.callback)); } }
public void Can_Delete_All_Items() { var cachedRecord = new CacheRecord { Id = "key", Children = { new CacheRecordChild { Id = "childKey", Data = "data" } } }; RedisTyped.Store(cachedRecord); Assert.That(RedisTyped.GetById("key"), Is.Not.Null); RedisTyped.DeleteAll(); Assert.That(RedisTyped.GetById("key"), Is.Null); }