コード例 #1
0
 // This event gets called whenever a change in any of MainViewModels properties (those who have UpdateSourceTrigger attached) is detected
 private void MainWindowViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     //MessageBox.Show(e.PropertyName);
     // Only raise event if OnPropertyChanged event of PubSubTestChecked is called
     if (e.PropertyName == nameof(PubSubTestChecked))
     {
         //When PubSubTestChanged's value is changed to either true or false, raise event
         if (PubSubTestChecked)
         {
             PubSub <object> .RaiseEvent("PubSubTest", this, new PubSubEventArgs <object>("Red"));
         }
         else
         {
             PubSub <object> .RaiseEvent("PubSubTest", this, new PubSubEventArgs <object>("Blue"));
         }
     }
 }
コード例 #2
0
 /// <summary>
 /// Event handler for the ChangeEnvironment command. Sets the active environment configuration and raises EnvironmentChanged event.
 /// </summary>
 public void ChangeEnvironmentHandler()
 {
     EnvironmentConfigurationManager.ActiveEnvironmentConfiguration = EnvironmentConfigurationManager.EnvironmentConfigurations.Single(c => c.Name == this.SelectedEnvironment);
     PubSub <string> .RaiseEvent(EventNames.EnvironmentChangedEvent, this, new PubSubEventArgs <string>(this.SelectedEnvironment));
 }
        private async void SearchCommandHandler(SearchOrganizationInformationModel obj)
        {
            this.logger.Debug(this.GetType().FullName + " Searching for: " + obj.SearchText + ", " + obj.SearchType);

            obj.LabelText  = string.Empty;
            obj.LabelBrush = Brushes.Green;

            // Removing all whitespaces from the search string.
            string searchText = new string(obj.SearchText.Where(c => !char.IsWhiteSpace(c)).ToArray());

            if (string.IsNullOrEmpty(searchText))
            {
                obj.LabelText  = Resources.SearchLabelEmptySearch;
                obj.LabelBrush = Brushes.Red;

                // Preventing an empty search. It takes a lot of time and the result is useless.
                return;
            }

            PubSub <bool> .RaiseEvent(EventNames.SearchStartedEvent, this, new PubSubEventArgs <bool>(true));

            // After having removed the radio buttons where the user could select search type, search is always Smart, but the check
            // is kept in case the radio buttons comes back in a future release. For example as advanced search.
            SearchType searchType = obj.SearchType == SearchType.Smart ? IdentifySearchType(searchText) : obj.SearchType;

            IList <Organization> organizations = new List <Organization>();

            try
            {
                switch (searchType)
                {
                case SearchType.EMail:
                    obj.LabelText = string.Format(Resources.SearchLabelResultat, Resources.EMail + " " + searchText);
                    organizations = await this.GetOrganizations(searchType, searchText);

                    break;

                case SearchType.PhoneNumber:
                    obj.LabelText = string.Format(Resources.SearchLabelResultat, Resources.PhoneNumber + " " + searchText);
                    organizations = await this.GetOrganizations(searchType, searchText);

                    break;

                case SearchType.OrganizationNumber:
                    obj.LabelText = string.Format(Resources.SearchLabelResultat, Resources.OrganizationNumber + " " + searchText);
                    Organization organization = await this.GetOrganization(searchText);

                    organizations.Add(organization);
                    break;

                case SearchType.Smart:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            catch (RestClientException rex)
            {
                this.logger.Error("Exception from the RestClient", rex);

                obj.LabelBrush = Brushes.Red;

                switch (rex.ErrorCode)
                {
                case RestClientErrorCodes.RemoteApiReturnedStatusBadRequest:
                    obj.LabelText = searchType == SearchType.OrganizationNumber
                            ? Resources.SearchLabelErrorOrganizationNotFound
                            : Resources.SearchLabelErrorGeneralError;
                    break;

                case RestClientErrorCodes.RemoteApiReturnedStatusUnauthorized:
                    obj.LabelText = Resources.SearchLabelErrorUnauthorized;
                    break;

                case RestClientErrorCodes.RemoteApiReturnedStatusForbidden:
                    obj.LabelText = Resources.SearchLabelErrorForbidden;
                    break;

                case RestClientErrorCodes.RemoteApiReturnedStatusNotFound:
                    obj.LabelText = Resources.SearchLabelErrorOrganizationNotFound;
                    break;

                default:
                    obj.LabelText = Resources.SearchLabelErrorGeneralError;
                    break;
                }
            }

            ObservableCollection <OrganizationModel> orgmodellist = organizations != null
                         ? this.mapper.Map <ICollection <Organization>, ObservableCollection <OrganizationModel> >(organizations)
                         : new ObservableCollection <OrganizationModel>();

            PubSub <ObservableCollection <OrganizationModel> > .RaiseEvent(
                EventNames.SearchResultReceivedEvent, this, new PubSubEventArgs <ObservableCollection <OrganizationModel> >(orgmodellist));
        }
        private async void SearchCommandHandler(SearchRolesAndRightsInformationModel obj)
        {
            this.logger.Debug(this.GetType().FullName + " Searching for subject " + obj.SubjectSearchText + " og reportee " + obj.ReporteeSearchText);

            obj.LabelText  = string.Empty;
            obj.LabelBrush = Brushes.Green;

            // Removing all whitespaces from the search strings.
            string subjectSearchText  = new string(obj.SubjectSearchText.Where(c => !char.IsWhiteSpace(c)).ToArray());
            string reporteeSearchText = new string(obj.ReporteeSearchText.Where(c => !char.IsWhiteSpace(c)).ToArray());

            if (string.IsNullOrEmpty(subjectSearchText) || string.IsNullOrEmpty(reporteeSearchText))
            {
                obj.LabelText  = Resources.SearchLabelEmptySearch;
                obj.LabelBrush = Brushes.Red;

                // Preventing an empty search. It takes a lot of time and the result is useless.
                return;
            }

            PubSub <bool> .RaiseEvent(EventNames.RoleSearchStartedEvent, this, new PubSubEventArgs <bool>(true));

            SearchType subjectSearchType  = IdentifySearchType(subjectSearchText);
            SearchType reporteeSearchType = IdentifySearchType(reporteeSearchText);

            IList <Role> roles = new List <Role>();

            try
            {
                if (subjectSearchType == SearchType.Unknown || reporteeSearchType == SearchType.Unknown)
                {
                    obj.LabelBrush = Brushes.Red;
                    obj.LabelText  = Resources.SearchLabelErrorInvalidInput;
                }
                else
                {
                    roles = await this.GetRoles(subjectSearchText, reporteeSearchText);
                }
            }
            catch (RestClientException rex)
            {
                this.logger.Error("Exception from the RestClient", rex);

                obj.LabelBrush = Brushes.Red;

                switch (rex.ErrorCode)
                {
                case RestClientErrorCodes.RemoteApiReturnedStatusBadRequest:
                    obj.LabelText = Resources.SearchLabelErrorGeneralError;
                    break;

                case RestClientErrorCodes.RemoteApiReturnedStatusUnauthorized:
                    obj.LabelText = Resources.SearchLabelErrorUnauthorized;
                    break;

                case RestClientErrorCodes.RemoteApiReturnedStatusForbidden:
                    obj.LabelText = Resources.SearchLabelErrorForbidden;
                    break;

                case RestClientErrorCodes.RemoteApiReturnedStatusNotFound:
                    obj.LabelText = Resources.SearchLabelErrorOrganizationNotFound;
                    break;

                default:
                    obj.LabelText = Resources.SearchLabelErrorGeneralError;
                    break;
                }
            }

            ObservableCollection <RoleModel> rolesmodellist = roles != null
                         ? this.mapper.Map <ICollection <Role>, ObservableCollection <RoleModel> >(roles)
                         : new ObservableCollection <RoleModel>();

            PubSub <ObservableCollection <RoleModel> > .RaiseEvent(
                EventNames.RoleSearchResultReceivedEvent, this, new PubSubEventArgs <ObservableCollection <RoleModel> >(rolesmodellist));
        }
コード例 #5
0
 public void DeleteWine()
 {
     _wineFacade.RemoveWine(Wine);
     PubSub <Wine> .RaiseEvent(PubSubEventNames.WineDeleted, Wine);
 }