Example #1
0
        private void RenderRepository(bool hasRepository, string domainEntityLabel)
        {
            var repositoryCode     = string.Empty;
            var repositoryAutoCode = string.Empty;

            if (hasRepository)
            {
                repositoryCode = @"

    /// <summary>
    /// $domainEntityLabel$ 仓库类。
    /// 负责 $domainEntityLabel$ 类的查询、保存。
    /// </summary>
    public partial class $domainEntityName$Repository : $domainBaseEntityName$Repository
    {
        /// <summary>
        /// 单例模式,外界不可以直接构造本对象。
        /// </summary>
        protected $domainEntityName$Repository() { }
    }"
                                 .Replace("$domainEntityLabel$", domainEntityLabel)
                                 .Replace("$domainEntityName$", _domainEntityName)
                                 .Replace("$domainBaseEntityName$", _domainBaseEntityName);

                repositoryAutoCode = ItemCodeTemplate.GetRepositoryCoreCode(_domainEntityName);
            }
            _replacementsDictionary.Add("$repositoryCode$", repositoryCode);
            _replacementsDictionary.Add("$repositoryAutoCode$", repositoryAutoCode);
        }
        public override void RunStarted(
            object automationObject,
            Dictionary <string, string> replacementsDictionary,
            WizardRunKind runKind, object[] customParams)
        {
            _replacementsDictionary = replacementsDictionary;

            base.RunStarted(automationObject, _replacementsDictionary, runKind, customParams);

            var repoNamespace = _replacementsDictionary["$rootnamespace$"];
            var dnsItems      = repoNamespace.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);

            var vm = new DomainEntityRepositoryWizardWindowViewModel();

            //如果文件的名称中没有以 Repository 结尾,则主动加上 Repository。
            var safeItemName = _replacementsDictionary["$safeitemname$"];

            if (safeItemName.EndsWith(Consts.RepositorySuffix))
            {
                vm.EntityTypeName = safeItemName.Substring(0, safeItemName.Length - Consts.RepositorySuffix.Length);
            }
            else
            {
                vm.EntityTypeName = safeItemName;
            }
            vm.BaseTypeName = dnsItems.Last() + Consts.EntityRepositorySuffix;
            vm.DTE          = automationObject as DTE;

            //显示向导窗口
            var win = new DomainEntityRepositoryWizardWindow();

            win.DataContext = vm;
            var res = win.ShowDialog();

            if (res != true)
            {
                _canceled = true;
                return;
            }

            //输出
            var repositoryAutoCode = ItemCodeTemplate.GetRepositoryCoreCode(vm.EntityTypeName);

            _replacementsDictionary.Add("$repositoryAutoCode$", repositoryAutoCode);
            _replacementsDictionary.Add("$domainNamespace$", vm.DomainNamespace);
            _replacementsDictionary.Add("$domainEntityName$", vm.EntityTypeName);
            _replacementsDictionary.Add("$baseRepositoryName$", vm.BaseTypeName);
        }