public override void ExecuteOption(OptionReport report)
        {
            string urlLoginName            = _databaseMaterialeBehovAssignment.urlLoginName;
            int    updateProgressFrequency = _databaseMaterialeBehovAssignment.updateProgressFrequency;

            DatabaseUrlLogin      login = DatabaseUrlLogin.GetUrlLogin(Connection, urlLoginName);
            DynamicsCrmConnection dynamicsCrmConnection = DynamicsCrmConnection.GetConnection(login.Url, login.Username, login.Password);

            Materiale materiale = Materiale.ReadCalculationNeed(dynamicsCrmConnection, Config.GetResourcePath);

            if (materiale == null)
            {
                report.Success = true;
                return;
            }

            materiale.FindBehovDefinitioner(Config.GetResourcePath);

            int total = CountTotalAccountsToUpdate(dynamicsCrmConnection, materiale);
            int staleMaterialeBehovCount = materiale.CountStaleMaterialeBehov(Config.GetResourcePath);

            total += staleMaterialeBehovCount;

            materiale.new_beregningsstatus = 0;
            materiale.Update();

            materiale.RemoveStaleMaterialeBehov(Config.GetResourcePath, currentProgress => updateProgress(materiale, currentProgress, total), updateProgressFrequency);

            int progress = staleMaterialeBehovCount;
            int materialeAddedCurrent = -1;

            MaterialeProcessState state = new MaterialeProcessState();

            state.pagingInformation  = new PagingInformation();
            state.owningbusinessunit = materiale.owningbusinessunitGuid.Value;

            while (materialeAddedCurrent != 0)
            {
                materiale.AddMissingMateriale(state, Config.GetResourcePath);
                materialeAddedCurrent = state.AccountsProcessed;
                progress += materialeAddedCurrent;
                updateProgress(materiale, progress, total);
            }
            materialeAddedCurrent = -1;

            materiale.behovsberegning      = Materiale.behovsberegningEnum.Afsluttet;
            materiale.new_beregningsstatus = null;
            materiale.Update();

            report.Success = true;
            return;
        }
Exemplo n.º 2
0
        public void GetIndsamlingsSted()
        {
            Materiale materiale  = Materiale.ReadCalculationNeed(_dynamicsCrmConnection, _config.GetResourcePath);
            Guid      businessId = materiale.owningbusinessunitGuid.Value;

            PagingInformation pagingInformation = new PagingInformation();

            int lastAccountCount = -1;
            int total            = 0;

            while (lastAccountCount != 0)
            {
                List <Account> accounts = Account.GetIndsamlingsSted(_dynamicsCrmConnection, 15, businessId, _config.GetResourcePath, pagingInformation);
                lastAccountCount = accounts.Count;
                total           += lastAccountCount;
                accounts.ForEach(account => Console.Out.WriteLine(account.Id));
                //Console.Out.Write($" {lastAccountCount} ");
            }
            Console.Out.WriteLine("-------");
            Console.Out.WriteLine(total);
        }