Exemplo n.º 1
0
        internal ResultBundle Validate(string originalCaptchaCode)
        {
            var result = ResultBundle.Success();

            if (string.IsNullOrEmpty(FirstName) || string.IsNullOrEmpty(LastName))
            {
                result.AddMessage("فیلد نام و نام خانوادگی نمیتواند خالی باشد.");
                result.IsSuccessful = false;
            }

            if (string.IsNullOrEmpty(Password) || (Password != PasswordConfirm))
            {
                result.AddMessage("رمز عبور و تایید آن باید مشابه یکدیگر باشند. لطفا مجددا رمز ورود را وارد نمایید.");
                result.IsSuccessful = false;
            }

            Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
            Match match = regex.Match(EmailAddress);

            if (!match.Success)
            {
                result.AddMessage("آدرس ایمیل وارد شده معتبر نمی باشد. لطفا آدرس ایمیل را مجددا بررسی نمایید.");
                result.IsSuccessful = false;
            }

            if (originalCaptchaCode != null && originalCaptchaCode != CaptchaCode)
            {
                result.AddMessage("کد تصویری صحیح نمی باشد لطفا مجددا تلاش نمایید");
                result.IsSuccessful = false;
            }

            return(result);
        }
Exemplo n.º 2
0
        // public string Rolename { get; set; } = "user";
        internal async Task <ResultBundle> Login(Models.DALContext context)
        {
            ResultBundle r = ResultBundle.Success();

            r.UserData     = context.Login(EmailAddress, Password);
            r.IsSuccessful = r.UserData != null;

            return(r);
        }
Exemplo n.º 3
0
 //Constructor
 /// <summary>
 /// Creates an uninitialized instance.
 /// </summary>
 /// <param name="readoutLayerConfig">The configuration of the readout layer.</param>
 public VerificationResults(ReadoutLayerSettings readoutLayerConfig)
 {
     ReadoutLayerConfig        = (ReadoutLayerSettings)readoutLayerConfig.DeepClone();
     ComputationResultBundle   = new ResultBundle();
     ReadoutUnitStatCollection = new List <ReadoutUnitErrorStat>(ReadoutLayerConfig.ReadoutUnitsCfg.ReadoutUnitCfgCollection.Count);
     for (int i = 0; i < ReadoutLayerConfig.ReadoutUnitsCfg.ReadoutUnitCfgCollection.Count; i++)
     {
         ReadoutUnitStatCollection.Add(new ReadoutUnitErrorStat(i, ReadoutLayerConfig.ReadoutUnitsCfg.ReadoutUnitCfgCollection[i]));
     }
     OneTakesAllGroupStatCollection = new List <OneTakesAllGroupErrorStat>();
     if (ReadoutLayerConfig.OneTakesAllGroupsCfg != null)
     {
         foreach (OneTakesAllGroupSettings groupCfg in ReadoutLayerConfig.OneTakesAllGroupsCfg.OneTakesAllGroupCfgCollection)
         {
             int[] unitIndexes = ReadoutLayerConfig.GetOneTakesAllGroupMemberRUnitIndexes(groupCfg.Name).ToArray();
             OneTakesAllGroupStatCollection.Add(new OneTakesAllGroupErrorStat(groupCfg.Name, unitIndexes, ReadoutLayerConfig.ReadoutUnitsCfg.ReadoutUnitCfgCollection));
         }
     }
     return;
 }
        private async Task <ResultBundle <T> > ExecuteRequest <T>(HttpRequestMessage requestMessage)
        {
            T                value;
            IErrorHolder     error;
            string           responseValue = null;
            ResultBundle <T> resultBundle  = new ResultBundle <T>(default(T));

            for (int i = 0; i < MaxRetry; i++)
            {
                try
                {
                    using (HttpResponseMessage response = await s_HttpClient.SendAsync(requestMessage))
                    {
                        responseValue = await response.Content.ReadAsStringAsync();

                        if (response.IsSuccessStatusCode)
                        {
                            responseValue = await response.Content.ReadAsStringAsync();

                            value = JsonConvert.DeserializeObject <T>(responseValue);

                            resultBundle = new ResultBundle <T>(value);
                        }
                        else
                        {
                            error = _ErrorFactory.CreateError(ErrorCodes.RequestFailure, responseValue);

                            resultBundle = new ResultBundle <T>(default(T), error);
                        }
                    }
                }
                catch (Exception e)
                {
                    error = _ErrorFactory.CreateError(ErrorCodes.Exception, e);

                    resultBundle = new ResultBundle <T>(default(T), error);
                }
            }

            return(resultBundle);
        }
Exemplo n.º 5
0
 //Constructor
 /// <summary>
 /// Creates initialized instance
 /// </summary>
 /// <param name="readoutLayerConfig">Configuration of the Readout Layer</param>
 public VerificationResults(ReadoutLayerSettings readoutLayerConfig)
 {
     ReadoutLayerConfig        = (ReadoutLayerSettings)readoutLayerConfig.DeepClone();
     ComputationResultBundle   = new ResultBundle();
     ReadoutUnitStatCollection = new List <ReadoutUnitStat>(ReadoutLayerConfig.ReadoutUnitsCfg.ReadoutUnitCfgCollection.Count);
     for (int i = 0; i < ReadoutLayerConfig.ReadoutUnitsCfg.ReadoutUnitCfgCollection.Count; i++)
     {
         ReadoutUnitStatCollection.Add(new ReadoutUnitStat(i, ReadoutLayerConfig.ReadoutUnitsCfg.ReadoutUnitCfgCollection[i]));
     }
     OneWinnerGroupStatCollection = new List <OneWinnerGroupStat>(ReadoutLayerConfig.ReadoutUnitsCfg.OneWinnerGroupCollection.Keys.Count);
     foreach (string groupName in ReadoutLayerConfig.ReadoutUnitsCfg.OneWinnerGroupCollection.Keys)
     {
         ReadoutUnitsSettings.OneWinnerGroup owg = ReadoutLayerConfig.ReadoutUnitsCfg.OneWinnerGroupCollection[groupName];
         int[] unitIndexes = new int[owg.Members.Count];
         for (int i = 0; i < owg.Members.Count; i++)
         {
             unitIndexes[i] = ReadoutLayerConfig.ReadoutUnitsCfg.GetReadoutUnitID(owg.Members[i].Name);
         }
         OneWinnerGroupStatCollection.Add(new OneWinnerGroupStat(groupName, unitIndexes, ReadoutLayerConfig.ReadoutUnitsCfg.OneWinnerGroupCollection[groupName].Members));
     }
     return;
 }
Exemplo n.º 6
0
        public async Task <IActionResult> Login(Models.Account.LoginViewModel model)
        {
            try
            {
                ResultBundle result = ResultBundle.Failed();

                if (ModelState.IsValid)
                {
                    result = await model.Login(_db);

                    if (result.IsSuccessful)
                    {
                        var selectedProperty = from property in result.UserData.GetType().GetProperties()
                                               where property.Name == "RoleId"
                                               select property.GetValue(result.UserData, null);

                        int s = 0;
                        foreach (var file in selectedProperty)
                        {
                            s = (Int32)file;
                        }


                        string Rolename = _db.Roles.FirstOrDefault(x => x.RoleId == s).Rolename;



                        var userClaims = new List <Claim>
                        {
                            new Claim(ClaimTypes.Name, model.EmailAddress),
                            new Claim(ClaimTypes.Role, Rolename)
                        };

                        var principal = new ClaimsPrincipal(new ClaimsIdentity(userClaims, "local"));

                        await HttpContext.Authentication.SignInAsync("MyCookieMiddlewareInstance4", principal);

                        if (Url.IsLocalUrl(model.ReturnUrl))
                        {
                            return(Redirect(model.ReturnUrl));
                        }
                        else
                        {
                            return(RedirectToAction("index", "Home"));
                        }
                    }
                    else
                    {
                        result.AddMessage("نام کاربری یا رمز عبور صحیح نمی باشد، لطفا مجددا تلاش نمایید");
                    }
                }
                else
                {
                    result.AddMessage("اطاعات را وارد نمایید");
                }


                ViewBag.errorMessage = result.FormattedMessages;

                return(View());
            }
            catch (Exception ex)
            {
                return(RedirectToAction(nameof(HomeController.Error), "Home"));
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Performs one demo case.
        /// Loads and prepares sample data, trains State Machine and displayes results
        /// </summary>
        /// <param name="log">Into this interface are written output messages</param>
        /// <param name="demoCaseParams">An instance of DemoSettings.CaseSettings to be performed</param>
        public static void PerformDemoCase(IOutputLog log, DemoSettings.CaseSettings demoCaseParams)
        {
            log.Write("  Performing demo case " + demoCaseParams.Name, false);
            log.Write(" ", false);
            //Instantiate the State Machine
            StateMachine stateMachine = new StateMachine(demoCaseParams.StateMachineCfg);

            //Prepare input object for regression stage
            StateMachine.RegressionInput rsi = null;
            //Prediction input vector (relevant only for input continuous feeding)
            double[] predictionInputVector = null;
            if (demoCaseParams.StateMachineCfg.NeuralPreprocessorConfig.InputConfig.FeedingType == NeuralPreprocessor.InputFeedingType.Continuous)
            {
                //Continuous input feeding
                //Load data bundle from csv file
                VectorBundle data = VectorBundle.LoadFromCsv(demoCaseParams.FileName,
                                                             demoCaseParams.StateMachineCfg.NeuralPreprocessorConfig.InputConfig.ExternalFieldNameCollection(),
                                                             demoCaseParams.StateMachineCfg.ReadoutLayerConfig.OutputFieldNameCollection,
                                                             out predictionInputVector
                                                             );
                rsi = stateMachine.PrepareRegressionData(data, PredictorsCollectionCallback, log);
            }
            else
            {
                //Patterned input feeding
                //Load data bundle from csv file
                PatternBundle data = PatternBundle.LoadFromCsv(demoCaseParams.FileName,
                                                               demoCaseParams.StateMachineCfg.NeuralPreprocessorConfig.InputConfig.ExternalFieldNameCollection(),
                                                               demoCaseParams.StateMachineCfg.ReadoutLayerConfig.OutputFieldNameCollection
                                                               );
                rsi = stateMachine.PrepareRegressionData(data, PredictorsCollectionCallback, log);
            }
            //Report key statistics of the State Machine's reservoirs
            string statisticsReport = rsi.CreateReport(4);

            log.Write(statisticsReport);
            log.Write(string.Empty);

            //Regression stage - building of trained readout layer
            log.Write("    Regression stage (training of readout layer)", false);
            //Perform the regression
            ResultBundle rcb = stateMachine.BuildReadoutLayer(rsi, RegressionControl, log);

            log.Write(string.Empty);

            //Report training (regression) results
            log.Write("    Training results", false);
            string trainingReport = stateMachine.RL.GetTrainingResultsReport(6);

            log.Write(trainingReport);
            log.Write(string.Empty);

            //Perform prediction if the input feeding is continuous (we know the input but we don't know the ideal output)
            if (demoCaseParams.StateMachineCfg.NeuralPreprocessorConfig.InputConfig.FeedingType == NeuralPreprocessor.InputFeedingType.Continuous)
            {
                double[] predictionOutputVector = stateMachine.Compute(predictionInputVector);
                string   predictionReport       = stateMachine.RL.GetForecastReport(predictionOutputVector, 6);
                log.Write("    Forecasts", false);
                log.Write(predictionReport);
                log.Write(string.Empty);
            }
            return;
        }