예제 #1
0
        private void KillDistribution_Click(object sender, RoutedEventArgs e)
        {
            Button           killButton   = (Button)sender;
            DistributionItem distribution = killButton.DataContext as DistributionItem;

            KillProcss(distribution);
        }
예제 #2
0
        public DistributionModelTests()
        {
            DebitCardAccount = new AccountModel
            {
                Id           = 1,
                AccountType  = AccountType.DebitCard,
                AvailBalance = 15000
            };
            CashAccount = new AccountModel
            {
                Id           = 2,
                AccountType  = AccountType.Cash,
                AvailBalance = 1200
            };
            FoodFlow = new ExpenseFlowModel
            {
                Id      = 1,
                Balance = 100,
            };
            TechFlow = new ExpenseFlowModel
            {
                Id      = 2,
                Balance = 0
            };

            Debit = new DistributionAccount
            {
                Account           = DebitCardAccount,
                UseInDistribution = true
            };
            Cash = new DistributionAccount
            {
                Account           = CashAccount,
                UseInDistribution = true
            };

            Food = new DistributionItem
            {
                Flow   = FoodFlow,
                Mode   = DistributionMode.RegularExpenses,
                Amount = 10000
            };
            Tech = new DistributionItem
            {
                Flow   = TechFlow,
                Mode   = DistributionMode.Accumulation,
                Amount = 1000
            };

            Model = new DistributionModel
            {
                Accounts = new List <DistributionAccount> {
                    Debit, Cash
                },
                Items = new List <DistributionItem> {
                    Food, Tech
                }
            };
        }
예제 #3
0
 private void KillProcss(DistributionItem distribution)
 {
     if (distribution.Proc != null && !distribution.Proc.HasExited)
     {
         AddToLog($"Kill process {distribution.Proc.ProcessName} ({distribution.Proc.Id})" + Environment.NewLine);
         distribution.Proc.Kill();
     }
     else
     {
         AddToLog("Process already has exited!" + Environment.NewLine);
     }
 }
예제 #4
0
 private void DistributionListChangedMethod(object sender, ListChangedEventArgs e)
 {
     if (e.ListChangedType == ListChangedType.ItemChanged)
     {
         if (e.PropertyDescriptor.Name == "ApplyToAllProperty")
         {
             DistributionItem itemModified = DistributionList[e.NewIndex];
             foreach (DistributionItem item in DistributionList)
             {
                 item[itemModified.ApplyToAllProperty] = itemModified[itemModified.ApplyToAllProperty];
             }
         }
     }
 }
예제 #5
0
        private void CopyDistribution_Click(object sender, RoutedEventArgs e)
        {
            Button           executeButton = (Button)sender;
            DistributionItem distribution  = executeButton.DataContext as DistributionItem;

            ClearLog();
            var nameExe = _ViewModel.GetSetting(Setting.Executables.CopyExe.ToString());

            if (nameExe.Length == 0)
            {
                AddToLog("Executable for copying is not defined!");
                return;
            }
            FileInfo copyExe = new FileInfo(nameExe);

            if (!copyExe.Exists)
            {
                AddToLog("Executable for copying does not exists!");
                return;
            }
            ExecuteDistribution(distribution, true, false, executor, copyExe);
        }
예제 #6
0
        private async Task CreateOrUpdateFlowSettings(DistributionItem item)
        {
            var settings = await _repository.GetQuery <ExpenseFlowSettings>()
                           .Where(x => x.ExpenseFlowId == item.Flow.Id)
                           .SingleOrDefaultAsync();

            if (settings == null)
            {
                settings = new ExpenseFlowSettings
                {
                    ExpenseFlowId     = item.Flow.Id,
                    IsRegularExpenses = item.Mode == DistributionMode.RegularExpenses,
                    Amount            = item.Amount,
                    CanFlow           = true
                };
                _repository.Create(settings);
            }
            else
            {
                settings.IsRegularExpenses = item.Mode == DistributionMode.RegularExpenses;
                settings.CanFlow           = true;
                settings.Amount            = item.Amount;
            }
        }
예제 #7
0
        private bool ExecuteDistribution(DistributionItem distribution, bool Copy, bool Start, Executor executor, FileInfo copyExe)
        {
            if (!Copy && !Start)
            {
                return(false);
            }

            Task   task   = null;
            string target = _ViewModel.GetSetting(distribution.Folder, Setting.Scopes.DistributionTarget);

            if (target.Count() == 0)
            {
                AddToLog($"No folder defined for DistributionTarget {distribution.Folder}\n");
                return(false);
            }
            if (Copy)
            {
                string source = _ViewModel.DistributionSourceMap[distribution.Source];
                target = target.Replace(@"{Platform}", distribution.Platform);
                target = target.Replace(@"{Configuration}", distribution.Configuration);
                target = target.Replace(@"{Name}", distribution.Folder);
                source = source.Replace(@"{Platform}", distribution.Platform);
                source = source.Replace(@"{Configuration}", distribution.Configuration);
                AddToLog($"Copy\n{source} -> {target}" + Environment.NewLine);
                InvalidateVisual();
                Distributor distributeExecution = new Distributor()
                {
                    copyExe  = copyExe.ToString(),
                    source   = source,
                    target   = target,
                    AddToLog = AddToLog
                };
                task = executor.Execute(action =>
                {
                    distributeExecution.Copy(action);
                });
            }
            if (Start)
            {
                if (task != null)
                {
                    Task.WaitAll(task);
                }
                target = target.Replace(@"{Platform}", distribution.Platform);
                target = target.Replace(@"{Configuration}", distribution.Configuration);
                target = target.Replace(@"{Name}", distribution.Folder);
                string exe = distribution.Executable;
                if (exe.Count() == 0)
                {
                    AddToLog($"No file defined for DistributionExe {distribution.Folder}\n");
                    return(false);
                }
                FileInfo exePath = new FileInfo(target + Path.DirectorySeparatorChar + exe);
                if (!exePath.Exists)
                {
                    AddToLog($"Executable for starting does not exist: {exePath.ToString()}");
                    return(false);
                }
                AddToLog($"Execute {exePath} {distribution.SelectedExecArgument}" + Environment.NewLine);
                task = Task.Factory.StartNew(() =>
                {
                    System.Diagnostics.Process process = new System.Diagnostics.Process();
                    process.StartInfo.FileName         = exePath.ToString();
                    process.StartInfo.Arguments        = distribution.SelectedExecArgument;
                    process.Start();
                    distribution.Proc = process;
                });
            }
            return(true);
        }