Пример #1
0
 public VssSnapshot(VssSnapshot.Type type, List <string> volumes)
 {
     if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
     {
         throw new Exception("VssSnapshot must be initialised and used in a Single Thread Apartment");
     }
     this.type    = type;
     this.volumes = volumes;
     wmisession   = WmiBase.Singleton.GetXenStoreSession("Snapshot");
     client       = VssClientInit(type);
     if (client.Equals(IntPtr.Zero))
     {
         throw new VssSnapshotException();
     }
     foreach (string vol in volumes)
     {
         Debug.Print("Attempting to add" + vol);
         VssClientAddVolume(client, vol);
     }
 }
Пример #2
0
        void snapshotThreadHandler()
        {
            try
            {
                WmiBase.Singleton.DebugMsg("SnapshotThread");


                if (!typeKey.Exists())
                {
                    type = VssSnapshot.Type.VM;
                }
                else
                {
                    switch (typeKey.value)
                    {
                    case "volume":
                        type = VssSnapshot.Type.VOLUME;
                        break;

                    case "vm":
                    default:
                        type = VssSnapshot.Type.VM;
                        break;
                    }
                }

                List <String> volumeNames;

                if (type == VssSnapshot.Type.VM)
                {
                    volumeNames = ListXenVolumes();
                }
                else
                {
                    volumeNames = ListXenStoreVolumes();
                }

                using (VssSnapshot vss = new VssSnapshot(type, volumeNames))
                {
                    Debug.Print("Create snapshot");

                    vss.CreateSnapshotSet();

                    Debug.Print("Created snapshot");
                    statusKey.value = "snapshot-created";
                }
            }
            catch (VssSnapshotException vsse)
            {
                Debug.Print(vsse.ToString());
                try {
                    wmisession.GetXenStoreItem("control/snapshot/error/message").value = GetHresult(vsse.code);
                    wmisession.GetXenStoreItem("control/snapshot/error/code").value    = vsse.code.ToString();
                    wmisession.GetXenStoreItem("control/snapshot/error").value         = vsse.state;
                    statusKey.value = "snapshot-error";
                }
                catch {}
            }
            catch (Exception e)
            {
                Debug.Print(e.ToString());
                try {
                    wmisession.GetXenStoreItem("control/snapshot/error").value = "Unknown Error";
                    statusKey.value = "snapshot-error";
                }
                catch {}
            }

            Debug.Print("Snapshot done");
        }
Пример #3
0
 public VssSnapshot(VssSnapshot.Type type, List<string> volumes)
 {
     if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
     {
         throw new Exception("VssSnapshot must be initialised and used in a Single Thread Apartment");
     }
     this.type = type;
     this.volumes = volumes;
     wmisession = WmiBase.Singleton.GetXenStoreSession("Snapshot");
     client = VssClientInit(type);
     if (client.Equals(IntPtr.Zero))
     {
         throw new VssSnapshotException();
     }
     foreach (string vol in volumes)
     {
         Debug.Print("Attempting to add" + vol);
         VssClientAddVolume(client, vol);
     }
 }
Пример #4
0
 private extern static IntPtr VssClientInit(VssSnapshot.Type type);
Пример #5
0
        void snapshotThreadHandler()
        {
            try
            {
                WmiBase.Singleton.DebugMsg("SnapshotThread");

                if (!typeKey.Exists())
                {
                    type = VssSnapshot.Type.VM;
                }
                else
                {
                    switch (typeKey.value)
                    {
                        case "volume":
                            type = VssSnapshot.Type.VOLUME;
                            break;
                        case "vm":
                        default:
                            type = VssSnapshot.Type.VM;
                            break;
                    }
                }

                List<String> volumeNames;

                if (type == VssSnapshot.Type.VM)
                {
                    volumeNames = ListXenVolumes();
                }
                else
                {
                    volumeNames = ListXenStoreVolumes();
                }

                using (VssSnapshot vss = new VssSnapshot(type, volumeNames))
                {

                    Debug.Print("Create snapshot");

                    vss.CreateSnapshotSet();

                    Debug.Print("Created snapshot");
                    statusKey.value = "snapshot-created";
                }
            }
            catch (VssSnapshotException vsse)
            {
                Debug.Print(vsse.ToString());
                try {
                    wmisession.GetXenStoreItem("control/snapshot/error/message").value = GetHresult(vsse.code);
                    wmisession.GetXenStoreItem("control/snapshot/error/code").value = vsse.code.ToString();
                    wmisession.GetXenStoreItem("control/snapshot/error").value = vsse.state;
                    statusKey.value = "snapshot-error";
                }
                catch{}
            }
            catch (Exception e)
            {
                Debug.Print(e.ToString());
                try {
                    wmisession.GetXenStoreItem("control/snapshot/error").value = "Unknown Error";
                    statusKey.value = "snapshot-error";
                }
                catch {}
            }

            Debug.Print("Snapshot done");
        }