コード例 #1
0
		/// <ToBeCompleted></ToBeCompleted>
		public void SetPropertyValue(object obj, string propertyName, object oldValue, object newValue) {
			try {
				try {
					AssertProjectExists();
					// ToDo: 
					// If the objects are not of the same type but of the same base type (or interface), this method will fail.
					// So we have to get the common base type/interface in this case.
					if (propertySetBuffer != null
						&& propertySetBuffer.Objects.Count > 0
						&& !IsOfType(obj.GetType(), propertySetBuffer.ObjectType))
						throw new InvalidOperationException("Another transaction is pending.");
					if (propertySetBuffer == null) {
						PropertyInfo propertyInfo = obj.GetType().GetProperty(propertyName);
						if (obj is Shape)
							propertySetBuffer = new PropertySetInfo<Shape>(propertyInfo, newValue);
						else if (obj is IModelObject)
							propertySetBuffer = new PropertySetInfo<IModelObject>(propertyInfo, newValue);
						else if (obj is Diagram)
							propertySetBuffer = new PropertySetInfo<Diagram>(propertyInfo, newValue);
						else if (obj is Layer)
							propertySetBuffer = new PropertySetInfo<Layer>(propertyInfo, newValue);
						else if (obj is Design)
							propertySetBuffer = new PropertySetInfo<Design>(propertyInfo, newValue);
						else if (obj is Style)
							propertySetBuffer = new PropertySetInfo<Style>(propertyInfo, newValue);
						else throw new NotSupportedException();
					}
					propertySetBuffer.Objects.Add(obj);
					propertySetBuffer.OldValues.Add(oldValue);

					// If all properties are set, commit changes.
					if (selectedPrimaryObjects.Contains(obj)
						&& propertySetBuffer.Objects.Count == selectedPrimaryObjects.Count)
						CommitSetProperty();
					else if (selectedSecondaryObjects.Contains(obj)
						&& propertySetBuffer.Objects.Count == selectedSecondaryObjects.Count)
						CommitSetProperty();
				} catch (TargetInvocationException exc) {
					if (exc.InnerException != null)
						throw exc.InnerException;
				}
			} catch (Exception) {
				CancelSetProperty();
				throw;
			}
		}
コード例 #2
0
 /// <ToBeCompleted></ToBeCompleted>
 public void CancelSetProperty()
 {
     AssertProjectExists();
     // Discard buffer
     propertySetBuffer = null;
 }
コード例 #3
0
        /// <ToBeCompleted></ToBeCompleted>
        public void CommitSetProperty()
        {
            AssertProjectExists();
            if (propertySetBuffer != null) {
                ICommand command = null;
                if (propertySetBuffer.Objects.Count != 0) {
                    if (IsOfType(propertySetBuffer.ObjectType, typeof(Shape))) {
                        command = new ShapePropertySetCommand(
                            ConvertEnumerator<Shape>.Create(propertySetBuffer.Objects),
                            propertySetBuffer.PropertyInfo,
                            propertySetBuffer.OldValues,
                            propertySetBuffer.NewValue);
                    } else if (IsOfType(propertySetBuffer.ObjectType, typeof(IModelObject))) {
                        command = new ModelObjectPropertySetCommand(
                            ConvertEnumerator<IModelObject>.Create(propertySetBuffer.Objects),
                            propertySetBuffer.PropertyInfo,
                            propertySetBuffer.OldValues,
                            propertySetBuffer.NewValue);
                    } else if (IsOfType(propertySetBuffer.ObjectType, typeof(Diagram))) {
                        command = new DiagramPropertySetCommand(
                            ConvertEnumerator<Diagram>.Create(propertySetBuffer.Objects),
                            propertySetBuffer.PropertyInfo,
                            propertySetBuffer.OldValues,
                            propertySetBuffer.NewValue);
                    } else if (IsOfType(propertySetBuffer.ObjectType, typeof(Layer))) {
                        Diagram diagram = null;
                        foreach (Diagram d in project.Repository.GetDiagrams()) {
                            foreach (Layer l in ConvertEnumerator<Layer>.Create(propertySetBuffer.Objects)) {
                                if (d.Layers.Contains(l)) {
                                    diagram = d;
                                    break;
                                }
                                if (diagram != null) break;
                            }
                        }
                        command = new LayerPropertySetCommand(
                            diagram,
                            ConvertEnumerator<Layer>.Create(propertySetBuffer.Objects),
                            propertySetBuffer.PropertyInfo,
                            propertySetBuffer.OldValues,
                            propertySetBuffer.NewValue);
                    } else if (IsOfType(propertySetBuffer.ObjectType, typeof(Design))) {
                        command = new DesignPropertySetCommand(
                            ConvertEnumerator<Design>.Create(propertySetBuffer.Objects),
                            propertySetBuffer.PropertyInfo,
                            propertySetBuffer.OldValues,
                            propertySetBuffer.NewValue);
                    } else if (IsOfType(propertySetBuffer.ObjectType, typeof(Style))) {
                        Design design = null;
                        if (project.Repository != null) {
                            foreach (Design d in project.Repository.GetDesigns()) {
                                foreach (Style s in ConvertEnumerator<Style>.Create(propertySetBuffer.Objects)) {
                                    if (d.ContainsStyle(s)) {
                                        design = d;
                                        break;
                                    }
                                }
                                if (design != null) break;
                            }
                        } else design = project.Design;
                        if (design != null) {
                            command = new StylePropertySetCommand(
                                design,
                                ConvertEnumerator<Style>.Create(propertySetBuffer.Objects),
                                propertySetBuffer.PropertyInfo,
                                propertySetBuffer.OldValues,
                                propertySetBuffer.NewValue);
                        }
                    } else throw new NotSupportedException();
                }

                if (command != null) {
                    // Check if command execution is allowed
                    Exception exc = command.CheckAllowed(Project.SecurityManager);
                    if (exc != null) throw exc;
                    //
                    if (updateRepository) Project.ExecuteCommand(command);
                    else command.Execute();
                    if (PropertyChanged != null) {
                        int pageIndex;
                        Hashtable selectedObjectsList;
                        GetSelectedObjectList(propertySetBuffer.Objects, out pageIndex, out selectedObjectsList);
                        if (pageIndex >= 0) {
                            PropertyControllerPropertyChangedEventArgs e = new PropertyControllerPropertyChangedEventArgs(
                                pageIndex,
                                propertySetBuffer.Objects,
                                propertySetBuffer.PropertyInfo,
                                propertySetBuffer.OldValues,
                                propertySetBuffer.NewValue);
                            PropertyChanged(this, e);
                        }
                    }
                } else
                    CancelSetProperty();
            }
            propertySetBuffer = null;
        }
コード例 #4
0
ファイル: PropertyController.cs プロジェクト: robness/Vixen
        /// <ToBeCompleted></ToBeCompleted>
        public void SetPropertyValue(object obj, string propertyName, object oldValue, object newValue)
        {
            try {
                try {
                    AssertProjectExists();
                    // ToDo:
                    // If the objects are not of the same type but of the same base type (or interface), this method will fail.
                    // So we have to get the common base type/interface in this case.
                    if (propertySetBuffer != null &&
                        propertySetBuffer.Objects.Count > 0 &&
                        !IsOfType(obj.GetType(), propertySetBuffer.ObjectType))
                    {
                        throw new InvalidOperationException("Another transaction is pending.");
                    }
                    if (propertySetBuffer == null)
                    {
                        PropertyInfo propertyInfo = obj.GetType().GetProperty(propertyName);
                        if (obj is Shape)
                        {
                            propertySetBuffer = new PropertySetInfo <Shape>(propertyInfo, newValue);
                        }
                        else if (obj is IModelObject)
                        {
                            propertySetBuffer = new PropertySetInfo <IModelObject>(propertyInfo, newValue);
                        }
                        else if (obj is Diagram)
                        {
                            propertySetBuffer = new PropertySetInfo <Diagram>(propertyInfo, newValue);
                        }
                        else if (obj is Layer)
                        {
                            propertySetBuffer = new PropertySetInfo <Layer>(propertyInfo, newValue);
                        }
                        else if (obj is Design)
                        {
                            propertySetBuffer = new PropertySetInfo <Design>(propertyInfo, newValue);
                        }
                        else if (obj is Style)
                        {
                            propertySetBuffer = new PropertySetInfo <Style>(propertyInfo, newValue);
                        }
                        else
                        {
                            throw new NotSupportedException();
                        }
                    }
                    propertySetBuffer.Objects.Add(obj);
                    propertySetBuffer.OldValues.Add(oldValue);

                    // If all properties are set, commit changes.
                    if (selectedPrimaryObjects.Contains(obj) &&
                        propertySetBuffer.Objects.Count == selectedPrimaryObjects.Count)
                    {
                        CommitSetProperty();
                    }
                    else if (selectedSecondaryObjects.Contains(obj) &&
                             propertySetBuffer.Objects.Count == selectedSecondaryObjects.Count)
                    {
                        CommitSetProperty();
                    }
                }
                catch (TargetInvocationException exc) {
                    if (exc.InnerException != null)
                    {
                        throw exc.InnerException;
                    }
                }
            }
            catch (Exception) {
                CancelSetProperty();
                throw;
            }
        }