/// <summary> /// Returns FetchKindResponse structs for a given ResourceId and Specifier /// </summary> /// <param name="resId">The ResourceId</param> /// <param name="specifier">The StoredDataSpecifier</param> /// <param name="fetchKindResponse">The Fetch result als FetchKindResonse</param> /// <returns>true, if value found</returns> public bool Fetch(ResourceId resId, StoredDataSpecifier specifier, out FetchKindResponse fetchKindResponse) { string resouceId = resId.ToString(); lock (resources) { if (!resources.ContainsKey(resouceId)) { fetchKindResponse = new FetchKindResponse(); return false; } Resource resource = resources[resouceId]; List<StoredData> machtes = resource.StoredData(specifier); if (machtes != null && machtes.Count >= 0) { fetchKindResponse = new FetchKindResponse( specifier.kindId, resource.GetGeneration(specifier.kindId), machtes); return true; } } fetchKindResponse = new FetchKindResponse(); return false; }
public bool Fetch(ResourceId res_id, StoredDataSpecifier specifier, out FetchKindResponse kindResponse) { FetchKindResponse result = null; if (storage.Fetch(res_id, specifier, out result)) { kindResponse = result; return true; } kindResponse = new FetchKindResponse(); return false; }
/// <summary> /// Creates a StoredDataSpecifier depending on the requested RELOAD Kind /// </summary> /// <param name="kindId">The Kind-ID of the requested data</param> /// <param name="type">If the data structure allows multiple types, insert here the number of the type. (as in the Usages spec.)</param> /// <param name="arguments">If dictionay, the dictionary keys, /// If array, index[1], idex[2] = first, last array index, /// If single value, argument == null</param> /// <returns></returns> public StoredDataSpecifier createSpecifier(UInt32 kindId, params object[] arguments) { ReloadGlobals.DataModel dataModel = GetDataModelfromKindId(kindId); StoredDataSpecifier spec = null; switch (dataModel) { case ReloadGlobals.DataModel.SINGLE_VALUE: // There is still no single value Kind break; case ReloadGlobals.DataModel.ARRAY: List<ArrayRange> ranges = new List<ArrayRange>(); for (int i = 1; i <= arguments.Length - 1; i++) { UInt32 first = UInt16.Parse(arguments[i].ToString()); UInt32 last = UInt16.Parse(arguments[++i].ToString()); ranges.Add(new ArrayRange(first, last)); } spec = new StoredDataSpecifier(ranges, kindId, 0, this); spec.ResourceName = arguments[0].ToString(); return spec; case ReloadGlobals.DataModel.DICTIONARY: List<string> keys = new List<string>(); if (arguments.Count<object>() > 1) { foreach (string key in arguments.ToList<object>().GetRange(1, arguments.Length)) keys.Add(new ResourceId(key).ToString()); } spec = new StoredDataSpecifier(keys, kindId, 0, this); spec.ResourceName = arguments[0].ToString(); return spec; default: throw new NotSupportedException(String.Format("Data Model {0} is not supported!", dataModel)); } throw new NotImplementedException(); }
public override RELOAD_MessageBody FromReader(ReloadMessage rm, BinaryReader reader, long reload_msg_size) { /* try to read the packet as a FetchReq packet */ try { long posBeforeMsg = reader.BaseStream.Position; RELOAD_MsgCode = (RELOAD_MessageCode)(UInt16)IPAddress.NetworkToHostOrder( reader.ReadInt16()); UInt32 message_len = (UInt32)(IPAddress.HostToNetworkOrder( reader.ReadInt32())); Byte res_id_length = reader.ReadByte(); if (res_id_length == 0) throw new System.Exception("Resource ID length == 0!"); resource = new ResourceId(reader.ReadBytes(res_id_length)); long posBeforeSpec = reader.BaseStream.Position; UInt16 specifiers_length = (UInt16)IPAddress.NetworkToHostOrder( reader.ReadInt16()); while (StreamUtil.ReadBytes(posBeforeSpec, reader) < specifiers_length) { UInt32 kindId = (UInt32)IPAddress.NetworkToHostOrder( reader.ReadInt32()); ReloadGlobals.DataModel model = myManager.GetDataModelfromKindId(kindId); UInt64 generation = (UInt64)IPAddress.NetworkToHostOrder( reader.ReadInt64()); long posBeforeIndex = reader.BaseStream.Position; UInt16 spec_length = (UInt16)IPAddress.NetworkToHostOrder( reader.ReadInt16()); var specifier = new StoredDataSpecifier(myManager); switch (model) { case ReloadGlobals.DataModel.SINGLE_VALUE: break; case ReloadGlobals.DataModel.ARRAY: List<ArrayRange> arrayRanges = new List<ArrayRange>(); while (StreamUtil.ReadBytes(posBeforeIndex, reader) < spec_length) { UInt32 first = (UInt32)IPAddress.NetworkToHostOrder( reader.ReadInt32()); UInt32 last = (UInt32)IPAddress.NetworkToHostOrder( reader.ReadInt32()); arrayRanges.Add(new ArrayRange(first, last)); } specifier = new StoredDataSpecifier(arrayRanges, kindId, generation, myManager); break; case ReloadGlobals.DataModel.DICTIONARY: List<string> keys = new List<string>(); if (spec_length == 0) { // wildcast specifier = new StoredDataSpecifier(keys, kindId, generation, myManager); } else { while (StreamUtil.ReadBytes(posBeforeIndex, reader) < spec_length) { UInt16 key_length = (UInt16)IPAddress.NetworkToHostOrder( reader.ReadInt16()); keys.Add(Encoding.ASCII.GetString(reader.ReadBytes((short)key_length), 0, key_length)); } specifier = new StoredDataSpecifier(keys, kindId, generation, myManager); } break; default: throw new Exception("An error at FetchReq.FromReader()"); } this.specifiers.Add(specifier); } UInt32 totalRead = StreamUtil.ReadBytes(posBeforeMsg, reader); reload_msg_size = reload_msg_size - (totalRead + 1); } catch (Exception ex) { myManager.m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, String.Format("FetchReq.FromBytes: {0}", ex.Message)); } return this; }