Exemple #1
0
 public void Initialize(bool isBackup, Stream topOfPipeline, IVirtualDevice device, IVirtualDeviceSet deviceSet)
 {
     mIsBackup      = isBackup;
     mTopOfPipeline = topOfPipeline;
     mDevice        = device;
     mDeviceSet     = deviceSet;
 }
Exemple #2
0
        protected virtual void Dispose(bool disposing)
        {
            if (!mDisposed)
            {
                if (disposing)
                {
                    // dispose of managed resources
                    if (mDevice != null)
                    {
                        mDevice = null;
                    }

                    mDeviceSet = null;

                    // the Program class will dispose of the streams

                    //if (mTopOfPipeline != null)
                    //{
                    //    mTopOfPipeline.Dispose();
                    //    mTopOfPipeline = null;
                    //}
                }

                // There are no unmanaged resources to release, but
                // if we add them, they need to be released here.
            }
            mDisposed = true;

            // If it is available, make the call to the
            // base class's Dispose(Boolean) method
            //base.Dispose(disposing);
        }
Exemple #3
0
        private static void BackupOrRestore(bool isBackup, ConfigPair storageConfig, ConfigPair databaseConfig, List <ConfigPair> pipelineConfig, IUpdateNotification updateNotifier)
        {
            string deviceSetName = Guid.NewGuid().ToString();

            IBackupStorage  storage      = storageConfig.TransformationType.GetConstructor(new Type[0]).Invoke(new object[0]) as IBackupStorage;
            IBackupDatabase databaseComp = databaseConfig.TransformationType.GetConstructor(new Type[0]).Invoke(new object[0]) as IBackupDatabase;


            try
            {
                int numDevices = storage.GetNumberOfDevices(storageConfig.Parameters);

                string instanceName       = databaseComp.GetInstanceName(databaseConfig.Parameters);
                string clusterNetworkName = databaseComp.GetClusterNetworkName(databaseConfig.Parameters);


                SqlPlatform sqlPlatform = VirtualBackupDeviceFactory.DiscoverSqlPlatform(instanceName,
                                                                                         clusterNetworkName);


                //NotifyWhenReady notifyWhenReady = new NotifyWhenReady(deviceName, isBackup);))
                using (IVirtualDeviceSet deviceSet = VirtualBackupDeviceFactory.NewVirtualDeviceSet(sqlPlatform))
                {
                    using (SqlThread sql = new SqlThread())
                    {
                        bool sqlStarted  = false;
                        bool sqlFinished = false;
                        ParallelExecutionException exceptions = new ParallelExecutionException();

                        try
                        {
                            IStreamNotification streamNotification = new InternalStreamNotification(updateNotifier);
                            long          estimatedTotalBytes;
                            List <string> deviceNames = sql.PreConnect(clusterNetworkName, instanceName, deviceSetName, numDevices, databaseComp, databaseConfig.Parameters, isBackup, updateNotifier, out estimatedTotalBytes);

                            using (DisposableList <Stream> fileStreams = new DisposableList <Stream>(isBackup ? storage.GetBackupWriter(storageConfig.Parameters) : storage.GetRestoreReader(storageConfig.Parameters, out estimatedTotalBytes)))
                                using (DisposableList <Stream> topOfPilelines = new DisposableList <Stream>(CreatePipeline(pipelineConfig, fileStreams, isBackup, streamNotification, estimatedTotalBytes)))
                                {
                                    VirtualDeviceSetConfig config = new VirtualDeviceSetConfig();
                                    config.Features    = FeatureSet.PipeLike;
                                    config.DeviceCount = (uint)topOfPilelines.Count;
                                    deviceSet.CreateEx(instanceName, deviceSetName, config);
                                    sql.BeginExecute();
                                    sqlStarted = true;
                                    deviceSet.GetConfiguration(TimeSpan.FromMinutes(1));
                                    List <IVirtualDevice> devices = new List <IVirtualDevice>();

                                    foreach (string devName in deviceNames)
                                    {
                                        devices.Add(deviceSet.OpenDevice(devName));
                                    }

                                    using (DisposableList <DeviceThread> threads = new DisposableList <DeviceThread>(devices.Count))
                                    {
                                        for (int i = 0; i < devices.Count; i++)
                                        {
                                            DeviceThread dThread = new DeviceThread();
                                            threads.Add(dThread);
                                            dThread.Initialize(isBackup, topOfPilelines[i], devices[i], deviceSet);
                                        }
                                        foreach (DeviceThread dThread in threads)
                                        {
                                            dThread.BeginCopy();
                                        }

                                        updateNotifier.OnStart();
                                        //Console.WriteLine(string.Format("{0} started", isBackup ? "Backup" : "Restore"));

                                        Exception sqlE = sql.EndExecute();
                                        sqlFinished = true;

                                        if (sqlE != null)
                                        {
                                            exceptions.Exceptions.Add(sqlE);
                                        }

                                        foreach (DeviceThread dThread in threads)
                                        {
                                            Exception devE = dThread.EndCopy();
                                            if (devE != null)
                                            {
                                                exceptions.Exceptions.Add(devE);
                                            }
                                        }
                                    }
                                }
                        }
                        catch (Exception e)
                        {
                            exceptions.Exceptions.Add(e);
                        }
                        finally
                        {
                            if (sqlStarted && !sqlFinished)
                            {
                                Exception sqlE = sql.EndExecute();
                                sqlFinished = true;
                                if (sqlE != null)
                                {
                                    exceptions.Exceptions.Add(sqlE);
                                }
                            }
                        }

                        if (exceptions.HasExceptions)
                        {
                            throw exceptions;
                        }
                    }
                }
            }
            catch
            {
                storage.CleanupOnAbort();
                throw;
            }
        }