private void OnOperationCompleted(OperationViewModel operationViewModel, ResourceViewModel resourceViewModel)
        {
            if ((operationViewModel.Type & OperationType.Detach) == OperationType.Detach
                || (operationViewModel.Type & OperationType.Start) == OperationType.Start
                || (operationViewModel.Type & OperationType.Stop) == OperationType.Stop
                || (operationViewModel.Type & OperationType.Reboot) == OperationType.Reboot
                || (operationViewModel.Type & OperationType.Update) == OperationType.Update)
            {
                this.UpdateResource(resourceViewModel, operationViewModel);
            }

            if ((operationViewModel.Type & OperationType.Detach) == OperationType.Detach
                || (operationViewModel.Type & OperationType.Create) == OperationType.Create)
            {
                dynamic operation = operationViewModel.Operation;

                if ((operationViewModel.Type & OperationType.Create) == OperationType.Create)
                {
                    if (operation is DiskOperation)
                    {
                        Disk disk = Service.Hosting.Fetch<Disk>(operation.DiskId);

                        this.AddResource(new DiskResource(disk), 20, 20);
                    }
                    else if (operation is InterfaceOperation)
                    {
                        Interface iface = Service.Hosting.Fetch<Interface>(operation.InterfaceId);

                        this.AddResource(new InterfaceResource(iface), 20, 20);
                    }
                    else if (operation is IpAddressOperation)
                    {
                    }
                    else if (operation is VirtualMachineOperation)
                    {
                        VirtualMachine virtualMachine = Service.Hosting.Fetch<VirtualMachine>(operation.VirtualMachineId.Value);

                        this.AddResource(new VirtualMachineResource(virtualMachine), 20, 20);
                    }
                }
                else if ((operationViewModel.Type & OperationType.Detach) == OperationType.Detach)
                {
                    if ((operationViewModel.Type & OperationType.Disk) == OperationType.Disk)
                    {
                        this.AddResource(new DiskResource(operation.Disk), 20, 20);
                    }
                    else if ((operationViewModel.Type & OperationType.Interface) == OperationType.Interface)
                    {
                        this.AddResource(new DiskResource(operation.Interface), 20, 20);
                    }
                }
            }
            else if ((operationViewModel.Type & OperationType.Attach) == OperationType.Attach
                || (operationViewModel.Type & OperationType.Delete) == OperationType.Delete)
            {
                this.RemoveResource(resourceViewModel);
            }
        }
 private void UpdateResource(ResourceViewModel resourceViewModel, OperationViewModel operationViewModel)
 {
     if (resourceViewModel.Type == ResourceType.Disk)
     {
         Disk disk = Service.Hosting.Fetch<Disk>(resourceViewModel.Id);
         resourceViewModel.Update(new DiskResource(disk));
     }
     else if (resourceViewModel.Type == ResourceType.Interface)
     {
         Interface iface = Service.Hosting.Fetch<Interface>(resourceViewModel.Id);
         resourceViewModel.Update(new InterfaceResource(iface));
     }
     else if (resourceViewModel.Type == ResourceType.VirtualMachine)
     {
         VirtualMachine virtualMachine = Service.Hosting.Fetch<VirtualMachine>(resourceViewModel.Id);
         resourceViewModel.Update(new VirtualMachineResource(virtualMachine));
     }
 }
        private void OnDetailAction(object sender, ResourceDetailActionEventArgs e)
        {
            if (e.Error)
            {
                this.ErrorMessage = e.ErrorMessage;
                this.DisplayError = true;
            }
            else
            {
                if (e.Operation != null)
                {
                    OperationViewModel operationViewModel = new OperationViewModel(e.Operation);

                    operationViewModel.Refreshed += delegate
                    {
                        ResourceViewModel resourceViewModel = (ResourceViewModel)sender;

                        if (operationViewModel.Step == OperationStep.Done)
                        {
                            this.OnOperationCompleted(operationViewModel, resourceViewModel);
                        }
                    };

                    this.OperationsViewModel.OperationViewModelCollection.Add(operationViewModel);
                }
            }
        }