Exemplo n.º 1
0
        /// <summary>Snippet for ListServices</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public void ListServicesRequestObject()
        {
            // Create client
            ServiceManagerClient serviceManagerClient = ServiceManagerClient.Create();
            // Initialize request argument(s)
            ListServicesRequest request = new ListServicesRequest
            {
                ProducerProjectId = "",
            };
            // Make the request
            PagedEnumerable <ListServicesResponse, ManagedService> response = serviceManagerClient.ListServices(request);

            // Iterate over all response items, lazily performing RPCs as required
            foreach (ManagedService item in response)
            {
                // Do something with each item
                Console.WriteLine(item);
            }

            // Or iterate over pages (of server-defined size), performing one RPC per page
            foreach (ListServicesResponse page in response.AsRawResponses())
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (ManagedService item in page)
                {
                    // Do something with each item
                    Console.WriteLine(item);
                }
            }

            // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
            int pageSize = 10;
            Page <ManagedService> singlePage = response.ReadPage(pageSize);

            // Do something with the page of items
            Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
            foreach (ManagedService item in singlePage)
            {
                // Do something with each item
                Console.WriteLine(item);
            }
            // Store the pageToken, for when the next page is required.
            string nextPageToken = singlePage.NextPageToken;
        }
Exemplo n.º 2
0
 //constructor
 public AdminServiceEdit(string Email, string PassHash, Service.Service service)
 {
     InitializeComponent();
     this.Email             = Email;
     this.PassHash          = PassHash;
     this.service           = service;
     this.ServicedCar       = service.ServicedCar;
     this.newService        = false;
     TotalUpDown.Value      = Convert.ToDecimal(service.TotalSpent);
     KilometersUpDown.Value = service.Kilometers;
     try
     {
         this.serviceManager = new ServiceManagerClient();
     }catch (Exception exc)
     {
         MessageBox.Show("Errore nella connessione al server.", "Proprio non riesco.", MessageBoxButtons.OK);
     }
 }
Exemplo n.º 3
0
        /// <summary>Snippet for ListServiceRolloutsAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task ListServiceRolloutsAsync()
        {
            // Create client
            ServiceManagerClient serviceManagerClient = await ServiceManagerClient.CreateAsync();

            // Initialize request argument(s)
            string serviceName = "";
            string filter      = "";
            // Make the request
            PagedAsyncEnumerable <ListServiceRolloutsResponse, Rollout> response = serviceManagerClient.ListServiceRolloutsAsync(serviceName, filter);

            // Iterate over all response items, lazily performing RPCs as required
            await response.ForEachAsync((Rollout item) =>
            {
                // Do something with each item
                Console.WriteLine(item);
            });

            // Or iterate over pages (of server-defined size), performing one RPC per page
            await response.AsRawResponses().ForEachAsync((ListServiceRolloutsResponse page) =>
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (Rollout item in page)
                {
                    // Do something with each item
                    Console.WriteLine(item);
                }
            });

            // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
            int            pageSize   = 10;
            Page <Rollout> singlePage = await response.ReadPageAsync(pageSize);

            // Do something with the page of items
            Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
            foreach (Rollout item in singlePage)
            {
                // Do something with each item
                Console.WriteLine(item);
            }
            // Store the pageToken, for when the next page is required.
            string nextPageToken = singlePage.NextPageToken;
        }
Exemplo n.º 4
0
        //constructor
        public AdminServiceList(string Email, string PassHash, string CarPlate)
        {
            this.Email          = Email;
            this.PassHash       = PassHash;
            this.CarPlate       = CarPlate;
            this.serviceManager = new ServiceManagerClient();
            this.carManager     = new CarManagerClient();
            InitializeComponent();
            servicesListView.View = View.Details;
            servicesListView.Columns.Add("ID", -2, HorizontalAlignment.Left);
            servicesListView.Columns.Add("Kilometri", -2, HorizontalAlignment.Left);
            servicesListView.Columns.Add("Spesa totale", -2, HorizontalAlignment.Left);

            try {
                this.serviceManager = new ServiceManagerClient();
                this.carManager     = new CarManagerClient();
                this.UpdateServices();
            }catch (Exception exc)
            {
                MessageBox.Show("Errore nella connessione al server.", "Proprio non riesco.", MessageBoxButtons.OK);
            }
        }
        /// <summary>Snippet for EnableServiceAsync</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task EnableServiceRequestObjectAsync()
        {
            // Create client
            ServiceManagerClient serviceManagerClient = await ServiceManagerClient.CreateAsync();

            // Initialize request argument(s)
            EnableServiceRequest request = new EnableServiceRequest
            {
                ServiceName = "",
                ConsumerId  = "",
            };

            // Make the request
#pragma warning disable CS0612
            Operation <EnableServiceResponse, OperationMetadata> response = await serviceManagerClient.EnableServiceAsync(request);

#pragma warning restore CS0612

            // Poll until the returned long-running operation is complete
            Operation <EnableServiceResponse, OperationMetadata> completedResponse = await response.PollUntilCompletedAsync();

            // Retrieve the operation result
            EnableServiceResponse result = completedResponse.Result;

            // Or get the name of the operation
            string operationName = response.Name;
            // This name can be stored, then the long-running operation retrieved later by name
#pragma warning disable CS0612
            Operation <EnableServiceResponse, OperationMetadata> retrievedResponse = await serviceManagerClient.PollOnceEnableServiceAsync(operationName);

#pragma warning restore CS0612
            // Check if the retrieved long-running operation has completed
            if (retrievedResponse.IsCompleted)
            {
                // If it has completed, then access the result
                EnableServiceResponse retrievedResult = retrievedResponse.Result;
            }
        }
Exemplo n.º 6
0
        public string Connect(string address, int port)
        {
            if (Client != null && Client.State == CommunicationState.Opened)
            {
                Client.Abort();
            }

            Client = new ServiceManagerClient(address, port);
            try
            {
                Client.RegisterClient();
            }
            catch (EndpointNotFoundException)
            {
                return("%!Unable to connect to " + address + ":" + port);
            }
            Client.Disconnected                  += OnServiceDisconnected;
            Client.NotificationReceived          += OnNotificationReceived;
            Client.ExtensionNotificationReceived += OnExtensionNotificationReceived;

            var dt = Client.GetServerTime();

            return("%~Connected. Server time is " + dt + ".");
        }
Exemplo n.º 7
0
        public void RunExtension(Guid guid, bool runDebugMethodOnExtension, string extensionID)
        {
            _logger.Info("Starting extension: {0} -- process monitor ID: {1}", extensionID, guid);

            lock(this)
                _runningExtension = Activate(extensionID);
            var ext = _runningExtension.Extension;

            Thread extThread = new Thread(new ThreadStart(() =>
            {
            //const TaskCreationOptions atp = TaskCreationOptions.AttachedToParent | TaskCreationOptions.LongRunning;
            //var task = Task.Factory.StartNew(() =>
            //{
                try
                {
                    _logger.Debug("Extension activation/monitoring task starting...");
                    lock (this)
                        _runningExtension.Task = Task.Factory.StartNew(() => ext.Run(_cancelSource), TaskCreationOptions.LongRunning);
                        //_runningExtension.Task = Task.Factory.StartNew(() => ext.Run(_cancelSource), _cancelSource.Token, atp, TaskScheduler.Current);
                    _extensionStarted = true;
                    if(runDebugMethodOnExtension)
                    {
                        while(!ext.RunCalled && !_cancelSource.IsCancellationRequested)
                            Thread.Sleep(250); // give the extension a chance to start up
                        _cancelSource.Token.ThrowIfCancellationRequested();
                        ext.Debug();
                    }

                    ServiceManagerClient client = null;
                    if(guid != Guid.Empty)
                    {
                        _logger.Info("Connecting to Service Manager...");
                        client = new ServiceManagerClient("ServiceManagerClient");
                        client.Disconnected += c =>
                        {
                            _logger.Info("Client state changed to: " + c.State);
                            _logger.Info("Disconnected from service manager. Execution on all extensions will be cancelled now to allow the process to shut down.");
                            _cancelSource.Cancel(); // process manager will take care of restarting this process
                        };

                        // Don't notify the server until Run has been called, otherwise the extension's Logger won't be available
                        while(!ext.RunCalled)
                            Thread.Sleep(250);
                        _logger.Info("Sending extension connection address: " + _runningExtension.Address);
                        client.NotifyExtensionServiceReady(guid, _runningExtension.Address);
                        _logger.Info("Connected.");

                    }

                    _logger.Info("Extension is now running.");
                    const string exitMsg = " Execution on all extensions will be cancelled now to allow the process to restart.";
                    while(!_cancelSource.IsCancellationRequested)
                    {
                        if(!ext.IsRunning)
                            _logger.Info("Extension {" + ext.Name + "} IsRunning == false." + exitMsg);
                        if(_runningExtension.Task.IsCompleted)
                            _logger.Info("Extension {" + ext.Name + "} Task.IsCompleted == true." + exitMsg);
                        if(_runningExtension.Task.IsFaulted)
                        {
                            _logger.Info("Extension {" + ext.Name + "} Task.IsFaulted == true." + exitMsg);
                            _logger.Info("The exception thrown by the task was: " + _runningExtension.Task.Exception);
                        }
                        if(!ext.IsRunning || _runningExtension.Task.IsCompleted || _runningExtension.Task.IsFaulted)
                            _cancelSource.Cancel();
                        if(client != null)
                        {
                            client.KeepExtensionProcessAlive(guid);
                        }
                        Thread.Sleep(3000);
                    }
                }
                catch(ThreadAbortException)
                {
                    _logger.Warn("Extension state monitoring terminating.");
                }
                catch(Exception ex)
                {
                    _logger.FatalException("EXTENSION MONITORING TASK EXCEPTION:", ex);
                }
            })); //, _cancelSource.Token, atp, TaskScheduler.Current);

            extThread.Start();

            _logger.Info("Waiting on task threads to finish...");
            try
            {
                extThread.Join();
                //task.Wait(_cancelSource.Token);
            }
            catch (ThreadAbortException) { }
            catch (ThreadInterruptedException) { }
            catch (ThreadStateException) { }
            catch (OperationCanceledException)
            {
            }
            _logger.Info("Task threads have all ended.");
        }
Exemplo n.º 8
0
 void OnServiceDisconnected(ServiceManagerClient psc)
 {
     Client = null;
 }
Exemplo n.º 9
0
 void OnServiceDisconnected(ServiceManagerClient psc)
 {
     Client = null;
 }
Exemplo n.º 10
0
        public string Connect(string address, int port)
        {
            if(Client != null && Client.State == CommunicationState.Opened)
                Client.Abort();

            Client = new ServiceManagerClient(address, port);
            try
            {
                Client.RegisterClient();
            }
            catch(EndpointNotFoundException)
            {
                return "%!Unable to connect to " + address + ":" + port;
            }
            Client.Disconnected += OnServiceDisconnected;
            Client.NotificationReceived += OnNotificationReceived;
            Client.ExtensionNotificationReceived += OnExtensionNotificationReceived;

            var dt = Client.GetServerTime();
            return "%~Connected. Server time is " + dt + ".";
        }