| IInfrascaleSdkSubscribeCallback Method |
Allows to receive notification about events are occurred in scope of specific backup account.
Namespace:
SOS.SDK.Contracts
Assembly:
SOS.SDK (in SOS.SDK.dll) Version: 7.6.1.5742
Syntax Exceptions Remarks
It's safe to make this request multiple times. You can make them before starting each Job.
You subscribe to all Infrascale Service events.
Examples Starting Online Backup Job, receive Backup Job callbacks and Unsubscribe after completion
using System;
using System.Diagnostics;
using System.Security.Principal;
using SOS.SDK.Contracts.DataContracts;
using SOS.SDK.Contracts.DataContracts.Jobs;
using SOS.SDK.Contracts.DataContracts.Jobs.Backup;
using SOS.SDK.Contracts.DataContracts.Requests;
using SOS.SDK.Tools.Creators;
using SOS.SDK.Tools.Runners;
namespace SOS.SDK.Test.Examples.OnlineBackup
{
public class RunOnlineBackupExamples
{
private string _testAccount = @"sdk.test@sosonlinebackup.com";
private string _testAccountPassword = @"qweqwe";
private InfrascaleClient _client;
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 RunBackupWithMonitoringAndUsingRawContractsAndUseStoredSettings()
{
SignIn();
_client.SubscribeCallback(new SubscribeCallbackRequest {Identity = _identity});
using (var listener = _client.ListenOnlineBackupJob(
OnStarted, OnProgress,
OnEvents, OnCompleted))
{
var currentProcessName = Process.GetCurrentProcess().ProcessName;
string currentUserName;
using (var windowsIdentity = WindowsIdentity.GetCurrent())
{
currentUserName = windowsIdentity.Name;
}
var session = _client.RunOnlineBackupJob(new RunOnlineBackupJobRequest
{
Identity = _identity,
CallingProcessName = currentProcessName,
WindowsUser = currentUserName
});
listener.FilterJobId = session.JobId;
listener.WaitForCompletion();
}
_client.UnsubscribeCallback(new UnsubscribeCallbackRequest {Identity = _identity});
SignOut();
}
private void OnStarted(OnlineBackupJobSessionContract started)
{
Console.WriteLine("Backup Job {0} is Started", started.JobId);
}
private void OnProgress(OnlineBackupJobSessionContract progress)
{
Console.WriteLine("JobID: {0}", progress.JobId);
Console.WriteLine("\tJob state: {0}", progress.BackupState);
Console.WriteLine("\tCompleted, %: {0}", progress.ProgressPercentage);
Console.WriteLine("\tBackupSet Total: {0}", CountAndSizeToString(progress.Progress.BackupSet));
Console.WriteLine("\tFailed: {0}", CountAndSizeToString(progress.Progress.Failed));
Console.WriteLine("\tModified: {0}", CountAndSizeToString(progress.Progress.Modified));
Console.WriteLine("\tProcessed: {0}", CountAndSizeToString(progress.Progress.Total));
Console.WriteLine("\tUnchanged: {0}", CountAndSizeToString(progress.Progress.Unchanged));
Console.WriteLine("\tUploaded: {0}", CountAndSizeToString(progress.Progress.Uploaded));
foreach (var progressFileState in progress.Progress.FileStates)
{
Console.WriteLine("\t{0}: {1} ({2} / {3})", progressFileState.Name, progressFileState.Status, progressFileState.CompletedSizeBytes, progressFileState.TotalSizeBytes);
}
}
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(OnlineBackupJobSessionContract completed)
{
Console.WriteLine("JobID: {0}", completed.JobId);
Console.WriteLine("\tBackup of {0} file(s) is completed.", completed.Progress.Total.Count);
}
private string CountAndSizeToString(CountAndSizeContract countAndSize)
{
return string.Format("{0} ({1} bytes)", countAndSize.Count, countAndSize.SizeBytes);
}
}
}
See Also