Exemple #1
0
 protected virtual void RaiseKnownServicesChanged(KnownServicesChangedAction _Action, DiscoveredService _Service)
 {
     // Raise the event by using the () operator.
     if (KnownServicesChanged != null)
         KnownServicesChanged(this, new KnownServicesChangedArgs(_Action,_Service));
 }
Exemple #2
0
        /// <summary>
        /// Handles a new incoming Notification
        /// </summary>
        /// <param name="NotificationMessage">this should be an NServiceDiscovery_Announcement message</param>
        /// <returns>true if everything was successful, false if something went wrong</returns>
        public bool HandleNotification(NotificationMessage NotificationMessage)
        {
            /*
             * DISCLAIMER:
             *
             * I DO KNOW THAT THIS IS UGLY BUT IT WORKS FOR NOW. I WILL REWRITE THIS PORTION ASAP,
             * ESPECIALLY THIS BIG IF CLAUSE DOWN THERE!
             *
             * */

            if (NotificationMessage.NotificationType == typeof(NSD_Filesystem).FullBaseName<ANotificationType>())
            {
                // we got the right messagetype
                NSD_Filesystem.Arguments Args = ((NSD_Filesystem.Arguments)NotificationMessage.Arguments);

                #region NSD_Filesystem
                lock (KnownServices)
                {
                    if (KnownServices.ContainsKey(Args.ServiceGlobalUniqueName))
                    {
                        DiscoveredService _Service = KnownServices[Args.ServiceGlobalUniqueName];

                        // you can change everything through a new announcement message but not the global unique name of the service, keep
                        // that in mind!
                        _Service.ServiceUri = Args.ServiceUri;
                        _Service.ServiceType = Args.ServiceType;

                        _Service.UpdateAnnouncementTime();
                        Debug.WriteLine("[Discovery] Updating Announcement time for Service "+_Service.ServiceGlobalUniqueName);
                        RaiseKnownServicesChanged(KnownServicesChangedAction.Modified, _Service);
                    }
                    else
                    {
                        DiscoveredService newService = new DiscoveredService(Args.ServiceGlobalUniqueName, Args.ServiceUri, Args.ServiceType);
                        Debug.WriteLine("[Discovery] Discovered new Service " + newService.ServiceGlobalUniqueName);
                        KnownServices.Add(Args.ServiceGlobalUniqueName, newService);
                        RaiseKnownServicesChanged(KnownServicesChangedAction.Added, newService);
                    }
                }
                #endregion
                return true;
            }
            else
                    if (NotificationMessage.NotificationType == typeof(NSD_StorageEngine).FullBaseName<ANotificationType>())
                    {
                        // we got the right messagetype
                        NSD_StorageEngine.Arguments Args = ((NSD_StorageEngine.Arguments)NotificationMessage.Arguments);

                        #region NSD_StorageEngine
                        lock (KnownServices)
                        {
                            if (KnownServices.ContainsKey(Args.ServiceGlobalUniqueName))
                            {
                                DiscoveredService _Service = KnownServices[Args.ServiceGlobalUniqueName];

                                // you can change everything through a new announcement message but not the global unique name of the service, keep
                                // that in mind!
                                _Service.ServiceUri = Args.ServiceUri;
                                _Service.ServiceType = Args.ServiceType;

                                _Service.UpdateAnnouncementTime();
                                Debug.WriteLine("[Discovery] Updating Announcement time for Service " + _Service.ServiceGlobalUniqueName);
                                RaiseKnownServicesChanged(KnownServicesChangedAction.Modified, _Service);

                            }
                            else
                            {
                                DiscoveredService newService = new DiscoveredService(Args.ServiceGlobalUniqueName, Args.ServiceUri, Args.ServiceType);
                                Debug.WriteLine("[Discovery] Discovered new Service " + newService.ServiceGlobalUniqueName);
                                KnownServices.Add(Args.ServiceGlobalUniqueName, newService);
                                RaiseKnownServicesChanged(KnownServicesChangedAction.Added, newService);
                            }
                        }
                        #endregion
                        return true;
                    }
                    else
                            if (NotificationMessage.NotificationType == typeof(NSD_Database).FullBaseName<ANotificationType>())
                            {
                                // we got the right messagetype
                                NSD_Database.Arguments Args = ((NSD_Database.Arguments)NotificationMessage.Arguments);

                                #region NSD_Database
                                lock (KnownServices)
                                {
                                    if (KnownServices.ContainsKey(Args.ServiceGlobalUniqueName))
                                    {
                                        DiscoveredService _Service = KnownServices[Args.ServiceGlobalUniqueName];

                                        // you can change everything through a new announcement message but not the global unique name of the service, keep
                                        // that in mind!
                                        _Service.ServiceUri = Args.ServiceUri;
                                        _Service.ServiceType = Args.ServiceType;

                                        _Service.UpdateAnnouncementTime();
                                        Debug.WriteLine("[Discovery] Updating Announcement time for Service " + _Service.ServiceGlobalUniqueName);
                                        RaiseKnownServicesChanged(KnownServicesChangedAction.Modified, _Service);

                                    }
                                    else
                                    {
                                        DiscoveredService newService = new DiscoveredService(Args.ServiceGlobalUniqueName, Args.ServiceUri, Args.ServiceType);
                                        Debug.WriteLine("[Discovery] Discovered new Service " + newService.ServiceGlobalUniqueName);
                                        KnownServices.Add(Args.ServiceGlobalUniqueName, newService);
                                        RaiseKnownServicesChanged(KnownServicesChangedAction.Added, newService);
                                    }
                                }
                                #endregion
                                return true;
                            }
            else
            {
                return false;
            }
        }