Example #1
0
        /**
         *
         *
         */
        private void doJob()
        {
            //ObservableCollection<Program> temp = Helper.GetAppsInstalledInSystem();
            //foreach (Program p in temp)
            //{
            //    //var uiContext = SynchronizationContext.Current;
            //    //uiContext.Send(x => changeData(p), null);
            //    App.Current.Dispatcher.Invoke(new Action(() => {
            //        changeData(p);
            //    }));
            //}

            var lstDownHis = log.GetListDownHis();
            IEnumerable <System.IO.FileInfo> files = iup.queryInstallFiles();
            int test = 1;

            foreach (System.IO.FileInfo field in files)
            {
                var           found   = lstDownHis.Where(o => o.DriverName == field.Name).FirstOrDefault();
                Model.Program program = new Model.Program(field.Name, "");
                program.Position  = test;
                program.Progress  = found != null ? found.Progress : 0;
                program.TotalSize = found != null ? found.TotalSize : 1000;
                program.Status    = found != null?int.Parse(found.Status) : Program.DOWNLOADING;

                program.ClickCommand = new RelayCommand <object>(p => { return(true); }, p => {
                    var item = programList[(int)p - 1] as Model.Program;
                    if (item.ButtonText == "download")
                    {
                        item.Status     = Program.DOWNLOADING;
                        item.ButtonText = "pause";
                    }
                    else if (item.ButtonText == "pause")
                    {
                        item.Status     = Program.PAUSE;
                        item.ButtonText = "download";
                    }
                    download.AddTask(item);
                });
                program.InstallCommand = new RelayCommand <object>((p) => { return(true); }, (p) =>
                {
                    Console.Out.WriteLine("InstallCommand called");
                    var programRunning = programList[(int)p - 1] as Model.Program;
                    try
                    {
                        // Call to install app.
                        Console.Out.WriteLine("Installing...");
                        iup.Install(String.Format(@"D:\Files\{0}", program.ProgramName));
                        Console.Out.WriteLine("Completed");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Install Exception: '{0}'", e.Message);
                    }
                });
                Console.WriteLine(field.Name);
                App.Current.Dispatcher.Invoke(new Action(() => {
                    changeData(program);
                }));
                //programList.Add(program);
                test++;
            }
        }