public DefinitionBase UnpackDefinition(FieldList source) { int appID = source[MessageOutFieldID.ApplicationID].AsInteger() ?? 0; int defID = source[MessageOutFieldID.DefinitionID].AsInteger() ?? 0; DefinitionBase liveEntity = CreateDefinition(source); if (liveEntity != null) { // find cache item ID and cache hint CacheItemID?ciid = null; byte cacheHint = 0; byte[] ciidData = source[MessageOutFieldID.CacheItemID].AsByteArray(); if (ciidData != null) { ciid = new CacheItemID(ciidData); cacheHint = source[MessageOutFieldID.CacheHint].AsByte() ?? 0; } // add to cache (global or local) if (ciid.HasValue) { Core.Cache.Server.Add( liveEntity, ciid, EntityID.Create(CacheEntityType.Definition, appID, defID), CacheEntityType.Definition, cacheHint, true); } } return(liveEntity); }
private void OnReceivedNode(FieldList source, NodeTransition transition, bool isPopup, long targetID) { // get node URI string currentNodeURI = source[MessageOutFieldID.ItemURI].AsString(); // unpack cache info and see if we have got some cache attributes CacheItemID?ciid = null; byte cacheHint = 0; byte[] ciidData = source[MessageOutFieldID.CacheItemID].AsByteArray(); if (ciidData != null) { ciid = new CacheItemID(ciidData); cacheHint = source[MessageOutFieldID.CacheHint].AsByte() ?? 0; } if (String.IsNullOrEmpty(currentNodeURI) && !ciid.HasValue) { return; // this field list does not contain any valid node data } // cache node message if (Core.Cache.ShouldCache(cacheHint)) { Core.Cache.Server.Add(source, ciid, StringHelper.GetBytes(currentNodeURI), CacheEntityType.Node, cacheHint); } UnpackNode(source, currentNodeURI, ciid, targetID, transition, isPopup); }
public void Remove(CacheItemID ciid) { if (ciidIndex.ContainsKey(ciid)) { // find record id long recordID = ciidIndex[ciid]; // try to find paired key byte[] key = null; if (linkIndex.ContainsKey(recordID)) { key = linkIndex[recordID]; } // remove CIID ciidIndex.Remove(ciid); // remove key and link (if any) if (key != null) { keyIndex.Remove(key); linkIndex.Remove(recordID); } // remove live entity (if any) if (liveIndex.ContainsKey(recordID)) { liveIndex.Remove(recordID); } } }
public bool Contains(CacheItemID ciid) { if (store != null) { return(indices.Contains(ciid)); } else { return(false); } }
public byte[] FindKey(CacheItemID ciid) { if (store != null) { return(indices.FindKey(ciid)); } else { return(null); } }
public byte[] FindKey(CacheItemID ciid) { long recordID = this[ciid]; if ((recordID != CacheStore.BadRecordID) && linkIndex.ContainsKey(recordID)) { return(linkIndex[recordID]); } return(null); }
public void OnMessageReceived(WaveServerComponent dest, Enum msgID, WaveMessage data) { if (msgID is CacheAgentMessageID) { if (data != null) { switch ((CacheAgentMessageID)msgID) { case CacheAgentMessageID.RequestCacheHash: { WaveMessage msgOut = new WaveMessage(); msgOut.AddBinary(CacheAgentFieldID.CacheHash, Server.CalculateHash()); // return cache's own CIID (if any) if (cacheID.HasValue) { msgOut.AddBinary(MessageOutFieldID.CacheItemID, cacheID.Value.ToByteArray()); } msgOut.Send(WaveServerComponent.CacheAgent, CacheAgentMessageID.CacheHashCheck); break; } case CacheAgentMessageID.SendWABCacheCIID: { BinaryField bin = (BinaryField)data[MessageOutFieldID.CacheItemID]; if (bin.Data != null) { CacheItemID temp = new CacheItemID(bin.Data); if (!cacheID.HasValue || !cacheID.Value.Equals(temp)) { cacheID = temp; goto case CacheAgentMessageID.ClearCache; } } break; } case CacheAgentMessageID.ClearCache: { Server.Clear(); break; } } } } }
public void Remove(CacheItemID ciid) { if (store != null) { long recordID = indices[ciid]; if (recordID != BadRecordID) { store.Remove(recordID); indices.Remove(ciid); } } }
public long this[CacheItemID ciid] { get { long res; if (ciidIndex.TryGetValue(ciid, out res)) { return(res); } else { return(CacheStore.BadRecordID); } } }
public object this[CacheItemID id] { get { if (store != null) { long recordID = indices[id]; if (recordID != BadRecordID) { ICacheRecord record = store[recordID]; if (record != null) { return(CacheHelper.Unpack(record.Data)); } } } return(null); } }
public void UnpackDefinitions(List <FieldList> sources) { if ((sources != null) && (sources.Count > 0)) { List <CacheDataTemplate> templates = new List <CacheDataTemplate>(sources.Count); foreach (FieldList source in sources) { int appID = source[MessageOutFieldID.ApplicationID].AsInteger() ?? 0; int defID = source[MessageOutFieldID.DefinitionID].AsInteger() ?? 0; DefinitionBase liveEntity = CreateDefinition(source); if (liveEntity != null) { // find cache item ID and cache hint CacheItemID?ciid = null; byte cacheHint = 0; byte[] ciidData = source[MessageOutFieldID.CacheItemID].AsByteArray(); if (ciidData != null) { ciid = new CacheItemID(ciidData); cacheHint = source[MessageOutFieldID.CacheHint].AsByte() ?? 0; } if (ciid.HasValue) { templates.Add(new CacheDataTemplate(liveEntity, ciid, EntityID.Create(CacheEntityType.Definition, appID, defID), CacheEntityType.Definition, cacheHint)); } } } Core.Cache.Server.AddRange(templates, true); } }
public void OnMessageReceived(WaveServerComponent dest, Enum msgID, WaveMessage data) { if (msgID is NaviAgentMessageID) { if (data != null) { switch ((NaviAgentMessageID)msgID) { case NaviAgentMessageID.ApplicationResponse: { UnpackApplicationID(data.RootList); // if we've got a cache item ID but no node URI in the message then the server is // telling us that the home node is already in our cache if (data.RootList.GetItemCount(MessageOutFieldID.ItemURI) == 0) { byte[] ciidData = data.RootList[MessageOutFieldID.CacheItemID].AsByteArray(); if (ciidData != null) { CacheItemID ciid = new CacheItemID(ciidData); byte[] bin = Core.Cache.Server.FindKey(ciid); if (bin != null) { string uri = StringHelper.GetString(bin); if (!String.IsNullOrEmpty(uri)) { FindAndStoreApplicationMessagePrefix(uri); } GoToNodeByID(ciid, String.Empty, NodeTransition.None, false, Core.UI.RootViewID); break; } } } // we also have the home node goto case NaviAgentMessageID.NodeResponse; } case NaviAgentMessageID.NodeResponse: { UnpackReceivedNode(data.RootList); break; } case NaviAgentMessageID.NodeIsInClientCache: { CacheItemID?ciid = null; short requestID = data.RootList[MessageOutFieldID.RequestID].AsShort() ?? -1; byte[] ciidData = data.RootList[MessageOutFieldID.CacheItemID].AsByteArray(); string uri = data.RootList[MessageOutFieldID.ItemURI].AsString(); if (ciidData != null) { ciid = new CacheItemID(ciidData); } RequestData rd = Core.Navigation.Requests.Remove(requestID); if (rd != null) { GoToNodeByID(ciid, uri, rd.Transition, rd.IsPopup, rd.ViewID); } else { GoToNodeByID(ciid, uri, NodeTransition.None, false, Core.UI.RootViewID); } break; } case NaviAgentMessageID.NodeResponseError: { View view = Core.UI[Core.Navigation.Requests.RemoveEx(data.RootList[MessageOutFieldID.RequestID].AsShort() ?? -1)]; if (view != null) { view.SignalNavigationFailure(); } break; } case NaviAgentMessageID.FormResponse: { if (data.RootList.GetItemCount(NaviAgentFieldID.SubmitFormResult) != 1) { break; // illegal message, only one form result should exist } SubmitFormResult sfr = (SubmitFormResult)(data[NaviAgentFieldID.SubmitFormResult].AsShort() ?? (short)SubmitFormResult.Empty); if (sfr == SubmitFormResult.NodeResponse) { UnpackReceivedNode(data.RootList); } //TODO: add waiting for result for form submit/response cycle (when navigation is replaced) break; } default: break; } } } }
private void UnpackNode(FieldList source, string currentNodeURI, CacheItemID?ciid, long targetID, NodeTransition transition, bool isPopup) { NodeData data = new NodeData(); data.ApplicationID = currentApplicationID; data.ShouldGoToBackStack = !(source[NaviAgentFieldID.DoNotAddNodeToBackStack].AsBoolean() ?? false); //IMPLEMENT: back stack skipping // set node uri if (String.IsNullOrEmpty(currentNodeURI)) { currentNodeURI = source[MessageOutFieldID.ItemURI].AsString(); } data.URI = currentNodeURI; // set current node ciid if (!ciid.HasValue) { data.WasCached = false; byte cacheHint = 0; byte[] ciidData = source[MessageOutFieldID.CacheItemID].AsByteArray(); if (ciidData != null) { ciid = new CacheItemID(ciidData); cacheHint = source[MessageOutFieldID.CacheHint].AsByte() ?? 0; data.WasCached = Core.Cache.ShouldCache(cacheHint); } } else { data.WasCached = true; } // unpack application id UnpackApplicationID(source, data); data.ID = ciid; data.Transition = transition; data.IsPopup = isPopup; // Update the system events ApplicationEvents = Core.Definitions.GetApplicationEvents(data.ApplicationID); data.Root = null; int definitionID = source[MessageOutFieldID.DefinitionID].AsInteger() ?? 0; data.Root = Core.Definitions.Find(data.ApplicationID, definitionID) as BlockDefinition; data.RootContent = source; // unpack signpost names (if any) List <StringField> signpostNames = source.GetItems <StringField>(NaviAgentFieldID.SignpostName); if (signpostNames.Count > 0) { data.SignpostNames = new List <string>(); foreach (StringField field in signpostNames) { data.SignpostNames.Add(field.Data); } } Core.UI.SignalViewNavigationSuccess(targetID, data); }
public bool Contains(CacheItemID ciid) { return(ciidIndex.ContainsKey(ciid)); }
public bool LoadFromStream(Stream str) { if (str != null) { if (str.ReadByte() == 0) { long id = str.ReadLong(); short entType = str.ReadShort(); short cacheMode = str.ReadShort(); if ((id != -1) && (entType != -1) && (cacheMode != -1)) { int ciidLength = str.ReadByte(); if (ciidLength != -1) { byte[] ciid = null; if (ciidLength > 0) { ciid = str.ReadBytes(ciidLength); } short keyLength = str.ReadShort(); if (keyLength != -1) { byte[] key = null; if (keyLength > 0) { key = str.ReadBytes(keyLength); } short dataFileLength = str.ReadShort(); if (dataFileLength != -1) { string dataFileName = null; if (dataFileLength > 0) { byte[] dataFileBytes = str.ReadBytes(dataFileLength); if (dataFileBytes != null) { dataFileName = StringHelper.GetString(dataFileBytes); } } if (!String.IsNullOrEmpty(dataFileName) && (id != CacheStore.BadRecordID) && IsolatedStorageHelper.FileExists( String.Format( CacheStore.CacheFilePathFormat, FileCacheStore.CacheDirectory, dataFileName, FileCacheStore.CacheFileExtension))) { ID = id; EntityType = (CacheEntityType)entType; CacheMode = (CacheMode)cacheMode; if (ciid != null) { CIID = new CacheItemID(ciid); } else { CIID = null; } Key = key; dataFile = dataFileName; return(true); } } } } } } } return(false); }