private ExtensibleMessageInfo[] GetExtensibleMessageInfo(MessageInfo[] legacyMessageInfoCollection) { List <ExtensibleMessageInfo> list = new List <ExtensibleMessageInfo>(); foreach (MessageInfo messageInfo in legacyMessageInfoCollection) { MessageIdentity messageIdentity = (MessageIdentity)messageInfo.Identity; list.Add(new PropertyBagBasedMessageInfo(messageIdentity.InternalId, messageIdentity.QueueIdentity) { Subject = messageInfo.Subject, InternetMessageId = messageInfo.InternetMessageId, FromAddress = messageInfo.FromAddress, Status = messageInfo.Status, Size = messageInfo.Size, MessageSourceName = messageInfo.MessageSourceName, SourceIP = messageInfo.SourceIP, SCL = messageInfo.SCL, DateReceived = messageInfo.DateReceived, ExpirationTime = messageInfo.ExpirationTime, LastErrorCode = messageInfo.LastErrorCode, LastError = messageInfo.LastError, RetryCount = messageInfo.RetryCount, Recipients = messageInfo.Recipients, ComponentLatency = messageInfo.ComponentLatency, MessageLatency = messageInfo.MessageLatency }); } return(list.ToArray()); }
private Dictionary <string, Word> GenarateWordsIndex(Message message, string words) { MessageIdentity inmessage = new MessageIdentity(message.User, message.ID); string[] wordsArray = SplitWords(words); int i = 0; // count of words Dictionary <string, Word> wordsIndex = new Dictionary <string, Word>(); foreach (string key in wordsArray) { if (!string.IsNullOrEmpty(key)) { // ### Make sure the Word object is in the index ONCE only if (wordsIndex.ContainsKey(key)) { Word theword = (Word)wordsIndex[key]; // get Word from Index, then add this message reference to the Word theword.Add(inmessage, i); } else { Word theword = new Word(key, inmessage, i); // create a new Word object and add to Index wordsIndex.Add(key, theword); } } i++; } return(wordsIndex); }
public void SerializesAndDeserializes() { var source = new MessagePrincipal { Identities = new List <MessageIdentity>() }; var sourceIdentity = new MessageIdentity { Claims = new List <MessageClaim>() }; var sourceClaim = new MessageClaim { Type = "Foo", Value = "Bar" }; sourceIdentity.Claims.Add(sourceClaim); source.Identities.Add(sourceIdentity); var bytes = MessagePackSerializer.Serialize(source); var actual = MessagePackSerializer.Deserialize <MessagePrincipal>(bytes); Assert.Single(actual.Identities); Assert.Single(actual.Identities[0].Claims); Assert.Equal("Foo", actual.Identities[0].Claims[0].Type); Assert.Equal("Bar", actual.Identities[0].Claims[0].Value); }
void NewTransaction(object sender, KJFramework.EventArgs.LightSingleArgEventArgs <IMessageTransaction <MetadataContainer> > e) { NewProcessorObject obj; MetadataMessageTransaction transaction = (MetadataMessageTransaction)e.Target; if (!transaction.Request.IsAttibuteExsits(0x00)) { throw new KeyHasNullException(); } MessageIdentity identity = transaction.Request.GetAttribute(0x00).GetValue <MessageIdentity>(); lock (_processorLockObj) { if (!_processors.TryGetValue(new Protocols { ProtocolId = identity.ProtocolId, ServiceId = identity.ServiceId, DetailsId = identity.DetailsId }, out obj)) { _tracing.Error("#Schedule message failed, because cannot find processor. #P:{0}, S{1}, D{2}", identity.ProtocolId, identity.ServiceId, identity.DetailsId); return; } } try { obj.Processor.Process(transaction); } catch (System.Exception ex) { _tracing.Error(ex, null); } }
/// <summary> /// 尝试读取一个完整的Thrift消息头类型的数据 /// </summary> /// <returns>返回一个值,该值标示了当前是否读取成功。如果返回False, 则证明内部还没有足够的可用数据以供读取</returns> public bool TryReadMessageIdentity(out MessageIdentity identity) { identity = new MessageIdentity(); int version, commandLength, seqId; string command; if (!TryReadInt32(out version)) { return(false); } if (!TryReadInt32(out commandLength)) { return(false); } if (!TryReadString(Encoding.UTF8, (commandLength = commandLength.ToLittleEndian()), out command)) { return(false); } if (!TryReadInt32(out seqId)) { return(false); } identity.Version = version.ToLittleEndian(); identity.CommandLength = (uint)commandLength; identity.Command = command; identity.SequenceId = (uint)seqId.ToLittleEndian(); return(true); }
public SearchResultEntity(string resultId, int sortRank, MessageIdentity msg) { MessageUserId = msg.UserId; MessageId = msg.MessageId; this.PartitionKey = resultId; this.RowKey = (int.MaxValue - sortRank).ToString("D10") + "_" + MessageId; }
internal static void HandleSucceedSituation(MetadataMessageTransaction transaction, MetadataContainer rspMessage) { _rspRemainningCounter.Decrement(); MessageIdentity msgIdentity = transaction.Request.GetAttributeAsType <MessageIdentity>(0x00); msgIdentity.DetailsId += 1; rspMessage.SetAttribute(0x00, new MessageIdentityValueStored(msgIdentity)); transaction.SendResponse(rspMessage); }
/// <summary> /// 从第三方客户数据转换为元数据 /// <para>* 此方法将会被轻量级的DataHelper所使用,并且写入的数据将不会拥有编号(Id)</para> /// </summary> /// <param name="proxy">内存片段代理器</param> /// <param name="target">目标对象实例</param> /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param> /// <param name="isNullable">是否为可空字段标示</param> public override void Process(IMemorySegmentProxy proxy, object target, bool isArrayElement = false, bool isNullable = false) { MessageIdentity identity = (MessageIdentity)target; proxy.WriteByte(identity.ProtocolId); proxy.WriteByte(identity.ServiceId); proxy.WriteByte(identity.DetailsId); proxy.WriteInt16(identity.Tid); }
/// <summary> /// 发送一个响应消息 /// </summary> /// <param name="message">响应消息</param> /// <param name="autoTransactionIdentity">一个标示,指示了当前是否在应答消息中加入请求消息的事务唯一标示 </param> public void SendResponse(MetadataContainer message, bool autoTransactionIdentity) { _response = message; if (message == null || Identity.IsOneway) { return; } //Automatically calculate the RSP message's protocol. MessageIdentity mIdentity = _request.GetAttributeAsType <MessageIdentity>(0x00); mIdentity.DetailsId += 1; message.SetAttribute(0x00, new MessageIdentityValueStored(mIdentity)); TransactionIdentityValueStored valueStored = (TransactionIdentityValueStored)_request.GetAttribute(0x01); TransactionIdentity tIdentity; if (valueStored != null) { tIdentity = valueStored.GetValue <TransactionIdentity>(); tIdentity.IsRequest = false; message.SetAttribute(0x01, new TransactionIdentityValueStored(tIdentity)); } if (!_channel.IsConnected) { _tracing.Warn("Cannot send a response message to {0}, because target msg channel has been disconnected.", _channel.RemoteEndPoint); return; } try { int sendCount = _channel.Send(message); if (sendCount == 0) { _tracing.Warn( "#Cannot send binary data to remote endpoint, serialized data maybe is null. \r\n#Ref protocol P: {0}, S: {1}, D: {2}\r\n#Ref Instant Message: \r\n{3}", mIdentity.ProtocolId, mIdentity.ServiceId, mIdentity.DetailsId, message); return; } //send failed. if (sendCount < 0) { _channel.Disconnect(); FailedHandler(null); return; } //calc RSP time. ResponseTime = DateTime.Now; _tracing.Info("SendCount: {0}\r\nL: {1}\r\nR: {2}\r\n{3}", sendCount, _channel.LocalEndPoint, _channel.RemoteEndPoint, message.ToString()); } catch { _channel.Disconnect(); FailedHandler(null); } }
/// <summary> /// 从第三方客户数据转换为元数据 /// </summary> /// <param name="proxy">内存片段代理器</param> /// <param name="attribute">字段属性</param> /// <param name="analyseResult">分析结果</param> /// <param name="target">目标对象实例</param> /// <param name="isArrayElement">当前写入的值是否为数组元素标示</param> public override void Process(IMemorySegmentProxy proxy, ThriftPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false) { MessageIdentity value = analyseResult.GetValue <MessageIdentity>(target); byte[] data = Encoding.UTF8.GetBytes(value.Command); proxy.WriteInt32(value.Version.ToBigEndian()); proxy.WriteInt32(((int)value.CommandLength).ToBigEndian()); proxy.WriteMemory(data, 0, (uint)data.Length); proxy.WriteInt32(((int)value.SequenceId).ToBigEndian()); }
/// <summary> /// 从第三方客户数据转换为元数据 /// </summary> /// <param name="proxy">内存片段代理器</param><param name="attribute">字段属性</param><param name="analyseResult">分析结果</param><param name="target">目标对象实例</param><param name="isArrayElement">当前写入的值是否为数组元素标示</param><param name="isNullable">是否为可空字段标示</param> public override void Process(IMemorySegmentProxy proxy, IntellectPropertyAttribute attribute, ToBytesAnalyseResult analyseResult, object target, bool isArrayElement = false, bool isNullable = false) { MessageIdentity identity = analyseResult.GetValue <MessageIdentity>(target); proxy.WriteByte((byte)attribute.Id); proxy.WriteByte(identity.ProtocolId); proxy.WriteByte(identity.ServiceId); proxy.WriteByte(identity.DetailsId); proxy.WriteInt16(identity.Tid); }
/// <summary> /// Request mesasge for creating HBase table command. /// </summary> public CreateTableRequestMessage() { uint version = VERSION_1 | (uint)(MessageTypes.Call); Identity = new MessageIdentity { Command = "createTable", Version = (int)version }; Identity.CommandLength = (uint)Identity.Command.Length; }
/// <summary> /// Request mesasge for creating HBase table command. /// </summary> public GetRowWithColumnsResponseMessage() { uint version = VERSION_1 | (uint)(MessageTypes.Reply); Identity = new MessageIdentity { Command = "getRowWithColumns", Version = (int)version }; Identity.CommandLength = (uint)Identity.Command.Length; }
/// <summary> /// 插入行集合请求 /// </summary> public InsertNewRowsRequestMessage() { uint version = VERSION_1 | (uint)(MessageTypes.Call); Identity = new MessageIdentity { Command = "mutateRows", Version = (int)version }; Identity.CommandLength = (uint)Identity.Command.Length; }
/// <summary> /// 按照RowKey范围查询数据应答 /// </summary> public ScannerOpenWithStopResponseMessage() { uint version = VERSION_1 | (uint)(MessageTypes.Reply); Identity = new MessageIdentity { Command = "scannerOpenWithStop", Version = (int)version }; Identity.CommandLength = (uint)Identity.Command.Length; }
/// <summary> /// 获取一个表所分布在HBase的区域范围应答消息 /// </summary> public IsTableEnableResponseMessage() { uint version = VERSION_1 | (uint)(MessageTypes.Call); Identity = new MessageIdentity { Command = "isTableEnabled", Version = (int)version }; Identity.CommandLength = (uint)Identity.Command.Length; }
/// <summary> /// Request mesasge for close scanner command. /// </summary> public ScannerCloseResponseMessage() { uint version = VERSION_1 | (uint)(MessageTypes.Call); Identity = new MessageIdentity { Command = "scannerClose", Version = (int)version }; Identity.CommandLength = (uint)Identity.Command.Length; }
/// <summary> /// 关闭表操作应答 /// </summary> public DisableTableResponseMessage() { uint version = VERSION_1 | (uint)(MessageTypes.Reply); Identity = new MessageIdentity { Command = "disableTable", Version = (int)version }; Identity.CommandLength = (uint)Identity.Command.Length; }
/// <summary> /// Request mesasge for scaning a row list. /// </summary> public ScannerGetRequestMessage() { uint version = VERSION_1 | (uint)(MessageTypes.Call); Identity = new MessageIdentity { Command = "scannerGet", Version = (int)version }; Identity.CommandLength = (uint)Identity.Command.Length; }
/// <summary> /// Request mesasge for inserting a new row into specified HBase table. /// </summary> public InsertNewRowResponseMessage() { uint version = VERSION_1 | (uint)(MessageTypes.Reply); Identity = new MessageIdentity { Command = "mutateRow", Version = (int)version }; Identity.CommandLength = (uint)Identity.Command.Length; }
/// <summary> /// 获取目前HBase内部所有的表名请求消息 /// </summary> public GetTableNamesResponseMessage() { uint version = VERSION_1 | (uint)(MessageTypes.Call); Identity = new MessageIdentity { Command = "getTableNames", Version = (int)version }; Identity.CommandLength = (uint)Identity.Command.Length; }
/// <summary> /// Atomically increment the column value specified. Returns the next value post increment. /// </summary> public AtomicIncrementResponseMessage() { uint version = VERSION_1 | (uint)(MessageTypes.Reply); Identity = new MessageIdentity { Command = "atomicIncrement", Version = (int)version }; Identity.CommandLength = (uint)Identity.Command.Length; }
private void SaveSearchResults(string searchId, Dictionary <string, int> searchResults) { foreach (var key in searchResults.Keys) { var mi = new MessageIdentity().FromMessageString(key); var rank = searchResults[key]; SearchResultEntity entity = new SearchResultEntity(searchId, rank, mi); TableOperation insertOperation = TableOperation.InsertOrReplace(entity); _searchResultsTable.Execute(insertOperation); } }
/// <summary> /// 将一个业务的通信协议与远程可访问地址注册到服务器上 /// </summary> /// <param name="identity">业务协议编号</param> /// <param name="protocolTypes">通信协议类型</param> /// <param name="level">KAE应用等级</param> /// <param name="resourceUri">远程可访问的资源地址</param> /// <param name="kppUniqueId">KPP全局唯一编号</param> public void Register(MessageIdentity identity, ProtocolTypes protocolTypes, ApplicationLevel level, Uri resourceUri, Guid kppUniqueId) { if (resourceUri == null) { throw new ArgumentNullException(nameof(resourceUri)); } string path = string.Format("{0}/{1}-{2}-{3}-{4}", _protocolPath, identity.ProtocolId, identity.ServiceId, identity.DetailsId, level); AddPath(path, CreateMode.PERSISTENT); path += string.Format("/{0};{1}", resourceUri.Address, kppUniqueId); AddPath(path, CreateMode.PERSISTENT); }
internal static void HandleErrorSituation(MetadataMessageTransaction transaction, KAEErrorCodes errorCode, string reason) { _rspRemainningCounter.Decrement(); _errorRspCounter.Increment(); MessageIdentity msgIdentity = transaction.Request.GetAttributeAsType <MessageIdentity>(0x00); msgIdentity.DetailsId += 1; MetadataContainer rspMsg = new MetadataContainer(); rspMsg.SetAttribute(0x00, new MessageIdentityValueStored(msgIdentity)); rspMsg.SetAttribute(0x0A, new ByteValueStored((byte)errorCode)); rspMsg.SetAttribute(0x0B, new StringValueStored(reason ?? string.Empty)); transaction.SendResponse(rspMsg); }
/// <summary> /// 网络事务处理函数 /// </summary> /// <param name="transaction">网络事务</param> public void Process(MetadataMessageTransaction transaction) { try { InnerProcess(transaction); } catch (System.Exception ex) { _tracing.Error(ex); //sends a default RSP-MESSGAE when there had an unexpected exception; MessageIdentity identity = transaction.Request.GetAttributeAsType <MessageIdentity>(0x00); identity.DetailsId++; MetadataContainer rspMsg = new MetadataContainer(); rspMsg.SetAttribute(0x00, new MessageIdentityValueStored(identity)); transaction.SendResponse(rspMsg); } }
void NewTransaction(object sender, KJFramework.EventArgs.LightSingleArgEventArgs <IMessageTransaction <BaseMessage> > e) { BusinessMessageTransaction transaction = (BusinessMessageTransaction)e.Target; IMessageProcessor processor; MessageIdentity identity = transaction.Request.MessageIdentity; if (!_processors.TryGetValue(new Protocols { ProtocolId = identity.ProtocolId, ServiceId = identity.ServiceId, DetailsId = identity.DetailsId }, out processor)) { _tracing.Error("#Schedule message failed, because cannot find processor. #P:{0}, S{1}, D{2}", identity.ProtocolId, identity.ServiceId, identity.DetailsId); return; } try { processor.Process(transaction); } catch (Exception ex) { _tracing.Error(ex, null); } }
//public string MessageSnapshot { get; set; } public WordIndexEntity(string word, MessageIdentity msg, List <int> posList) { Word = word; MessageUserId = msg.UserId; MessageId = msg.MessageId; WordCount = posList.Count(); WordPositions = Utils.Array2String <int>(posList.ToArray()); ///MessageSnapshot = GenarateMessageSnapshot(word, posList, msgWords); DateTime createdDate = DateTime.UtcNow; this.PartitionKey = string.Format("{0}_{1}", Word.Length <= 350 ? Word : Word.Substring(0, 350), Utils.ToAzureStorageDayBasedString(createdDate)); this.RowKey = Utils.ToAzureStorageSecondBasedString(createdDate) + "_" + MessageId; }
/// <summary> /// 执行相应的KAE系统命令 /// </summary> /// <param name="msg">系统请求消息</param> /// <param name="logger">状态记录器实例</param> /// <returns>返回执行后的结果</returns> public static IExecuteResult Execute(MetadataContainer msg, IKAEStateLogger logger) { MessageIdentity messageIdentity = msg.GetAttributeAsType <MessageIdentity>(0x00); IKAESystemCommand command; if (!_commands.TryGetValue(messageIdentity, out command)) { return(ExecuteResult.Fail((byte)KAEErrorCodes.NotSupportedCommand, string.Format("#Not supported system command protocol: {0}", messageIdentity))); } try { return(command.Execute(msg, logger)); } catch (Exception ex) { logger.Log(string.Format("#Occured an unhandled exception while executing a system level KAE command. #Command msg struct: {0}. \r\n#Error: {1}", msg, ex.Message)); _tracing.Error(ex, null); return(ExecuteResult.Fail((byte)KAEErrorCodes.Unknown, ex.Message)); } }
private void SaveWordsIndex(Dictionary <string, Word> wordsIndex) { foreach (var key in wordsIndex.Keys) { var word = wordsIndex[key] as Word; var msgWithPos = word.InMessagesWithPosition(); foreach (var m in msgWithPos) { var msg = new MessageIdentity(); msg.FromMessageString(m.Key); var pos = m.Value; WordIndexEntity entity = new WordIndexEntity(word.Text, msg, pos); TableOperation insertOperation = TableOperation.InsertOrReplace(entity); _wordsIndexTable.Execute(insertOperation); } } }
protected Message() { _parameters = new ParameterCollection(); _identity = GetMessageIdentity(this.GetType()); }