コード例 #1
0
ファイル: Utils.cs プロジェクト: wugelis/DDDTaiwan2020.Sample
        /// <summary>
        /// 建立 與 初始化 Create Command Handler for (CQRS)
        /// </summary>
        /// <param name="project"></param>
        /// <param name="currentFolder"></param>
        /// <param name="commandClassName"></param>
        /// <param name="dtoClassName"></param>
        public static void CreateCQRSCreateCommandClassFromSource(Project project, ProjectItem currentFolder, string commandClassName, string dtoClassName)
        {
            Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();

            SQLStore      store       = new SQLStore();
            StringBuilder sb          = new StringBuilder();
            int           columnOrder = 0;

            string commandHandlerDefined = CreateCommandDef.GetClassTemplate;

            commandHandlerDefined = commandHandlerDefined.Replace("$(NAMESPACE_DEF)$", string.Format("{0}", project.Name));
            commandHandlerDefined = commandHandlerDefined.Replace("$(CREATE_COMMAND_NAME)$", commandClassName);

            ClassDef.GetClassProperties(store.GetNoDataDataTableByName(dtoClassName), new string[] { }, sb, columnOrder);
            commandHandlerDefined = commandHandlerDefined.Replace("$(CLASS_PROPERTIES_DEF)$", sb.ToString());

            string CommandHandlerFileName = $"Create{commandClassName}Command.cs";

            //產生 CQRS Create Command 檔案,並先暫放在 Temp 資料夾下.
            string TempPath = AddFile2ProjectItem(currentFolder, commandHandlerDefined, CommandHandlerFileName);

            //刪除掉暫存檔案
            try
            {
                File.Delete(TempPath);
            }
            catch (Exception ex) { } //刪除暫存檔案若失敗不處理任何訊息.
        }