IInfrascaleSdkListenerListenRecoveryJob Method |
Namespace: SOS.SDK.Contracts
RecoveryAggregatedListener ListenRecoveryJob( Action<RecoveryJobSessionContract> startedHandler = null, Action<RecoveryJobSessionContract> progressHandler = null, Action<JobEventsContract> eventsHandler = null, Action<RecoveryJobSessionContract> completedHandler = null )
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); } } }