public override void ProcessCommand(string[] arguments, Authentication authentication, User caller)
        {
            if (arguments.Length < 2)
            {
                OutputConsole.WriteLine("Usage: removeaccounttag <userid> <tag>");
                return;
            }

            string userId = arguments[0];
            string tag    = arguments[1];

            User user = UserManager.Instance.GetUserFromId(userId);

            if (user == null)
            {
                OutputConsole.WriteLine("Could not find user with it \"" + userId + "\"");
                return;
            }

            bool removed = user.AccoutTags.Remove(tag);

            if (removed)
            {
                user.Save();
                OutputConsole.WriteLine("Removed tag \"" + tag + "\" from " + user.Username + ".");
            }
            else
            {
                OutputConsole.WriteLine(user.Username + " doesnt have a \"" + tag + "\" tag.");
            }
        }
        public override void ProcessCommand(string[] arguments, Authentication authentication, User caller)
        {
            if (arguments.Length < 1)
            {
                OutputConsole.WriteLine("Usage: getaccounttags <userid>");
                return;
            }

            string userId = arguments[0];

            User user = UserManager.Instance.GetUserFromId(userId);

            if (user == null)
            {
                OutputConsole.WriteLine("Could not find user with it \"" + userId + "\"");
                return;
            }

            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("Tags on " + user.Username + ": ");
            for (int i = 0; i < user.AccoutTags.Count; i++)
            {
                stringBuilder.Append(user.AccoutTags[i]);

                if (i != (user.AccoutTags.Count - 1))
                {
                    stringBuilder.Append(", ");
                }
            }
            stringBuilder.Append(".");

            OutputConsole.WriteLine(stringBuilder.ToString());
        }
        public override JsonOperationResponseBase OnOperation(Arguments arguments, Authentication authentication)
        {
            ContentType = "text/plain";

            SignInData request = new SignInData()
            {
                password = arguments["password"],
                username = arguments["username"]
            };

            if (!request.IsValidRequest())
            {
                return(new SignInResponse()
                {
                    Error = "All fields were not filled out"
                });
            }

            Session session = UserManager.Instance.SignInAsUser(request.username, request.password);

            if (session == null)
            {
                return(new SignInResponse()
                {
                    Error = "Either the specified username or the password was wrong"
                });
            }

            OutputConsole.WriteLine(request.username + " signed in");

            return(new SignInResponse()
            {
                sessionID = session.Key
            });
        }
        private static void MyCustomCallback(MessageType messageType, string data)
        {
            // this is our custom callback we can do whatever we want with the data here
            OutputConsole.WriteLine($"{DateTime.UtcNow}: Received {messageType} message in private channel callback", ConsoleColor.Green);

            switch (messageType)
            {
            // if you want to deserialize into one of the premade classes you can do so quite easily by checking the MessageType and deserializing into the apropriate response class
            case MessageType.TradeData:
                try
                {
                    var deserializedClass = TradeResponse.FromJson(_client.Options.Serializer, data);
                    OutputConsole.WriteLine($"{DateTime.UtcNow}: We have deserialized a trade in our custom callback and the price in that trade is {deserializedClass.TradeData.Trade.Price}", ConsoleColor.Green);
                }
                catch (Exception ex)
                {
                    OutputConsole.WriteLine(ex.Message);
                }

                break;

            case MessageType.OrderData:
                try
                {
                    var deserializedClass = OrderResponse.FromJson(_client.Options.Serializer, data);
                    OutputConsole.WriteLine($"{DateTime.UtcNow}: We have deserialized an orderbook in our custom callback and the first price in that data is {deserializedClass.OrderData.Orders[0].Price}", ConsoleColor.Green);
                }
                catch (Exception ex)
                {
                    OutputConsole.WriteLine(ex.Message);
                }

                break;

            case MessageType.NewsData:
                break;

            case MessageType.BlockData:
                break;

            case MessageType.FavoriteData:
                break;

            case MessageType.NewMarket:
                break;

            case MessageType.NotificationData:
                break;

            case MessageType.Unknown:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(messageType), messageType, null);
            }
        }
Exemple #5
0
        public void End()
        {
            OutputConsole.WriteLine(Resources.Finished);

            if (ErrorListProvider.Tasks.Count > 0)
            {
                ErrorListProvider.BringToFront();
                ErrorListProvider.ForceShowErrors();
            }
        }
 public void Log(MessageLevel level, string message, params object[] args)
 {
     if (level == MessageLevel.Info ||
         level == MessageLevel.Error ||
         level == MessageLevel.Warning)
     {
         var s = string.Format(CultureInfo.CurrentCulture, message, args);
         OutputConsole.WriteLine(s);
     }
 }
Exemple #7
0
        public override void ProcessCommand(string[] arguments, Authentication authentication, User caller)
        {
            User user = UserManager.Instance.GetUserFromUsername(arguments[0]);

            if (user == null)
            {
                OutputConsole.WriteLine("The provided user, \"" + arguments[0] + "\" doesnt exist");
                return;
            }
            OutputConsole.WriteLine(arguments[0] + "s userId is: " + user.UserID);
        }
Exemple #8
0
        private static void MyCustomCallback(MessageType messageType, string data)
        {
            // this is our custom callback we can do whatever we want with the data here
            OutputConsole.WriteLine($"{DateTime.UtcNow}: Received {messageType} message in private channel callback", ConsoleColor.Green);

            // if you want to deserialize into one of thhe premade classes you can do so quite easily by checking the MessageType and deserializing into the apropriate response class
            if (messageType == MessageType.TradeData)
            {
                var deserializedClass = TradeResponse.FromJson(data);
                OutputConsole.WriteLine($"{DateTime.UtcNow}: We have deserialized a trade in our custom callbeck and the price in that trade is {deserializedClass.TradeData.Trade.Price}", ConsoleColor.Green);
            }
        }
Exemple #9
0
        public override void ProcessCommand(string[] arguments, Authentication authentication, User caller)
        {
            if (arguments.Length == 0)
            {
                OutputConsole.WriteLine("the setlauncherversion command takes at least 1 argument");
                return;
            }

            string version = getAfterAsString(arguments, 0);

            ModBotInfoManager.Instance.SetModBotLauncherVersion(version);
            OutputConsole.WriteLine("Mod bot Launcher version updated to \"" + version + "\"");
        }
        public override void ProcessCommand(string[] arguments, Authentication authentication, User caller)
        {
            if (arguments.Length == 0)
            {
                OutputConsole.WriteLine("the setdownload command takes at least 1 argument");
                return;
            }

            string download = getAfterAsString(arguments, 0);

            ModBotInfoManager.Instance.SetModBotDownloadLink(download);
            OutputConsole.WriteLine("Mod bot download link updated to \"<a href=\"" + download + "\">" + download + "</a>\"", true);
        }
        public void End()
        {
            NuGetUIThreadHelper.JoinableTaskFactory.Run(async delegate
            {
                await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                OutputConsole.WriteLine(Resources.Finished);
                OutputConsole.WriteLine(string.Empty);

                // Give the error list focus
                ErrorListTableDataSource.Value.BringToFront();
            });
        }
        public void Log(MessageLevel level, string message, params object[] args)
        {
            if (level == MessageLevel.Info ||
                level == MessageLevel.Error ||
                level == MessageLevel.Warning ||
                _verbosityLevel > DefaultVerbosityLevel)
            {
                if (args.Length > 0)
                {
                    message = string.Format(CultureInfo.CurrentCulture, message, args);
                }

                RunTaskOnUI(() => OutputConsole.WriteLine(message));
            }
        }
        public void End()
        {
            NuGetUIThreadHelper.JoinableTaskFactory.Run(async delegate
            {
                await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                OutputConsole.WriteLine(Resources.Finished);
                OutputConsole.WriteLine(string.Empty);

                if (ErrorListProvider.Tasks.Count > 0)
                {
                    ErrorListProvider.BringToFront();
                    ErrorListProvider.ForceShowErrors();
                }
            });
        }
        public void Log(ILogMessage message)
        {
            if (message.Level == LogLevel.Information ||
                message.Level == LogLevel.Error ||
                message.Level == LogLevel.Warning ||
                _verbosityLevel > DefaultVerbosityLevel)
            {
                RunTaskOnUI(() => OutputConsole.WriteLine(message.FormatWithCode()));

                if (message.Level == LogLevel.Error ||
                    message.Level == LogLevel.Warning)
                {
                    RunTaskOnUI(() => ReportError(message));
                }
            }
        }
        public override void ProcessCommand(string[] arguments, Authentication authentication, User caller)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append("Signed up Users:\n");
            for (int i = 0; i < UserManager.Instance.Users.Count; i++)
            {
                User user = UserManager.Instance.Users[i];
                builder.Append(user.Username + " (UserId: " + user.UserID + ")");

                if (i != (UserManager.Instance.Users.Count - 1))
                {
                    builder.Append("\n");
                }
            }
            OutputConsole.WriteLine(builder.ToString());
        }
Exemple #16
0
        public override JsonOperationResponseBase OnOperation(Arguments arguments, Authentication authentication)
        {
            ContentType = "text/plain";

            CreateAccountData request = new CreateAccountData()
            {
                username = arguments["username"],
                password = arguments["password"]
            };

            if (!request.IsValidRequest())
            {
                return(new CreateAccountResponse()
                {
                    Error = "All fields were not filled out"
                });
            }

            if (!User.IsValidUsername(request.username, out string usernameError))
            {
                return(new CreateAccountResponse()
                {
                    Error = string.Format("Invalid username, {0}", usernameError)
                });
            }
            if (!User.IsValidPassword(request.password, out string passwordError))
            {
                return(new CreateAccountResponse()
                {
                    Error = string.Format("Invalid password, {0}", passwordError)
                });
            }

            User newUser = User.CreateNewUser(request.username, request.password);

            Session session = UserManager.Instance.SignInAsUser(request.username, request.password);

            OutputConsole.WriteLine("New user signed up " + newUser.UserID + " (" + newUser.Username + ")");

            return(new CreateAccountResponse()
            {
                sessionID = session.Key
            });
        }
Exemple #17
0
        static void Main(string[] args)
        {
            // We can use the console built into the CoinigyWebsocketClient to ensure we don't lock up our program or cause delays. Even though
            // the normal console will work, be aware that writing to the console is a blocking operation and lots of writes can slow down
            // your program. This is why using the builtin OutpuConsole class is a better option.
            OutputConsole.WriteLine("Starting Coinigy Websocket Demo Client!", ConsoleColor.DarkGreen, ConsoleColor.White);

            // lets setup our credentials
            var creds = new ApiCredentials("ApiKey", "ApiSecret");

            // lets  create an instance of the client class and set it to debug mode, normally we would not use any debug mode
            _client = new CoinigyWsClient(creds, true);
            // if we want in depth debug information we can set the debug mode to on for the underlying connection
            // _client.ConnectionDebug = true;

            // lets hook up some events
            _client.OnClientReady  += Client_OnClientReady;
            _client.OnFatality     += _client_OnFatality;
            _client.OnClosed       += _client_OnClosed;
            _client.OnStateChanged += _client_OnStateChanged;
            // there are many more events for us to use, play around

            // we can handle messages in a few different ways
            // 1. we can specificly handle certain messages such as orders and trades
            _client.OnOrderMessage        += _client_OnOrderMessage;
            _client.OnTradeMessage        += _client_OnTradeMessage;
            _client.OnBlockMessage        += _client_OnBlockMessage;
            _client.OnFavoriteMessage     += _client_OnFavoriteMessage;
            _client.OnNewsMessage         += _client_OnNewsMessage;
            _client.OnNotificationMessage += _client_OnNotificationMessage;
            // 2. we can handle all messages ourself if we want
            _client.OnMessage += _client_OnMessage;

            // 3. when we subcribe to a channel we can attach a callback as demonstrated in Client_OnClientReady with MyCustomCallback

            // lets try and open our connection, we must remember we are not authorized to do anything until OnClientReady is fired
            var connectionResult = _client.Connect();

            OutputConsole.WriteLine($"Connected = {connectionResult}", ConsoleColor.Green);

            // we don't want our app to close so lets block
            _manualResetEvent.WaitOne();
        }
        public override void ProcessCommand(string[] arguments, Authentication authentication, User caller)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("Sessions:\n");
            for (int i = 0; i < SessionsManager.Instance.Sessions.Count; i++)
            {
                Session session = SessionsManager.Instance.Sessions[i];

                stringBuilder.Append(session.OwnerUserID);
                stringBuilder.Append(" (");
                stringBuilder.Append(UserManager.Instance.GetUserFromId(session.OwnerUserID).Username);
                stringBuilder.Append("): ");
                stringBuilder.Append("Expiery time: ");
                stringBuilder.Append(session.ExpieryTime.ToString());
                stringBuilder.Append("\n");
            }

            OutputConsole.WriteLine(stringBuilder.ToString());
        }
Exemple #19
0
        private static void Client_OnClientReady()
        {
            // we can now do whatever we want now since we have an authorized connection, do not try to do anythign before this state is reached

            // Some calls are simply informational, these have been wrapped up for you into a simple method and will return the results to you
            // lets get the list of all available channels
            var channels = _client.GetChannels();

            foreach (var channel in channels)
            {
                OutputConsole.WriteLine(channel, ConsoleColor.Blue);
            }

            // lets get all channels for BTRX
            //var markets = _client.GetChannels("BTRX");
            //foreach (var market in markets)
            //{
            //    OutputConsole.WriteLine(market, ConsoleColor.Blue);
            //}

            // lets get all exchanges
            //var exchanges = _client.GetExchanges();
            //foreach (var exchange in exchanges)
            //{
            //    OutputConsole.WriteLine(exchange.ExchCode, ConsoleColor.Blue);
            //}

            // Unlike the calls above Subscribtion calls provide streaming data and will received data as it is pushed from the server so we must
            // have some way of handling when data is received. As shown in the Main method we have several options for this.
            // lets subscribe to a channel
            //_client.SubscribeToChannel("TRADE-BITF--ETH--BTC");
            // this can also be achieved by calling
            _client.SubscribeToTradeChannel("BITF", "ETH", "BTC");

            // this is how to subscribe to your private channel or any other channel or any call that is not predefined for you
            //_client.SubscribeToChannel("44444444-4444-4444-4444-444444444444");
            //_client.SubscribeToChannel("NEWMARKET");

            // we can also subscribe to a channel and supply our own callback instead of using the builtin events
            _client.SubscribeToChannel("TRADE-BITF--ETH--BTC", MyCustomCallback);
        }
Exemple #20
0
        public override void ProcessCommand(string[] arguments, Authentication authentication, User caller)
        {
            if (arguments.Length == 0 || string.IsNullOrWhiteSpace(arguments[0]))
            {
                OutputConsole.WriteLine("Invalid arguments, you did not provide a argument");
                return;
            }

            string userId = arguments[0];

            User user = UserManager.Instance.GetUserFromId(userId);

            if (user == null)
            {
                OutputConsole.WriteLine("Could not find user with id \"" + userId + "\"");
                return;
            }

            BannedUsersManager.Instance.UnbanUser(userId);
            OutputConsole.WriteLine("Tried to unban user \"" + userId + "\".");
        }
        public override void ProcessCommand(string[] arguments, Authentication authentication, User caller)
        {
            if (arguments.Length == 0)
            {
                OutputConsole.WriteLine("You did not provide a user id to delete");
                return;
            }

            string userid = getAfterAsString(arguments, 0);

            User user = UserManager.Instance.GetUserFromId(userid);

            if (user == null)
            {
                OutputConsole.WriteLine("Could not find user with id \"" + userid + "\"");
                return;
            }

            user.DeleteUser();

            OutputConsole.WriteLine("Deleted user \"" + userid + "\" with the name \"" + user.Username + "\"");
        }
        public override void ProcessCommand(string[] arguments, Authentication authentication, User caller)
        {
            if (arguments.Length < 2)
            {
                OutputConsole.WriteLine("Usage: addaccounttag <userid> <tag>");
                return;
            }

            string userId = arguments[0];
            string tag    = arguments[1];

            User user = UserManager.Instance.GetUserFromId(userId);

            if (user == null)
            {
                OutputConsole.WriteLine("Could not find user with it \"" + userId + "\"");
                return;
            }

            user.AccoutTags.Add(tag);
            user.Save();
            OutputConsole.WriteLine("Added tag \"" + tag + "\" to " + user.Username + ".");
        }
Exemple #23
0
        static void executeAdminCommand(string[] subStrings, Authentication authentication)
        {
            User   user        = UserManager.Instance.GetUserFromId(authentication.UserID);
            string baseCommand = subStrings[0].ToLower();

            string[] arguments = new string[subStrings.Length - 1];
            Array.Copy(subStrings, 1, arguments, 0, subStrings.Length - 1);

            OutputConsole.WriteLine(user.Username + ": " + getAfterAsString(subStrings, 0));

            if (_adminCommands == null)
            {
                populateAdminCommands();
            }

            if (baseCommand == "help")
            {
                StringBuilder helpResponseBuilder = new StringBuilder();

                helpResponseBuilder.Append("Commands:\n");

                foreach (KeyValuePair <string, AdminCommand> item in _adminCommands)
                {
                    helpResponseBuilder.Append(item.Key);
                    helpResponseBuilder.Append('\n');
                }

                OutputConsole.WriteLine(helpResponseBuilder.ToString());
                return;
            }

            if (_adminCommands.TryGetValue(baseCommand, out AdminCommand value))
            {
                value.ProcessCommand(arguments, authentication, user);
            }
        }
Exemple #24
0
        public override void ProcessCommand(string[] arguments, Authentication authentication, User caller)
        {
            if (arguments.Length < 2)
            {
                OutputConsole.WriteLine("usage setrequiredtag <tagid> <account tag>");
                return;
            }

            string tagid      = arguments[0];
            string accountTag = arguments[1];

            if (accountTag == "null")
            {
                accountTag = null;
            }

            TagInfo tag = TagsManager.Instance.GetTag(tagid);

            if (tag == null)
            {
                OutputConsole.WriteLine("Could not find tag with the id \"" + tagid + "\"");
                return;
            }

            tag.RequiredAccountTag = accountTag;
            TagsManager.Instance.SaveTag(tag);

            if (accountTag != null)
            {
                OutputConsole.WriteLine("Set the required account tag on the tag with the id \"" + tagid + "\" to \"" + accountTag + "\".");
            }
            else
            {
                OutputConsole.WriteLine("Removed all required account tags from the tag with the id \"" + tagid + "\".");
            }
        }
Exemple #25
0
 public override void ProcessCommand(string[] arguments, Authentication authentication, User user)
 {
     OutputConsole.WriteLine(user.Username + ": " + getAfterAsString(arguments, 0));
 }
 private static void _client_OnNewsMessage(NewsDataItem news)
 {
     // we received a news article
     OutputConsole.WriteLine($"{DateTime.UtcNow}: Received news item \"{news.Title}\"", ConsoleColor.Green);
 }
 private static void _client_OnFavoriteMessage(FavoriteDataItem[] favorites)
 {
     // a message about our favorited markets
     OutputConsole.WriteLine($"{DateTime.UtcNow}: Received favorites count {favorites.Length}", ConsoleColor.Green);
 }
 private static void _client_OnBlockMessage(string curr, BlockItem block)
 {
     // a new block has been discovered on a chain
     OutputConsole.WriteLine($"{DateTime.UtcNow}: Received new block for {curr} height {block.BlockId}", ConsoleColor.Green);
 }
Exemple #29
0
        public void Log(NuGet.ProjectManagement.MessageLevel level, string message, params object[] args)
        {
            var s = string.Format(CultureInfo.CurrentCulture, message, args);

            OutputConsole.WriteLine(s);
        }
Exemple #30
0
        public override void ProcessCommand(string[] arguments, Authentication authentication, User caller)
        {
            if (arguments.Length < 1)
            {
                OutputConsole.WriteLine("The logs command takes at least one argument, try \"logs list\" and \"logs get [log]\"");
                return;
            }


            if (arguments[0] == "list")
            {
                float daysBack = 2;
                if (arguments.Length >= 2)
                {
                    if (!float.TryParse(arguments[1], out daysBack))
                    {
                        daysBack = 2;
                    }
                }

                StringBuilder builder = new StringBuilder();
                builder.Append("Saved logs:\n");
                string[] logs = Directory.GetFiles(LogsManager.Instance.FolderPath);
                for (int i = 0; i < logs.Length; i++)
                {
                    FileInfo info = new FileInfo(logs[i]);

                    if (info.CreationTime.AddDays(daysBack) >= DateTime.Now)
                    {
                        builder.Append(info.Name + " (" + GetByteAmountWithUnit(info.Length) + ")");

                        if (i != (logs.Length - 1))
                        {
                            builder.Append('\n');
                        }
                    }
                }
                OutputConsole.WriteLine(builder.ToString());
                return;
            }
            else if (arguments[0] == "get")
            {
                if (arguments.Length < 2)
                {
                    OutputConsole.WriteLine("The paramiter \"get\" on the logs command takes 1 more argument");
                    return;
                }
                string log  = arguments[1];
                string path = LogsManager.Instance.FolderPath + log;
                if (!File.Exists(path))
                {
                    OutputConsole.WriteLine("The log \"" + log + "\" could not be found");
                    return;
                }

                if (TemporaryFilesMananger.Instance.CreateTemporaryFile(path, out string key))
                {
                    string download = "<a href='/api/?operation=downloadTempFile&key=" + key + "'>here</a>";
                    OutputConsole.WriteLine("Download the log " + download + " (link valid for 30 seconds)", true);
                }
                else
                {
                    OutputConsole.WriteLine("Something went wrong when trying to read the log...");
                }
            }
        }