private ObservableCollection <ComputerModel> GenerateDataFromNetwork()
        {
            ComputerDetection.FirmId = FirmId;
            List <ComputerModel> list = ComputerDetection.Execute();

            return(new ObservableCollection <ComputerModel>(list));
        }
        public void GenerateCommandInstantly()
        {
            IsButtonEnable    = false;
            _executedComputer = 0;
            _totalComputer    = 0;

            StartNotification();

            List <ComputerModel> computers = new List <ComputerModel>();

            Computers = GenerateDataFromNetwork();

            try
            {
                TotalComputer = Computers.Count;
                foreach (var item in Computers)
                {
                    ComputerDetection.GetAdditionalInfo(item);

                    item.IsProgress = false;

                    ExecutedComputer++;

                    if (ExecutedComputer == TotalComputer)
                    {
                        Computers = new ObservableCollection <ComputerModel>(Computers.DistinctBy(p => p.Ip).ToList());
                        Computers = ComputerDetection.FilterComputer(Computers);

                        if (AutoSave && Computers.Count > 0)
                        {
                            SaveCommand();
                        }
                        EndNotification("Network searching has finished!!");
                    }
                }
            }
            catch (System.Exception ex)
            {
                EndNotification(ex.Message);
                return;
            }
        }
Beispiel #3
0
        public MTObservableCollection <CheckLicenseModel> PrepareCheckLicenseModel()
        {
            var checklicense = new MTObservableCollection <CheckLicenseModel>();

            switch (IsRemote)
            {
            case true:

                switch (IsCompInstantly)
                {
                case true:
                    ProgressContent = "Searching Computer From Network...";
                    ComputerViewModel compgenerator = new ComputerViewModel(FirmId);
                    compgenerator.GenerateCommandInstantly();
                    if (compgenerator.Computers.Count > 0)
                    {
                        var comps = Converter.Convert <ComputerDTO, ComputerModel>(compgenerator.Computers.ToList());
                        Computers = new ObservableCollection <LicenseController.autocad.masterkey.ws.ComputerDTO>(comps);
                    }
                    break;

                case false:
                    Computers = new ObservableCollection <LicenseController.autocad.masterkey.ws.ComputerDTO>(client.ComputerList(FirmId).ToList());

                    break;

                default:
                    break;
                }
                foreach (var item in Computers)
                {
                    foreach (var sft in SoftwareList)
                    {
                        checklicense.Add(new CheckLicenseModel()
                        {
                            ComputerId = item.Id, Name = item.Name, Ip = item.Ip, FirmId = item.FirmId, IsProgress = true, OperationId = OprId, App = sft
                        });
                    }
                }

                break;

            case false:
                Computers = new ObservableCollection <LicenseController.autocad.masterkey.ws.ComputerDTO>();


                var localcomp = ComputerDetection.ExecuteLocal();
                localcomp.FirmId = FirmId;
                Computers.Add(localcomp);
                var cmpid = client.ComputerUpsert(localcomp);

                foreach (var soft in SoftwareList)
                {
                    checklicense.Add(new CheckLicenseModel()
                    {
                        ComputerId = cmpid, Name = localcomp.Name, Ip = localcomp.Ip, FirmId = FirmId, IsProgress = true, OperationId = OprId, App = soft
                    });
                }
                break;

            default:
                break;
            }
            return(checklicense);
        }
        private void GenerateCommand()
        {
            IsButtonEnable    = false;
            _executedComputer = 0;
            _totalComputer    = 0;

            StartNotification();



            List <ComputerModel> computers = new List <ComputerModel>();

            Computers = GenerateDataFromNetwork();

            System.Action DoInBackground = new System.Action(() =>
            {
                try
                {
                    TotalComputer = Computers.Count;
                    foreach (var item in Computers)
                    {
                        System.Action ChildDoInBackground = new System.Action(() =>
                        {
                            ComputerDetection.GetAdditionalInfo(item);
                        });

                        System.Action ChildDoOnUiThread = new System.Action(() =>
                        {
                            item.IsProgress = false;

                            ExecutedComputer++;

                            if (ExecutedComputer == TotalComputer)
                            {
                                Computers = new ObservableCollection <ComputerModel>(Computers.DistinctBy(p => p.Ip).ToList());
                                Computers = ComputerDetection.FilterComputer(Computers);
                                if (AutoSave)
                                {
                                    SaveCommand();
                                }
                                EndNotification("Network searching has finished!!");
                            }
                        });
                        Canceller = new CancellationTokenSource();
                        var t3    = Task.Factory.StartNew(() =>
                        {
                            using (Canceller.Token.Register(Thread.CurrentThread.Abort))
                            {
                                ChildDoInBackground();
                            }
                        }, Canceller.Token);

                        // when t1 is done run t1..on the Ui thread.
                        var t4 = t3.ContinueWith(t =>
                        {
                            using (Canceller.Token.Register(Thread.CurrentThread.Abort))
                            {
                                ChildDoOnUiThread();
                            }
                        }, Canceller.Token);
                    }
                }
                catch (System.Exception ex)
                {
                    EndNotification(ex.Message);
                    return;
                }
            });

            System.Action DoOnUiThread = new System.Action(() =>
            {
            });
            Canceller = new CancellationTokenSource();
            // start the background task
            var t1 = Task.Factory.StartNew(() =>
            {
                using (Canceller.Token.Register(Thread.CurrentThread.Abort))
                {
                    DoInBackground();
                }
            }, Canceller.Token);
            // when t1 is done run t1..on the Ui thread.
            var t2 = t1.ContinueWith(t =>
            {
                using (Canceller.Token.Register(Thread.CurrentThread.Abort))
                {
                    DoOnUiThread();
                }
            }, Canceller.Token);
            //I assume BitmapFromUri is the slow step.

            //Now that we have our bitmap, now go to the main thread.
        }