File Index Symbol Index

#include "GuiInstanceCompiledWorkflow.h"
#include "../Controls/GuiApplication.h"
namespace
vl
{
namespace
presentation
{
using
namespace
stream
;
using
namespace
workflow
::
runtime
;
using
namespace
controls
;
using
namespace
reflection
;
using
namespace
reflection
::
description
;
/*********************************************************************** GuiInstanceSharedScript ***********************************************************************/
GuiInstanceCompiledWorkflow
::
GuiInstanceCompiledWorkflow
() { }
GuiInstanceCompiledWorkflow
::
~
GuiInstanceCompiledWorkflow
() {
UnloadAssembly
(); }
bool
GuiInstanceCompiledWorkflow
::
Initialize
(
bool
initializeContext
,
workflow
::
runtime
::
WfAssemblyLoadErrors
&
loadErrors
) {
if
(
binaryToLoad
) {
assembly
=
WfAssembly
::
Deserialize
(*
binaryToLoad
.
Obj
(),
loadErrors
);
if
(!
assembly
) {
return
false
; }
binaryToLoad
=
nullptr
;
#ifdef VCZH_DESCRIPTABLEOBJECT_WITH_METADATA
context
=
nullptr
;
#endif
}
#ifdef VCZH_DESCRIPTABLEOBJECT_WITH_METADATA
if
(
initializeContext
&& !
context
) {
context
=
new
WfRuntimeGlobalContext
(
assembly
);
LoadFunction
<
void
()>(
context
,
L"<initialize>"
)(); }
#else
if (initializeContext)
{
if (assembly->typeImpl)
{
if (auto tm = GetGlobalTypeManager())
{
tm->AddTypeLoader(assembly->typeImpl);
}
}
} #endif
return
true
; }
void
GuiInstanceCompiledWorkflow
::
UnloadAssembly
() {
UnloadTypes
();
assembly
=
nullptr
; }
void
GuiInstanceCompiledWorkflow
::
UnloadTypes
() {
#ifdef VCZH_DESCRIPTABLEOBJECT_WITH_METADATA
context
=
nullptr
;
#else
if (assembly && assembly->typeImpl)
{
if (auto tm = GetGlobalTypeManager())
{
tm->RemoveTypeLoader(assembly->typeImpl);
}
} #endif
}
/*********************************************************************** Compiled Workflow Type Resolver (Workflow) ***********************************************************************/
class
GuiResourceCompiledWorkflowTypeResolver
:
public
Object
,
public
IGuiResourceTypeResolver
,
private
IGuiResourceTypeResolver_Initialize
,
private
IGuiResourceTypeResolver_DirectLoadStream
{
public
:
WString
GetType
()
override
{
return
L"Workflow"
; }
bool
XmlSerializable
()
override
{
return
false
; }
bool
StreamSerializable
()
override
{
return
true
; }
vint
GetMaxPassIndex
()
override
{
return
1
; }
void
Initialize
(
Ptr
<
GuiResourceItem
>
resource
,
GuiResourceInitializeContext
&
context
,
GuiResourceError
::
List
&
errors
)
override
{
if
(
auto
compiled
=
resource
-
>
GetContent
().
Cast
<
GuiInstanceCompiledWorkflow
>()) {
switch
(
context
.
passIndex
) {
case
0
:
if
(
compiled
-
>
type
==
GuiInstanceCompiledWorkflow
::
InstanceClass
) {
if
(
context
.
usage
==
GuiResourceUsage
::
InstanceClass
) {
WfAssemblyLoadErrors
loadErrors
;
if
(!
compiled
-
>
Initialize
(
true
,
loadErrors
)) { {
errors
.
Add
({ {
resource
},
L"Failed to add an existing type: "
+
loadError
}); } {
errors
.
Add
({ {
resource
},
L"Unable to resolve type: "
+
loadError
}); } {
errors
.
Add
({ {
resource
},
L"Unable to resolve member: "
+
loadError
}); } } } }
break
; } } }
IGuiResourceTypeResolver_Initialize
*
Initialize
()
override
{
return
this
; }
IGuiResourceTypeResolver_DirectLoadStream
*
DirectLoadStream
()
override
{
return
this
; }
void
SerializePrecompiled
(
Ptr
<
GuiResourceItem
>
resource
,
Ptr
<
DescriptableObject
>
content
,
stream
::
IStream
&
resourceStream
)
override
{
if
(
auto
obj
=
content
.
Cast
<
GuiInstanceCompiledWorkflow
>()) {
internal
::
ContextFreeWriter
writer
(
resourceStream
);
vint
type
= (
vint
)
obj
-
>
type
;
writer
<
<
type
;
if
(
obj
-
>
type
==
GuiInstanceCompiledWorkflow
::
InstanceClass
) {
stream
::
MemoryStream
memoryStream
;
obj
-
>
assembly
-
>
Serialize
(
memoryStream
);
writer
<
<
(
stream
::
IStream
&)
memoryStream
; } } }
Ptr
<
DescriptableObject
>
ResolveResourcePrecompiled
(
Ptr
<
GuiResourceItem
>
resource
,
stream
::
IStream
&
resourceStream
,
GuiResourceError
::
List
&
errors
)
override
{
internal
::
ContextFreeReader
reader
(
resourceStream
);
vint
type
;
reader
<
<
type
;
auto
obj
=
MakePtr
<
GuiInstanceCompiledWorkflow
>();
obj
-
>
type
= (
GuiInstanceCompiledWorkflow
::
AssemblyType
)
type
;
if
(
obj
-
>
type
==
GuiInstanceCompiledWorkflow
::
InstanceClass
) {
auto
memoryStream
=
MakePtr
<
stream
::
MemoryStream
>();
reader
<
<
(
stream
::
IStream
&)*
memoryStream
.
Obj
();
obj
-
>
binaryToLoad
=
memoryStream
; }
return
obj
; } };
/*********************************************************************** Plugin ***********************************************************************/
class
GuiRuntimeTypeResolversPlugin
:
public
Object
,
public
IGuiPlugin
{
public
: { }
void
Load
()
override
{
IGuiResourceResolverManager
*
manager
=
GetResourceResolverManager
();
manager
->
SetTypeResolver
(
new
GuiResourceCompiledWorkflowTypeResolver
); }
void
Unload
()
override
{ } }; } }