private void HandleVariableNodes(DoshikExternalApi api, List <DoshikNodeDefinition> nodes) { foreach (var node in nodes) { bool CheckIsValid() { if (node.InputParameters.Length != 5 || node.OutputParameters.Length != 0) { return(false); } if (node.InputParameters[0].Type != node.Type) { return(false); } if (node.InputParameters[1].Name != "name" || node.InputParameters[1].Type != typeof(string)) { return(false); } if (node.InputParameters[2].Name != "public" || node.InputParameters[2].Type != typeof(bool)) { return(false); } if (node.InputParameters[3].Name != "synced" || node.InputParameters[3].Type != typeof(bool)) { return(false); } if (node.InputParameters[4].Name != "syncMode" || node.InputParameters[4].Type != typeof(string)) { return(false); } return(true); } var externalTypeName = node.Identifier.Remove(0, "Variable_".Length); if (!CheckIsValid()) { LogWarning?.Invoke("invalid variable node"); continue; } var apiType = GetOrCreateApiType(api, externalTypeName); apiType.DeclaredAsVariableNode = true; if (apiType.DotnetTypeString == null) { apiType.DotnetTypeString = GetDotnetTypeAsString(apiType, node); } if (apiType.DotnetTypeString != GetDotnetTypeAsString(apiType, node)) { LogWarning?.Invoke("different dotnet types for single node type"); } } }
public void EmitWarning(string message) { if (SuppressWarnings) { return; } LogWarning?.Invoke(message); }
/// <summary> /// Handle incoming data from the websocket. /// </summary> /// <remarks>Check it is valid, handle if RPC.</remarks> /// <param name="client">The client connection.</param> /// <param name="jsonMessage">The message payload as JSON.</param> private void HandleMessage(IWebSocketConnection client, string jsonMessage) { // Convert to BlipRequest. BlipRequest request; try { request = JsonConvert.DeserializeObject <BlipRequest>(jsonMessage); request.Validate(); } catch (Exception) { LogWarning?.Invoke(this, "Dropped bad Blip request from " + client.ConnectionInfo.ClientIpAddress); return; } // Locate target delegate. if (!RegisteredServices.TryGetValue(request.Target, out var target)) { LogWarning?.Invoke(this, "Missing RPC registered handler for target from " + client.ConnectionInfo.ClientIpAddress); return; } // Dynamic invoke. string responseJson = null; try { var result = target.DynamicInvoke(request.Arguments); responseJson = JsonConvert.SerializeObject(new BlipResponse { Target = request.Call, Success = true, Result = result }); } catch (Exception e) { var err = e.InnerException; if (err != null) { e = err; } responseJson = JsonConvert.SerializeObject(new BlipResponse { Target = request.Call, Success = false, Result = new { e.Message, Stacktrace = e.StackTrace } }); } // Pass it back. DispatchData(client, responseJson); }
/// <summary> /// Attempt to send data to a client. /// </summary> /// <param name="client">The client to send data too.</param> /// <param name="data">The data to send.</param> private void DispatchData(IWebSocketConnection client, string data) { try { client.Send(data); } catch (Exception) { LogWarning?.Invoke(this, "Error sending data to " + client.ConnectionInfo.ClientIpAddress); } }
public void Execute() { if (string.IsNullOrEmpty(FindExpression)) { throw new ArgumentException("'FindExpression' is required."); } var options = RegexOptions.None; if (IgnoreCase) { options |= RegexOptions.IgnoreCase; } if (Multiline) { options |= RegexOptions.Multiline; } if (Singleline) { options |= RegexOptions.Singleline; } var replaceRegex = new Regex(FindExpression, options); foreach (var file in _files) { if (File.Exists(file)) { var contents = File.ReadAllText(file); if (replaceRegex.IsMatch(contents) != true) { LogWarning.Invoke( $"[find/replace - no matches] : file = '{file}' / find expression = '{FindExpression}'"); } else { contents = replaceRegex.Replace(contents, ReplacementText); File.WriteAllText(file, contents); LogMessage($"[find/replace] : file = '{file}' / find expression = '{FindExpression}' / replacement text = '{ReplacementText}'"); } } else { LogWarning.Invoke($"" + $"[find/replace - file not found] : file = '{file}'"); } } }
private void HandleEventNodes(DoshikExternalApi api, List <DoshikNodeDefinition> nodes) { foreach (var node in nodes) { bool CheckIsValid() { if (node.InputParameters.Length != 0) { return(false); } return(true); } // Игнорируем кастомные события if (node.Identifier == "Event_Custom") { continue; } var externalEventName = "_" + FirstLetterToLowerCase(node.Identifier.Remove(0, "Event_".Length)); if (!CheckIsValid()) { LogWarning?.Invoke("invalid event node"); continue; } bool eventCreated; var apiEvent = GetOrCreateApiEvent(api, externalEventName, out eventCreated); if (!eventCreated) { LogWarning?.Invoke("event already defined"); continue; } for (var nodeOutputParameterIdx = 0; nodeOutputParameterIdx < node.OutputParameters.Length; nodeOutputParameterIdx++) { var nodeParameter = node.OutputParameters[nodeOutputParameterIdx]; var apiType = GetOrCreateApiType(api, nodeParameter.Type); apiEvent.InParameters.Add(new DoshikExternalApiMethodParameter() { Name = string.IsNullOrEmpty(nodeParameter.Name) ? ("_" + nodeOutputParameterIdx.ToString()) : nodeParameter.Name, Type = apiType }); } } }
private void HandleConstNodes(DoshikExternalApi api, List <DoshikNodeDefinition> nodes) { foreach (var node in nodes) { bool CheckIsValid() { if (node.InputParameters.Length != 1 || node.OutputParameters.Length != 1) { return(false); } if (node.InputParameters[0].Type != node.OutputParameters[0].Type || node.InputParameters[0].Type != node.Type) { return(false); } return(true); } // Игнорируем тип null if (node.Identifier == "Const_Null") { continue; } var externalTypeName = node.Identifier.Remove(0, "Const_".Length); if (!CheckIsValid()) { LogWarning?.Invoke("invalid const node"); continue; } var apiType = GetOrCreateApiType(api, externalTypeName); apiType.DeclaredAsConstNode = true; if (apiType.DotnetTypeString == null) { apiType.DotnetTypeString = GetDotnetTypeAsString(apiType, node); } if (apiType.DotnetTypeString != GetDotnetTypeAsString(apiType, node)) { LogWarning?.Invoke("different dotnet types for single node type"); } } }
private DoshikExternalApiType GetOrCreateApiType(DoshikExternalApi api, Type dotnetType) { var externalName = MakeExternalNameFromDotnetType(dotnetType); var apiType = GetOrCreateApiType(api, externalName); if (apiType.DotnetTypeString == null) { apiType.DotnetTypeString = GetDotnetTypeAsString(dotnetType); } if (apiType.DotnetTypeString != GetDotnetTypeAsString(dotnetType)) { LogWarning?.Invoke("different dotnet types for single node type"); } return(apiType); }
public override void Warning(string message) { LogWarning.Invoke(logtype, message); }
internal static void WriteLogWarning(string LogLine) => LogWarning?.Invoke(null, new SingleInstanceLogEventArgs(LogLine));
private void HandleMethodNodes(DoshikExternalApi api, List <DoshikNodeDefinition> nodes) { foreach (var node in nodes) { bool CheckIsValid() { return(true); } const string typeAndFullSignatureSeparatorString = ".__"; const string methodAndSignatureSeparatorString = "__"; var typeAndFullSignatureSeparator = node.Identifier.IndexOf(typeAndFullSignatureSeparatorString); var externalTypeName = node.Identifier.Substring(0, typeAndFullSignatureSeparator); var fullSignature = node.Identifier.Substring(typeAndFullSignatureSeparator + typeAndFullSignatureSeparatorString.Length, node.Identifier.Length - (typeAndFullSignatureSeparator + typeAndFullSignatureSeparatorString.Length)); var methodAndSignatureSeparator = fullSignature.IndexOf(methodAndSignatureSeparatorString); var externalMethodName = fullSignature.Substring(0, methodAndSignatureSeparator); var externalMethodSignatureName = fullSignature.Substring(methodAndSignatureSeparator + methodAndSignatureSeparatorString.Length, fullSignature.Length - (methodAndSignatureSeparator + methodAndSignatureSeparatorString.Length)); if (!CheckIsValid()) { LogWarning?.Invoke("invalid method node"); continue; } var apiType = GetOrCreateApiType(api, externalTypeName); if (apiType.DotnetTypeString == null) { apiType.DotnetTypeString = GetDotnetTypeAsString(apiType, node); } if (apiType.DotnetTypeString != GetDotnetTypeAsString(apiType, node)) { LogWarning?.Invoke("different dotnet types for single node type"); } var apiMethod = GetOrCreateMethod(apiType, externalMethodName); bool methodOverloadCreated; // externalTypeName в данном случае не всегда будет равно apiType.ExternalName var apiMethodOverload = GetOrCreateMethodOverload(apiMethod, externalTypeName, externalMethodSignatureName, out methodOverloadCreated); if (!methodOverloadCreated) { LogWarning?.Invoke("method overload already defined"); continue; } apiMethodOverload.IsStatic = true; for (var nodeInputParameterIdx = 0; nodeInputParameterIdx < node.InputParameters.Length; nodeInputParameterIdx++) { var nodeParameter = node.InputParameters[nodeInputParameterIdx]; var parameterApiType = GetOrCreateApiType(api, nodeParameter.Type); var isInstanceParameter = false; if (nodeInputParameterIdx == 0 && nodeParameter.Name == "instance") { // ToDo: раньше я проверял еще на apiType == parameterApiType для того чтобы уточнить что это именно instance метод, // но для интерфейсов, которые имплементятся в udonbehaviour-е почему-то первый параметр имеет тип UnityEngine.Object, // а не тип интерфейса (который указан в текущем apiType), по этому я оставляю только проверку по имени первого параметра // есть еще варианты с проверкой по extern-сигнатуры, т.к. для instance методов в ней не указывается instance параметр, // но там вроде тоже конвенция нестабильно соблюдается, так что не хочется на нее опираться. isInstanceParameter = true; } if (isInstanceParameter) { apiMethodOverload.IsStatic = false; } else { apiMethodOverload.InParameters.Add(new DoshikExternalApiMethodParameter() { Name = string.IsNullOrEmpty(nodeParameter.Name) ? ("_" + nodeInputParameterIdx.ToString()) : nodeParameter.Name, Type = parameterApiType }); } } for (var nodeOutputParameterIdx = 0; nodeOutputParameterIdx < node.OutputParameters.Length; nodeOutputParameterIdx++) { var nodeParameter = node.OutputParameters[nodeOutputParameterIdx]; var parameterApiType = GetOrCreateApiType(api, nodeParameter.Type); var isMain = nodeOutputParameterIdx == 0 && string.IsNullOrEmpty(nodeParameter.Name); if (isMain) { apiMethodOverload.OutParameterType = parameterApiType; } else { apiMethodOverload.ExtraOutParameters.Add(new DoshikExternalApiMethodParameter() { Name = string.IsNullOrEmpty(nodeParameter.Name) ? ("_" + nodeOutputParameterIdx.ToString()) : nodeParameter.Name, Type = parameterApiType }); } } } }