Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node: Create a locker for multiple Console.Write #2995

Open
shargon opened this issue Nov 15, 2023 · 10 comments
Open

node: Create a locker for multiple Console.Write #2995

shargon opened this issue Nov 15, 2023 · 10 comments
Labels

Comments

@shargon
Copy link
Member

shargon commented Nov 15, 2023

Currently we can receive from plugins some outputs that can be mixed with the entered command. We should be able to send these results together.

Related to neo-project/neo-node#905 (comment)

We need somthing like:

 public static class ConsoleHelper
    {
        public static readonly object Locker = new();
...
        public static void Info(params string[] values)
        {
            lock (Locker)
            {
                var currentColor = new ConsoleColorSet();

                for (int i = 0; i < values.Length; i++)
                {
                    if (i % 2 == 0)
                        InfoColor.Apply();
                    else
                        currentColor.Apply();
                    Console.Write(values[i]);
                }
                currentColor.Apply();
                Console.WriteLine();
            }
        }

In order to allow lock(ConsoleHelper.Lock){ ... multiple out ... }

@cschuchardt88
Copy link
Member

cschuchardt88 commented Nov 15, 2023

Wouldn't it be better to do this on neo-core

namespace Neo
{
    public delegate void LogEventHandler(string source, LogLevel level, object message);

    public static class Utility
    {
        internal class Logger : ReceiveActor
        {
            public Logger()
            {
                Receive<InitializeLogger>(_ => Sender.Tell(new LoggerInitialized()));
                Receive<LogEvent>(e => Log(e.LogSource, (LogLevel)e.LogLevel(), e.Message));
            }
        }

        public static event LogEventHandler Logging;

        public static Encoding StrictUTF8 { get; }

        static Utility()
        {
            StrictUTF8 = (Encoding)Encoding.UTF8.Clone();
            StrictUTF8.DecoderFallback = DecoderFallback.ExceptionFallback;
            StrictUTF8.EncoderFallback = EncoderFallback.ExceptionFallback;
        }

        public static object ConsoleLock { get; } = new(); // Add this line
        public static void Log(string source, LogLevel level, object message)
        {
            lock (ConsoleLock) // Add this line
                Logging?.Invoke(source, level, message);
        }
    }
}

Because the plugin you were talking about uses, Utility.Log

@cschuchardt88
Copy link
Member

I did find this in neo-cli; syncRoot its for locking so you can sync root of console.

@cschuchardt88
Copy link
Member

this can be closed. has one built-in

@Jim8y
Copy link
Contributor

Jim8y commented Nov 24, 2023

@shargon

@shargon
Copy link
Member Author

shargon commented Nov 24, 2023

I did find this in neo-cli; syncRoot its for locking so you can sync root of console.

Where is syncRoot?

@shargon
Copy link
Member Author

shargon commented Nov 24, 2023

But is private, how can be used in neo-project/neo-node#905 ?

@cschuchardt88
Copy link
Member

Its a partial class

https://github.com/neo-project/neo-node/blob/da786195cfb6d70236bb37611c37d7016bbc3aae/neo-cli/CLI/MainService.cs#L41

@shargon
Copy link
Member Author

shargon commented Nov 24, 2023

But we also use Console outside this repo, in plugins, we should have access to it

@cschuchardt88
Copy link
Member

We can make it public and do something like #2995

@shargon shargon changed the title Create a locker for multiple Console.Write node: Create a locker for multiple Console.Write Dec 5, 2023
@shargon shargon added the node label Dec 5, 2023
@shargon shargon transferred this issue from neo-project/neo-node Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants