示例#1
0
        protected override AclFileStructure Execute(CodeActivityContext context)
        {
            IWorkflowContext workflowContext = context.GetExtension <IWorkflowContext>();
            ParameterStack   pstack          = context.GetValue <ParameterStack>(this.Parameter);

            var workspace = pstack.GetValue <Workspace>(ActivityParameterStack.WORKSPACE);
            var relative  = pstack.GetValue <string>(ActivityParameterStack.WORKSPACE_FILEPATH);

            var virtualFileFullPath = Path.Combine(workspace.WorkspacePath, relative);

            var fileInfo = new FileInfo(virtualFileFullPath);

            if (!fileInfo.Exists)
            {
                LOG.Warn("対象ファイルが、見つかりませんでした。");
                return(null);
            }
            if (fileInfo.Extension != ".aclgene")
            {
                LOG.Warn("対象ファイルが、ACLファイルではありません。");
                return(null);
            }

            pstack.SetValue(ActivityParameterStack.WORKSPACE_FILEINFO, fileInfo);

            using (var file = File.OpenRead(virtualFileFullPath))
            {
                return(Serializer.Deserialize <AclFileStructure>(file));
            }
        }
示例#2
0
        /// <summary>
        /// ファイルの移動(転送)を行います
        /// </summary>
        /// <param name="context"></param>
        void MoveVirtualFile(CodeActivityContext context)
        {
            ParameterStack pstack    = context.GetValue <ParameterStack>(this.Parameter);
            var            workspace = pstack.GetValue <Workspace>(ActivityParameterStack.WORKSPACE);
            var            target    = pstack.GetValue <FileMappingInfo>(ActivityParameterStack.TARGET);

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

            var fromFilePath = new FileInfo(Path.Combine(workspace.WorkspacePath, target.MappingFilePath));
            var toFilePath   = Path.Combine(workspace.PhysicalPath, target.MappingFilePath + ".tmp");

            if (!File.Exists(fromFilePath.FullName))
            {
                new ApplicationException(fromFilePath.FullName + "が見つかりません");
            }

            // 移動先のディレクトリがサブディレクトリを含む場合、
            // 存在しないサブディレクトリを作成します。
            var newFileInfo = new FileInfo(Path.Combine(workspace.PhysicalPath, target.MappingFilePath));

            Directory.CreateDirectory(newFileInfo.Directory.FullName);

            File.Move(fromFilePath.FullName, toFilePath);
        }
示例#3
0
        protected override void Execute(CodeActivityContext context)
        {
            IWorkflowContext workflowContext = context.GetExtension <IWorkflowContext>();
            ParameterStack   pstack          = context.GetValue <ParameterStack>(this.Parameter);

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

            var workspace = pstack.GetValue <Workspace>(ActivityParameterStack.WORKSPACE);
            var fileinfo  = pstack.GetValue <FileSystemInfo>(ActivityParameterStack.WORKSPACE_FILEINFO);

            // Guard
            Ensure.That(workspace).IsNotNull();
            Ensure.That(fileinfo).IsNotNull();

            var entity = new FileMappingInfo
            {
                AclHash         = aclhash,
                Workspace       = workspace,
                Mimetype        = "image/png",          // 未実装(テスト実装)
                MappingFilePath = workspace.TrimWorekspacePath(fileinfo.FullName, false),
            };

            pstack.SetValue(outputname, entity);
        }
示例#4
0
        protected override bool Execute(CodeActivityContext context)
        {
            IWorkflowContext workflowContext = context.GetExtension <IWorkflowContext>();
            ParameterStack   pstack          = context.GetValue <ParameterStack>(this.Parameter);

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

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

            var aclfilepath = Path.Combine(workspace.WorkspacePath, target.MappingFilePath);

            aclfilepath += ".aclgene";

            // ACLファイルの作成を行います。
            //
            var data = new AclFileStructure();

            data.Version    = AclFileStructure.CURRENT_VERSION;
            data.LastUpdate = DateTime.Now;
            data.Data       = new KeyValuePair <string, string>[] {
                new KeyValuePair <string, string>("ACLHASH", target.AclHash)
            };

            using (var file = File.Create(aclfilepath))
            {
                Serializer.Serialize(file, data);
            }

            return(true);
        }
示例#5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="workflowContext"></param>
        /// <param name="pstack"></param>
        private void GenerateMisc(IWorkflowContext workflowContext, ParameterStack pstack)
        {
            var key  = pstack.GetValue <string>(ActivityParameterStack.GENERATETHUMBNAIL_KEY);
            var path = pstack.GetValue <string>(ActivityParameterStack.GENERATETHUMBNAIL_IMAGEPATH);

            // Guard
            Ensure.That(key).IsNotNullOrEmpty();
            Ensure.That(path).IsNotNullOrEmpty();

            var thumbnailManager = workflowContext.ThumbnailManager;

            thumbnailManager.BuildThumbnail(key, path);
        }
示例#6
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);
        }
示例#7
0
        /// <summary>
        /// Artifactから画像ファイルパスを取得し、サムネイルを生成します。
        /// </summary>
        /// <param name="workflowContext"></param>
        /// <param name="pstack"></param>
        private void GenerateArtifact(IWorkflowContext workflowContext, ParameterStack pstack)
        {
            var artifact = pstack.GetValue <ImageArtifact>(ActivityParameterStack.TARGET);

            if (artifact == null)
            {
                throw new ArgumentNullException();
            }

            var imageArtifactRepository = new ImageArtifactRepository(workflowContext.DbContext);

            if (artifact.Id != 0L)
            {
                artifact = imageArtifactRepository.Load(artifact.Id);
            }

            var fullpath         = System.IO.Path.Combine(artifact.FileMappingInfo.Workspace.PhysicalPath, artifact.FileMappingInfo.MappingFilePath);
            var thumbnailManager = workflowContext.ThumbnailManager;

            if (string.IsNullOrEmpty(artifact.ThumbnailKey))
            {
                var thumbnailKey = thumbnailManager.BuildThumbnail(null, fullpath);
                artifact.ThumbnailKey = thumbnailKey;
            }
            else
            {
                var thumbnailKey = thumbnailManager.BuildThumbnail(artifact.ThumbnailKey, fullpath);
            }
        }
示例#8
0
        // アクティビティが値を返す場合は、CodeActivity<TResult> から派生して、 Execute メソッドから値を返します。
        protected override IEntity <long> Execute(CodeActivityContext context)
        {
            IWorkflowContext workflowContext = context.GetExtension <IWorkflowContext>();

            var entity = this.Entity.Get(context);

            if (entity == null)
            {
                ParameterStack pstack = context.GetValue <ParameterStack>(this.Parameter);
                string         key    = this.ParameterKey.Get(context);
                entity = pstack.GetValue <IEntity <long> >(key);
            }

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

            var dbset = workflowContext.DbContext.Set(entity.GetType());

            if (entity.Id == 0)
            {
                dbset.Add(entity);
            }
            else
            {
                workflowContext.DbContext.Entry(entity).State = System.Data.Entity.EntityState.Modified;
            }

            return(entity);
        }
示例#9
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);
            var filepath  = pstack.GetValue <string>(ActivityParameterStack.WORKSPACE_PHYFILEPATH_OLD);
            var workspace = pstack.GetValue <Workspace>(ActivityParameterStack.WORKSPACE);

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

            var srcFileInfo = new FileInfo(Path.Combine(workspace.PhysicalPath, filepath));

            if (!File.Exists(srcFileInfo.FullName))
            {
                throw new ApplicationException(srcFileInfo.FullName + "が見つかりません");
            }

            var oldFileDirectory = new DirectoryInfo(srcFileInfo.DirectoryName);

            // 移動先のディレクトリがサブディレクトリを含む場合、
            // 存在しないサブディレクトリを作成します。
            var newFileInfo = new FileInfo(Path.Combine(workspace.PhysicalPath, target.MappingFilePath));

            Directory.CreateDirectory(newFileInfo.Directory.FullName);

            srcFileInfo.MoveTo(newFileInfo.FullName);

            // 移動元の物理ディレクトリ空間のフォルダが空の場合、フォルダ自体を削除する
            // ※移動元のファイルがあったディレクトリと、その上位階層にむけて空である場合、フォルダを削除します。
            //   このディレクトリにサブディレクトリがある場合は削除しません。(サブディレクトリ内が空であっても、削除は行わない)
            DirectoryInfo deleteTragetDirectory = oldFileDirectory;

            while (deleteTragetDirectory != null &&
                   deleteTragetDirectory.GetFileSystemInfos().Count() == 0)
            {
                deleteTragetDirectory.Delete();
                deleteTragetDirectory = deleteTragetDirectory.Parent;
            }
        }
示例#10
0
        private void DeleteMisc(IWorkflowContext workflowContext, ParameterStack pstack)
        {
            var key = pstack.GetValue <string>(ActivityParameterStack.GENERATETHUMBNAIL_KEY);

            // Guard
            Ensure.That(key).IsNotNullOrEmpty();

            var thumbnailManager = workflowContext.ThumbnailManager;

            thumbnailManager.RemoveThumbnail(key);
        }
示例#11
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);
            var workspace = pstack.GetValue <Workspace>(ActivityParameterStack.WORKSPACE);

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

            var file = new FileInfo(Path.Combine(workspace.PhysicalPath, target.MappingFilePath));

            if (!file.Exists)
            {
                throw new ApplicationException();
            }
            file.Delete();
        }
示例#12
0
        private void DeleteeArtifact(IWorkflowContext workflowContext, ParameterStack pstack)
        {
            var artifact         = pstack.GetValue <ImageArtifact>(ActivityParameterStack.TARGET);
            var thumbnailManager = workflowContext.ThumbnailManager;

            if (artifact == null)
            {
                throw new ArgumentNullException();
            }

            thumbnailManager.RemoveThumbnail(artifact.ThumbnailKey);
        }
示例#13
0
        /// <summary>
        /// 物理ディレクトリ空間のファイル名から、「tmp」を除去します
        /// </summary>
        /// <param name="context"></param>
        void ClearedTemporaryFile(CodeActivityContext context)
        {
            ParameterStack pstack    = context.GetValue <ParameterStack>(this.Parameter);
            var            workspace = pstack.GetValue <Workspace>(ActivityParameterStack.WORKSPACE);
            var            target    = pstack.GetValue <FileMappingInfo>(ActivityParameterStack.TARGET);

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


            var clearedFileInfo = new FileInfo(Path.Combine(workspace.PhysicalPath, target.MappingFilePath) + ".tmp");

            if (!File.Exists(clearedFileInfo.FullName))
            {
                throw new ApplicationException(clearedFileInfo.FullName + "が見つかりません");
            }

            var extFileName = Path.GetFileNameWithoutExtension(clearedFileInfo.Name);

            clearedFileInfo.MoveTo(Path.Combine(clearedFileInfo.DirectoryName, extFileName));
        }
示例#14
0
        protected override void Execute(CodeActivityContext context)
        {
            IWorkflowContext workflowContext = context.GetExtension <IWorkflowContext>();
            ParameterStack   pstack          = context.GetValue <ParameterStack>(this.Parameter);
            string           distKey         = context.GetValue <string>(this.DistKey);
            string           srcKey          = context.GetValue <string>(this.SrcKey);

            var obj = pstack.GetValue(srcKey, false);

            pstack.SetValue(distKey, obj);

            pstack.ClearKey(srcKey);
        }
示例#15
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);
            var filepath  = pstack.GetValue <string>(ActivityParameterStack.WORKSPACE_FILEPATH);
            var workspace = pstack.GetValue <Workspace>(ActivityParameterStack.WORKSPACE);

            // Guard
            Ensure.That(target).IsNotNull();
            Ensure.That(filepath).IsNotNullOrEmpty();
            Ensure.That(workspace).IsNotNull();

            if (string.IsNullOrEmpty(filepath))
            {
                var aclfilepath = Path.Combine(workspace.WorkspacePath, target.MappingFilePath);
                aclfilepath += Path.DirectorySeparatorChar + ".aclgene";

                try
                {
                    File.Delete(aclfilepath);
                }
                catch (Exception)
                {
                }
            }
            else
            {
                try
                {
                    File.Delete(filepath);
                }
                catch (Exception)
                {
                }
            }
        }
示例#16
0
        protected override bool Execute(CodeActivityContext context)
        {
            IWorkflowContext workflowContext = context.GetExtension <IWorkflowContext>();
            ParameterStack   pstack          = context.GetValue <ParameterStack>(this.Parameter);


            var filepath  = pstack.GetValue <string>(ActivityParameterStack.WORKSPACE_FILEPATH);
            var workspace = pstack.GetValue <Workspace>(ActivityParameterStack.WORKSPACE);

            // Guard
            Ensure.That(workspace).IsNotNull();
            Ensure.That(filepath).IsNotNullOrEmpty();

            string path = Path.Combine(workspace.WorkspacePath, filepath);
            var    fi   = new FileInfo(path);

            // ACLファイルかどうかの判定には、拡張子で確認します。
            if (fi.Extension == ".aclgene")
            {
                return(true);
            }

            return(false);
        }
示例#17
0
        protected override void Execute(CodeActivityContext context)
        {
            IWorkflowContext workflowContext = context.GetExtension <IWorkflowContext>();
            ParameterStack   pstack          = context.GetValue <ParameterStack>(this.Parameter);

            var cleared = pstack.GetValue <Boolean>(ActivityParameterStack.MOVEPHYSICALFILEFROMVIRTUAL_CLEAREDFLAG);


            if (!cleared)
            {
                MoveVirtualFile(context);
            }
            else
            {
                ClearedTemporaryFile(context);
            }
        }
示例#18
0
        protected override void Execute(CodeActivityContext context)
        {
            IWorkflowContext workflowContext = context.GetExtension <IWorkflowContext>();
            ParameterStack   pstack          = context.GetValue <ParameterStack>(this.Parameter);

            var readKey    = this.ReadKey.Get(context);
            var outputname = context.GetValue <string>(OutputName);

            switch (readKey)
            {
            case "FileMappingInfo":
                var target = pstack.GetValue <FileMappingInfo>(ActivityParameterStack.TARGET);
                var a      = ReadByFileMappingInfo(target, workflowContext.DbContext);
                pstack.SetValue(outputname, a);
                break;

            default:
                throw new ApplicationException("不明なReadKeyです。");
            }
        }
示例#19
0
        protected override void Execute(CodeActivityContext context)
        {
            IWorkflowContext workflowContext = context.GetExtension <IWorkflowContext>();
            var repo = new FileMappingInfoRepository(workflowContext.DbContext);

            var entity = this.Entity.Get(context);

            if (entity != null)
            {
                repo.Delete(entity);
            }
            else
            {
                ParameterStack pstack          = context.GetValue <ParameterStack>(this.Parameter);
                var            targetEntityKey = this.ParameterTargetKey.Get(context);
                entity = pstack.GetValue(targetEntityKey, true) as FileMappingInfo;
                if (entity != null)
                {
                    repo.Delete(entity);
                }
            }
        }
示例#20
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 メソッド
    }