コード例 #1
0
        /// <summary>
        /// スクリプトファイル名を変更する。
        /// </summary>
        /// <param name="parameters">パラメータ。</param>
        private void RenameScriptFileName(KeyValueMap parameters)
        {
            ScriptDefinition definition = parameters["Definition"];

            using (var dialog = new SaveFileDialog())
            {
                dialog.InitialDirectory = Project.ScriptFolderFullPath;
                dialog.FileName = definition.FileName;
                dialog.Filter = ApplicationConstants.ScriptFileFilterString;
                dialog.OverwritePrompt = false;
                dialog.Title = "ファイル名の変更";

                if (dialog.ShowDialog(MainForm) != DialogResult.OK) return;

                var validator = new ScriptDefinitionValidator(Message, Project, definition);
                ProvidedMessage result;
                string newPath = null;

                result = validator.ValidateFileFullPath(dialog.FileName, ref newPath);
                if (result != null)
                {
                    InvokeMessage(result);

                    return;
                }

                if (definition.FileName.ToLower() == newPath.ToLower()) return;

                result = validator.ValidateFileName(newPath);
                if (result != null)
                {
                    InvokeMessage(result);

                    return;
                }

                try
                {
                    File.Move(Project.GetScriptFullPath(definition.FileName), Project.GetScriptFullPath(newPath));
                }
                catch (Exception ex)
                {
                    ProvideMessage("Default.Exception.Error", "スクリプトファイルのリネーム", ex.Message);

                    return;
                }

                definition.FileName = newPath;

                RefreshSelectedNodeProperty();

                if (!SaveProject()) return;

                RefreshObjectDefinition();
            }
        }
コード例 #2
0
        /// <summary>
        /// スクリプトプロパティ変更時処理。
        /// </summary>
        /// <param name="parameters">パラメータ。</param>
        private void ChangeScriptProperty(KeyValueMap parameters)
        {
            ScriptDefinition definition = parameters["Definition"];
            String name = parameters["Name"];
            dynamic value = parameters["Value"];
            dynamic oldValue = parameters["oldValue"];

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

            switch (name)
            {
                case "Name":
                    definition.DisplayName = value;

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

                        return;
                    }

                    try
                    {
                        File.Move(Project.GetScriptFullPath(definition.FileName), Project.GetScriptFullPath(value));
                    }
                    catch (Exception ex)
                    {
                        ProvideMessage("Default.Exception.Error", "スクリプトファイルのリネーム", ex.Message);

                        return;
                    }

                    definition.FileName = value;

                    break;
                default:
                    throw new NotImplementedException();
            }

            if (!SaveProject()) return;
            RefreshScriptNode(definition);
        }
コード例 #3
0
        /// <summary>
        /// スクリプト定義を作成する。
        /// </summary>
        /// <param name="parameters">パラメータ。</param>
        private void CreateScriptDefinition(KeyValueMap parameters)
        {
            ScriptDefinition definition = parameters["Definition"];

            using (var dialog = new SaveFileDialog())
            {
                dialog.InitialDirectory = Project.ScriptFolderFullPath;
                dialog.Filter = ApplicationConstants.ScriptFileFilterString;
                dialog.OverwritePrompt = false;

                if (dialog.ShowDialog(MainForm) != DialogResult.OK) return;

                var validator = new ScriptDefinitionValidator(Message, Project, definition);
                ProvidedMessage result;
                string newPath = null;

                result = validator.ValidateFileFullPath(dialog.FileName, ref newPath);
                if (result != null)
                {
                    InvokeMessage(result);

                    return;
                }

                result = validator.ValidateFileName(newPath);
                if (result != null)
                {
                    InvokeMessage(result);

                    return;
                }

                var newDefinition = new ScriptDefinition()
                {
                    FileName = newPath,
                    DisplayName = ApplicationConstants.DefaultScriptName,
                    Guid = Project.NewScriptGuid()
                };

                if (definition == null)
                {
                    Project.ScriptDefinitions.Add(newDefinition);
                    RefreshScriptNode(newDefinition);
                }
                else
                {
                    definition.Children.Add(newDefinition);
                    RefreshScriptNode(definition);
                }

                if (!SaveProject()) return;

                if (!File.Exists(Project.GetScriptFullPath(newDefinition.FileName)))
                {
                    try
                    {
                        using (var fs = File.Create(Project.GetScriptFullPath(newDefinition.FileName))) { }
                    }
                    catch (Exception ex)
                    {
                        ProvideMessage("Default.Exception.Error", "スクリプトファイルの作成", ex.Message);

                        return;
                    }
                }

                RefreshObjectDefinition();

                RegisterScriptEditor(newDefinition);
            }
        }