コード例 #1
0
        public void AddMessage(LogMessage message)
        {
            Dispatcher UIDispatcher = VMModel.GetInstance().UIDispatcher;

            UIDispatcher.Invoke(
                new Action <LogMessage> (
                    delegate(LogMessage m)
            {
                VMLog.GetInstance().Add(m);
            }),
                message);
        }
コード例 #2
0
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     if (value is VM)
     {
         VMDetailsViewModel viewModel = new VMDetailsViewModel(value as VM);
         return(viewModel.View);
     }
     else if (value is VMGroup)
     {
         VMListViewModel viewModel = new VMListViewModel(VMModel.GetInstance());
         return(viewModel.View);
     }
     return(null);
 }
コード例 #3
0
 public VMTreeViewModel(VMModel vmModel)
 {
     this.vmModel = vmModel;
     this.View    = new VMTreeView();
     vmGroups     = new ObservableCollection <VMGroup>();
     vmGroups.Add(vmModel.RootVMGroup);
     VMGroupCreate     = new DelegateCommand <object>(CreateVMGroup, CanCreateVMGroup);
     VMGroupRemove     = new DelegateCommand <object>(RemoveVMGroup, CanRemoveVMGroup);
     RenameTreeNode    = new DelegateCommand <object>(RenameNode, CanRenameNode);
     CanExecuteRaisers = new List <Action> {
         vmGroupCreate.RaiseCanExecuteChanged,
         vmGroupRemove.RaiseCanExecuteChanged,
         renameTreeNode.RaiseCanExecuteChanged
     };
     this.vmModel.ActiveVMGroupChanged +=
         (o, e) =>
     {
         this.ActiveVMGroup = this.vmModel.ActiveVMGroup;
     };
     View.SetViewModel(this);
     this.GroupCommandsView = new TreeCommandsView();
     this.GroupCommandsView.SetViewModel(this);
 }
コード例 #4
0
        public VMDetailsViewModel(VM vm) : base(vm)
        {
            view            = new VMDetailsView();
            this.vmModel    = VMModel.GetInstance();
            this.IsActiveVM = true;
            //lock (vmModel.ActiveVMList)
            //{
            //    vmModel.ActiveVMList.Clear();
            //    vmModel.ActiveVMList.Add(this.VirtualMachine);
            //}

            VMName         = this.VirtualMachine.Name;
            vmstatusString = this.VirtualMachine.StatusString;
            VMDomainName   = this.VirtualMachine.GetDomainName();
            GuestOS guestOS = this.VirtualMachine.GetGuestOS();

            if (guestOS == null)
            {
                guestOS = new GuestOS(string.Empty, string.Empty, string.Empty, string.Empty);
            }
            OSName      = guestOS.OSName;
            OSVersion   = guestOS.OSVersion;
            CSDVersion  = guestOS.CSDVersion;
            IPv4Address = guestOS.IPv4Address;
            VMSnapshot snapshotTree = this.VirtualMachine.SnapshotTree;

            if (snapshotTree != null)
            {
                VMSnapshots = new VMSnapshotViewModel[] { new VMSnapshotViewModel(snapshotTree, this.VirtualMachine, vmModel) };
            }
            else
            {
                VMSnapshots = new  VMSnapshotViewModel [] {};
            }

            foreach (VMSnapshotViewModel snapshotVM in VMSnapshots)
            {
                snapshotVM.Selected +=
                    (o, e) =>
                {
                    this.SelectedSnapshotItem = snapshotVM.SnapshotInstance;
                };
            }


            this.VirtualMachine.VMSnapshotsChanged +=
                (o, e) =>
            {
                snapshotTree = this.VirtualMachine.SnapshotTree;
                if (snapshotTree != null)
                {
                    VMSnapshots = new VMSnapshotViewModel[] { new VMSnapshotViewModel(snapshotTree, this.VirtualMachine, vmModel) };
                }
            };
            ThreadStart backgroundThreadStart = new ThreadStart(() =>
            {
                while (true)
                {
                    GCHandle pinnedArray = GCHandle.Alloc(this.VirtualMachine.MediumThumbnailImage, GCHandleType.Pinned);
                    IntPtr ptr           = pinnedArray.AddrOfPinnedObject();
                    Bitmap BI            = new Bitmap(160, 120, 320, System.Drawing.Imaging.PixelFormat.Format16bppRgb565, ptr);
                    MemoryStream st      = new MemoryStream();
                    BI.Save(st, System.Drawing.Imaging.ImageFormat.Bmp);
                    BitmapImage bmp = new BitmapImage();
                    bmp.BeginInit();
                    bmp.StreamSource = new MemoryStream(st.ToArray());
                    bmp.EndInit();
                    bmp.Freeze();
                    ThumbnailImage = bmp;
                    Thread.Sleep(2000);
                    pinnedArray.Free();
                }
            });

            if ((this.VirtualMachine.Status != VMState.Unknown) && (this.VirtualMachine.Status != VMState.Disabled))
            {
                BackgroundThread = new Thread(backgroundThreadStart);
                BackgroundThread.IsBackground = true;
                BackgroundThread.Priority     = ThreadPriority.Lowest;
                BackgroundThread.Start();
            }

            this.VirtualMachine.VMStatusChanged +=
                (o, e) =>
            {
                this.VMName         = this.VirtualMachine.Name;
                this.VMStatusString = this.VirtualMachine.GetStatusString();
                this.VMDomainName   = this.VirtualMachine.GetDomainName();
                guestOS             = this.VirtualMachine.GetGuestOS();
                if (guestOS == null)
                {
                    guestOS = new GuestOS(string.Empty, string.Empty, string.Empty, string.Empty);
                }
                OSName      = guestOS.OSName;
                OSVersion   = guestOS.OSVersion;
                CSDVersion  = guestOS.CSDVersion;
                IPv4Address = guestOS.IPv4Address;
                if ((this.VirtualMachine.Status != VMState.Unknown) && (this.VirtualMachine.Status != VMState.Disabled))
                {
                    if (BackgroundThread != null)
                    {
                        if (!BackgroundThread.IsAlive)
                        {
                            BackgroundThread = new Thread(backgroundThreadStart);
                            BackgroundThread.IsBackground = true;
                            BackgroundThread.Priority     = ThreadPriority.Lowest;
                            BackgroundThread.Start();
                        }
                    }
                    else
                    {
                        BackgroundThread = new Thread(backgroundThreadStart);
                        BackgroundThread.IsBackground = true;
                        BackgroundThread.Priority     = ThreadPriority.Lowest;
                        BackgroundThread.Start();
                    }
                }
                else
                {
                    if (BackgroundThread != null)
                    {
                        BackgroundThread.Abort();
                        BackgroundThread.Join(10);
                    }
                }
            };
            view.SetViewModel(this);
        }