/// <summary>
        /// [LLD-03-05-01:01-01-02]
        /// </summary>
        private void file_create_acl(AppDbContext dbc, FileUpdateQueueItem item, Workspace workspace)
        {
            // 1. 対象ファイルが存在するかチェック
            if (!item.Target.Exists)
            {
                throw new ApplicationException("対象ファイルが指定位置に存在しません。");
            }

            // 3. ACLファイルから、ACLハッシュを取得する
            var aclbin  = VfsLogicUtils.ReadACLFile(new FileInfo(item.Target.FullName));
            var aclhash = aclbin.FindKeyValue("ACLHASH");

            // 4. データベースを参照し、ACLハッシュとファイルマッピング情報(AclHash)を突き合わせる
            FileMappingInfo entity = null;

            var repo = new FileMappingInfoRepository(dbc);

            entity = repo.LoadByAclHash(aclhash);
            if (entity == null)
            {
                throw new ApplicationException();
            }
            if (entity.Workspace == null || entity.Workspace.Id != workspace.Id)
            {
                throw new ApplicationException();
            }


            // 5. ファイルマッピング情報を参照し、物理ファイルが存在するかチェックする
            var phyFileInfo = new FileInfo(Path.Combine(workspace.PhysicalSpacePath, entity.MappingFilePath));

            if (!phyFileInfo.Exists)
            {
                throw new ApplicationException();
            }

            // 6. 物理ファイルを、ACLファイルのパスに対応する物理空間のパスへ移動する
            //    移動先が、同じ場所となる場合は処理しない。
            var aclfileLocalPath_Update = workspace.TrimWorekspacePath(item.Target.FullName, false);
            var extFilePath             = Path.Combine(Path.GetDirectoryName(aclfileLocalPath_Update), Path.GetFileNameWithoutExtension(aclfileLocalPath_Update));
            var toFileInfo = new FileInfo(Path.Combine(workspace.PhysicalSpacePath, extFilePath));

            if (phyFileInfo.FullName != toFileInfo.FullName)
            {
                Directory.CreateDirectory(toFileInfo.Directory.FullName);
                File.Move(phyFileInfo.FullName, toFileInfo.FullName);

                // 7. ファイルマッピング情報をDBに書き込む(コンテキスト初期化)
                entity = repo.LoadByAclHash(aclhash);
                entity.MappingFilePath = extFilePath;                 // 新しいファイルマップパス
                dbc.SaveChanges();
            }
        }
Esempio n. 2
0
        // アクティビティが値を返す場合は、CodeActivity<TResult> から派生して、
        // Execute メソッドから値を返します。
        protected override FileMappingInfo Execute(CodeActivityContext context)
        {
            IWorkflowContext workflowContext = context.GetExtension <IWorkflowContext>();
            var repo = new FileMappingInfoRepository(workflowContext.DbContext);

            string keyType  = this.KeyType.Get(context);
            string keyValue = this.KeyValue.Get(context);

            FileMappingInfo returnEntity = null;

            switch (keyType)
            {
            case "Id":
                returnEntity = repo.Load(long.Parse(keyValue));
                if (returnEntity == null)
                {
                    LOG.WarnFormat("FileMappingInfoの読み込みに失敗しました。 Id={0}", long.Parse(keyValue));
                }
                break;

            case "AclHash":
                returnEntity = repo.LoadByAclHash(keyValue);
                if (returnEntity == null)
                {
                    LOG.WarnFormat("FileMappingInfoの読み込みに失敗しました。 AclHash={0}", keyValue);
                }
                break;

            case "MappingFilePath":
                returnEntity = repo.LoadByPath(keyValue);
                if (returnEntity == null)
                {
                    LOG.WarnFormat("FileMappingInfoの読み込みに失敗しました。 MappingFilePath={0}", keyValue);
                }
                break;

            default:
                throw new ApplicationException("キータイプの指定が不正です");
            }

            var resultKey = this.ParameterResultKey.Get(context);

            if (resultKey != null)
            {
                ParameterStack pstack = context.GetValue <ParameterStack>(this.Parameter);
                pstack.SetValue(resultKey, returnEntity);
            }

            return(returnEntity);
        }