Example #1
0
        protected override void GenerateSqlCommand(SqlCommand command)
        {
            LoadWorkflowByInstanceKeyCommand keyLoadCommand = base.InstancePersistenceCommand as LoadWorkflowByInstanceKeyCommand;
            LoadType loadType = keyLoadCommand.AcceptUninitializedInstance ? LoadType.LoadOrCreateByKey : LoadType.LoadByKey;
            Guid     key      = keyLoadCommand.LookupInstanceKey;
            List <CorrelationKey> keysToAssociate = CorrelationKey.BuildKeyList(keyLoadCommand.InstanceKeysToAssociate, base.Store.InstanceEncodingOption);
            Guid instanceId = keyLoadCommand.AssociateInstanceKeyToInstanceId;

            GenerateLoadSqlCommand(command, loadType, key, instanceId, keysToAssociate);
        }
Example #2
0
 private void SerializeAssociatedData(SqlParameterCollection parameters, SaveWorkflowCommand saveWorkflowCommand, StringBuilder commandTextBuilder)
 {
     if (saveWorkflowCommand.CompleteInstance && (base.Store.InstanceCompletionAction == InstanceCompletionAction.DeleteAll))
     {
         SqlParameter parameter = new SqlParameter {
             ParameterName = "@keysToAssociate",
             SqlDbType     = SqlDbType.Xml,
             Value         = DBNull.Value
         };
         parameters.Add(parameter);
         SqlParameter parameter2 = new SqlParameter {
             ParameterName = "@singleKeyId",
             SqlDbType     = SqlDbType.UniqueIdentifier,
             Value         = DBNull.Value
         };
         parameters.Add(parameter2);
         SqlParameter parameter3 = new SqlParameter {
             ParameterName = "@keysToComplete",
             SqlDbType     = SqlDbType.Xml,
             Value         = DBNull.Value
         };
         parameters.Add(parameter3);
         SqlParameter parameter4 = new SqlParameter {
             ParameterName = "@keysToFree",
             SqlDbType     = SqlDbType.Xml,
             Value         = DBNull.Value
         };
         parameters.Add(parameter4);
         SqlParameter parameter5 = new SqlParameter {
             ParameterName = "@concatenatedKeyProperties",
             SqlDbType     = SqlDbType.VarBinary,
             Value         = DBNull.Value
         };
         parameters.Add(parameter5);
         SqlParameter parameter6 = new SqlParameter {
             ParameterName = "@primitiveDataProperties",
             SqlDbType     = SqlDbType.VarBinary,
             Value         = DBNull.Value
         };
         parameters.Add(parameter6);
         SqlParameter parameter7 = new SqlParameter {
             ParameterName = "@complexDataProperties",
             SqlDbType     = SqlDbType.VarBinary,
             Value         = DBNull.Value
         };
         parameters.Add(parameter7);
         SqlParameter parameter8 = new SqlParameter {
             ParameterName = "@writeOnlyPrimitiveDataProperties",
             SqlDbType     = SqlDbType.VarBinary,
             Value         = DBNull.Value
         };
         parameters.Add(parameter8);
         SqlParameter parameter9 = new SqlParameter {
             ParameterName = "@writeOnlyComplexDataProperties",
             SqlDbType     = SqlDbType.VarBinary,
             Value         = DBNull.Value
         };
         parameters.Add(parameter9);
         SqlParameter parameter10 = new SqlParameter {
             ParameterName = "@metadataProperties",
             SqlDbType     = SqlDbType.VarBinary,
             Value         = DBNull.Value
         };
         parameters.Add(parameter10);
         SqlParameter parameter11 = new SqlParameter {
             ParameterName = "@metadataIsConsistent",
             SqlDbType     = SqlDbType.Bit,
             Value         = DBNull.Value
         };
         parameters.Add(parameter11);
         SqlParameter parameter12 = new SqlParameter {
             ParameterName = "@encodingOption",
             SqlDbType     = SqlDbType.TinyInt,
             Value         = DBNull.Value
         };
         parameters.Add(parameter12);
         SqlParameter parameter13 = new SqlParameter {
             ParameterName = "@lastMachineRunOn",
             SqlDbType     = SqlDbType.NVarChar,
             Value         = DBNull.Value
         };
         parameters.Add(parameter13);
         SqlParameter parameter14 = new SqlParameter {
             ParameterName = "@executionStatus",
             SqlDbType     = SqlDbType.NVarChar,
             Value         = DBNull.Value
         };
         parameters.Add(parameter14);
         SqlParameter parameter15 = new SqlParameter {
             ParameterName = "@blockingBookmarks",
             SqlDbType     = SqlDbType.NVarChar,
             Value         = DBNull.Value
         };
         parameters.Add(parameter15);
     }
     else
     {
         List <CorrelationKey> correlationKeys = CorrelationKey.BuildKeyList(saveWorkflowCommand.InstanceKeysToAssociate, base.Store.InstanceEncodingOption);
         List <CorrelationKey> list2           = CorrelationKey.BuildKeyList(saveWorkflowCommand.InstanceKeysToComplete);
         List <CorrelationKey> list3           = CorrelationKey.BuildKeyList(saveWorkflowCommand.InstanceKeysToFree);
         ArraySegment <byte>[] segmentArray    = SerializationUtilities.SerializePropertyBag(saveWorkflowCommand.InstanceData, base.Store.InstanceEncodingOption);
         ArraySegment <byte>   segment         = SerializationUtilities.SerializeMetadataPropertyBag(saveWorkflowCommand, base.InstancePersistenceContext, base.Store.InstanceEncodingOption);
         byte[]       buffer      = SerializationUtilities.CreateKeyBinaryBlob(correlationKeys);
         bool         flag        = base.InstancePersistenceContext.InstanceView.InstanceMetadataConsistency == InstanceValueConsistency.None;
         bool         flag2       = (correlationKeys != null) && (correlationKeys.Count == 1);
         SqlParameter parameter16 = new SqlParameter {
             ParameterName = "@keysToAssociate",
             SqlDbType     = SqlDbType.Xml,
             Value         = flag2 ? DBNull.Value : SerializationUtilities.CreateCorrelationKeyXmlBlob(correlationKeys)
         };
         parameters.Add(parameter16);
         SqlParameter parameter17 = new SqlParameter {
             ParameterName = "@singleKeyId",
             SqlDbType     = SqlDbType.UniqueIdentifier,
             Value         = flag2 ? ((object)correlationKeys[0].KeyId) : ((object)DBNull.Value)
         };
         parameters.Add(parameter17);
         SqlParameter parameter18 = new SqlParameter {
             ParameterName = "@keysToComplete",
             SqlDbType     = SqlDbType.Xml,
             Value         = SerializationUtilities.CreateCorrelationKeyXmlBlob(list2)
         };
         parameters.Add(parameter18);
         SqlParameter parameter19 = new SqlParameter {
             ParameterName = "@keysToFree",
             SqlDbType     = SqlDbType.Xml,
             Value         = SerializationUtilities.CreateCorrelationKeyXmlBlob(list3)
         };
         parameters.Add(parameter19);
         SqlParameter parameter20 = new SqlParameter {
             ParameterName = "@concatenatedKeyProperties",
             SqlDbType     = SqlDbType.VarBinary,
             Size          = -1,
             Value         = buffer ?? DBNull.Value
         };
         parameters.Add(parameter20);
         SqlParameter parameter21 = new SqlParameter {
             ParameterName = "@metadataIsConsistent",
             SqlDbType     = SqlDbType.Bit,
             Value         = flag
         };
         parameters.Add(parameter21);
         SqlParameter parameter22 = new SqlParameter {
             ParameterName = "@encodingOption",
             SqlDbType     = SqlDbType.TinyInt,
             Value         = base.Store.InstanceEncodingOption
         };
         parameters.Add(parameter22);
         SqlParameter parameter23 = new SqlParameter {
             ParameterName = "@lastMachineRunOn",
             SqlDbType     = SqlDbType.NVarChar,
             Size          = 450,
             Value         = SqlWorkflowInstanceStoreConstants.MachineName
         };
         parameters.Add(parameter23);
         SqlParameter parameter24 = new SqlParameter {
             ParameterName = "@executionStatus",
             SqlDbType     = SqlDbType.NVarChar,
             Size          = 450,
             Value         = GetExecutionStatus(saveWorkflowCommand) ?? DBNull.Value
         };
         parameters.Add(parameter24);
         SqlParameter parameter25 = new SqlParameter {
             ParameterName = "@blockingBookmarks",
             SqlDbType     = SqlDbType.NVarChar,
             Size          = -1,
             Value         = GetBlockingBookmarks(saveWorkflowCommand) ?? DBNull.Value
         };
         parameters.Add(parameter25);
         ArraySegment <byte>[] segmentArray2 = new ArraySegment <byte>[] { segmentArray[0], segmentArray[1], segmentArray[2], segmentArray[3], segment };
         string[] strArray = new string[] { "@primitiveDataProperties", "@complexDataProperties", "@writeOnlyPrimitiveDataProperties", "writeOnlyComplexDataProperties", "@metadataProperties" };
         for (int i = 0; i < 5; i++)
         {
             AddSerializedProperty(segmentArray2[i], parameters, strArray[i]);
         }
         this.SerializePromotedProperties(parameters, commandTextBuilder, saveWorkflowCommand);
     }
 }
        void SerializeAssociatedData(SqlParameterCollection parameters, SaveWorkflowCommand saveWorkflowCommand, StringBuilder commandTextBuilder)
        {
            if (saveWorkflowCommand.CompleteInstance && base.Store.InstanceCompletionAction == InstanceCompletionAction.DeleteAll)
            {
                parameters.Add(new SqlParameter {
                    ParameterName = "@keysToAssociate", SqlDbType = SqlDbType.Xml, Value = DBNull.Value
                });
                parameters.Add(new SqlParameter {
                    ParameterName = "@singleKeyId", SqlDbType = SqlDbType.UniqueIdentifier, Value = DBNull.Value
                });
                parameters.Add(new SqlParameter {
                    ParameterName = "@keysToComplete", SqlDbType = SqlDbType.Xml, Value = DBNull.Value
                });
                parameters.Add(new SqlParameter {
                    ParameterName = "@keysToFree", SqlDbType = SqlDbType.Xml, Value = DBNull.Value
                });
                parameters.Add(new SqlParameter {
                    ParameterName = "@concatenatedKeyProperties", SqlDbType = SqlDbType.VarBinary, Value = DBNull.Value
                });
                parameters.Add(new SqlParameter {
                    ParameterName = "@primitiveDataProperties", SqlDbType = SqlDbType.VarBinary, Value = DBNull.Value
                });
                parameters.Add(new SqlParameter {
                    ParameterName = "@complexDataProperties", SqlDbType = SqlDbType.VarBinary, Value = DBNull.Value
                });
                parameters.Add(new SqlParameter {
                    ParameterName = "@writeOnlyPrimitiveDataProperties", SqlDbType = SqlDbType.VarBinary, Value = DBNull.Value
                });
                parameters.Add(new SqlParameter {
                    ParameterName = "@writeOnlyComplexDataProperties", SqlDbType = SqlDbType.VarBinary, Value = DBNull.Value
                });
                parameters.Add(new SqlParameter {
                    ParameterName = "@metadataProperties", SqlDbType = SqlDbType.VarBinary, Value = DBNull.Value
                });
                parameters.Add(new SqlParameter {
                    ParameterName = "@metadataIsConsistent", SqlDbType = SqlDbType.Bit, Value = DBNull.Value
                });
                parameters.Add(new SqlParameter {
                    ParameterName = "@encodingOption", SqlDbType = SqlDbType.TinyInt, Value = DBNull.Value
                });
                parameters.Add(new SqlParameter {
                    ParameterName = "@lastMachineRunOn", SqlDbType = SqlDbType.NVarChar, Value = DBNull.Value
                });
                parameters.Add(new SqlParameter {
                    ParameterName = "@executionStatus", SqlDbType = SqlDbType.NVarChar, Value = DBNull.Value
                });
                parameters.Add(new SqlParameter {
                    ParameterName = "@blockingBookmarks", SqlDbType = SqlDbType.NVarChar, Value = DBNull.Value
                });

                return;
            }

            List <CorrelationKey> keysToAssociate = CorrelationKey.BuildKeyList(saveWorkflowCommand.InstanceKeysToAssociate, base.Store.InstanceEncodingOption);
            List <CorrelationKey> keysToComplete  = CorrelationKey.BuildKeyList(saveWorkflowCommand.InstanceKeysToComplete);
            List <CorrelationKey> keysToFree      = CorrelationKey.BuildKeyList(saveWorkflowCommand.InstanceKeysToFree);

            ArraySegment <byte>[] dataProperties     = SerializationUtilities.SerializePropertyBag(saveWorkflowCommand.InstanceData, base.Store.InstanceEncodingOption);
            ArraySegment <byte>   metadataProperties = SerializationUtilities.SerializeMetadataPropertyBag(saveWorkflowCommand, base.InstancePersistenceContext, base.Store.InstanceEncodingOption);

            byte[] concatenatedKeyProperties = SerializationUtilities.CreateKeyBinaryBlob(keysToAssociate);
            bool   metadataConsistency       = (base.InstancePersistenceContext.InstanceView.InstanceMetadataConsistency == InstanceValueConsistency.None);
            bool   singleKeyToAssociate      = (keysToAssociate != null && keysToAssociate.Count == 1);

            parameters.Add(new SqlParameter {
                ParameterName = "@keysToAssociate", SqlDbType = SqlDbType.Xml, Value = singleKeyToAssociate ? DBNull.Value : SerializationUtilities.CreateCorrelationKeyXmlBlob(keysToAssociate)
            });
            parameters.Add(new SqlParameter {
                ParameterName = "@singleKeyId", SqlDbType = SqlDbType.UniqueIdentifier, Value = singleKeyToAssociate ? keysToAssociate[0].KeyId : (object)DBNull.Value
            });
            parameters.Add(new SqlParameter {
                ParameterName = "@keysToComplete", SqlDbType = SqlDbType.Xml, Value = SerializationUtilities.CreateCorrelationKeyXmlBlob(keysToComplete)
            });
            parameters.Add(new SqlParameter {
                ParameterName = "@keysToFree", SqlDbType = SqlDbType.Xml, Value = SerializationUtilities.CreateCorrelationKeyXmlBlob(keysToFree)
            });
            parameters.Add(new SqlParameter {
                ParameterName = "@concatenatedKeyProperties", SqlDbType = SqlDbType.VarBinary, Size = -1, Value = (object)concatenatedKeyProperties ?? DBNull.Value
            });
            parameters.Add(new SqlParameter {
                ParameterName = "@metadataIsConsistent", SqlDbType = SqlDbType.Bit, Value = metadataConsistency
            });
            parameters.Add(new SqlParameter {
                ParameterName = "@encodingOption", SqlDbType = SqlDbType.TinyInt, Value = base.Store.InstanceEncodingOption
            });
            parameters.Add(new SqlParameter {
                ParameterName = "@lastMachineRunOn", SqlDbType = SqlDbType.NVarChar, Size = 450, Value = SqlWorkflowInstanceStoreConstants.MachineName
            });
            parameters.Add(new SqlParameter {
                ParameterName = "@executionStatus", SqlDbType = SqlDbType.NVarChar, Size = 450, Value = GetExecutionStatus(saveWorkflowCommand) ?? (object)DBNull.Value
            });
            parameters.Add(new SqlParameter {
                ParameterName = "@blockingBookmarks", SqlDbType = SqlDbType.NVarChar, Size = -1, Value = GetBlockingBookmarks(saveWorkflowCommand) ?? (object)DBNull.Value
            });

            ArraySegment <byte>[] properties = { dataProperties[0], dataProperties[1], dataProperties[2], dataProperties[3], metadataProperties };
            string[] dataPropertyParameters  = { "@primitiveDataProperties", "@complexDataProperties", "@writeOnlyPrimitiveDataProperties", @"writeOnlyComplexDataProperties", "@metadataProperties" };

            for (int i = 0; i < 5; i++)
            {
                SaveWorkflowAsyncResult.AddSerializedProperty(properties[i], parameters, dataPropertyParameters[i]);
            }

            this.SerializePromotedProperties(parameters, commandTextBuilder, saveWorkflowCommand);
        }