/// <summary>
        /// クラスプロパティ変更時処理。
        /// </summary>
        /// <param name="parameters">パラメータ。</param>
        private void ChangeClassProperty(KeyValueMap parameters)
        {
            ClassDefinition definition = parameters["Definition"];
            String name = parameters["Name"];
            dynamic value = parameters["Value"];
            dynamic oldValue = parameters["oldValue"];

            var validator = new ClassDefinitionValidator(Message, Project, definition);
            ProvidedMessage result;
            if (value != null) value = ((string)value).Trim();

            switch (name)
            {
                case "Name":
                    result = validator.ValidateName(value);
                    if (result != null)
                    {
                        InvokeMessage(result);

                        return;
                    }

                    result = validator.ValidateNameAndNamespace(definition.Namespace, value);
                    if (result != null)
                    {
                        InvokeMessage(result);

                        return;
                    }

                    definition.Name = value;

                    break;
                case "Namespace":
                    result = validator.ValidateNamespace(value);
                    if (result != null)
                    {
                        InvokeMessage(result);

                        return;
                    }

                    result = validator.ValidateNameAndNamespace(value, definition.Name);
                    if (result != null)
                    {
                        InvokeMessage(result);

                        return;
                    }

                    definition.Namespace = value;

                    break;
                default:
                    throw new NotImplementedException();
            }

            if (!SaveProject()) return;
            RefreshClassNode(definition);
        }
Пример #2
0
        /// <summary>
        /// 画面項目の入力チェックを行う。
        /// </summary>
        /// <returns>入力チェックOK時はtrue。</returns>
        private bool ValidateInput()
        {
            ctlName.Text = ctlName.Text.TrimEnd();
            ctlNamespace.Text = ctlNamespace.Text.TrimEnd();

            var message = GetMessageProvider();
            var validator = new ClassDefinitionValidator(message, Project, Definition);
            ProvidedMessage result;

            // クラス名
            result = validator.ValidateName(ctlName.Text);
            if (result != null)
            {
                ActiveControl = ctlName;
                InvokeMessage(result);

                return false;
            }

            // モジュール名
            result = validator.ValidateNamespace(ctlNamespace.Text);
            if (result != null)
            {
                ActiveControl = ctlNamespace;
                InvokeMessage(result);

                return false;
            }

            // モジュール名とクラス名のチェックを行う
            result = validator.ValidateNameAndNamespace(ctlNamespace.Text, ctlName.Text);
            if (result != null)
            {
                ActiveControl = ctlName;
                InvokeMessage(result);

                return false;
            }

            result = validator.ValidateExtends(
                ((ListItem)ctlExtends.SelectedItem).Text,
                ctlNamespace.Text,
                ctlName.Text
            );
            if (result != null)
            {
                ActiveControl = ctlExtends;
                InvokeMessage(result);

                return false;
            }

            // アクセサのチェック
            var accessorList = (DataTable)ctlAccessorList.DataSource;
            int rowCount = 0;

            // 全行のTrim実行
            foreach (DataRow row in accessorList.Rows)
            {
                foreach (var columnName in new string[] { "Name", "DisplayName", "ValueType" })
                {
                    if (!String.IsNullOrEmpty(row.Field<string>(columnName)))
                    {
                        row.SetField(columnName, row.Field<string>(columnName).TrimEnd());
                    }
                }
            }

            var definedAccessorNames = (
                from DataRow r in accessorList.Rows
                where !IsBlankAccessorRow(r)
                select r.Field<string>("Name")
            ).ToList();

            for (int i = 0; i < accessorList.Rows.Count; i++)
            {
                var row = accessorList.Rows[i];

                if (IsBlankAccessorRow(row)) continue;

                rowCount++;

                if (!ValidateAccessorRow(message, definedAccessorNames, row, i))
                {
                    ActiveControl = ctlAccessorList;

                    return false;
                }
            }

            // 一行も定義されていない場合はエラー
            if (rowCount == 0)
            {
                ActiveControl = ctlAccessorList;
                ProvideMessage("AccessorDefinition.Validation.Empty.Error");

                return false;
            }

            return true;
        }