Click or drag to resize

IInfrascaleSdkGetRecoveryItems Method

Retrieves the list of folders and files available for recovery at specified Path. If Path is not specified returns a list of systems.

Namespace:  SOS.SDK.Contracts
Assembly:  SOS.SDK (in SOS.SDK.dll) Version: 7.6.1.5742
Syntax
C#
GetRecoveryItemsResponse GetRecoveryItems(
	GetRecoveryItemsRequest request
)

Parameters

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

Return Value

Type: GetRecoveryItemsResponse
Operation execution results.
Exceptions
ExceptionCondition
NotSignedIn
MethodCallFailed
Examples
Refreshing RecoveryInfo, getting and printing recovery items tree
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 ExtractAllRecoveryItemsTree()
        {
            //Init SDK
            SignIn();

            RefreshRecoveryInfoWithRunner();

            //Extract metadata items
            var request = new GetRecoveryItemsRequest
            {
                Identity = _identity,
                Path = Environment.MachineName
            };

            var output = _client.GetRecoveryItems(request);

            //Handle files tree
            PrintRecoveryItemsTree(output);

            //Detach client
            SignOut();
        }

        private void RefreshRecoveryInfoWithRunner()
        {
            var runner = new RefreshRecoveryInfoJobRunner(_client);
            runner.Run(_identity, _refreshRecoveryInfoTimeout);
        }

        private static void PrintRecoveryItemsTree(GetRecoveryItemsResponse response)
        {
            Action<RecoveryItemContract, int> handleLevel = null;
            handleLevel = (treeItem, level) =>
            {
                var padding = Enumerable.Range(0, level).Aggregate(new StringBuilder(), (sb, i) => sb.Append(" "));
                var dir = treeItem as RecoveryDirectoryContract;
                if (dir != null)
                {
                    foreach (var dirItem in dir.Children)
                    {
                        if (dirItem is RecoveryDirectoryContract)
                            Console.WriteLine(padding + dirItem.Path);
                        else
                            Console.WriteLine(padding + Path.GetFileName(dirItem.Path));
                        handleLevel(dirItem, level + 1);
                    }
                }
            };

            foreach (var item in response.Items)
            {
                Console.WriteLine(item.Path);
                handleLevel(item, 0);
            }
        }
    }
}
See Also