Esempio n. 1
0
        public void Run_UpdateVirtualSpaceAppFlowTest_RenameFileName()
        {
            LOG.Debug("execute method run");

            UpdateVirtualSpaceAppFlowTestSupport.RemoveVirtualFile(1L);
            UpdateVirtualSpaceAppFlowTestSupport.RemovePhysicalFile(1L);
            UpdateVirtualSpaceAppFlowTestSupport.CopyPhysicalSpace_Kinkaku(1L);

            var aclfile = UpdateVirtualSpaceAppFlowTestSupport.CopyVirtualSpace_Kinkaku_aclgene(1L);

            aclfile.MoveTo(Path.Combine(aclfile.DirectoryName, "Kinkaku2.jpg.aclgene"));             //  新しいACLファイル名前にリネームする
            aclfile = new FileInfo(Path.Combine(aclfile.DirectoryName, "Kinkaku2.jpg.aclgene"));

            // ...
            using (var dbc = new AppDbContext())
            {
                var workspace = WorkspaceRepository.Load(dbc, 1L);
                var workflow  = new WorkflowInvoker(new UpdateVirtualSpaceAppFlow());
                workflow.Extensions.Add(new WorkflowExtention(dbc));

                var pstack = new ParameterStack();
                pstack.SetValue("Event", Mogami.Core.Constructions.UpdateVirtualStatusEventType.RENAME);
                pstack.SetValue(ActivityParameterStack.WORKSPACE_FILEPATH, "Kinkaku2.jpg.aclgene");                 // リネーム後のファイル名
                pstack.SetValue(ActivityParameterStack.WORKSPACE, workspace);

                var results = workflow.Invoke(new Dictionary <string, object>
                {
                    { "ParameterStack", pstack }
                });

                dbc.SaveChanges();
            }

            using (var dbc = new AppDbContext())
            {
                var filemapinginfoRepository = new FileMappingInfoRepository(dbc);
                var entity = filemapinginfoRepository.Load(1L);

                var workspace = WorkspaceRepository.Load(dbc, 1L);

                // エンティティの値が変わっていることの確認
                Assert.AreEqual("Kinkaku2.jpg", entity.MappingFilePath);

                // 物理ディレクトリ空間での、ファイル名称が変更していることの確認
                var physicalFileInfo = new FileInfo(Path.Combine(workspace.PhysicalPath, "Kinkaku2.jpg"));
                Assert.IsTrue(physicalFileInfo.Exists);
            }
        }
Esempio n. 2
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);
        }
Esempio n. 3
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));
            }
        }
Esempio n. 4
0
        protected override void Execute(CodeActivityContext context)
        {
            ParameterStack pstack = context.GetValue <ParameterStack>(this.Parameter);
            object         value  = context.GetValue <object>(this.Value);
            string         key    = context.GetValue <string>(this.Key);

            pstack.SetValue(key, value);
        }
Esempio n. 5
0
        public void Run_UpdateVirtualSpaceAppFlowTest_DeleteFileName()
        {
            UpdateVirtualSpaceAppFlowTestSupport.RemoveVirtualFile(1L);
            UpdateVirtualSpaceAppFlowTestSupport.RemovePhysicalFile(1L);
            UpdateVirtualSpaceAppFlowTestSupport.CopyPhysicalSpace_Kinkaku(1L);

            var aclfile = UpdateVirtualSpaceAppFlowTestSupport.CopyVirtualSpace_Kinkaku_aclgene(1L);

            aclfile.Delete();


            using (var dbc = new AppDbContext())
            {
                var workspace = WorkspaceRepository.Load(dbc, 1L);
                var workflow  = new WorkflowInvoker(new UpdateVirtualSpaceAppFlow());
                workflow.Extensions.Add(new WorkflowExtention(dbc));

                var pstack = new ParameterStack();
                pstack.SetValue("Event", Mogami.Core.Constructions.UpdateVirtualStatusEventType.DELETE);
                pstack.SetValue(ActivityParameterStack.WORKSPACE_FILEPATH, "Kinkaku.jpg.aclgene");                 // 削除したファイル
                pstack.SetValue(ActivityParameterStack.WORKSPACE, workspace);
                pstack.SetValue("WF_DeleteAclHash", "Test");

                var results = workflow.Invoke(new Dictionary <string, object>
                {
                    { "ParameterStack", pstack }
                });

                dbc.SaveChanges();
            }

            using (var dbc = new AppDbContext())
            {
                var workspace = WorkspaceRepository.Load(dbc, 1L);

                // 物理ファイルが削除されていることを確認する
                var physicalFileInfo = new FileInfo(Path.Combine(workspace.PhysicalPath, "Kinkaku.jpg"));
                Assert.IsFalse(physicalFileInfo.Exists);

                var entity = FileMappingInfoRepository.Load(dbc, 1L);
                Assert.IsNull(entity);
            }
        }
Esempio n. 6
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);
        }
Esempio n. 7
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);
        }
Esempio n. 8
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);
        }
Esempio n. 9
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です。");
            }
        }
Esempio n. 10
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 メソッド
    }
Esempio n. 11
0
        /// <summary>
        /// インデックス作成処理を一定間隔で行います
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        async void OnIndexTimerElapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (this.IsSuspendIndex)
            {
                return;                                  // サスペンド時はインデックス生成処理はスキップする
            }
            // インデックス生成処理中は、このメソッドを呼び出すタイマーは停止しておきます。
            var timer = sender as System.Timers.Timer;

            timer.Enabled = false;

            LOG.Info("タイマー処理の実行");

            // ディレクトリ削除イベントが発生している場合、
            // 削除したディレクトリに含まれていたファイルを、削除したパスから見つけ出して削除処理を行うキューに追加する
            lock (sameDirectoryOperation_Locker)
            {
                if (sameDirectoryOperation_Name != "")
                {
                    sameDirectoryOperation_Name = "";
                    var relativeDirPath = _Workspace.TrimWorekspacePath(sameDirectoryOperation_FullPath, false);
                    using (var dbc = new AppDbContext())
                    {
                        var repo = new FileMappingInfoRepository(dbc);
                        foreach (var prop in repo.FindBy(p => p.MappingFilePath.StartsWith(relativeDirPath)))
                        {
                            var fileUpdateQueueItem = new FileUpdateQueueItem {
                                Target = new FileInfo(Path.Combine(_Workspace.WorkspacePath, prop.MappingFilePath + ".aclgene"))
                            };
                            fileUpdateQueueItem.Recents.Add(new RecentInfo {
                                EventType = WatcherChangeTypes.Deleted
                            });
                            _UpdatesWatchFiles.AddOrUpdate(prop.MappingFilePath, fileUpdateQueueItem, (_key, _value) => fileUpdateQueueItem);
                        }
                    }
                }
            }

            //
            foreach (var @pair in _UpdatesWatchFiles.ToList())
            {
                // 最後のファイル監視状態から、一定時間経過している場合のみ処理を行う。
                var @diff = DateTime.Now - @pair.Value.LastUpdate;

                if (@diff.Seconds >= 10)                 // 10秒 以上経過
                {
                    FileUpdateQueueItem item;            // work
                    if (_UpdatesWatchFiles.TryRemove(@pair.Key, out item))
                    {
                        var @lastItem = item.Recents.LastOrDefault();

                        // NOTE: UpdateVirtualSpaceFlowワークフローを呼び出す
                        LOG.InfoFormat("ワークフロー実行 [{1}] 対象ファイルパス={0}", item.Target.FullName, @lastItem.EventType);

                        // ワークフロー処理中に発生するファイル更新イベントにより、更新キューに項目が追加されてしまうことを防ぐため、
                        // 処理中のファイルを更新キューから除外するための除外リストに、処理中のファイルを追加する。
                        //
                        // ※処理中のファイルがACLファイル以外の場合、対象ファイルのACLファイル名も除外リストに追加する
                        _IgnoreUpdateFiles.Enqueue(item.Target.FullName);
                        if (item.Target.Extension != ".aclgene")
                        {
                            _IgnoreUpdateFiles.Enqueue(item.Target.FullName + ".aclgene");
                        }

                        try
                        {
                            using (var dbc = new AppDbContext())
                            {
                                var workspace = WorkspaceRepository.Load(dbc, _Workspace.Id);
                                var workflow  = new WorkflowInvoker(new UpdateVirtualSpaceAppFlow());
                                workflow.Extensions.Add(new WorkflowExtention(dbc));
                                var pstack = new ParameterStack();

                                // 処理対象のファイルがACLファイルか、物理ファイルかで処理を切り分けます
                                // ■ACLファイルの場合
                                //    リネーム更新イベントに対応します。
                                // ■物理ファイルの場合
                                //    リネーム更新イベントも、UPDATEイベントとして処理します。
                                if (item.Target.Extension == ".aclgene")
                                {
                                    var fileNameWithputExtension = item.Target.Name.Replace(item.Target.Extension, "");
                                    switch (@lastItem.EventType)
                                    {
                                    case WatcherChangeTypes.Renamed:
                                        pstack.SetValue("Event", Mogami.Core.Constructions.UpdateVirtualStatusEventType.RENAME);
                                        pstack.SetValue(ActivityParameterStack.WORKSPACE_FILEINFO, item.Target);
                                        pstack.SetValue(ActivityParameterStack.WORKSPACE_FILEPATH, item.Target.Name);                                                 // リネーム後のファイル名
                                        pstack.SetValue(ActivityParameterStack.WORKSPACE, workspace);

                                        var results_renamed = workflow.Invoke(new Dictionary <string, object>
                                        {
                                            { "ParameterStack", pstack },
                                            //{"EventType", UpdateVirtualStatusEventType.RENAME},
                                            //{"Target", item.Target},
                                            //{"BeforeRenameName",item.OldRenameNamePath},
                                            //{"Workspace", workspace}
                                        });
                                        break;

                                    case WatcherChangeTypes.Changed:
                                    case WatcherChangeTypes.Created:
                                        var aclfileLocalPath = workspace.TrimWorekspacePath(item.Target.FullName, false);
                                        pstack.SetValue("Event", Mogami.Core.Constructions.UpdateVirtualStatusEventType.UPDATE);
                                        pstack.SetValue(ActivityParameterStack.WORKSPACE_FILEINFO, item.Target);
                                        pstack.SetValue(ActivityParameterStack.WORKSPACE_FILEPATH, aclfileLocalPath);                                                 // 移動後のファイルパス
                                        pstack.SetValue(ActivityParameterStack.WORKSPACE, workspace);
                                        var results_changed = workflow.Invoke(new Dictionary <string, object>
                                        {
                                            { "ParameterStack", pstack },
                                            //{"EventType", UpdateVirtualStatusEventType.UPDATE},
                                            //{"Target", item.Target},
                                            //{"Workspace", workspace}
                                        });
                                        break;

                                    case WatcherChangeTypes.Deleted:
                                        var aclfileLocalPath_Delete = workspace.TrimWorekspacePath(item.Target.FullName, false);
                                        pstack.SetValue("Event", Mogami.Core.Constructions.UpdateVirtualStatusEventType.DELETE);
                                        pstack.SetValue(ActivityParameterStack.WORKSPACE_FILEINFO, item.Target);
                                        pstack.SetValue(ActivityParameterStack.WORKSPACE_FILEPATH, aclfileLocalPath_Delete);                                                 // 削除したファイル
                                        pstack.SetValue(ActivityParameterStack.WORKSPACE, workspace);
                                        pstack.SetValue("WF_DeleteAclMappingFilePath", fileNameWithputExtension);

                                        var results_deleted = workflow.Invoke(new Dictionary <string, object>
                                        {
                                            { "ParameterStack", pstack },
                                            //{"EventType", UpdateVirtualStatusEventType.DELETE},
                                            //{"Target", item.Target},
                                            //{"DeleteAclHash", @pair.Key},
                                            //{"Workspace", workspace}
                                        });
                                        break;
                                    }
                                }
                                else
                                {
                                    if (File.Exists(item.Target.FullName))
                                    {
                                        switch (@lastItem.EventType)
                                        {
                                        case WatcherChangeTypes.Renamed:
                                        case WatcherChangeTypes.Changed:
                                        case WatcherChangeTypes.Created:
                                            var aclfileLocalPath_Update = workspace.TrimWorekspacePath(item.Target.FullName, false);
                                            pstack.SetValue("Event", Mogami.Core.Constructions.UpdateVirtualStatusEventType.UPDATE);
                                            pstack.SetValue(ActivityParameterStack.WORKSPACE_FILEINFO, item.Target);
                                            pstack.SetValue(ActivityParameterStack.WORKSPACE_FILEPATH, aclfileLocalPath_Update);                                                     // 削除したファイル
                                            pstack.SetValue(ActivityParameterStack.WORKSPACE, workspace);

                                            var results_changed = workflow.Invoke(new Dictionary <string, object>
                                            {
                                                { "ParameterStack", pstack },
                                                //{"EventType", UpdateVirtualStatusEventType.UPDATE},
                                                //{"Target", item.Target},
                                                //{"Workspace", workspace}
                                            });
                                            break;

                                        case WatcherChangeTypes.Deleted:
                                            var aclfileLocalPath_Delete = workspace.TrimWorekspacePath(item.Target.FullName, false);
                                            pstack.SetValue("Event", Mogami.Core.Constructions.UpdateVirtualStatusEventType.DELETE);
                                            pstack.SetValue(ActivityParameterStack.WORKSPACE_FILEINFO, item.Target);
                                            pstack.SetValue(ActivityParameterStack.WORKSPACE_FILEPATH, aclfileLocalPath_Delete);                                                     // 削除したファイル
                                            pstack.SetValue(ActivityParameterStack.WORKSPACE, workspace);

                                            var results_deleted = workflow.Invoke(new Dictionary <string, object>
                                            {
                                                { "ParameterStack", pstack },
                                                //{"EventType", UpdateVirtualStatusEventType.DELETE},
                                                //{"Target", item.Target},
                                                //{"Workspace", workspace}
                                            });
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        LOG.InfoFormat("「{0}」は存在しない物理ファイルのため、処理をスキップします。", item.Target.FullName);
                                    }
                                }

                                dbc.SaveChanges();
                            }
                        }
                        catch (Exception expr)
                        {
                            LOG.ErrorFormat("タイマー処理時エラー = {0}", expr.Message);
                        }

                        // 処理を終了したファイルを、除外リストから削除します
                        string ignoreUpdateFile;
                        _IgnoreUpdateFiles.TryDequeue(out ignoreUpdateFile);
                        if (item.Target.Extension != ".aclgene")
                        {
                            _IgnoreUpdateFiles.TryDequeue(out ignoreUpdateFile);
                        }
                    }
                }

                // [CPU使用率に対するループ遅延を行う]
                var cpuPer = _CpuCounter.NextValue();
                if (cpuPer > 90.0)
                {
                    await Task.Delay(100);                     // 100msec待機
                }
                else if (cpuPer > 30.0)
                {
                    //await Task.Delay(10); // 10msec待機
                }
            }

            timer.Enabled = true;
        }