Ejemplo n.º 1
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");
        }
Ejemplo n.º 2
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);
     }
 }
Ejemplo n.º 3
0
 private static extern IntPtr VssClientInit(VssSnapshot.Type type);
Ejemplo n.º 4
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");
        }