public static VirtualMachineSnapshot GetFromWmi(ManagementBaseObject objSnapshot)
        {
            if (objSnapshot == null || objSnapshot.Properties.Count == 0)
                return null;

            VirtualMachineSnapshot snapshot = new VirtualMachineSnapshot();
            snapshot.Id = (string)objSnapshot["InstanceID"];
            snapshot.Name = (string)objSnapshot["ElementName"];

            string parentId = (string)objSnapshot["Parent"];
            if (!String.IsNullOrEmpty(parentId))
            {
                int idx = parentId.IndexOf("Microsoft:");
                snapshot.ParentId = parentId.Substring(idx, parentId.Length - idx - 1);
                snapshot.ParentId = snapshot.ParentId.ToLower().Replace("microsoft:", "");
            }
            if (!String.IsNullOrEmpty(snapshot.Id))
            {
                snapshot.Id = snapshot.Id.ToLower().Replace("microsoft:", "");
            }
            snapshot.Created = Wmi.ToDateTime((string)objSnapshot["CreationTime"]);

            if (string.IsNullOrEmpty(snapshot.ParentId))
                snapshot.ParentId = null; // for capability

            return snapshot;
        }
Example #2
0
        public static VirtualMachineSnapshot GetFromWmi(ManagementBaseObject objSnapshot)
        {
            if (objSnapshot == null || objSnapshot.Properties.Count == 0)
            {
                return(null);
            }

            VirtualMachineSnapshot snapshot = new VirtualMachineSnapshot();

            snapshot.Id   = (string)objSnapshot["InstanceID"];
            snapshot.Name = (string)objSnapshot["ElementName"];

            string parentId = (string)objSnapshot["Parent"];

            if (!String.IsNullOrEmpty(parentId))
            {
                int idx = parentId.IndexOf("Microsoft:");
                snapshot.ParentId = parentId.Substring(idx, parentId.Length - idx - 1);
                snapshot.ParentId = snapshot.ParentId.ToLower().Replace("microsoft:", "");
            }
            if (!String.IsNullOrEmpty(snapshot.Id))
            {
                snapshot.Id = snapshot.Id.ToLower().Replace("microsoft:", "");
            }
            snapshot.Created = Wmi.ToDateTime((string)objSnapshot["CreationTime"]);

            if (string.IsNullOrEmpty(snapshot.ParentId))
            {
                snapshot.ParentId = null; // for capability
            }
            return(snapshot);
        }
        public static void Delete(PowerShellManager powerShell, VirtualMachineSnapshot snapshot, bool includeChilds)
        {
            Command cmd = new Command("Remove-VMSnapshot");
            cmd.Parameters.Add("VMName", snapshot.VMName);
            cmd.Parameters.Add("Name", snapshot.Name);
            if (includeChilds) cmd.Parameters.Add("IncludeAllChildSnapshots", true);

            powerShell.Execute(cmd, true);
        }
Example #4
0
        public static void Delete(PowerShellManager powerShell, VirtualMachineSnapshot snapshot, bool includeChilds)
        {
            Command cmd = new Command("Remove-VMSnapshot");

            cmd.Parameters.Add("VMName", snapshot.VMName);
            cmd.Parameters.Add("Name", snapshot.Name);
            if (includeChilds)
            {
                cmd.Parameters.Add("IncludeAllChildSnapshots", true);
            }

            powerShell.Execute(cmd, true);
        }
        public static VirtualMachineSnapshot GetFromPS(PSObject psObject, string runningSnapshotId = null)
        {
            var snapshot = new VirtualMachineSnapshot
            {
                Id = psObject.GetString("Id"),
                Name = psObject.GetString("Name"),
                VMName = psObject.GetString("VMName"),
                ParentId = psObject.GetString("ParentSnapshotId"),
                Created = psObject.GetProperty<DateTime>("CreationTime")
            };

            if (string.IsNullOrEmpty(snapshot.ParentId))
                snapshot.ParentId = null; // for capability

            if (!String.IsNullOrEmpty(runningSnapshotId))
                snapshot.IsCurrent = snapshot.Id == runningSnapshotId;

            return snapshot;
        }
Example #6
0
        public static VirtualMachineSnapshot GetFromPS(PSObject psObject, string runningSnapshotId = null)
        {
            var snapshot = new VirtualMachineSnapshot
            {
                Id       = psObject.GetString("Id"),
                Name     = psObject.GetString("Name"),
                VMName   = psObject.GetString("VMName"),
                ParentId = psObject.GetString("ParentSnapshotId"),
                Created  = psObject.GetProperty <DateTime>("CreationTime")
            };

            if (string.IsNullOrEmpty(snapshot.ParentId))
            {
                snapshot.ParentId = null; // for capability
            }
            if (!String.IsNullOrEmpty(runningSnapshotId))
            {
                snapshot.IsCurrent = snapshot.Id == runningSnapshotId;
            }

            return(snapshot);
        }
Example #7
0
        private VirtualMachineSnapshot CreateSnapshotFromWmiObject(ManagementBaseObject objSnapshot)
        {
            if (objSnapshot == null || objSnapshot.Properties.Count == 0)
                return null;

            VirtualMachineSnapshot snapshot = new VirtualMachineSnapshot();
            snapshot.Id = (string)objSnapshot["InstanceID"];
            snapshot.Name = (string)objSnapshot["ElementName"];

            string parentId = (string)objSnapshot["Parent"];
            if (!String.IsNullOrEmpty(parentId))
            {
                int idx = parentId.IndexOf("Microsoft:");
                snapshot.ParentId = parentId.Substring(idx, parentId.Length - idx - 1);
            }
            snapshot.Created = wmi.ToDateTime((string)objSnapshot["CreationTime"]);

            return snapshot;
        }
        private void AddChildNodes(TreeNodeCollection parent, string parentId, VirtualMachineSnapshot[] snapshots)
        {
            foreach (VirtualMachineSnapshot snapshot in snapshots)
            {
                if (snapshot.ParentId == parentId)
                {
                    // add node
                    TreeNode node = new TreeNode(snapshot.Name, snapshot.Id);
                    node.Expanded = true;
                    node.ImageUrl = PortalUtils.GetThemedImage("VPS2012/snapshot.png");
                    parent.Add(node);

                    // check if the current
                    if (snapshot.IsCurrent)
                    {
                        TreeNode nowNode = new TreeNode(GetLocalizedString("Now.Text"), "");
                        nowNode.ImageUrl = PortalUtils.GetThemedImage("VPS2012/start2.png");
                        nowNode.SelectAction = TreeNodeSelectAction.None;
                        node.ChildNodes.Add(nowNode);
                    }

                    // fill children
                    AddChildNodes(node.ChildNodes, snapshot.Id, snapshots);
                }
            }
        }