Example #1
0
        public GeneralHubResponseObject CreateMiningRoom(System.Security.Principal.IPrincipal User, MiningRoomRequesObject mrRequest)
        {
            GeneralHubResponseObject result = new GeneralHubResponseObject();

            if (!User.Identity.IsAuthenticated)
            {
                result.Success      = false;
                result.ErrorMessage = SignalRService.Localization.BaseResource.Get("MsgLoginFirst");
                return(result);
            }
            string toParse = ((dynamic)mrRequest.CommandData).CoinType;

            if (!Enum.TryParse(toParse, out Enums.EnumMiningRoomType coinType))
            {
                result.ErrorMessage = "Invalid type given";
                result.Success      = false;
                return(result);
            }

            //if it's not this implementation, use coinimp
            switch (coinType)
            {
            case Enums.EnumMiningRoomType.CoinIMP:
                var roomImplementation = Factories.MiningRoomFactory.GetImplementation(Enums.EnumMiningRoomType.CoinIMP);
                return(roomImplementation.CreateMiningRoom(User, mrRequest));

            case Enums.EnumMiningRoomType.JSECoin:

                break;

            default:
                break;
            }



            string roomName = ((dynamic)mrRequest.CommandData).RoomName;
            string clientId = ((dynamic)mrRequest.CommandData).ClientId;
            string siteId   = ((dynamic)mrRequest.CommandData).SiteId;
            string subId    = ((dynamic)mrRequest.CommandData).SubId;

            var mrMinLength = (int)Utils.GeneralSettingsUtils.GetSettingValue(Enums.EnumGeneralSetting.MiningRoomNameMinLength);
            var MrMaxLength = (int)Utils.GeneralSettingsUtils.GetSettingValue(Enums.EnumGeneralSetting.MiningRoomNameMaxLength);

            if (roomName.Length > MrMaxLength || roomName.Length < mrMinLength)
            {
                result.ErrorMessage = "Name has to be from " + mrMinLength + " to " + MrMaxLength + " characters.";
                result.Success      = false;
                return(result);
            }

            bool isDangerous = Utils.ValidationUtils.IsDangerousString(roomName, out int badIdx);

            if (isDangerous)
            {
                result.ErrorMessage = "Invalid character in Name";
                result.Success      = false;
                return(result);
            }

            var clIdMinLength = (int)Utils.GeneralSettingsUtils.GetSettingValue(Enums.EnumGeneralSetting.JSECoinClientIdMinLength);
            var clIdMaxLength = (int)Utils.GeneralSettingsUtils.GetSettingValue(Enums.EnumGeneralSetting.JSECoinClientIdMaxLength);

            if (clientId.Length > clIdMaxLength || clientId.Length < clIdMinLength)
            {
                result.ErrorMessage = "ClientId has to be from " + clIdMinLength + " to " + clIdMaxLength + " characters.";
                result.Success      = false;
                return(result);
            }

            var user = userRepo.GetDbUser(User.Identity.Name);

            var newService = serviceRepo.GetNewService(Enums.EnumServiceType.CrowdMinerCoinIMP, user, roomName);

            var defaultMinerConf = minerRepo.GetDefaultMinerConfig();
            var newMinerConf     = minerRepo.GetNewMinerConfig(clientId, siteId, subId);

            newService.JSECoinMinerConfiguration = newMinerConf;

            var theRoom = miningRoomRepo.CreateRoom(newService);

            //    db.PredefinedMinerClients.Remove(predefClient);
            db.SaveChanges();

            result.Success      = true;
            result.ResponseData = theRoom.ServiceSetting.ServiceUrl;
            return(result);
        }
Example #2
0
        public GeneralHubResponseObject CreateMiningRoom(System.Security.Principal.IPrincipal User, MiningRoomRequesObject mrRequest)
        {
            GeneralHubResponseObject result = new GeneralHubResponseObject();

            if (!User.Identity.IsAuthenticated)
            {
                result.Success      = false;
                result.ErrorMessage = SignalRService.Localization.BaseResource.Get("MsgLoginFirst");
                return(result);
            }

            string roomName = ((dynamic)mrRequest.CommandData).RoomName;
            string clientId = ((dynamic)mrRequest.CommandData).ClientId;

            var mrMinLength = (int)Utils.GeneralSettingsUtils.GetSettingValue(Enums.EnumGeneralSetting.MiningRoomNameMinLength);
            var MrMaxLength = (int)Utils.GeneralSettingsUtils.GetSettingValue(Enums.EnumGeneralSetting.MiningRoomNameMaxLength);

            if (roomName.Length > MrMaxLength || roomName.Length < mrMinLength)
            {
                result.ErrorMessage = "Name has to be from " + mrMinLength + " to " + MrMaxLength + " characters.";
                result.Success      = false;
                return(result);
            }

            bool isDangerous = Utils.ValidationUtils.IsDangerousString(roomName, out int badIdx);

            if (isDangerous)
            {
                result.ErrorMessage = "Invalid character in Name";
                result.Success      = false;
                return(result);
            }

            var clIdMinLength = (int)Utils.GeneralSettingsUtils.GetSettingValue(Enums.EnumGeneralSetting.CoinImpClientIdMinLength);
            var clIdMaxLength = (int)Utils.GeneralSettingsUtils.GetSettingValue(Enums.EnumGeneralSetting.CoinImpClientIdMaxLength);

            if (clientId.Length > clIdMaxLength || clientId.Length < clIdMinLength)
            {
                result.ErrorMessage = "Name has to be from " + clIdMinLength + " to " + clIdMaxLength + " characters.";
                result.Success      = false;
                return(result);
            }


            if (db.PredefinedMinerClients.Count() == 0)
            {
                result.ErrorMessage = "No more slots open, please come back later.";
                result.Success      = false;
                return(result);
            }

            var predefClient = db.PredefinedMinerClients.FirstOrDefault();

            var user = userRepo.GetDbUser(User.Identity.Name);

            var newService = serviceRepo.GetNewService(Enums.EnumServiceType.CrowdMinerCoinIMP, user, roomName);

            var defaultMinerConf = minerRepo.GetDefaultMinerConfig();
            var newMinerConf     = minerRepo.GetNewMinerConfig(clientId, predefClient.ScriptUrl, float.Parse(defaultMinerConf.Throttle), defaultMinerConf.StartDelayMs, defaultMinerConf.ReportStatusIntervalMs);

            newService.CoinIMPMinerConfiguration = newMinerConf;

            var theRoom = miningRoomRepo.CreateRoom(newService);

            //    db.PredefinedMinerClients.Remove(predefClient);
            db.SaveChanges();

            result.Success      = true;
            result.ResponseData = theRoom.ServiceSetting.ServiceUrl;
            return(result);
        }