Пример #1
0
 public DocumentLogEvent(ImageArtifact artifact) : base(artifact)
 {
     IsImage      = true;
     Categories   = string.Join(",", artifact.Categories.Select(c => c.Name).ToArray());
     Tags         = string.Join(",", artifact.Tags);
     IsAdultImage = artifact.IsAdultContent || artifact.IsRacy;
     UserOp       = artifact.HasFileSource ? (artifact.Source as FileArtifact).UserOp.ToString() : string.Empty;
     Global.Logger.Debug("Created Azure Log Analytics log event {0} for image artifact {1} from user op {2} at {3}.", Name, artifact.Id, UserOp, DateTime.Now);
 }
Пример #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 メソッド
    }