Click or drag to resize

IInfrascaleSdkUnsubscribeCallback Method

Stops receiving 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
C#
UnsubscribeCallbackResponse UnsubscribeCallback(
	UnsubscribeCallbackRequest request
)

Parameters

request
Type: SOS.SDK.Contracts.DataContracts.RequestsUnsubscribeCallbackRequest
Container with request parameters.

Return Value

Type: UnsubscribeCallbackResponse
Operation execution results.
Exceptions
ExceptionCondition
NotSignedIn
MethodCallFailed
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();

            // It's safe to make this request multiple times.
            // You can call them before starting each Job.
            _client.SubscribeCallback(new SubscribeCallbackRequest {Identity = _identity});

            using (var listener = _client.ListenOnlineBackupJob(
                OnStarted, OnProgress,
                OnEvents, OnCompleted))
            {
                // Used by Infrascale Server for impersonation under required user permissions
                var currentProcessName = Process.GetCurrentProcess().ProcessName;

                // Used by Infrascale Server for impersonation under required user permissions
                string currentUserName;
                using (var windowsIdentity = WindowsIdentity.GetCurrent())
                {
                    currentUserName = windowsIdentity.Name;
                }

                // Starting Online Backup Job using stored backup settings
                var session = _client.RunOnlineBackupJob(new RunOnlineBackupJobRequest
                {
                    Identity = _identity,
                    CallingProcessName = currentProcessName,
                    WindowsUser = currentUserName
                });

                listener.FilterJobId = session.JobId;

                listener.WaitForCompletion();
            }

            // Note: this call unsubscribes you from all Infrascale Server callbacks, not just from current session events.
            // Don't call this method, if you want to receive other sessions callbacks.
            _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