IInfrascaleSdkListenerListenRefreshRecoveryInfoJob Method |
Namespace: SOS.SDK.Contracts
RefreshRecoveryAggregatedListener ListenRefreshRecoveryInfoJob( Action<RefreshRecoveryInfoJobSessionContract> startedHandler = null, Action<RefreshRecoveryInfoJobSessionContract> progressHandler = null, Action<JobEventsContract> eventsHandler = null, Action<RefreshRecoveryInfoJobSessionContract> 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 }); } } 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); } } } }