private void CheckEntityHasUniqueLabel(IId id, ICachedEntity entity) { if (idLabelCache.TryGetValue(id, out var originalEntity)) { Extractor.Message(new Message { message = "Label collision for " + id.ToString(), severity = Severity.Warning }); } else { idLabelCache[id] = entity; } }
/// <summary> /// 获取可视信息 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entity"></param> /// <returns></returns> public static string GetText(this IId entity, Func <IId, string> textFactory = null) { if (textFactory != null) { return(textFactory(entity)); } if (entity is IText) { return(((IText)entity).Text); } var pi = entity.GetType().GetPropertyAny(typeof(string), "DisplayName", "Name", "Description"); if (pi != null) { return(pi.GetValue(entity) as string); } return(entity.ToString()); }
private void _LogIt(String Command, IId Id, String PropertyKey, Object JSON) { Command = Command?.Trim(); PropertyKey = PropertyKey?.Trim(); if (Command.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(Command), "The given command must not be null or empty!"); } if (PropertyKey.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(PropertyKey), "The given property key must not be null or empty!"); } var data = JSONObject.Create( new JProperty("timestamp", DateTime.UtcNow.ToIso8601()), new JProperty("id", Id.ToString()), new JProperty("command", Command), new JProperty(PropertyKey, JSON) ).ToString(Newtonsoft.Json.Formatting.None) + Environment.NewLine; if (!DisableLogfiles) { lock (Lock) { File.AppendAllText(LogfileName, data); } } if (!DisableNetworkSync) { lock (Lock) { foreach (var networkInfo in RoamingNetworkInfos) { var client = new TCPClient(RemoteHost: networkInfo.hostname, RemotePort: networkInfo.port, UseTLS: TLSUsage.NoTLS, ConnectionTimeout: TimeSpan.FromSeconds(5), DNSClient: DNSClient); client.Connect(); if (client.TCPStream != null) { if (client.TCPStream.CanWrite) { client.TCPStream.Write(data.ToUTF8Bytes()); } if (client.TCPStream.CanRead) { client.TCPStream.ReadTimeout = 5000; // msec var message = new StringBuilder(); var buffer = new Byte[4096]; var numberOfBytesRead = 0; do { numberOfBytesRead = client.TCPStream.Read(buffer, 0, buffer.Length); message.Append(Encoding.UTF8.GetString(buffer, 0, numberOfBytesRead)); if (message.ToString() == "ack") { break; } } while (client.TCPStream.DataAvailable); } } } } } }
/// <summary> /// Determines whether the beginning of this string instance matches the specified string. /// </summary> /// <param name="Id">An identificator.</param> /// <param name="Prefix"></param> public static Boolean StartsWith(this IId Id, String Prefix) => Id.ToString().StartsWith(Prefix);
/// <summary> /// Return a JSON representation of the given identificator. /// </summary> /// <param name="Id">An identificator.</param> /// <param name="JPropertyKey">The name of the JSON property key to use.</param> public static JProperty ToJSON(this IId Id, String JPropertyKey) => Id != null ? new JProperty(JPropertyKey, Id.ToString()) : null;