예제 #1
0
        private Mogami.Model.Category CreateOrSelectCategory(Mogami.Model.Category parentCategory, string categoryName, CategoryRepository repo)
        {
            Mogami.Model.Category category = null;
            foreach (var child in parentCategory.ChildCategories)
            {
                if (child.Name == categoryName)
                {
                    category = child;
                    break;
                }
            }

            // Create
            if (category == null)
            {
                category = new Mogami.Model.Category()
                {
                    Name             = categoryName,
                    CategoryTypeCode = Core.Constructions.CategoryType.APPLICATION,
                    ParentCategory   = parentCategory
                };
                repo.Add(category);
                _IsCreate = true;
            }

            return(category);
        }
예제 #2
0
        protected override void Execute(CodeActivityContext context)
        {
            IWorkflowContext workflowContext = context.GetExtension <IWorkflowContext>();
            ParameterStack   pstack          = context.GetValue <ParameterStack>(this.Parameter);

            string categoryPath = null;

            var target = pstack.GetValue <FileMappingInfo>(ActivityParameterStack.TARGET);

            if (target != null)
            {
                categoryPath = target.MappingFilePath;
            }
            else
            {
                categoryPath = pstack.GetValue <string>(ActivityParameterStack.MAKECATEGORY_CURRENT_CATEGORY);
            }

            if (string.IsNullOrEmpty(categoryPath))
            {
                throw new ApplicationException("有効なカテゴリパス文字列ではありません");
            }

            var catrepo = new CategoryRepository(workflowContext.DbContext);
            var appcat  = catrepo.Load(3L);

            if (appcat == null)
            {
                throw new ApplicationException();
            }
            _IsCreate = false;

            Mogami.Model.Category targetCategory = appcat;
            var tokens   = target.MappingFilePath.Split(new string[] { @"\" }, StringSplitOptions.None);
            var sttokens = new Stack <string>(tokens);
            var title    = sttokens.Pop();
            var qutokens = new Queue <string>(sttokens.Reverse <string>());

            while (qutokens.Count > 0)
            {
                var oneText = qutokens.Dequeue();
                targetCategory = CreateOrSelectCategory(targetCategory, oneText, catrepo);
            }

            workflowContext.DbContext.SaveChanges();

            pstack.SetValue(ActivityParameterStack.CATEGORY, targetCategory);

            this.AlreadyCategoryFlag.Set(context, !_IsCreate);
        }
예제 #3
0
        protected override void Execute(CodeActivityContext context)
        {
            IWorkflowContext workflowContext = context.GetExtension <IWorkflowContext>();
            ParameterStack   pstack          = context.GetValue <ParameterStack>(this.Parameter);

            var target = pstack.GetValue <FileMappingInfo>(ActivityParameterStack.TARGET);

            Mogami.Model.Category category = null;
            if (pstack.ContainsKey(ActivityParameterStack.CATEGORY))
            {
                category = pstack.GetValue <Mogami.Model.Category>(ActivityParameterStack.CATEGORY);
            }

            var outputname = context.GetValue <string>(OutputName);

            // Guard
            Ensure.That(target).IsNotNull();

            // FileMappingInfoがArtifactとの関連が存在する場合、
            // 新規のArtifactは作成できないので、例外を投げる。
            if (target.Id != 0L)
            {
                var r = new ArtifactRepository(workflowContext.DbContext);
                var a = r.LoadByFileMappingInfo(target);
                if (a != null)
                {
                    throw new ApplicationException("すでに作成済みのFileMappingInfoです。");
                }
            }

            if (category == null)
            {
                var catrepo = new CategoryRepository(workflowContext.DbContext);
                var appcat  = catrepo.Load(3L);
                if (appcat == null)
                {
                    throw new ApplicationException();
                }
            }

            var tokens   = target.MappingFilePath.Split(new string[] { @"\" }, StringSplitOptions.None);
            var sttokens = new Stack <string>(tokens);
            var title    = sttokens.Pop();

            // 現Verでは画像のみ、メタ情報を生成できる。
            // (それ以外のファイルは、例外を投げる)
            if (target.Mimetype == "image/png")
            {
                var repo   = new ImageArtifactRepository(workflowContext.DbContext);
                var entity = new ImageArtifact
                {
                    Title           = title,
                    IdentifyKey     = RandomAlphameric.RandomAlphanumeric(10),
                    FileMappingInfo = target,
                    ImageHeight     = -1,                // 未実装
                    ImageWidth      = -1,                // 未実装
                };

                if (category != null)
                {
                    entity.Category = new T_Artifact2Category()
                    {
                        Artifact = entity,
                        Category = category,
                        OrderNo  = 1
                    }
                }
                ;

                repo.Add(entity);

                pstack.SetValue(outputname, entity);
            }
            else
            {
                throw new ApplicationException("処理不能なMIMEタイプです");
            }
        }

        #endregion メソッド
    }