Beispiel #1
0
        private async Task ValidateAndHandleCrateSelection()
        {
            //CrateChooser requests data only on click. So in order to autoselect a single crate - we need to make a request on our own
            var crateChooser = GetControl <CrateChooser>("Available_Crates");

            var upstreamCrates = await HubCommunicator.GetAvailableData(ActivityId, CrateDirection.Upstream, AvailabilityType.RunTime);


            if (crateChooser.CrateDescriptions == null)
            {
                crateChooser.CrateDescriptions = upstreamCrates.AvailableCrates;
            }
            else
            {
                //elements in crate chooser that are not in upstream
                var inCrateChooser = crateChooser.CrateDescriptions
                                     .Where(y => !upstreamCrates.AvailableCrates.Any(z => z.ManifestId == y.ManifestId && z.SourceActivityId == y.SourceActivityId && z.Label == y.Label));
                //elements in upstream that are not in crate chooser
                var inUpstream = upstreamCrates.AvailableCrates
                                 .Where(y => !crateChooser.CrateDescriptions.Any(z => z.ManifestId == y.ManifestId && z.SourceActivityId == y.SourceActivityId && z.Label == y.Label));
                if (inUpstream.Count() > 0 || inCrateChooser.Count() > 0)
                {
                    //check if selected crate is no more available
                    var old_selected = crateChooser.CrateDescriptions.FirstOrDefault(x => x.Selected);
                    if (old_selected != null)
                    {
                        var selected_in_upstream = upstreamCrates.AvailableCrates
                                                   .Where(a => a.Label == old_selected.Label && a.SourceActivityId == old_selected.SourceActivityId && a.ManifestId == old_selected.ManifestId)
                                                   .FirstOrDefault();
                        if (selected_in_upstream != null)
                        {
                            //it is available
                            selected_in_upstream.Selected = true;
                        }
                    }

                    //updated CrateChooser.CrateDescriptions
                    crateChooser.CrateDescriptions = upstreamCrates.AvailableCrates;
                }
            }

            var selected = crateChooser.CrateDescriptions.FirstOrDefault(x => x.Selected);

            if (selected != null)
            {
                SignalRowCrate(selected);
            }
            else
            {
                selected = SelectTheCrateIfThereIsOnlyOne(crateChooser);
                if (selected != null)
                {
                    SignalRowCrate(selected);
                }
            }
        }