Exemplo n.º 1
0
        public void SetID(string UserID, string UserEndpoint)
        {
            userID       = UserID;
            userEndpoint = UserEndpoint;

            UserDirectory = UserDirectories + @"\" + userID;

            if (!Directory.Exists(UserDirectory))
            {
                Directory.CreateDirectory(UserDirectory);
            }

            ClientStorage.ShowLog           = false;
            ClientStorage.SettingsFileName  = "UserData.dat";
            ClientStorage.SettingsDirectory = UserDirectory;

            this.IsLoggedIn = true;

            if (ClientStorage.CheckSetting(_UserLoginDates))
            {
                List <string> oldData = ClientStorage.ReadSetting(_UserLoginDates).Split(Seperators, StringSplitOptions.RemoveEmptyEntries).ToList();
                oldData.Add(DateTime.Now.ToString() + internalSeperator + userEndpoint);

                string newData = String.Join(Seperators[0], oldData);
                ClientStorage.EditSetting(_UserLoginDates, newData);
            }
            else
            {
                string newData = DateTime.Now.ToString() + internalSeperator + userEndpoint;
                ClientStorage.EditSetting(_UserLoginDates, newData);
            }

            ILogger.AddToLog("INFO", "Client [" + userEndpoint + "] has logged in with ID [" + userID + "]");
        }
        public void LogDisconnect()
        {
            if (ClientStorage.CheckSetting(_UserDisconnectedDates))
            {
                List <string> oldData = ClientStorage.ReadSetting(_UserDisconnectedDates).Split(Seperators, StringSplitOptions.RemoveEmptyEntries).ToList();
                oldData.Add(DateTime.Now.ToString() + internalSeperator + userServerEndPoint);

                string newData = String.Join(Seperators[0], oldData);
                ClientStorage.EditSetting(_UserDisconnectedDates, newData);
            }
            else
            {
                string newData = DateTime.Now.ToString() + internalSeperator + userServerEndPoint;
                ClientStorage.EditSetting(_UserDisconnectedDates, newData);
            }

            ILogger.AddToLog(Levels.INFO, "Client [" + userServerEndPoint + "] has disconnected with id [" + userID + "]");
        }
        public static void VaultMethod()
        {
            MSMVault msm = new MSMVault(Path.Combine(Environment.CurrentDirectory, "key.pem"));

            msm.SettingsDirectory = Environment.CurrentDirectory;

            while (true)
            {
                string consoleRead = Console.ReadLine();

                string[] consoleArgs = consoleRead.Split(' ');
                consoleArgs[0] = consoleArgs[0].ToUpper();

                if (consoleArgs[0] == "EDITSETTING")
                {
                    msm.EditSetting(consoleArgs[1], consoleArgs[2]);
                }
                if (consoleArgs[0] == "DELETESETTING")
                {
                    msm.DeleteSetting(consoleArgs[1]);
                }
                if (consoleArgs[0] == "READSETTING")
                {
                    Console.WriteLine("Returned value : " + msm.ReadSetting(consoleArgs[1]));
                }
                if (consoleArgs[0] == "CHECKSETTING")
                {
                    Console.WriteLine("Returned Value : " + msm.CheckSetting(consoleArgs[1]));
                }
                if (consoleArgs[0] == "HELP")
                {
                    Console.WriteLine("Showing help - Help displays all of the public methods in MSM");
                    Console.WriteLine("There are currently 5 commands. All of these commands you can use in your project code");
                    Console.WriteLine(" ");
                    Console.WriteLine("EditSetting [SettingTitle] [SettingValue] - Edits a setting in the settings array.");
                    Console.WriteLine("ReadSetting [SettingTitle] - Returns the value in that setting.");
                    Console.WriteLine("CheckSetting [SettingTitle] - Returns a bool value if the setting exists or not.");
                    Console.WriteLine("DeleteSetting [SettingTitle] - Deletes that setting from the settings array.");
                    Console.WriteLine("SaveSettings [SettingTitle] - Saves the settings array to a file.");
                }
            }
        }
        public void SetID(string UserID, string UserServerEndPoint, string UserClientEndPoint)
        {
            userID             = UserID;
            userServerEndPoint = UserServerEndPoint;
            userClientEndPoint = UserClientEndPoint;

            UserDirectory = Path.Combine(userDirectories, userID);
            UserKeyFile   = Path.Combine(UserDirectory, "key.key");

            if (!Directory.Exists(UserDirectory))
            {
                Directory.CreateDirectory(UserDirectory);
            }

            ClientStorage = new MSMVault(UserKeyFile)
            {
                ShowLog           = false,
                SettingsFileName  = "UserData.dat",
                SettingsDirectory = UserDirectory
            };

            this.IsLoggedIn = true;

            if (ClientStorage.CheckSetting(_UserLoginDates))
            {
                List <string> oldData = ClientStorage.ReadSetting(_UserLoginDates).Split(Seperators, StringSplitOptions.RemoveEmptyEntries).ToList();
                oldData.Add(DateTime.Now.ToString() + internalSeperator + userServerEndPoint);

                string newData = String.Join(Seperators[0], oldData);
                ClientStorage.EditSetting(_UserLoginDates, newData);
            }
            else
            {
                string newData = DateTime.Now.ToString() + internalSeperator + userServerEndPoint;
                ClientStorage.EditSetting(_UserLoginDates, newData);
            }

            ILogger.AddToLog(Levels.INFO, "Client [" + userServerEndPoint + "] has logged in with ID [" + userID + "]");
        }