Click or drag to resize

IInfrascaleSdkListenerListenTStarted, TProgress, TEvents, TCompleted Method (ActionTStarted, ActionTProgress, ActionTEvents, ActionTCompleted)

Create an instance of the JobSessionAggregatedListenerBaseTStarted, TProgress, TEvents, TCompleted for listen all Job callbacks with specified callback types. Handles all callbacks. Use other specified Jobs related listeners, if you know real type of the listened Job.

Namespace:  SOS.SDK.Contracts
Assembly:  SOS.SDK (in SOS.SDK.dll) Version: 7.6.1.5742
Syntax
C#
JobSessionAggregatedListenerBase<TStarted, TProgress, TEvents, TCompleted> Listen<TStarted, TProgress, TEvents, TCompleted>(
	Action<TStarted> startedHandler = null,
	Action<TProgress> progressHandler = null,
	Action<TEvents> eventsHandler = null,
	Action<TCompleted> completedHandler = null
)
where TStarted : JobSessionContract
where TProgress : JobSessionContract
where TEvents : JobEventsContract
where TCompleted : JobSessionContract

Parameters

startedHandler (Optional)
Type: SystemActionTStarted
A delegate for handle JobStarted callbacks.
progressHandler (Optional)
Type: SystemActionTProgress
A delegate for handle JobProgress callbacks.
eventsHandler (Optional)
Type: SystemActionTEvents
A delegate for handle JobEvents callbacks.
completedHandler (Optional)
Type: SystemActionTCompleted
A delegate for handle JobCompleted callbacks.

Type Parameters

TStarted
Base type for JobStarted event data. All events with other message type ignored.
TProgress
Base type for JobProgress event data. All events with other message type ignored.
TEvents
Base type for JobEvents event data. All events with other message type ignored.
TCompleted
Base type for JobCompleted event data. All events with other message type ignored.

Return Value

Type: JobSessionAggregatedListenerBaseTStarted, TProgress, TEvents, TCompleted
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.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

Reference