Exemplo n.º 1
0
        /// <summary>
        /// Validates this instance.
        /// </summary>
        /// <param name="edc">The <see cref="Entities"/>.</param>
        /// <param name="disposals">The list of disposals created already.</param>
        /// <exception cref="InputDataValidationException">Batch content validate failed;XML content validation</exception>
        public void Validate(Entities edc, IEnumerable <Disposal> disposals)
        {
            ErrorsList _validationErrors = new ErrorsList();

            if (Product == null)
            {
                _validationErrors.Add(new Warnning("Unrecognized finished good", true));
            }
            SKULookup = SKUCommonPart.Find(edc, Product.SKU);
            if (SKULookup == null)
            {
                string _msg = "Cannot find finished good SKU={0} in the SKU dictionary - dictionary update is required";
                _validationErrors.Add(new Warnning(String.Format(_msg, Product.SKU), true));
            }
            if (Product.ProductType != ProductType.Cigarette)
            {
                return;
            }
            Dictionary <string, IGrouping <string, Disposal> > _disposalGroups;

            _disposalGroups = (from _mx in disposals
                               group _mx by _mx.Disposal2IPRIndex.Batch).ToDictionary <IGrouping <string, Disposal>, string>(k => k.Key);
            Dictionary <string, decimal> _materials = new Dictionary <string, decimal>();

            //sum disposed material
            foreach (IGrouping <string, Disposal> _groupX in _disposalGroups.Values)
            {
                _materials.Add(_groupX.Key, _groupX.Sum <Disposal>(x => x.SettledQuantityDec));
            }
            foreach (Material _materialX in this.Values)
            {
                if (_materialX.ProductType.Value != Linq.ProductType.IPRTobacco)
                {
                    continue;
                }
                decimal _disposed = 0;
                if (_materials.ContainsKey(_materialX.Batch))
                {
                    _disposed = _materials[_materialX.Batch];
                }
                decimal _diff = _materialX.Accounts2Dispose.Sum <IPR>(a => a.TobaccoNotAllocatedDec) + _disposed - _materialX.TobaccoQuantityDec;
                if (_diff < -Settings.MinimalOveruse)
                {
                    string _mssg = "Cannot find any IPR account to dispose the quantity {3}: Tobacco batch: {0}, fg batch: {1}, quantity to dispose: {2} kg";
                    _validationErrors.Add(new Warnning(String.Format(_mssg, _materialX.Batch, Product.Batch, _materialX.TobaccoQuantityDec, -_diff), true));
                }
            }
            if (_validationErrors.Count > 0)
            {
                throw new InputDataValidationException("Batch content validation failed", "XML content validation", _validationErrors);
            }
        }
 public void AddError(string error)
 {
     ErrorsList.Add(error);
     RaisePropertyChanged(() => DawgVisible);
     RaisePropertyChanged(() => NumOfErrors);
     RaisePropertyChanged(() => Errors);
 }
Exemplo n.º 3
0
        private async Task <User> UpdatePassword(User selectedUser)
        {
            User userDetails = await _DbContext.Users.FindAsync(selectedUser.Id).ConfigureAwait(false);

            if (userDetails == null)
            {
                CoreFunc.Error(ref ErrorsList, "User not found!");
                return(null);
            }
            string passResetToken = await _UserManager.GeneratePasswordResetTokenAsync(userDetails).ConfigureAwait(false);

            IdentityResult result = await _UserManager.ResetPasswordAsync(
                userDetails, passResetToken, selectedUser.Password).ConfigureAwait(false);

            if (!result.Succeeded)
            {
                foreach (var error in result.Errors)
                {
                    ErrorsList.Add(new Error(error.Code, error.Description));
                }
                return(null);
            }

            return(userDetails);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Маппинг IdentityError в словарь для ValidationResult
        /// </summary>
        /// <param name="errors">Коллекция Identity Error</param>
        /// <returns>Словарь ошибок для ValidationResult</returns>
        public static Dictionary <string, List <string> > ConvertToValidationResult(this IEnumerable <IdentityError> errors)
        {
            Dictionary <string, List <string> > result = new Dictionary <string, List <string> >();

            if (errors != null)
            {
                foreach (IdentityError error in errors)
                {
                    if (result.TryGetValue(error.Code, out List <string> ErrorsList))
                    {
                        ErrorsList.Add(error.Description);
                    }
                    else
                    {
                        result.TryAdd(error.Code, new List <string>()
                        {
                            error.Description
                        });
                    }
                }

                return(result);
            }

            return(result);
        }
Exemplo n.º 5
0
        private static InvoiceContent CreateInvoiceContent(Entities edc, InvoiceLib parent, InvoiceItemXml item, ErrorsList errors)
        {
            Batch _batch = Batch.FindLookup(edc, item.Batch);

            if (_batch == null)
            {
                errors.Add(new Warnning(String.Format("Cannot find batch {0} for stock record {1}.", item.Batch, item.Description), true));
                return(null);
            }
            InvoiceContentStatus _invoiceContentStatus = InvoiceContentStatus.OK;
            double?_Quantity = item.Bill_qty_in_SKU.ConvertToDouble();

            if (_batch.FGQuantityAvailable.Value < _Quantity.Value)
            {
                _invoiceContentStatus = InvoiceContentStatus.NotEnoughQnt;
            }
            return(new InvoiceContent()
            {
                InvoiceContent2BatchIndex = _batch,
                InvoiceIndex = parent,
                SKUDescription = item.Description,
                ProductType = _batch.ProductType,
                Quantity = _Quantity,
                Units = item.BUn,
                Title = "Creating",
                InvoiceContentStatus = _invoiceContentStatus
            });
        }
Exemplo n.º 6
0
        public async Task <IActionResult> ConfirmEmail([FromBody] string pathName)
        {
            try
            {
                string tokenValue = "";

                for (int i = pathName.Length - 1; i >= 0; i--)
                {
                    if (pathName[i] == '/')
                    {
                        i = -1;
                    }
                    else
                    {
                        tokenValue = pathName[i] + tokenValue;
                    }
                }

                Token token = await _DbContext.Tokens
                              .Include(t => t.User)
                              .FirstOrDefaultAsync(t => t.Url.Contains(pathName) && t.Value.Equals(tokenValue))
                              .ConfigureAwait(false);

                if (token == null || token.Type != Extras.CustomTypes.TokenTypes.ConfirmEmail)
                {
                    ErrorsList.Add(new Error("0", "Invalid Request/Token."));
                    return(StatusCode(412, ErrorsList));
                }

                if (token.ExpiaryDateTime < DateTime.UtcNow)
                {
                    ErrorsList.Add(new Error("0", "Token Expired"));
                    return(StatusCode(412, ErrorsList));
                }

                IdentityResult result = await _UserManager.ConfirmEmailAsync(token.User,
                                                                             await _UserManager.GenerateEmailConfirmationTokenAsync(token.User).ConfigureAwait(false))
                                        .ConfigureAwait(false);

                _DbContext.Entry(token.User).State = EntityState.Unchanged;
                _DbContext.Remove(entity: token);
                await _DbContext.SaveChangesAsync().ConfigureAwait(false);

                if (result.Succeeded)
                {
                    return(Ok());
                }
                else
                {
                    ErrorsList.Add(new Error("0", "Unable to process your request."));
                    return(StatusCode(412, ErrorsList));
                }
            }
            catch (Exception ex)
            {
                CoreFunc.Error(ref ErrorsList, _LoggingService.LogException(Request.Path, ex, User));
                return(StatusCode(417, ErrorsList));
            }
        }
Exemplo n.º 7
0
        public void Process4TotalsItems()
        {
            // verzamel de posten
            // maak alle csv posten 0

            foreach (var item in ItemsList)
            {
                item.Total = 0.0; // maak de csv post 0
            }

            // verzamel de bij/af bedragen per csv post

            foreach (var transaction in TransactionsFilteredList)
            {
                bool lFound = false;
                foreach (var item in ItemsList)
                {
                    if (transaction.IsTegenrekeningEnBevat(item.Tegenrekening, item.Bevat))
                    {
                        lFound = true;
                        try
                        {
                            if (transaction.Af_Bij == "Bij")
                            {
                                item.Total += double.Parse(transaction.Bedrag);
                            }
                            else if (transaction.Af_Bij == "Af")
                            {
                                item.Total -= double.Parse(transaction.Bedrag);
                            }
                        }
                        catch (Exception)
                        {
                            ErrorsList.Add(transaction.Naam_Omschrijving + " " + "error in double parse");
                        }
                    }
                }
                if (!lFound)
                {
                    var item = ItemsList[0];                                         // item unkown
                    if (transaction.Item.CategoryId == CategoriesList[1].CategoryId) // collect unknown
                    {
                        if (transaction.Af_Bij == "Bij")
                        {
                            item.Total += double.Parse(transaction.Bedrag);
                        }
                        else if (transaction.Af_Bij == "Af")
                        {
                            item.Total -= double.Parse(transaction.Bedrag);
                        }
                    }
                    ErrorsList.Add(transaction.ToString() + "-- not to item");
                }
            }

            // post: ivListOfCSVPosten is gevuld
        }
Exemplo n.º 8
0
 public void AddError(string message, LookUps.ErrorType errorType, string propertyName = "")
 {
     ErrorsList.Add(new Error
     {
         Message      = message,
         PropertyName = propertyName,
         ErrorType    = errorType
     });
 }
Exemplo n.º 9
0
        public void AddModelError(ErrorModel errorModel)
        {
            if (ErrorsList == null)
            {
                ErrorsList = new List <ErrorModel>();
            }

            ErrorsList.Add(errorModel);
        }
Exemplo n.º 10
0
        /// <summary>
        /// This method is stopping the starting procedure
        /// </summary>
        public void StopStartingProcedure()
        {
            GapCountTimer.Stop();
            IsCancelled = true;
            HasErrors   = true;

            ErrorLog log = new ErrorLog(DateTime.Now, LogNameProgramStarter, LogNameStartingProgramsHandler, "Starting procedure cancelled by User");

            ErrorsList.Add(log);
        }
Exemplo n.º 11
0
        public List <Item> ReadListOfItems(string itemsFile)
        {
            List <Item> lListOfItems = new List <Item>();
            List <Item> lItemsToSkip = new List <Item> {
                new Item {
                    ItemName = "Post"
                }, new Item {
                    ItemName = "category"
                }, new Item {
                    ItemName = "comment"
                }
            };
            string lLine;
            int    lCounter = 0;

            lListOfItems.Clear();

            lListOfItems.Add(new Item()
            {
                ItemName = "unknown", Tegenrekening = "xxx", Bevat = "xxx", CategoryId = 0, CategoryStr = "unknown"
            });

            System.IO.StreamReader file =
                new System.IO.StreamReader(itemsFile);
            while ((lLine = file.ReadLine()) != null)
            {
                Item lItem = new Item();
                lItem.ReadLine(lLine);

                if (!lItemsToSkip.Exists(x => x.ItemName == lItem.ItemName))
                {
                    lItem.CategoryId = Convert2Id(lItem.CategoryStr);

                    if (lListOfItems.Exists(i => i.ItemName == lItem.ItemName))
                    {
                        ErrorsList.Add(lItem.ItemName + " " + lItem.Bevat + " " + "-- already exists");
                    }

                    lListOfItems.Add(lItem);

                    lCounter++;
                }
                else
                {
                    // skip item
                    int i = 1;
                }
            }
            file.Close();

            return(lListOfItems);
        }
Exemplo n.º 12
0
        public void SetItem4Transactions()
        {
            string itemListNewFile = "posten_nieuw.csv";
            var    path            = Path.Combine(pathServer, itemListNewFile);

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            int           count                 = 0;
            int           volgnummer            = 0;
            List <string> lListNaamOmschrijving = new List <string>();

            foreach (var t in TransactionsFilteredList)
            {
                bool lFound = false;
                foreach (var p in ItemsList) // transaction of known item gets last found item (last item can overrule previous items)
                {
                    if (t.IsTegenrekeningEnBevat(p.Tegenrekening, p.Bevat))
                    {
                        lFound = true;
                        t.Item = p;
                    }
                }
                if (!lFound)                                           // transaction of unkonw item get item unknown
                {
                    Item i = ItemsList[0];                             // item unknown
                    t.Item             = i;
                    t.Item.CategoryId  = CategoriesList[1].CategoryId; // category unknown
                    t.Item.CategoryStr = CategoriesList[1].CategoryStr;

                    count++;
                    ErrorsList.Add(t.ToString() + "-- transaction not found in itemslist; set to item unknown");

                    if (!lListNaamOmschrijving.Contains(t.Naam_Omschrijving))
                    {
                        lListNaamOmschrijving.Add(t.Naam_Omschrijving);

                        using (StreamWriter sw = File.AppendText(path))
                        {
                            sw.WriteLine("");
                            //              item                                      tegenrekening                         bevat                                     category
                            sw.Write("\"" + t.Naam_Omschrijving + "\"" + "," + "\"" + t.Tegenrekening + "\"" + "," + "\"" + t.Naam_Omschrijving + "\"" + "," + "\"" + "unknown" + "\"");
                            sw.Close();
                            volgnummer++;
                        }
                    }
                }
            }
        }
Exemplo n.º 13
0
        private void AddNewErrorItem(JToken jtError, string keyMessage)
        {
            var error     = CreateError(jtError, keyMessage);
            var exisError = ErrorsList.FirstOrDefault(model => model.Message == error.Message);

            if (exisError == null)
            {
                ErrorsList.Add(error);
            }
            else
            {
                exisError.CountFounded++;
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Analyzes the goods description.
        /// </summary>
        /// <param name="edc">The <see cref="Entities"/> instance</param>
        /// <param name="goodsDescription">The _ goods description.</param>
        /// <exception cref="InputDataValidationException">Syntax errors in the good description. AnalyzeGoodsDescription</exception>
        /// <exception cref="CAS.SmartFactory.IPR.WebsiteModel.InputDataValidationException">Syntax errors in the good description.</exception>
        private void AnalyzeGoodsDescription(Entities edc, string goodsDescription)
        {
            List <string> _sErrors = new List <string>();
            string        _na      = "Not recognized";

            TobaccoName  = goodsDescription.GetFirstCapture(Settings.GetParameter(edc, SettingsEntry.GoodsDescriptionTobaccoNamePattern), _na, _sErrors);
            GradeName    = goodsDescription.GetFirstCapture(Settings.GetParameter(edc, SettingsEntry.GoodsDescriptionWGRADEPattern), _na, _sErrors);
            SKU          = goodsDescription.GetFirstCapture(Settings.GetParameter(edc, SettingsEntry.GoodsDescriptionSKUPattern), _na, _sErrors);
            this.BatchId = goodsDescription.GetFirstCapture(Settings.GetParameter(edc, SettingsEntry.GoodsDescriptionBatchPattern), _na, _sErrors);
            if (_sErrors.Count > 0)
            {
                ErrorsList _el = new ErrorsList();
                _el.Add(_sErrors, true);
                throw new InputDataValidationException("Syntax errors in the good description.", "AnalyzeGoodsDescription", _el);
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Метод добавления ошибок
        /// </summary>
        /// <param name="key"></param>
        /// <param name="errorMessage"></param>
        public void AddError(string key, string errorMessage)
        {
            IsFailed = true;

            if (Errors.TryGetValue(key, out List <string> ErrorsList))
            {
                ErrorsList.Add(errorMessage);
            }
            else
            {
                Errors.TryAdd(key, new List <string>()
                {
                    errorMessage
                });
            }
        }
Exemplo n.º 16
0
 private void GetBatchLookup(Entities edc, ErrorsList warnings)
 {
     if (ProductType != Linq.ProductType.Cigarette && ProductType != Linq.ProductType.Cutfiller)
     {
         return;
     }
     if (!IPRType.GetValueOrDefault(false))
     {
         return;
     }
     this.BatchIndex = Linq.Batch.FindStockToBatchLookup(edc, this.Batch);
     if (this.BatchIndex != null)
     {
         return;
     }
     warnings.Add(new Warnning(NoMachingBatchWarningMessage, false));
 }
Exemplo n.º 17
0
        [Authorize(AppConst.AccessPolicies.Secret)] /// Done
        public async Task <IActionResult> PutTemplate([FromBody] EmailTemplate emailTemplate)
        {
            try
            {
                /// if model validation failed
                if (!TryValidateModel(emailTemplate))
                {
                    CoreFunc.ExtractErrors(ModelState, ref ErrorsList);
                    /// return Unprocessable Entity with all the errors
                    return(UnprocessableEntity(ErrorsList));
                }


                EmailTemplate foundTemplate = await _DbContext.EmailTemplates
                                              .FirstOrDefaultAsync((et) => et.Id == emailTemplate.Id)
                                              .ConfigureAwait(false);

                if (foundTemplate == null)
                {
                    ErrorsList.Add(new Error("", "Template cannot be found."));
                    /// return Unprocessable Entity with all the errors
                    return(UnprocessableEntity(ErrorsList));
                }

                foundTemplate.PrepareHtml(WebHost.WebRootPath);
                emailTemplate.RemoveHtmlComment();
                if (foundTemplate.HTML != emailTemplate.HTML)
                {
                    emailTemplate.SaveFilesToWWWRoot(WebHost.WebRootPath);
                }
                else
                {
                    emailTemplate.FolderName = foundTemplate.FolderName;
                }
                _DbContext.EmailTemplates.Update(emailTemplate);
                await _DbContext.SaveChangesAsync().ConfigureAwait(false);

                return(Ok(emailTemplate));
            }
            catch (Exception ex)
            {
                CoreFunc.Error(ref ErrorsList, _LoggingService.LogException(Request.Path, ex, User));
                return(StatusCode(417, ErrorsList));
            }
        }
Exemplo n.º 18
0
        private static bool GetXmlContent(InvoiceItemXml[] invoiceEntries, Entities edc, InvoiceLib parent)
        {
            List <InvoiceContent> _invcs    = new List <InvoiceContent>();
            ErrorsList            _warnings = new ErrorsList();
            bool _result = true;

            foreach (InvoiceItemXml item in invoiceEntries)
            {
                try
                {
                    InvoiceContent _ic = CreateInvoiceContent(edc, parent, item, _warnings);
                    if (_ic == null)
                    {
                        continue;
                    }
                    _invcs.Add(_ic);
                    _result &= _ic.InvoiceContentStatus.Value == InvoiceContentStatus.OK;
                    if (parent.BillDoc.IsNullOrEmpty())
                    {
                        parent.BillDoc             = item.Bill_doc.ToString();
                        parent.InvoiceCreationDate = item.Created_on;
                    }
                }
                catch (Exception ex)
                {
                    string _msg = "Cannot create new entry for the invoice No={0}/{1}, SKU={2}, because of error: {3}";
                    _warnings.Add(new Warnning(String.Format(_msg, item.Bill_doc, item.Item, item.Description, ex.Message), true));
                }
            }
            if (_warnings.Count > 0)
            {
                throw new InputDataValidationException("there are fatal errors in the XML message.", "GetBatchLookup", _warnings);
            }
            edc.InvoiceContent.InsertAllOnSubmit(_invcs);
            edc.SubmitChanges();
            foreach (InvoiceContent _ic in _invcs)
            {
                _ic.CreateTitle();
            }
            edc.SubmitChanges();
            return(_result);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Begining starting procedure for all programs in the list
        /// </summary>
        public void Start()
        {
            //if programs list is not empty then begin starting programs
            if (ProgramsToStartList.Any())
            {
                //Start first program in the list
                StartNextProgram();

                //Start GapCountTimer and every timer tick next program will be started
                GapCountTimer.Start();
            }
            //if list is empty then don't begin starting programs and update ErrorLog
            else
            {
                HasErrors     = true;
                IsStartupDone = true;
                ErrorLog log = new ErrorLog(DateTime.Now, LogNameProgramStarter, LogNameStartingProgramsHandler, "List of programs to start is empty!");
                ErrorsList.Add(log);
            }
        }
Exemplo n.º 20
0
 public void SetCategory4Transactions()
 {
     foreach (var t in TransactionsFilteredList)
     {
         bool lFound = false;
         foreach (var i in ItemsList)
         {
             if (t.Item.CategoryId == i.CategoryId)
             {
                 lFound     = true;
                 t.Category = new Category()
                 {
                     CategoryId = i.CategoryId, CategoryStr = i.CategoryStr
                 };
             }
         }
         if (!lFound)
         {
             ErrorsList.Add(t.ToString() + "-- not to category");
         }
     }
 }
Exemplo n.º 21
0
        [Authorize(AppConst.AccessPolicies.Secret)] /// Done
        public async Task <IActionResult> Put([FromBody] bool status)
        {
            try
            {
                Settings settings = new Settings();

                string settingsPath = AppFunc.GetFilePath(@"StaticFiles\Settings.json");
                if (string.IsNullOrEmpty(settingsPath))
                {
                    ErrorsList.Add(new Error("0", "Unable to change maintenance mode"));
                    /// return Unprocessable Entity with all the errors
                    return(UnprocessableEntity(ErrorsList));
                }

                JsonConvert.PopulateObject(System.IO.File.ReadAllText(settingsPath), settings);

                settings.MaintenanceModeStatus          = status;
                AppConst.Settings.MaintenanceModeStatus = status;

                await System.IO.File.WriteAllTextAsync(settingsPath, JsonConvert.SerializeObject(settings, Formatting.Indented, new JsonSerializerSettings
                {
                    Converters = new List <JsonConverter> {
                        new StringEnumConverter(), new DecimalFormatConverter()
                    },
                    ContractResolver = new DynamicContractResolver("OpenCors", "AntiforgeryCookieDomain", "ClientApp", "AdminApp", "MailServer"
                                                                   , "Sender", "Password", "AdminEmail", "PayPal", "ExternalLoginSecrets", "DbConnectionString", "GooglereCAPTCHASecret")
                }))
                .ConfigureAwait(false);

                AppConst.SetSettings();
                return(Ok(status));
            }
            catch (Exception ex)
            {
                CoreFunc.Error(ref ErrorsList, _LoggingService.LogException(Request.Path, ex, User));
                return(StatusCode(417, ErrorsList));
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// This method is starting next program in the list, calculating PercentOfStartedPrograms and incrementing CurrentProgramStartingOrder
        /// </summary>
        private void StartNextProgram()
        {
            //Start program
            ProgramToStart program = ProgramsToStartList.Where(p => p.StartingOrder == CurrentProgramStartingOrder).FirstOrDefault();
            string         path    = ProgramsToStartList.Where(p => p.StartingOrder == CurrentProgramStartingOrder).Select(x => x.Path).FirstOrDefault().ToString();

            try
            {
                StartProgram(path);
            }
            catch (Exception ex)
            {
                HasErrors = true;
                ErrorLog log = new ErrorLog(DateTime.Now, program.ProgramName, program.Path, ex.ToString());
                ErrorsList.Add(log);
            }

            //Calculate percentage of started programs
            PercentOfStartedPrograms = ((float)CurrentProgramStartingOrder / ProgramsToStartList.Count()) * 100;

            //Increment CurrentProgramStartingOrder
            CurrentProgramStartingOrder++;
        }
Exemplo n.º 23
0
        private static void IportXml(StockXml document, Entities edc, StockLib parent, ErrorsList _warnings, ProgressChangedEventHandler progressChanged)
        {
            List <StockEntry> stockEntities = new List <StockEntry>();

            foreach (StockXmlRow _row in document.Row)
            {
                try
                {
                    StockEntry nse = CreateStockEntry(_row, parent);
                    nse.ProcessEntry(edc, _warnings);
                    progressChanged(_row, new ProgressChangedEventArgs(1, _row.Material));
                    stockEntities.Add(nse);
                }
                catch (Exception ex)
                {
                    _warnings.Add(new Warnning(String.Format("Stock entry {1} fatal import error: {0}", ex.ToString(), _row.MaterialDescription), true));
                }
            }
            if (stockEntities.Count > 0)
            {
                edc.StockEntry.InsertAllOnSubmit(stockEntities);
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// создание Error object
        /// </summary>
        public static void CreateError(string output)
        {
            dynamic jsOutput = JObject.Parse(output);

            var stastus = jsOutput.status;

            if (stastus != null && stastus == "OK")
            {
                var result = JArray.Parse(jsOutput.RESULT.ToString());
                foreach (var res in result)
                {
                    var jsError = res.error;
                    if (jsError != null)
                    {
                        var error = new Error();
                        error.Message      = res.error;
                        error.ResponsError = BsonDocument.Parse(jsOutput.ToString());
                        CreateUnKnownError(error);
                        ErrorsList.Add(error);
                    }
                }
            }
            else
            {
                var jsError = jsOutput.error;
                if (jsError != null)
                {
                    var error = new Error();
                    error.Message      = jsOutput.error.message;
                    error.Details      = jsOutput.error.data;
                    error.ResponsError = BsonDocument.Parse(jsOutput.ToString());
                    CreateUnKnownError(error);
                    ErrorsList.Add(error);
                }
            }
        }
Exemplo n.º 25
0
        public void Process4TotalsCategories()
        {
            // verzamel de posten
            // maak alle csv posten 0

            foreach (var category in CategoriesList)
            {
                category.Total    = 0.0; // maak de csv post 0
                category.TotalAf  = 0.0;
                category.TotalBij = 0.0;
            }

            // verzamel de bij/af bedragen per csv post

            foreach (var transaction in TransactionsFilteredList)
            {
                bool lFound = false;
                foreach (var category in CategoriesList)
                {
                    if (transaction.Category.CategoryId == category.CategoryId)
                    {
                        lFound = true;
                        try
                        {
                            if (transaction.Af_Bij == "Bij")
                            {
                                category.Total    += double.Parse(transaction.Bedrag);
                                category.TotalBij += double.Parse(transaction.Bedrag);
                            }
                            else if (transaction.Af_Bij == "Af")
                            {
                                category.Total   -= double.Parse(transaction.Bedrag);
                                category.TotalAf -= double.Parse(transaction.Bedrag);
                            }
                        }
                        catch (Exception)
                        {
                            ErrorsList.Add(transaction.Naam_Omschrijving + " " + "error in double parse");
                        }
                    }
                }
                if (!lFound)
                {
                    ErrorsList.Add(transaction.ToString() + "-- not to item");
                }

                var category2 = CategoriesList[0]; // not selected
                try
                {
                    if (transaction.Af_Bij == "Bij")
                    {
                        category2.Total    += double.Parse(transaction.Bedrag);
                        category2.TotalBij += double.Parse(transaction.Bedrag);
                    }
                    else if (transaction.Af_Bij == "Af")
                    {
                        category2.Total   -= double.Parse(transaction.Bedrag);
                        category2.TotalAf -= double.Parse(transaction.Bedrag);
                    }
                }
                catch (Exception ex)
                { }
            }

            // post: ivListOfCSVPosten is gevuld
        }
Exemplo n.º 26
0
    /// <summary>
    /// Back propagates and send the derivatives.
    /// </summary>
    /// <param name="errorList">The error list of the current layer.</param>
    /// <param name="previousErrorList">The error list of the previous layer.</param>
    public void BackPropagateSecondDerivatives(ErrorsList errorList, ErrorsList previousErrorList)
    {
        // nomenclature (repeated from NeuronalNetwork class)
        // NOTE: even though we are addressing SECOND derivatives ( and not first derivatives),
        // we use nearly the same notation as if there were first derivatives, since otherwise the
        // ASCII look would be confusing.  We add one "2" but not two "2's", such as "d2Err_wrt_dXn",
        // to give a gentle emphasis that we are using second derivatives
        //
        // Err is output error of the entire neuronal network
        // Xn is the output vector on the n-th layer
        // Xnm1 is the output vector of the previous layer
        // Wn is the vector of weights of the n-th layer
        // Yn is the activation value of the n-th layer, i.e., the weighted sum of inputs BEFORE the squashing function is applied
        // F is the squashing function: Xn = F(Yn)
        // F' is the derivative of the squashing function
        //   Conveniently, for F = tanh, then F'(Yn) = 1 - Xn^2, i.e., the derivative can be calculated from the output, without knowledge of the input
        int    ii, jj;
        uint   kk;
        double output;
        double tempValue;

        var neuronsErrorList = new ErrorsList(this.Neurons.Count);
        var weightsErrorList = new double[this.Weights.Count];

        for (ii = 0; ii < this.Weights.Count; ii++)
        {
            weightsErrorList[ii] = 0.0;
        }

        // Calculate d2Err_wrt_dYn = ( F'(Yn) )^2 * dErr_wrt_Xn (where dErr_wrt_Xn is actually a second derivative )
        for (ii = 0; ii < this.Neurons.Count; ii++)
        {
            output    = this.Neurons[ii].Output;
            tempValue = SigmoidFunction.DeSigmoid(output);
            neuronsErrorList.Add(errorList[ii] * tempValue * tempValue);
        }

        // Calculate d2Err_wrt_Wn = ( Xnm1 )^2 * d2Err_wrt_Yn (where dE2rr_wrt_Yn is actually a second derivative)
        // For each neuron in this layer, go through the list of connections from the prior layer, and
        // update the differential for the corresponding weight
        ii = 0;

        foreach (var neuron in this.Neurons)
        {
            foreach (var connection in neuron.Connections)
            {
                try
                {
                    if (this.previousLayer is null)
                    {
                        continue;
                    }

                    kk     = connection.NeuronIndex;
                    output = kk == 0xffffffff ? 1.0 : this.previousLayer.Neurons[(int)kk].Output;
                    weightsErrorList[connection.WeightIndex] = neuronsErrorList[ii] * output * output;
                }
                catch (Exception)
                {
                    // ignored
                }
            }

            ii++;
        }

        // Calculate d2Err_wrt_Xnm1 = ( Wn )^2 * d2Err_wrt_dYn (where d2Err_wrt_dYn is a second derivative not a first).
        // d2Err_wrt_Xnm1 is needed as the input value of
        // d2Err_wrt_Xn for back propagation of second derivatives for the next (i.e., previous spatially) layer
        // For each neuron in this layer
        ii = 0;

        foreach (var neuron in this.Neurons)
        {
            foreach (var connection in neuron.Connections)
            {
                try
                {
                    kk = connection.NeuronIndex;

                    // We exclude ULONG_MAX, which signifies the phantom bias neuron with
                    // constant output of "1", since we cannot train the bias neuron
                    if (kk == 0xffffffff)
                    {
                        continue;
                    }

                    var index = (int)kk;
                    tempValue = this.Weights[(int)connection.WeightIndex].Value;
                    previousErrorList[index] += neuronsErrorList[ii] * tempValue * tempValue;
                }
                catch (Exception)
                {
                    return;
                }
            }

            // ii tracks the neuron iterator
            ii++;
        }

        // Finally, update the diagonal Hessians for the weights of this layer neuron using dErr_wrt_dW.
        // By design, this function (and its iteration over many (approx 500 patterns) is called while a
        // single thread has locked the neuronal network, so there is no possibility that another
        // thread might change the value of the Hessian.  Nevertheless, since it's easy to do, we
        // use an atomic compare-and-exchange operation, which means that another thread might be in
        // the process of back propagation of second derivatives and the Hessians might have shifted slightly
        for (jj = 0; jj < this.Weights.Count; jj++)
        {
            var oldValue = this.Weights[jj].DiagonalHessian;
            var newValue = oldValue + weightsErrorList[jj];
            this.Weights[jj].DiagonalHessian = newValue;
        }
    }
Exemplo n.º 27
0
    /// <summary>
    /// Back propagates the neuronal network layer.
    /// </summary>
    /// <param name="errorList">The error list.</param>
    /// <param name="previousErrorList">The previous error list.</param>
    /// <param name="thisLayerOutput">The values of this layer.</param>
    /// <param name="previousLayerOutput">The values of the previous layer.</param>
    /// <param name="etaLearningRate">The ETA learning rate.</param>
    public void BackPropagate(ErrorsList errorList, ErrorsList previousErrorList, NeuronalNetworkNeuronOutputs?thisLayerOutput, NeuronalNetworkNeuronOutputs?previousLayerOutput, double etaLearningRate)
    {
        // nomenclature (repeated from NeuronalNetwork class):
        //
        // Err is output error of the entire neuronal network
        // Xn is the output vector on the n-th layer
        // Xnm1 is the output vector of the previous layer
        // Wn is the vector of weights of the n-th layer
        // Yn is the activation value of the n-th layer, i.e., the weighted sum of inputs BEFORE the squashing function is applied
        // F is the squashing function: Xn = F(Yn)
        // F' is the derivative of the squashing function
        //   Conveniently, for F = tanh, then F'(Yn) = 1 - Xn^2, i.e., the derivative can be calculated from the output, without knowledge of the input
        try
        {
            int    ii, jj;
            uint   kk;
            double output;
            var    neuronsErrorList = new ErrorsList(this.Neurons.Count);
            var    weightsErrorList = new double[this.Weights.Count];

            for (ii = 0; ii < this.Weights.Count; ii++)
            {
                weightsErrorList[ii] = 0.0;
            }

            var memorized = thisLayerOutput != null && previousLayerOutput != null;

            // Calculate dErr_wrt_dYn = F'(Yn) * dErr_wrt_Xn
            for (ii = 0; ii < this.Neurons.Count; ii++)
            {
                if (thisLayerOutput is null)
                {
                    continue;
                }

                output = memorized ? thisLayerOutput[ii] : this.Neurons[ii].Output;
                neuronsErrorList.Add(SigmoidFunction.DeSigmoid(output) * errorList[ii]);
            }

            // Calculate dErr_wrt_Wn = Xnm1 * dErr_wrt_Yn
            // For each neuron in this layer, go through the list of connections from the prior layer, and
            // update the differential for the corresponding weight
            ii = 0;

            foreach (var neuron in this.Neurons)
            {
                foreach (var connection in neuron.Connections)
                {
                    kk = connection.NeuronIndex;
                    if (kk == 0xffffffff)
                    {
                        // This is the bias weight
                        output = 1.0;
                    }
                    else
                    {
                        if (this.previousLayer is null || previousLayerOutput is null)
                        {
                            continue;
                        }

                        output = memorized
                                     ? previousLayerOutput[(int)kk]
                                     : this.previousLayer.Neurons[(int)kk].Output;
                    }

                    weightsErrorList[connection.WeightIndex] += neuronsErrorList[ii] * output;
                }

                ii++;
            }

            // Calculate dErr_wrt_Xnm1 = Wn * dErr_wrt_dYn, which is needed as the input value of
            // dErr_wrt_Xn for back propagation of the next (i.e., previous) layer
            // For each neuron in this layer
            ii = 0;

            foreach (var neuron in this.Neurons)
            {
                foreach (var connection in neuron.Connections)
                {
                    kk = connection.NeuronIndex;

                    // We exclude ULONG_MAX, which signifies the phantom bias neuron with
                    // constant output of "1", since we cannot train the bias neuron
                    if (kk == 0xffffffff)
                    {
                        continue;
                    }

                    var index = (int)kk;
                    previousErrorList[index] += neuronsErrorList[ii] * this.Weights[(int)connection.WeightIndex].Value;
                }

                // ii tracks the neuron iterator
                ii++;
            }

            // Finally, update the weights of this layer neuron using dErr_wrt_dW and the learning rate eta
            // Use an atomic compare-and-exchange operation, which means that another thread might be in
            // the process of back propagation and the weights might have shifted slightly
            const double Micron = 0.10;

            for (jj = 0; jj < this.Weights.Count; ++jj)
            {
                var divisor = this.Weights[jj].DiagonalHessian + Micron;

                // The following code has been rendered unnecessary, since the value of the Hessian has been
                // verified when it was created, so as to ensure that it is strictly
                // zero-positive. Thus, it is impossible for the diagHessian to be less than zero,
                // and it is impossible for the divisor to be less than micron
                var epsilon            = etaLearningRate / divisor;
                var oldValue           = this.Weights[jj].Value;
                var newValue           = oldValue - (epsilon * weightsErrorList[jj]);
                var currentWeightValue = this.Weights[jj].Value;

                while (Math.Abs(oldValue - Interlocked.CompareExchange(ref currentWeightValue, newValue, oldValue)) > 0.00000000000000000001)
                {
                    // Another thread must have modified the weight.
                    // Obtain its new value, adjust it, and try again
                    oldValue = this.Weights[jj].Value;
                    newValue = oldValue - (epsilon * weightsErrorList[jj]);
                }
            }
        }
        catch (Exception)
        {
            // ignored
        }
    }
Exemplo n.º 28
0
 public void AddError(ErrorType error)
 {
     ErrorsList.Add(error);
 }
Exemplo n.º 29
0
        public async Task <IActionResult> UpdatePasswordWithToken([FromBody] dynamic data)
        {
            try
            {
                string passwordString = data.password;
                string pathName       = data.pathName;
                bool   justCheckToken = data.justCheckToken;

                string tokenValue = "";

                for (int i = pathName.Length - 1; i >= 0; i--)
                {
                    if (pathName[i] == '/')
                    {
                        i = -1;
                    }
                    else
                    {
                        tokenValue = pathName[i] + tokenValue;
                    }
                }

                Token token = await _DbContext.Tokens
                              .Include(t => t.User)
                              .SingleOrDefaultAsync(t => t.Value.Equals(tokenValue) && t.Url.Contains(pathName))
                              .ConfigureAwait(false);

                if (token == null || token.Type != Extras.CustomTypes.TokenTypes.ChangePassword)
                {
                    ErrorsList.Add(new Error("0", "Invalid Request/Token."));
                    return(StatusCode(412, ErrorsList));
                }

                if (token.ExpiaryDateTime < DateTime.UtcNow)
                {
                    ErrorsList.Add(new Error("0", "Token Expired"));
                    return(StatusCode(412, ErrorsList));
                }

                if (justCheckToken)
                {
                    return(Ok("👌"));
                }


                token.User.Password = passwordString;

                User result = await UpdatePassword(token.User).ConfigureAwait(false);

                if (result == null)
                {
                    return(StatusCode(412, ErrorsList));
                }

                if (!result.EmailConfirmed)
                {
                    await _UserManager.ConfirmEmailAsync(result,
                                                         await _UserManager.GenerateEmailConfirmationTokenAsync(result).ConfigureAwait(false))
                    .ConfigureAwait(false);
                }
                //result.Role = token.User.Role;
                token.User = null;
                //_DbContext.Entry(token.User).State = EntityState.Unchanged;
                _DbContext.Remove(token);
                await _DbContext.SaveChangesAsync().ConfigureAwait(false);

                await _SignInManager.SignInAsync(result, false).ConfigureAwait(false);

                return(Ok("😜"));
            }
            catch (Exception ex)
            {
                CoreFunc.Error(ref ErrorsList, _LoggingService.LogException(Request.Path, ex, User));
                return(StatusCode(417, ErrorsList));
            }
        }