//The persistence engine will send a variety of commands to the configured InstanceStore,
        //such as CreateWorkflowOwnerCommand, SaveWorkflowCommand, and LoadWorkflowCommand.
        //This method is where we will handle those commands
        protected override IAsyncResult BeginTryCommand(InstancePersistenceContext context, InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state)
        {
            IDictionary <XName, InstanceValue> data = null;

            //The CreateWorkflowOwner command instructs the instance store to create a new instance owner bound to the instanace handle
            if (command is CreateWorkflowOwnerCommand)
            {
                context.BindInstanceOwner(ownerInstanceID, ownerInstanceID);
            }
            //The SaveWorkflow command instructs the instance store to modify the instance bound to the instance handle or an instance key
            else if (command is SaveWorkflowCommand)
            {
                SaveWorkflowCommand saveCommand = (SaveWorkflowCommand)command;
                data = saveCommand.InstanceData;


                Save(data);
                //_saveWaitHandler.WaitOne(new TimeSpan(0, 0, 1));
            }
            //The LoadWorkflow command instructs the instance store to lock and load the instance bound to the identifier in the instance handle
            else if (command is LoadWorkflowCommand)
            {
                string fileName = GetFileName(this.ownerInstanceID);

                data = LoadInstanceDataFromFile(fileName);
                var nonWriteOnly = data.Where(kvp => (kvp.Value.Options & InstanceValueOptions.WriteOnly) != InstanceValueOptions.WriteOnly).ToDictionary(k => k.Key, v => v.Value);


                //load the data into the persistence Context
                context.LoadedInstance(InstanceState.Initialized, nonWriteOnly, null, null, null);
            }
            else if (command.Name.LocalName == "CreateWorkflowOwner")
            {
                //do nothing
            }
            var result = new CompletedAsyncResult <bool>(true, callback, state);

            return(result);
        }
 protected override bool EndTryCommand(IAsyncResult result)
 {
     return(CompletedAsyncResult <bool> .End(result));
 }