예제 #1
0
        private DeviceGroupViewModel Copy(Guid pId)
        {
            var itemCopy = _deviceGroup.Clone() as DeviceGroup;

            if (itemCopy != null)
            {
                itemCopy.parentId      = pId;
                itemCopy.DeviceFactory = DeviceContext.Instance.DeviceFactories.Find(pId);
            }
            DeviceContext.Instance.DeviceGroups.AddOrUpdate(itemCopy);
            DeviceContext.Instance.SaveChanges();
            return(new DeviceGroupViewModel(itemCopy));
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="group"></param>
        private void PasteGroup(DeviceGroup group, DeviceGroupViewModel parentViewModel)
        {
            var vgg = mDocument.GetGroups(group);
            var ggg = group.Clone();

            DeviceGroup parent = (this.Parent is DeviceGroupViewModel) ? (Parent as DeviceGroupViewModel).Model : null;

            ggg.Name = Document.GetAvaiableGroupName(ggg.Name, parent != null ? parent.FullName : string.Empty);

            Document.AddDeviceGroup(parent, ggg);
            var vmodel = new DeviceGroupViewModel()
            {
                Model = ggg, Document = this.Document, Parent = parentViewModel
            };

            parentViewModel.Children.Add(vmodel);


            foreach (IDeviceDevelop vv in ggg.Devices.ToArray())
            {
                vv.Group = ggg.FullName;
                Document.AddDevice(vv);

                vmodel.Children.Add(new DeviceTreeViewModel()
                {
                    Model = vv, Document = this.Document, Parent = vmodel
                });

                var driver = (vv as DeviceDevelop).Driver;
                if (driver != null)
                {
                    var driverdoc = GetMachineViewModel(this).Model.Driver;
                    driverdoc?.AddDriver(driver);
                }
            }

            foreach (var vv in vgg)
            {
                PasteGroup(vv, vmodel);
            }
            parentViewModel.RefreshView();
        }