New Posts New Posts RSS Feed: Silverlight & IdeaBlade.... is it everytime ok?
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Silverlight & IdeaBlade.... is it everytime ok?

 Post Reply Post Reply
Author
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Topic: Silverlight & IdeaBlade.... is it everytime ok?
    Posted: 12-Jan-2012 at 4:44pm
Hi Paolo,

One suggestion is to construct the code as follows using a combination of Thread.Sleep and a flag indicating whether the async query has completed or not. For example,

    while (true) {
        DoSomeQueryHere();
        // Sleep for 5 seconds between checks.
        Thread.Sleep(1000 * 5 * 1);
        if (__hasQueryCompleted) {
          __hasQueryCompleted = false;
          __notificationManager.Send(__serviceKey, __message);
        }
      }

   private static void DoSomeQueryHere() {
      var query = __entityManager.Orders;
      query.ExecuteAsync(args => {
        var count = args.Results.Count();
        __message = String.Format("Received {0} Orders", count);
        __hasQueryCompleted = true;
      };
    }
Back to Top
pponzano View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Apr-2011
Location: Italy
Posts: 165
Post Options Post Options   Quote pponzano Quote  Post ReplyReply Direct Link To This Post Posted: 12-Jan-2012 at 4:05am
Hello Denisk...
it worked!!
Just last question about this (I promise!)
 
I wish to call for each subscriber a SP that check if the're user message for each user... since due to user's profile I need to show basic or advanced information... for now I've done it sync, calling for each user the SP, can I do it async?
 

  

private static void CheckForNewUserMessages()

     {

         foreach (var subscriber in _notificationManager.GetSubscribers(_serviceKey))

         {

             var args = subscriber.ClientArguments;

             if (args != null && args.Count() == 2)

             {

                 var currentUser = args[0] as myUser;

                 bool expired = Convert.ToBoolean(args[1]);

 

                 var query = _entityManager.SP_USER_MESSAGES_SELECTQuery(currentUser.IDIstituto,currentUser.IDUser,DateTime.Now,(expired ? 1 : 0));

 

                 query.ExecuteAsync((results=>

                 {

                     if (!results.HasError)

                     {

                         var items = results.Results.Cast<UserMessagesResult>();

                         _notificationManager.Send(_serviceKey, subscriber, new object[] { items });

                     }

                     else

                     {

                         //todo : add logging

                     }

                 }));

This won't work...it will be called only once... what you suggest to do? I know this breaks a bit notifications... but I forgot to tell you before that there're notification per user, per group and generic

Thanks
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 11-Jan-2012 at 3:36pm
Hi Paolo,

I was looking at your sample solution and started to realize there are many things unnecessary in your app.config and web.config files. So instead, I've created another solution that's similar to what you're trying to do.


A couple of things to note:

1. The type exception you're getting is due to using ServerNotifyDelegate in n-tier environment with a separate client and server assembly. This is not supported yet. Instead, please use the other EntityManager.RegisterCallback overload where you have to specify the type and method name.

2. You shouldn't need a lot of the bindings, services, etc, in your config files. If you see my sample, the config files are pretty minimal and that's all you need for this purpose.

Hope this helps.
Back to Top
pponzano View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Apr-2011
Location: Italy
Posts: 165
Post Options Post Options   Quote pponzano Quote  Post ReplyReply Direct Link To This Post Posted: 11-Jan-2012 at 9:00am
Removing the Client class (thing I cannot do), pointing to server it works...
otherwise I got

---------------------------

---------------------------
Unable to subscribe to service.  Make sure the EntityServer is listening for INotificationService operations.
---------------------------
OK  
---------------------------

Inner exception

Unable to load type: Server.UserMessageWatcher, Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

This file is a shared link... HELP PLEASEEEE!
Back to Top
pponzano View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Apr-2011
Location: Italy
Posts: 165
Post Options Post Options   Quote pponzano Quote  Post ReplyReply Direct Link To This Post Posted: 11-Jan-2012 at 8:16am
Hello,
I've created a simple project you can download here

http://www.megaupload.com/?d=C5C7NXLU

The problem seems to be    <clientSettings isDistributed="true" />

When I remove it in the demo it works (with or without specifing bindings and so on... )

if I remove this in my main application I got a lot o error, first of all authentication problem...

Hope you can send me a working demo back based upon mine

Thanks


Edited by pponzano - 11-Jan-2012 at 8:31am
Back to Top
pponzano View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Apr-2011
Location: Italy
Posts: 165
Post Options Post Options   Quote pponzano Quote  Post ReplyReply Direct Link To This Post Posted: 11-Jan-2012 at 7:07am
I also get this :

Virtual path provider error - The virtual path name must begin with 'EntityServer'  when calling http://localhost:9009/EntityServer.svc/NotificationService.svc from IE

is this of any suggestion?

my global asax is

 protected void Application_Start(Object sender, EventArgs e) {

      // To enable remote viewing of trace messages via the TraceViewer:
      // TODO:  Uncomment following line if you want to provide this feature. 
      //IdeaBlade.Core.TracePublisher.LocalInstance.MakeRemotable();       

      // If you don't want to create a .svc file for every EntityServer service, you
      // can instead register a "virtual path provider".      
      // You do not need to supply .svc files for the EntityService and EntityServer services
      // when the provider is registered.     
     System.Web.Hosting.HostingEnvironment.RegisterVirtualPathProvider(new IdeaBlade.EntityModel.Web.ServiceVirtualPathProvider());    
      
    }   

Thanks

p.s. sorry for the spam, but I'm in italy, you USA, since you answer me while I'm out of office, more info I give you the best its
Back to Top
pponzano View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Apr-2011
Location: Italy
Posts: 165
Post Options Post Options   Quote pponzano Quote  Post ReplyReply Direct Link To This Post Posted: 11-Jan-2012 at 6:05am
I went a bit further but I got still problems... here's what I've got

Client Config

ideablade.configuration version="6.00" xmlns="http://schemas.ideablade.com/2010/IdeaBladeConfig">
    <notificationService clientPort="9012"/>
    <logging logFile="DebugLog.xml"/>

    <objectServer remoteBaseURL="http://localhost" serviceName="EntityService.svc" serverPort="9009">
      <clientSettings isDistributed="true" />
    </objectServer>

    <!-- Additional configuration can be added to override defaults.
         See the sample config files in the Learning Resources for more information.
    -->
  </ideablade.configuration>
  <system.serviceModel>
    <client>
      <endpoint name="EntityService"
                address="http://localhost:9009/EntityService.svc/"
                binding="customBinding" bindingConfiguration="compressedBinaryBinding"
                contract="IdeaBlade.EntityModel.IEntityServiceContract"
                />

      <endpoint name="EntityServer"
                address="http://localhost:9009/EntityServer.svc/"
                binding="customBinding" bindingConfiguration="compressedBinaryBinding"
                contract="IdeaBlade.EntityModel.IEntityServerContract"
                />

      
      <endpoint name="NotificationService"
                address="http://localhost:9009/EntityService.svc/NotificationService"
                binding="wsDualHttpBinding" bindingConfiguration="DualBinding"
                contract="IdeaBlade.EntityModel.INotificationService"
                />
    </client>

    <bindings>

      <customBinding>
        <binding name="compressedBinaryBinding"
                 closeTimeout="00:01:00"
                 openTimeout="00:01:00"
                 receiveTimeout="00:10:00"
                 sendTimeout="00:01:00">
          <gzipMessageEncoding>
            <readerQuotas
                 maxDepth="2147483647"
                 maxStringContentLength="2147483647"
                 maxArrayLength="2147483647" />
          </gzipMessageEncoding>
          <httpTransport maxReceivedMessageSize="2147483647" />
        </binding>
      </customBinding>

      <!-- If using the Notification service - uncomment this binding.
       Change the clientBaseAddress to something appropriate for your site.
       The base address must be unique for each push client.
      -->
     
      <wsDualHttpBinding>
        <binding name="DualBinding" messageEncoding="Mtom">
          <security mode="None" />
        </binding>
      </wsDualHttpBinding>
     

    </bindings>
    <extensions>
      <bindingElementExtensions>
        <add name="gzipMessageEncoding"
             type="IdeaBlade.Core.Wcf.Extensions.GZipMessageEncodingElement, IdeaBlade.Core"/>
      </bindingElementExtensions>

    </extensions>

  </system.serviceModel>

Server (web.config)

 <ideablade.configuration version="6.00" xmlns="http://schemas.ideablade.com/2010/IdeaBladeConfig">
    <logging logFile="log\DebugLog.xml" />
    <objectServer>
      <serverSettings useAspNetSecurityServices="false" allowAnonymousLogin="false" />
    </objectServer>
    <!-- Additional configuration can be added to override defaults.
         See the sample config files in the Learning Resources for more information.
    -->
    <notificationService enabled="true" clientPort="9012"/>
  </ideablade.configuration>
  <system.serviceModel>
    <!-- Set aspNetCompatibilityEnabled to true to allow use of ASP.NET security features.
         Set multipleSiteBindingsEnabled to true for Azure or if your web site has multiple http bindings.
    -->
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"  />
    <!--multipleSiteBindingsEnabled="true"-->
    <!-- The default EntityService and EntityServer services use by DevForce. 
         Note that this configuration requires modifications in order to support Silverlight clients.
    -->
    <services>
      <service name="EntityService">
        <endpoint address=""
                  binding="customBinding" bindingConfiguration="compressedBinaryBinding"
                  contract="IdeaBlade.EntityModel.IEntityServiceContract"/>
      </service>

      <service name="EntityServer">
        <endpoint address=""
                  binding="customBinding" bindingConfiguration="compressedBinaryBinding"
                  contract="IdeaBlade.EntityModel.IEntityServerContract"/>
        <endpoint address="NotificationService"
               binding="wsDualHttpBinding"  bindingConfiguration="DualBinding"
               contract="IdeaBlade.EntityModel.INotificationService"
                  />
      </service>
    </services>
    <!-- The gzipMessageEncoding binding element is used to provide compressed binary encoding.
     Several quotas have been to maximum values here, but can be reduced based on your site needs.
     Other properties are allowed to default here, but you may set as needed. 
     Additional binding elements may also be added.
        -->
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyServiceTypeBehaviors">
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <customBinding>
        <binding name="compressedBinaryBinding"
                 closeTimeout="00:01:00"
                 openTimeout="00:01:00"
                 receiveTimeout="00:10:00"
                 sendTimeout="00:01:00">
          <gzipMessageEncoding>
            <readerQuotas
              maxDepth="2147483647"
              maxStringContentLength="2147483647"
              maxArrayLength="2147483647" />
          </gzipMessageEncoding>
          <httpTransport maxReceivedMessageSize="2147483647" />
        </binding>
      </customBinding>

      <wsDualHttpBinding>
        <binding name="DualBinding" messageEncoding="Mtom" >
          <security mode="None" />
        </binding>
      </wsDualHttpBinding>


    </bindings>
   
    <extensions>
      <bindingElementExtensions>
        <add name="gzipMessageEncoding" type="IdeaBlade.Core.Wcf.Extensions.GZipMessageEncodingElement, IdeaBlade.Core" />
      </bindingElementExtensions>
    </extensions>
  </system.serviceModel>

I receive a

{"Content Type multipart/related; type=\"application/xop+xml\";start=\"<http://tempuri.org/0>\";boundary=\"uuid:9aeaeae3-6eaa-4001-a9da-085c2cf8fbf4+id=1\";start-info=\"application/soap+xml\" was not supported by service http://localhost:9009/EntityService.svc/NotificationService.  The client and service bindings may be mismatched."}

and here's a piece of log

2012-01-1115:01:15
IdeaBlade.Core.Composition.CompositionHost:CheckMultiExportCompositionContext: '-IbDefault-' - Probed for non-default 'IKnownTypeProvider' and found no matching exports.
2012-01-1115:01:15
IdeaBlade.EntityModel.RemoteServiceFns:AddSerializationBehaviorUsing DC serializer for EntityServer
2012-01-1115:01:15
IdeaBlade.EntityModel.RemoteServiceFns:AddSerializationBehaviorUsing DC serializer for NotificationService
2012-01-1115:01:15
IdeaBlade.EntityModel.Server.EntityServerHostFactory:CreateServiceHostEntityServer listening on http://localhost:9009/EntityServer.svc
2012-01-1115:01:15
IdeaBlade.EntityModel.Server.EntityServerHostFactory:CreateServiceHostEntityServer listening on http://localhost:9009/EntityServer.svc/NotificationService
2012-01-1115:01:19
IdeaBlade.Core.Composition.CompositionHost:CheckSingleExportCompositionContext: '-IbDefault-' - Probed for default 'IDataSourceKeyResolver' and found 'IdeaBlade.EntityModel.DefaultDataSourceKeyResolver'.
2012-01-1115:01:19
IdeaBlade.Core.Composition.CompositionHost:CheckSingleExportCompositionContext: '-IbDefault-' - Probed for any 'EntityServerQueryInterceptor' and found 'IdeaBlade.EntityModel.Server.EntityServerQueryInterceptor'.


What have I to check?

Back to Top
pponzano View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Apr-2011
Location: Italy
Posts: 165
Post Options Post Options   Quote pponzano Quote  Post ReplyReply Direct Link To This Post Posted: 11-Jan-2012 at 1:39am
Hello Denisk,
I'm trying to use it right now... but I got an exeption
 
Caught exception: IdeaBlade.Core.IdeaBladeException: Unable to create the server delegate 'myProject.DomainModel.UserMessageWatcher, myProject.DomainModel.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.NewUserMessageService' ---> IdeaBlade.Core.IdeaBladeException: Unable to load type: myProject.DomainModel.UserMessageWatcher, myProject.DomainModel.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null at IdeaBlade.Core.ReflectionFns.GetLatestType(String pTypeName, Boolean pThrowOnError, Boolean pIgnoreCase) at IdeaBlade.Core.ReflectionFns.GetDelegate[T](String pTypeName, String pMethodName, Type[] pSignature) at IdeaBlade.EntityModel.Server.NotificationServiceManager.Subscribe(SessionBundle sessionBundle, SubscribeWorkState workstate) --- End of inner exception stack trace --- at IdeaBlade.EntityModel.Server.NotificationServiceManager.Subscribe(SessionBundle sessionBundle, SubscribeWorkState workstate) at IdeaBlade.EntityModel.Server.EntityServer.Subscribe(SessionBundle sessionBundle, SubscribeWorkState workstate) at SyncInvokeSubscribe(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
 
I think that's due to the fact I've a Client/Server application (the server is the module hosted by web) meanwhile the client is used by WPF ... I shared the file as a shared link between the server and the client
 
Thanks
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 10-Jan-2012 at 5:06pm
Hi Paolo,

As the exception indicates, it seems that you're using the same EntityManager for the main thread as well as the the new "task" thread.

Try creating a separate EntityManager used solely for the "task" thread.

I still don't understand why you can't use DevForce Push Notification feature. Could you elaborate?
Back to Top
pponzano View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Apr-2011
Location: Italy
Posts: 165
Post Options Post Options   Quote pponzano Quote  Post ReplyReply Direct Link To This Post Posted: 10-Jan-2012 at 6:24am
Hello Denisk,
I was developing a viewmodel that polls a store procedure to check if there're some notification message to show to the user and I got the problem

---------------------------

---------------------------
An EntityManager can only execute on a single thread. This EntityManager is authorized to execute on the thread with id=’9’; the requested operation came from the thread with Id=‘13’.

Consider calling the EntityManager’s asynchronous methods; they work safely on background threads managed by DevForce.

You may have to disable this cross-thread checking for specific reasons such as automated testing. Please review our documentation on multi-threading issues and the EntityManager.AuthorizedThreadId property.
---------------------------
OK  
---------------------------

my code was :

private System.Threading.CancellationToken _cancellationToken = new System.Threading.CancellationToken();

       private readonly System.Threading.Tasks.Task task = null;

       private int _checkInterval = 10;

 

       public int CheckInterval

       {

           get

           {

               return _checkInterval;

           }

           set

           {

               _checkInterval = value;

               NotifyOfPropertyChange(() => CheckInterval);

           }

       }


[...]

task = new System.Threading.Tasks.Task(() =>

         {

             while (true)

             {

                 LoadUserMessages();

                 System.Threading.Thread.Sleep(_checkInterval * 1000);

             }

         }, _cancellationToken, System.Threading.Tasks.TaskCreationOptions.LongRunning);

 

     }

 

     protected override void OnInitialize()

     {

         base.OnInitialize();

 

         if (task != null)

             task.Start();

     }


Is there any way of having this polling situation? since I can't use ideablade notification (I can't access to the table direcly, I need to perform it via store) I tougth using this way... but with no luck...
I'm using DAF as MVVM pattern
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 12-Oct-2011 at 2:08pm
Hi Paolo;

Yes, it's correct to set the Completed event after the call since you can only get the EntityQueryOperation after it. DevForce will also handle the case if the call completes really fast and still raise the Completed event.

No, you can't access the model in a thread-safe manner since the EntityManager and other entity related classes are not thread safe. You can create and use an EntityManager within a task or async method, but you can't create an EntityManager on one thread and then put actions like query or save in a task.

Since 4.5 has just recently come out, we haven't done any testing with this yet. But it's on our to do list.
Back to Top
pponzano View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Apr-2011
Location: Italy
Posts: 165
Post Options Post Options   Quote pponzano Quote  Post ReplyReply Direct Link To This Post Posted: 11-Oct-2011 at 5:17am
Hello,
I'm new to IdeaBlade and trying to figure how how it works....
I've done some testing following your sample,
I did so :

   StoredProcQuery query = mgr.fCalendarEventsQuery(84, 1234, DataSelezionataInizio, DataSelezionataFine, 0);

 

          EntityQueryOperation operation = query.ExecuteAsync();

 

          operation.Completed += (sender, e) =>

          {

              IsBusy = false;

              if (!e.HasError)

              {

                  e.Results.Cast<RisultatiCalendario>().ForEach(Result.Add);

              }

              else

              {

                  MessageBox.Show(e.Error.Message);

              }

        };

I was wondering if it's right to set the Completed event after the call to the ExecuteAsync... it the call completes really fast (before the completed event has been attached) what should happen?

 
Usually in Silverlight when calling a WCF service I attach the handler and then I call the async method...
 
Can someone explain me how things work here?
 
Another question, using multi-threaded library as TPL or the new FW 4.5 async can I access to the Model items in a thread-safe way?
Thanks
 
Paolo
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down