Example #1
0
 private static void RemovePackagesFromChannel(AvailableChannelViewModel channel)
 {
     if (channel.NoOfTimesPresentedDone < 5)
     {
         channel.NoOfTimesPresentedDone++;
     }
     else
     {
         channel.PackageId = Guid.Empty;
         channel.MessagesProcessed = null;
     }
 }
Example #2
0
        internal static ObservableCollection<AvailableChannelViewModel> AddToChannels(this IEnumerable<MapChannel> inCollection, ObservableCollection<AvailableChannelViewModel> beforeImage)
        {
            if (beforeImage == null)
                beforeImage = new ObservableCollection<AvailableChannelViewModel>();
            else
                RemoveAllDonePackages(beforeImage);
            if(inCollection==null)
            {
                MakeNullChannelsInvisible(beforeImage);
                return beforeImage;
            }
            foreach (var mapChannel in inCollection)
            {
                AvailableChannelViewModel availableChannelViewModel = new AvailableChannelViewModel
                                                                          {
                                                                              MapChannelPublisherTitle =
                                                                                  mapChannel.PublisherInfo.InstanceName + ":" + mapChannel.PublisherInfo.Port,
                                                                                  PublisherStatus=mapChannel.PublisherInfo.Status,
                                                                                  PublisherRootPath=mapChannel.PublisherInfo.RootPath,
                                                                                  MapChannelSubscriberTitle =
                                                                                  mapChannel.SubscriberInfo.InstanceName + ":" + mapChannel.SubscriberInfo.Port,
                                                                                  SubscriberStatus=mapChannel.SubscriberInfo.Status,
                                                                                  SubscriberRootPath=mapChannel.SubscriberInfo.RootPath
                                                                          };
                //availableChannelViewModel.MessagesVisible = Visibility.Hidden;
                if(mapChannel.PublisherInfo.CurrentPackage!=null)
                {
                    availableChannelViewModel.PackageId = mapChannel.PublisherInfo.CurrentPackage.Id;
                    availableChannelViewModel.PublisherPackageState = mapChannel.PublisherInfo.CurrentPackage.State;
                    availableChannelViewModel.MessagesProcessed =
                        mapChannel.PublisherInfo.CurrentPackage.PackageMessages.AddToMessages((mapChannel.SubscriberInfo.CurrentPackage==null)?null:
                            mapChannel.SubscriberInfo.CurrentPackage.PackageMessages, mapChannel.PublisherInfo.RootPath,
                            mapChannel.SubscriberInfo.RootPath);
                    //availableChannelViewModel.MessagesVisible = (availableChannelViewModel.MessagesProcessed.Count == 0)
                    //                                                ? Visibility.Hidden
                    //                                                : Visibility.Visible;
                }
                if(mapChannel.SubscriberInfo.CurrentPackage!=null)
                    availableChannelViewModel.SubscriberPackageState = mapChannel.SubscriberInfo.CurrentPackage.State;

                if (!beforeImage.Contains(availableChannelViewModel, new AvailableChannelViewModelEqualityComparer()))
                {
                    if(Application.Current==null)
                        beforeImage.Add(availableChannelViewModel);
                    else
                        Application.Current.Dispatcher.Invoke((Action)(() => beforeImage.Add(availableChannelViewModel)));
                }
                else
                {
                    var existingItem = beforeImage.FirstOrDefault(
                        b =>
                        b.MapChannelPublisherTitle ==
                        mapChannel.PublisherInfo.InstanceName + ":" + mapChannel.PublisherInfo.Port
                        && b.MapChannelSubscriberTitle==mapChannel.SubscriberInfo.InstanceName + ":" +mapChannel.SubscriberInfo.Port);
                    if (existingItem != null)
                    {
                        existingItem.PublisherStatus = mapChannel.PublisherInfo.Status;
                        existingItem.SubscriberStatus = mapChannel.SubscriberInfo.Status;
                        existingItem.PublisherRootPath = mapChannel.PublisherInfo.RootPath;
                        existingItem.SubscriberRootPath = mapChannel.SubscriberInfo.RootPath;
                        if(mapChannel.PublisherInfo.CurrentPackage!=null)
                        {
                            existingItem.PackageId = mapChannel.PublisherInfo.CurrentPackage.Id;
                            existingItem.PublisherPackageState = mapChannel.PublisherInfo.CurrentPackage.State;
                            existingItem.MessagesProcessed=
                                mapChannel.PublisherInfo.CurrentPackage.PackageMessages.AddToMessages((mapChannel.SubscriberInfo.CurrentPackage==null)?null:mapChannel.SubscriberInfo.CurrentPackage.PackageMessages,mapChannel.PublisherInfo.RootPath,mapChannel.SubscriberInfo.RootPath,
                            existingItem.MessagesProcessed);
                        }
                        else
                        {
                            RemovePackagesFromChannel(existingItem);
                        }
                        //availableChannelViewModel.MessagesVisible = (availableChannelViewModel.PackageId ==Guid.Empty)
                        //                    ? Visibility.Hidden
                        //                    : Visibility.Visible;

                        if(mapChannel.SubscriberInfo.CurrentPackage!=null)
                            existingItem.SubscriberPackageState = mapChannel.SubscriberInfo.CurrentPackage.State;
                    }
                }
            }
            MakeNullChannelsInvisible(beforeImage);
            return beforeImage;
        }