Example #1
0
        private void LoadForEdit()
        {
            try
            {
                IResourceAction resourceAction = AddActionState.GetResourcesForAction(m_resourceManager, InitialAction);
                string type = InitialAction[LanguageItemKeys.TYPE].Value;
				if ( (null == resourceAction) || (string.IsNullOrEmpty(type)) )
				{
					ShowEditActionNotInstalledMessageBox(InitialAction.Name.Value);
					ExitForm();
					return;
				}

				ActionObjectDefinition aoDef = new ActionObjectDefinition(type);
                aoDef.AssemblyName = InitialAction.Assembly;
                aoDef.ClassName = InitialAction.Class;
				aoDef.ActionName = InitialAction.Name.Value;
                aoDef.Precedence = InitialAction.Precedence;
                aoDef.RunAt = InitialAction.RunAt;
                //TODO: we shouldn't be reading from the resourceAction as this may have changed since the action was created.
                //However, Steve C says do it this way for now.
                aoDef.AllowTransparent =  m_allowTransparent && resourceAction.AllowTransparent;
                aoDef.PropertySetLayout = resourceAction.PropertySetLayout;
                aoDef.CustomDataTypeUIHandler = resourceAction.CustomDataTypeUI;

                bool updateCheckBoxAtStart = ActionHasSelectAllCheckBox(aoDef);
                bool resetValueSelectAll = true;
                bool resetOverrideSelectAll = true;
                bool resetVisibleSelectAll = true;

                foreach (IDataElement property in InitialAction.DataElements)
                {
                    // Supported File Types is added in as a property but we don't
                    // want to retrieve it here as one. The same applies to 'Transparent'
                    if (property.Name.Value == "SupportedFileTypes" ||
                        property.Name.Value == "NonSupportedFileTypes" ||
                        property.Name.Value == LanguageItemKeys.TRANSPARENT)
                        continue;

                    if (0 == string.Compare("EXECUTE", property.Name.Value, StringComparison.InvariantCultureIgnoreCase))
                    {
                        bool executePropValue = (bool)((IDataItem)property.Data).Value;
                        bool allowOverride = property["allowoverride"].Value.ToLower(CultureInfo.InvariantCulture) == "true";

                        if (allowOverride)
                        {
                            aoDef.ExecutionOption = executePropValue ? ExecutionOption.OverridableDefaultTrue : ExecutionOption.OverridableDefaultFalse;
                        }
                        else
                        {
                            aoDef.ExecutionOption = ExecutionOption.AlwaysExecute;
                        }
                        continue;
                    }

                    ActionDataElement ade = new ActionDataElement();
                   
                    ade.ShowInUI = ShowPropertyInUIForType(aoDef.Type, property.Name.Value);

                    if (property["icustomdatatypehandler"].Value.ToString() != "")
                    {
                        ade.IsCustomDisplayType = true;
                    }
                    if (property["allowoverride"].Value.ToLower(CultureInfo.InvariantCulture) == "true")
                    {
                        ade.Override = true;
                    }
                    else
                    {
                        ade.Override = false;
                        if (ade.ShowInUI)
                            resetOverrideSelectAll = false;
                    }

                    if (property["visible"].Value.ToLower(CultureInfo.InvariantCulture) == "true")
                    {
                        ade.Visible = true;
                    }
                    else
                    {
                        ade.Visible = false;
                        if (ade.ShowInUI)
                            resetVisibleSelectAll = false;
                    }

                    if (property["iscustomproperty"].Value.ToLower(CultureInfo.InvariantCulture) == "true")
                    {
                        ade.IsCustomProperty = true;
                    }


                    // If the property is a data source then it is assumed to be
                    // a system property
                    if (property.Data is IDataSource)
                    {
                        IDataSource dataSource = property.Data as IDataSource;
                        ade.IsSystemProperty = true;
                        ade.IsDataSource = true;
                        ISystemProperty systemProperty = ResourceManagerFactory.CreateSystemProperty(dataSource.Assembly,
                                                                            typeof(object),
                                                                            dataSource.Class,
                                                                            dataSource.Method.Name.Value,
                                                                            String.Empty // Description - not being populated yet
                                                                            );

                        ade.MappedSystemProperty = systemProperty;
                    }

                    switch (property.Type)
                    {
                        case DataType.String:
                            foreach (IResourceActionProperty rap in resourceAction.Properties)
                            {
                                if (rap.Name == property.Name.Value)
                                    ade.IsCustomDisplayType = rap.DisplayType == PropertyDisplayType.CustomUI;
                            }
                            ade.Value = ((IDataItem)property.Data).Value;
                            break;
                        case DataType.Boolean:
                            {
                                ade.Value = (bool)((IDataItem)property.Data).Value;
                                if ((bool)ade.Value == false && ade.ShowInUI)
                                    resetValueSelectAll = false;
                            }
                            break;
                        case DataType.DateTime:
                            {
                                ade.Value = (DateTime)((IDataItem)property.Data).Value;
                                break;
                            }
                        case DataType.Object:
                            ade.Value = property.Data;
                            break;
                        case DataType.StringArray:
                            ade.Value = ConversionUtils.PolicyObjectModelStringArrayToStringArray(property.Data as IPolicyObjectCollection<IDataItem>);
                            break;
                        default:
                            ShowUnsupportedTypeMessageBox();
                            throw new PolicyDesignerException("Unsupported data element type");
                    }
                    ade.Identifier = property.Identifier;
                    ade.Name = property.Name.Value;
                    ade.DisplayName = property.DisplayName.Value;
                    aoDef.ActionProperties[property.Identifier] = ade;
                }

                if (InitialAction.Filetypes.Count == 0)
                    AddBaseFileTypes(ref aoDef);
                else
                {
                    foreach (IActionFiletype ftype in InitialAction.Filetypes)
                    {
                        ActionFileTypeObject aft = new ActionFileTypeObject();
                        aft.Apply = ftype.Apply;
                        aft.Filetype = ftype.Type;
                        aft.Identifier = ftype.Identifier;
                        aoDef.FileTypes[FileTypeBridge.GetFileType(aft.Filetype)] = aft;
                    }
                }

				m_baseAction = aoDef.Type;
                m_actions[m_baseAction] = aoDef;
                
                comboBoxActions.Items.Add(new ActionUIItem(GetResourceActionForType(m_baseAction)));
                comboBoxActions.SelectedIndex = 0;

                InitMyNameControl(InitialAction.Name.Value);
                m_override = InitialAction.Override;
                
                Text = Properties.Resources.ACTION_EDIT;
                cbProcessTransparently.Checked = Transparent;
                //cbAutoExpand.Checked = AutoExpand;
                PopulateExecutionOptionControl();

                if (updateCheckBoxAtStart)
                {
                    SetSelectAllCheckBox(actionOptionsListView.Columns.IndexOf(columnValue), resetValueSelectAll);
                    SetSelectAllCheckBox(actionOptionsListView.Columns.IndexOf(columnOverride), resetOverrideSelectAll);
                    SetSelectAllCheckBox(actionOptionsListView.Columns.IndexOf(columnVisible), resetVisibleSelectAll);
                }
            }
            catch (PolicyDesignerException)
            {
                DialogResult = DialogResult.Cancel;
                Close();
            }
        }
Example #2
0
        private void LoadNewActionData(IResourceAction resourceAction)
        {
			ActionObjectDefinition aoDef = new ActionObjectDefinition(resourceAction.Name);
            aoDef.AssemblyName = resourceAction.Assembly;
            aoDef.ClassName = resourceAction.ActionClass;
            aoDef.Precedence = resourceAction.Sequence;
            aoDef.ActionName = resourceAction.Name;
            aoDef.AllowTransparent = m_allowTransparent && resourceAction.AllowTransparent;
            aoDef.PropertySetLayout = resourceAction.PropertySetLayout;
			
            if (aoDef.ActionName.Length == 0)
            {
                string[] strs = (resourceAction.Name).Split(new Char[] { '.' });
                aoDef.ActionName = strs[strs.Length - 1];
            }

            foreach (IResourceActionProperty resourceActionProperty in resourceAction.Properties)
            {
                try
                {
                    ActionDataElement ade = new ActionDataElement();
                    ade.Override = resourceActionProperty.Override; //false;
                    ade.Visible = resourceActionProperty.Visible; //true;
                    if (resourceActionProperty.MappedSystemProperty != null)
                    {
                        ade.IsDataSource = true;
                        ade.IsSystemProperty = true;
                        ade.MappedSystemProperty = resourceActionProperty.MappedSystemProperty;
                    }
                    else
                    {
                        ade.IsDataSource = false;
                        ade.IsSystemProperty = false;
                    }
                    ade.IsCustomProperty = resourceActionProperty.CustomProperty;
                    ade.Value = resourceActionProperty.Value;
                    ade.Name = resourceActionProperty.Name;
                    ade.DisplayName = resourceActionProperty.DefaultDisplayName;
                    ade.Identifier = Guid.NewGuid();
                    ade.ShowInUI = ShowPropertyInUIForType(resourceAction.Name, resourceActionProperty.Name);
                    ade.IsCustomDisplayType = resourceActionProperty.DisplayType == PropertyDisplayType.CustomUI;
                    aoDef.ActionProperties[ade.Identifier] = ade;
                    aoDef.AutoExpand = resourceAction.AutoExpand;
                    aoDef.CustomDataTypeUIHandler = resourceAction.CustomDataTypeUI;
                    aoDef.ExecutionOption = resourceAction.ExecutionOption;
                }
                catch (ArgumentException ex)
                {
					Logger.LogError(string.Format(CultureInfo.CurrentCulture, Properties.Resources.ACTION_UNSUPPORTED_ERROR, ex.Message));
					Logger.LogError(ex);
                    ShowUnsupportedTypeMessageBox();
                }
            }

            AddBaseFileTypes(ref aoDef);
            
            m_actions[aoDef.ActionName] = aoDef;
        }
Example #3
0
        public Control AddCustomUIHandlerButton(ActionDataElement ade, int col, int row)
        {
            if (!ade.IsCustomDisplayType)
                return null;

            ButtonWithValue c = null;
            c = new ButtonWithValue();
            c.Image = Properties.Resources.InvokeCustomDataUI;
            c.ImageAlign = ContentAlignment.MiddleCenter;
            c.Tag = ade;
            c.Value = ade.Value == null ? string.Empty : ade.Value.ToString();
            //c.Text = Properties.Resources.ACTION_CUSTOM_DATATYPE_BUTTON;
            //c.TextAlign = ContentAlignment.MiddleCenter;
            AddEmbeddedControl(c, col, row);
            return c;
        }