示例#1
0
        private void btnUploadLicenseSets_Click(object sender, RoutedEventArgs e)
        {
            if (cboServices.SelectedValue != null)
            {
                if (gridLocalServices.SelectedItem != null)
                {
                    if (DoesLicenseSetExistOnService() == false)
                    {
                        BackgroundWorker worker = new BackgroundWorker();
                        loadingAnimation.Visibility = Visibility.Visible;

                        var productDisplayData = gridLocalServices.SelectedItem as UploadProductDisplayData;

                        worker.DoWork += delegate(object s, DoWorkEventArgs args)
                        {
                            object[] data = args.Argument as object[];

                            IServicesService   servicesService   = ObjectLocator.GetInstance <IServicesService>();
                            ILicenseSetService licenseSetService = ObjectLocator.GetInstance <ILicenseSetService>();
                            ILicenseService    licenseService    = ObjectLocator.GetInstance <ILicenseService>();

                            //LicenseSet licenseSet = (LicenseSet) data[0];
                            License    license    = licenseService.GetLicenseById(((UploadProductDisplayData)data[0]).LicenseId);
                            LicenseSet licenseSet = licenseSetService.GetLiceseSetById(((UploadProductDisplayData)data[0]).LicenseSetId);

                            List <LicenseSet> sets = new List <LicenseSet>();
                            sets.Add(licenseSet);

                            servicesService.AddProductToService(license, sets, data[1] as Service);
                            Dictionary <License, List <LicenseSet> > _servicesData = servicesService.GetServiceLicenses((Service)data[1]);

                            args.Result = _servicesData;
                        };

                        worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
                        {
                            servicesData = (Dictionary <License, List <LicenseSet> >)args.Result;
                            gridRemoteServices.ItemsSource = DataConverters.ConvertAllLicensesSetsToDisplay(servicesData);

                            loadingAnimation.Visibility = Visibility.Collapsed;
                        };

                        worker.RunWorkerAsync(new object[]
                        {
                            productDisplayData,
                            cboServices.SelectedValue
                        });
                    }
                    else
                    {
                        MessageBox.Show("The License Set you selected already exists in the service");
                    }
                }
                else
                {
                    MessageBox.Show("You must select a License/LicenseSet to upload");
                }
            }
            else
            {
                MessageBox.Show("You must select a service to upload to.");
            }
        }