Esempio n. 1
0
        void ConnectToScribbler(DateTime dt)
        {
            Uri driveUri = null;

            // Look for any active generic drive contract service running
            Arbiter.Activate(DssEnvironment.TaskQueue,
                             Arbiter.Choice(DssEnvironment.DirectoryQuery(drive.Contract.Identifier),
                                            delegate(ServiceInfoType success)
            {
                driveUri = new Uri(success.Service);
                Console.WriteLine("================\n" + driveUri);

                // Initialize the port and subscribe to the service
                motorsOn  = false;
                drivePort = DssEnvironment.ServiceForwarder <drive.DriveOperations>(driveUri);
                drive.DriveOperations driveNotificationPort = new drive.DriveOperations();
                drivePort.Subscribe(driveNotificationPort);

                // Set up notifications
                Arbiter.Activate(DssEnvironment.TaskQueue,
                                 Arbiter.Receive <drive.Update>(true, driveNotificationPort, NotifyDriveUpdate)
                                 );

                autolock.Set();
            },
                                            delegate(W3C.Soap.Fault failure)
            {
                // Request failed. Sleep for 1 sec and look for 30 times.
                if (++attemptCount >= 30)
                {
                    DssEnvironment.LogError("Unable to find Drive Service, aborting - Press <Enter>");
                    Console.ReadLine();
                    DssEnvironment.Shutdown();
                }
                else
                {
                    // Post a timer message that expires in 30 seconds
                    TimeSpan timeout = new TimeSpan(0, 0, 30);
                    DssEnvironment.TaskQueue.EnqueueTimer(timeout, _timerPort);
                }
            }
                                            ));
        }