internal DurableInstanceManager(WorkflowServiceHost host)
 {
     this.DurableInstancingOptions = new System.ServiceModel.Activities.DurableInstancingOptions(this);
     this.createOwnerCommand = new CreateWorkflowOwnerCommand();
     this.instanceMetadataChanges = new Dictionary<XName, InstanceValue>();
     this.thisLock = new object();
     InstanceValue value2 = new InstanceValue(XNamespace.Get("http://tempuri.org").GetName("Sentinel"));
     this.createOwnerCommand.InstanceOwnerMetadata.Add(WorkflowNamespace.WorkflowHostType, value2);
     this.instanceMetadataChanges.Add(WorkflowNamespace.WorkflowHostType, value2);
     this.instanceMetadataChanges.Add(PersistenceMetadataNamespace.InstanceType, new InstanceValue(WorkflowNamespace.WorkflowHostType, InstanceValueOptions.WriteOnly));
     this.Host = host;
 }
        internal DurableInstanceManager(WorkflowServiceHost host)
        {
            DurableInstancingOptions = new DurableInstancingOptions(this);
            this.instanceOwnerMetadata = new Dictionary<XName, InstanceValue>();
            this.instanceMetadataChanges = new Dictionary<XName, InstanceValue>();
            this.thisLock = new object();

            // This is for collision detection.  Will replace with the real service name prior to executing.
            InstanceValue sentinel = new InstanceValue(XNamespace.Get("http://tempuri.org").GetName("Sentinel"));
            this.instanceOwnerMetadata.Add(WorkflowNamespace.WorkflowHostType, sentinel);
            this.instanceMetadataChanges.Add(WorkflowNamespace.WorkflowHostType, sentinel);
            this.instanceMetadataChanges.Add(PersistenceMetadataNamespace.InstanceType, new InstanceValue(WorkflowNamespace.WorkflowHostType, InstanceValueOptions.WriteOnly));

            this.Host = host;
        }
예제 #3
0
        static InstanceStore CreateInstanceStore()
        {
            string connectionString = ConfigurationManager.ConnectionStrings["InstanceStore"].ConnectionString;
            var instanceStore = new SqlWorkflowInstanceStore(connectionString);
            var instanceHandle = instanceStore.CreateInstanceHandle();
            var ownerCommand = new CreateWorkflowOwnerCommand();
            XNamespace hostNamespace = XNamespace.Get("urn:schemas-microsoft-com:System.Activities/4.0/properties");
            XName hostKey = hostNamespace.GetName("WorkflowHostType");
            var hostValue = new InstanceValue(XNamespace.Get("http://tempuri.org").GetName("SampleInstance"));
            ownerCommand.InstanceOwnerMetadata.Add(hostKey, hostValue);
            instanceStore.DefaultInstanceOwner = instanceStore.Execute(
                               instanceHandle,
                               ownerCommand,
                               TimeSpan.FromSeconds(30)).InstanceOwner;
            instanceHandle.Free();

            return instanceStore;
        }
 public static bool IsPropertyTypeSqlVariantCompatible(InstanceValue value)
 {
     if ((value.IsDeletedValue) ||
         (value.Value == null) ||
         (value.Value is string && ((string)value.Value).Length <= 4000) ||
         (value.Value is Guid) ||
         (value.Value is DateTime) ||
         (value.Value is int) ||
         (value.Value is double) ||
         (value.Value is float) ||
         (value.Value is long) ||
         (value.Value is short) ||
         (value.Value is byte) ||
         (value.Value is decimal && CanDecimalBeStoredAsSqlVariant((decimal)value.Value)))
     {
         return true;
     }
     else
     {
         return false;
     }
 }
예제 #5
0
 public static bool IsWriteOnly(this InstanceValue value)
 {
     return((value.Options & InstanceValueOptions.WriteOnly) != 0);
 }
예제 #6
0
 public static bool IsOptional(this InstanceValue value)
 {
     return((value.Options & InstanceValueOptions.Optional) != 0);
 }
 private void LoadSingleEntry(NetDataContractSerializer serializer, IDictionary<XName, InstanceValue> instanceData, XElement entry)
 {
     XName key =
         (XName)Deserialize(serializer, entry.Element("Key"));
     Object value =
         Deserialize(serializer, entry.Element("Value"));
     InstanceValue iv = new InstanceValue(value);
     InstanceValueOptions options =
         (InstanceValueOptions)Deserialize(
             serializer, entry.Element("Options"));
     if(!options.HasFlag(InstanceValueOptions.WriteOnly))
     {
         instanceData.Add(key, iv);
     }
 }
예제 #8
0
		public void WroteInstanceKeyMetadataValue (Guid key, XName name, InstanceValue value)
		{
			throw new NotImplementedException ();
		}
예제 #9
0
 public void WroteInstanceOwnerMetadataValue(XName name, InstanceValue value)
 {
     throw new NotImplementedException();
 }
        public void WroteInstanceOwnerMetadataValue(XName name, InstanceValue value)
        {
            if (name == null)
            {
                throw Fx.Exception.ArgumentNull("name");
            }
            if (value == null)
            {
                throw Fx.Exception.ArgumentNull("value");
            }
            ThrowIfNoOwner();
            ThrowIfNotTransactional("WroteInstanceOwnerMetadataValue");

            InstanceView.AccumulatedOwnerMetadataWrites.Add(name, value);
        }
        public void WroteInstanceMetadataValue(XName name, InstanceValue value)
        {
            if (name == null)
            {
                throw Fx.Exception.ArgumentNull("name");
            }
            if (value == null)
            {
                throw Fx.Exception.ArgumentNull("value");
            }
            ThrowIfNotLocked();
            ThrowIfCompleted();
            ThrowIfNotTransactional("WroteInstanceMetadataValue");

            InstanceView.AccumulatedMetadataWrites[name] = value;
        }
 public SerializableInstanceValue(InstanceValue instanceValue)
 {
     this.value = instanceValue.Value;
     this.options = (int)instanceValue.Options;
 }
        //Reads data from xml file and creates a dictionary based off of that.
        IDictionary<XName, InstanceValue> LoadInstanceDataFromFile(Stream inputStream)
        {
            IDictionary<XName, InstanceValue> data = new Dictionary<XName, InstanceValue>();

            NetDataContractSerializer s = new NetDataContractSerializer();

            XmlReader rdr = XmlReader.Create(inputStream);
            XmlDocument doc = new XmlDocument();
            doc.Load(rdr);

            XmlNodeList instances = doc.GetElementsByTagName("InstanceValue");
            foreach (XmlElement instanceElement in instances)
            {
                XmlElement keyElement = (XmlElement)instanceElement.SelectSingleNode("descendant::key");
                XName key = (XName)DeserializeObject(s, keyElement);

                XmlElement valueElement = (XmlElement)instanceElement.SelectSingleNode("descendant::value");
                object value = DeserializeObject(s, valueElement);
                InstanceValue instVal = new InstanceValue(value);

                data.Add(key, instVal);
            }

            return data;
        }
        /// <summary>
        /// The deserialize data.
        /// </summary>
        /// <param name="payload">The payload.</param>
        /// <returns>The <see cref="IDictionary" />.</returns>
        private static IDictionary<XName, InstanceValue> DeserializeData(string payload)
        {
            var xmlDocument = new XmlDocument();
            xmlDocument.LoadXml(payload);
            IDictionary<XName, InstanceValue> data = new Dictionary<XName, InstanceValue>();
            var netDataContractSerializer = new NetDataContractSerializer();
            var instances = xmlDocument.GetElementsByTagName("InstanceValue");
            foreach (XmlElement instanceElement in instances)
            {
                var keyElement = (XmlElement)instanceElement.SelectSingleNode("descendant::key");
                var key = (XName)DeserializeObject(netDataContractSerializer, keyElement);
                var valueElement = (XmlElement)instanceElement.SelectSingleNode("descendant::value");
                var value = DeserializeObject(netDataContractSerializer, valueElement);
                var instVal = new InstanceValue(value);
                data.Add(key, instVal);
            }

            return data;
        }
 private Dictionary<XName, InstanceValue> GeneratePersistenceData()
 {
     Dictionary<XName, InstanceValue> dictionary = new Dictionary<XName, InstanceValue>(10);
     dictionary[WorkflowNamespace.Bookmarks] = new InstanceValue(base.Controller.GetBookmarks(), InstanceValueOptions.WriteOnly | InstanceValueOptions.Optional);
     dictionary[WorkflowNamespace.LastUpdate] = new InstanceValue(DateTime.UtcNow, InstanceValueOptions.WriteOnly | InstanceValueOptions.Optional);
     foreach (KeyValuePair<string, LocationInfo> pair in base.Controller.GetMappedVariables())
     {
         XName name = WorkflowNamespace.VariablesPath.GetName(pair.Key);
         dictionary[name] = new InstanceValue(pair.Value, InstanceValueOptions.WriteOnly | InstanceValueOptions.Optional);
     }
     Fx.AssertAndThrow(base.Controller.State != WorkflowInstanceState.Aborted, "Cannot generate data for an aborted service instance.");
     if (base.Controller.State != WorkflowInstanceState.Complete)
     {
         dictionary[WorkflowNamespace.Workflow] = new InstanceValue(base.Controller.PrepareForSerialization());
         if (this.creationContext != null)
         {
             dictionary[WorkflowServiceNamespace.CreationContext] = new InstanceValue(this.creationContext);
         }
         dictionary[WorkflowNamespace.Status] = new InstanceValue((base.Controller.State == WorkflowInstanceState.Idle) ? "Idle" : "Executing", InstanceValueOptions.WriteOnly);
         return dictionary;
     }
     dictionary[WorkflowNamespace.Workflow] = new InstanceValue(base.Controller.PrepareForSerialization(), InstanceValueOptions.Optional);
     this.GetCompletionState();
     if (this.completionState == ActivityInstanceState.Faulted)
     {
         dictionary[WorkflowNamespace.Status] = new InstanceValue("Faulted", InstanceValueOptions.WriteOnly);
         dictionary[WorkflowNamespace.Exception] = new InstanceValue(this.terminationException, InstanceValueOptions.WriteOnly | InstanceValueOptions.Optional);
         return dictionary;
     }
     if (this.completionState == ActivityInstanceState.Closed)
     {
         dictionary[WorkflowNamespace.Status] = new InstanceValue("Closed", InstanceValueOptions.WriteOnly);
         if (this.workflowOutputs != null)
         {
             foreach (KeyValuePair<string, object> pair2 in this.workflowOutputs)
             {
                 XName introduced13 = WorkflowNamespace.OutputPath.GetName(pair2.Key);
                 dictionary[introduced13] = new InstanceValue(pair2.Value, InstanceValueOptions.WriteOnly | InstanceValueOptions.Optional);
             }
         }
         return dictionary;
     }
     Fx.AssertAndThrow(this.completionState == ActivityInstanceState.Canceled, "Cannot be executing a service instance when WorkflowState was completed.");
     dictionary[WorkflowNamespace.Status] = new InstanceValue("Canceled", InstanceValueOptions.WriteOnly);
     return dictionary;
 }
 static InstanceValue()
 {
     DeletedValue       = new InstanceValue(null);
     DeletedValue.Value = DeletedValue; // recursion!
 }
 public static bool IsPropertyTypeSqlVariantCompatible(InstanceValue value)
 {
     if (((!value.IsDeletedValue && (value.Value != null)) && (!(value.Value is string) || (((string) value.Value).Length > 0xfa0))) && (((!(value.Value is Guid) && !(value.Value is DateTime)) && (!(value.Value is int) && !(value.Value is double))) && ((!(value.Value is float) && !(value.Value is long)) && ((!(value.Value is short) && !(value.Value is byte)) && (!(value.Value is decimal) || !CanDecimalBeStoredAsSqlVariant((decimal) value.Value))))))
     {
         return false;
     }
     return true;
 }
        public void WroteInstanceKeyMetadataValue(Guid key, XName name, InstanceValue value)
        {
            if (key == Guid.Empty)
            {
                throw Fx.Exception.Argument("key", SRCore.InvalidKeyArgument);
            }
            if (name == null)
            {
                throw Fx.Exception.ArgumentNull("name");
            }
            if (value == null)
            {
                throw Fx.Exception.ArgumentNull("value");
            }
            ThrowIfNotLocked();
            ThrowIfCompleted();
            ThrowIfNotTransactional("WroteInstanceKeyMetadataValue");

            InstanceKeyView keyView;
            if (!InstanceView.InstanceKeys.TryGetValue(key, out keyView))
            {
                if (InstanceView.InstanceKeysConsistency == InstanceValueConsistency.None)
                {
                    throw Fx.Exception.AsError(new InvalidOperationException(SRCore.KeyNotAssociated));
                }

                if (!value.IsWriteOnly() && !value.IsDeletedValue)
                {
                    Dictionary<Guid, InstanceKeyView> copy = new Dictionary<Guid, InstanceKeyView>(InstanceView.InstanceKeys);
                    keyView = new InstanceKeyView(key);
                    keyView.AccumulatedMetadataWrites.Add(name, value);
                    keyView.InstanceKeyMetadataConsistency = InstanceValueConsistency.Partial;
                    copy[keyView.InstanceKey] = keyView;
                    InstanceView.InstanceKeys = new ReadOnlyDictionaryInternal<Guid, InstanceKeyView>(copy);
                    InstanceView.InstanceKeysConsistency |= InstanceValueConsistency.Partial;
                }
            }
            else
            {
                keyView.AccumulatedMetadataWrites.Add(name, value);
            }
        }
 public void WroteInstanceKeyMetadataValue(Guid key, XName name, InstanceValue value)
 {
     InstanceKeyView view;
     if (key == Guid.Empty)
     {
         throw Fx.Exception.Argument("key", SRCore.InvalidKeyArgument);
     }
     if (name == null)
     {
         throw Fx.Exception.ArgumentNull("name");
     }
     if (value == null)
     {
         throw Fx.Exception.ArgumentNull("value");
     }
     this.ThrowIfNotLocked();
     this.ThrowIfCompleted();
     this.ThrowIfNotTransactional("WroteInstanceKeyMetadataValue");
     if (!this.InstanceView.InstanceKeys.TryGetValue(key, out view))
     {
         if (this.InstanceView.InstanceKeysConsistency == InstanceValueConsistency.None)
         {
             throw Fx.Exception.AsError(new InvalidOperationException(SRCore.KeyNotAssociated));
         }
         if (!value.IsWriteOnly() && !value.IsDeletedValue)
         {
             Dictionary<Guid, InstanceKeyView> dictionary = new Dictionary<Guid, InstanceKeyView>(this.InstanceView.InstanceKeys);
             view = new InstanceKeyView(key);
             view.AccumulatedMetadataWrites.Add(name, value);
             view.InstanceKeyMetadataConsistency = InstanceValueConsistency.Partial;
             dictionary[view.InstanceKey] = view;
             this.InstanceView.InstanceKeys = new ReadOnlyDictionary<Guid, InstanceKeyView>(dictionary, false);
             System.Runtime.DurableInstancing.InstanceView instanceView = this.InstanceView;
             instanceView.InstanceKeysConsistency |= InstanceValueConsistency.Partial;
         }
     }
     else
     {
         view.AccumulatedMetadataWrites.Add(name, value);
     }
 }
예제 #20
0
 public void WroteInstanceKeyMetadataValue(Guid key, XName name, InstanceValue value)
 {
     throw new NotImplementedException();
 }
예제 #21
0
        //Reads data from xml file and creates a dictionary based off of that.
        static IDictionary<XName, InstanceValue> LoadInstanceDataFromFile(Stream inputStream)
        {
            IDictionary<XName, InstanceValue> data = new Dictionary<XName, InstanceValue>();

            var serializer = new NetDataContractSerializer();

            using (var xmlReader = XmlReader.Create(inputStream))
            {
                var doc = new XmlDocument();
                doc.Load(xmlReader);

                var instances = doc.GetElementsByTagName("InstanceValue");
                foreach (XmlElement instanceElement in instances)
                {
                    var keyElement = (XmlElement)instanceElement.SelectSingleNode("descendant::key");
                    var key = (XName)DeserializeObject(serializer, keyElement);

                    var valueElement = (XmlElement)instanceElement.SelectSingleNode("descendant::value");
                    var value = DeserializeObject(serializer, valueElement);
                    var instVal = new InstanceValue(value);

                    data.Add(key, instVal);
                }
            }

            return data;
        }
예제 #22
0
		static InstanceValue ()
		{
			DeletedValue = new InstanceValue (null);
			DeletedValue.Value = DeletedValue; // recursion!
		}
예제 #23
0
		public void WroteInstanceOwnerMetadataValue (XName name, InstanceValue value)
		{
			throw new NotImplementedException ();
		}