Click or drag to resize

IInfrascaleSdkListenerListenRecoveryJob Method

Create an instance of the RecoveryAggregatedListener for listen all Recovery Job callbacks.

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

Parameters

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

Return Value

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

Return Value

Type: RecoveryAggregatedListener
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 });
            }
        }

        public void RecoveryOfCurrentSystemWithListener()
        {
            SignIn();

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

            RefreshRecoveryInfoWithRunner();

            using (var listener = _client.ListenRecoveryJob(OnStarted, OnProgress, OnEvents, OnCompleted))
            {
                var session = _client.RunRecoveryJob(new RunRecoveryJobRequest
                {
                    Identity = _identity,
                    Items = new RecoveryItemContract[]
                    {
                        new RecoveryDirectoryContract
                        {
                            Path = Environment.MachineName
                        }
                    },
                    ConflictResolution = ConflictResolutionContract.Override,
                    IncludePath = true,
                    RestoreDestination = _recoveryDestination
                });

                listener.FilterJobId = session.JobId;

                listener.WaitForCompletion();
            }

            //Detach client
            SignOut();
        }

        private void OnStarted(RecoveryJobSessionContract started)
        {
            Console.WriteLine("Recovery Job {0} is Started", started.JobId);
        }

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

            Console.WriteLine("\tRecoverySet Total: {0}", CountAndSizeToString(progress.Progress.Total));
            Console.WriteLine("\tFailed:          {0}", CountAndSizeToString(progress.Progress.Failed));
            Console.WriteLine("\tInProgress:        {0}", CountAndSizeToString(progress.Progress.InProgress));
            Console.WriteLine("\tCompleted:       {0}", CountAndSizeToString(progress.Progress.Completed));
        }

        private void OnEvents(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 OnCompleted(RecoveryJobSessionContract completed)
        {
            Console.WriteLine("JobID: {0}", completed.JobId);
            Console.WriteLine("\tRecovery of {0} file(s) is completed.", completed.Progress.Total.Count);
            Console.WriteLine("JobState: {0}", completed.State);
            if (completed.State == SessionStateContract.Failed)
            {
                Console.WriteLine("Error: {0}", completed.ErrorMessage);
            }
        }

        private string CountAndSizeToString(CountAndSizeContract countAndSize)
        {
            return string.Format("{0} ({1} bytes)", countAndSize.Count, countAndSize.SizeBytes);
        }
    }
}
See Also