locked
Combining LINQ filter and SQLClient RRS feed

  • Question

  • Hi

    I am trying to subscribe a LINQ filter to the SQLClient service in order to get a filtered DataSet

    This is my filter:

    public class DatabaseFilter : dssp.DataContractFilter
        {        
            public DatabaseFilter()
            {
                Expression<Func<sqlstore.SqlStoreState, IEnumerable<sqlstore.FilteredRow>>> exp = (sqlstore.SqlStoreState state) =>
                  (from r in state.Store.Tables["Customers"].AsEnumerable()
                  where r.Field<string>("Country")== "Germany"
                  select new sqlstore.FilteredRow(r.Field<string>("ContactName")));
    
                base.QueryHandler = exp.Compile();
            }
                    
        }

    This is the code I added to the SQLClient to manage subscriptions:

     /// <summary>
            /// Handles Subscribe messages
            /// </summary>
            /// <param name="subscribe">the subscribe request</param>
            [ServiceHandler(ServiceHandlerBehavior.Concurrent, PortFieldName = "_pStore")]
            public IEnumerator<ITask> StoreSubscribeHandler(store.Subscribe subscribe)
            {
                SubscribeRequestType request = subscribe.Body;
                
                LogInfo("Subscribe Request from: " + request.Subscriber);
                LogInfo("Subscribe HasHeaders: " +  subscribe.HasHeaders);
    
                // Use the Subscription Manager to handle the subscribers
                yield return Arbiter.Choice(
                    SubscribeHelper(_submgrPort, request, subscribe.ResponsePort),
                    delegate(SuccessResult success)
                    {
                        LogError("Subscription Succesful");
                        base.SendNotificationToTarget<Replace>(request.Subscriber, _submgrPort, _storeState);
                    },
                    delegate(Exception e)
                    {
                        LogError(null, "Subscribe failed", e);
                    }
                );
    
                yield break;
            }
    This  is the code to add the filter to the subscribe message:

                var subscribe02 = new sqlstore.Subscribe();
                subscribe02.NotificationPort = autoid02databaseNotify;
                          
                // Add a filter to the Subscribe message before sending it
                var databaseFilter = new DatabaseFilters.DatabaseFilter();
             
                subscribe02.AddHeader(databaseFilter);
    
                autoid02databasePort.Post(subscribe02);          
                Activate<ITask>
                (
                    Arbiter.Choice(subscribe02.ResponsePort,
                    delegate(dssp.SubscribeResponseType success)
                    {
                        LogInfo("Subscription successful");
                    },
                    delegate(W3C.Soap.Fault failure)
                    {
                        LogInfo("Subscription Failed");
    
                    })
                );
    
     Activate<ITask>(Arbiter.Receive<sqlstore.Replace>(true, autoid02databaseNotify, NotifyReplaceHandler));
    And this is the notification handler:

      private void NotifyReplaceHandler(sqlstore.Replace replace)
            {
                LogInfo("Notification successful");
               
                if (!replace.HasHeaders)
                {
                    LogInfo("Unfiltered Directory Notification Received");
    
                    this._state.FilteredStore = replace.Body.Store;
                                                
                }
                else
                {
                    LogInfo("Filtered Directory Notification Received");
                                  
                    var filteredResults = replace.GetHeader<DataContractFilterResults<sqlstore.FilteredRow>>();
                  
                }
    
                     }
    For some reason the notification message never contains headers. I checked in the subscription handler and the message there does contain header. I am wondering if the content of the header needs to be explicitly applied or passed to the SubscribeHelper.

    Any idea?
    Wednesday, May 27, 2009 1:01 AM

Answers

  • Solution: use a different overload of the SubscribeHelper

     [ServiceHandler(ServiceHandlerBehavior.Concurrent, PortFieldName = "_pStore")]
            public IEnumerator<ITask> StoreSubscribeHandler(store.Subscribe subscribe)
            {
               
                
                // Use the Subscription Manager to handle the subscribers
                yield return Arbiter.Choice(
                    SubscribeHelper(_submgrPort, subscribe, subscribe.ResponsePort),
                    delegate(SuccessResult success)
                    {
                        LogError("Subscription Succesful");
                        
                        Replace replace = new Replace(_storeState.Store);
                        base.SendNotification(_submgrPort, replace);
                    },
                    delegate(Exception e)
                    {
                        LogError(null, "Subscribe failed", e);
                    }
                );
    
                yield break;
            }

    • Marked as answer by sergherrero Wednesday, May 27, 2009 5:46 PM
    Wednesday, May 27, 2009 5:45 PM