Exemple #1
0
        private Artifact ReadByFileMappingInfo(FileMappingInfo fileMappingInfo, DbContext dbcontext)
        {
            var repo = new ArtifactRepository(dbcontext);

            return(repo.LoadByFileMappingInfo(fileMappingInfo));
        }
Exemple #2
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 メソッド
    }