Click or drag to resize

IInfrascaleSdkListenerListenRefreshRecoveryInfoJob Method

Create an instance of the RefreshRecoveryAggregatedListener for listen all RefreshRecovery Job callbacks.

Namespace:  SOS.SDK.Contracts
Assembly:  SOS.SDK (in SOS.SDK.dll) Version: 7.6.1.5742
Syntax
C#
RefreshRecoveryAggregatedListener ListenRefreshRecoveryInfoJob(
	Action<RefreshRecoveryInfoJobSessionContract> startedHandler = null,
	Action<RefreshRecoveryInfoJobSessionContract> progressHandler = null,
	Action<JobEventsContract> eventsHandler = null,
	Action<RefreshRecoveryInfoJobSessionContract> completedHandler = null
)

Parameters

startedHandler (Optional)
Type: SystemActionRefreshRecoveryInfoJobSessionContract
A delegate for handle JobStarted callbacks.
progressHandler (Optional)
Type: SystemActionRefreshRecoveryInfoJobSessionContract
A delegate for handle JobProgress callbacks.
eventsHandler (Optional)
Type: SystemActionJobEventsContract
A delegate for handle JobEvents callbacks.
completedHandler (Optional)
Type: SystemActionRefreshRecoveryInfoJobSessionContract
A delegate for handle JobCompleted callbacks.

Return Value

Type: RefreshRecoveryAggregatedListener
RefreshRecoveryAggregatedListener, subscribed to the current Infrascale Service callbacks.

Return Value

Type: RefreshRecoveryAggregatedListener
JobSessionEventsListenerT, subscribed to the current Infrascale Service callbacks.
Remarks
Set the FilterJobId property for start listening. Dispose Listener after Job Completion for unsubscribe from Infrascale Service callbacks.
Examples
Run Online Backup using stored settings
using System;
using System.IO;
using System.Linq;
using System.Text;
using SOS.SDK.Contracts.DataContracts;
using SOS.SDK.Contracts.DataContracts.Enums;
using SOS.SDK.Contracts.DataContracts.Jobs;
using SOS.SDK.Contracts.DataContracts.Jobs.Recovery;
using SOS.SDK.Contracts.DataContracts.Requests;
using SOS.SDK.Contracts.DataContracts.Responses;
using SOS.SDK.Tools.Runners;

namespace SOS.SDK.Test.Examples.Recovery
{
    public class RecoveryExamples
    {
        private readonly string _testAccount = @"sdk.test@sosonlinebackup.com";
        private readonly string _testAccountPassword = @"qweqwe";
        private IInfrascaleClient _client;

        private readonly string _recoveryDestination = @"C:\Obrm.Sdk.TestRecovery\";

        private readonly TimeSpan _refreshRecoveryInfoTimeout = TimeSpan.FromMinutes(10);
        private readonly TimeSpan _recoveryTimeout = TimeSpan.FromMinutes(10);
        private IdentityContract _identity;

        public void SignIn()
        {
            if (_client == null)
            {
                _client = new InfrascaleClient();
                _client.Connect();
                _identity = null;
            }

            if (_identity == null)
            {
                var signInResponse = _client.SignIn(new SignInRequest
                {
                    Credentials = new CredentialsContract { Login = _testAccount, Password = _testAccountPassword }
                });

                _identity = signInResponse.Identity;

                _client.SubscribeCallback(new SubscribeCallbackRequest { Identity = _identity });
            }
        }

        private void RefreshRecoveryInfoWithListener()
        {
            using (var listener = _client.ListenRefreshRecoveryInfoJob(OnRefreshStarted, OnRefreshProgress, OnRefreshEvents, OnRefreshCompleted))
            {
                var session =
                    _client.RunRefreshRecoveryInfoJob(new RunRefreshRecoveryInfoJobRequest {Identity = _identity});
                listener.FilterJobId = session.JobId;
                listener.WaitForCompletion();
            }
        }

        private void OnRefreshStarted(RefreshRecoveryInfoJobSessionContract started)
        {
            Console.WriteLine("RefreshRecoveryInfo Job {0} is Started", started.JobId);
        }

        private void OnRefreshProgress(RefreshRecoveryInfoJobSessionContract progress)
        {
            Console.WriteLine("JobID: {0}", progress.JobId);
            Console.WriteLine("\tJob state: {0}", progress.State);
            Console.WriteLine("\tCompleted, %: {0}", progress.ProgressPercentage);
        }

        private void OnRefreshEvents(JobEventsContract events)
        {
            Console.WriteLine("JobID: {0}", events.JobId);
            Console.WriteLine("\tEvents:");

            foreach (var jobEventContract in events.Events)
            {
                Console.WriteLine("\t{0}: [{1}] {2}", jobEventContract.EventTime, jobEventContract.MessageType, jobEventContract.Message);
            }
        }

        private void OnRefreshCompleted(RefreshRecoveryInfoJobSessionContract completed)
        {
            Console.WriteLine("JobID: {0}", completed.JobId);
            Console.WriteLine("JobState: {0}", completed.State);
            if (completed.State == SessionStateContract.Failed)
            {
                Console.WriteLine("Error: {0}", completed.ErrorMessage);
            }
        }
    }
}
See Also