Esempio n. 1
0
        //public IList<WorkflowChangeAction> Diff(object originalDefinition, object changedDefinition)
        //{
        //    RuleDefinitions originalRules = originalDefinition as RuleDefinitions;
        //    RuleDefinitions changedRules = changedDefinition as RuleDefinitions;
        //    if ((originalRules == null) || (changedRules == null))
        //        return new List<WorkflowChangeAction>();

        //    IList<WorkflowChangeAction> cdiff = Conditions.Diff(originalRules.Conditions, changedRules.Conditions);
        //    IList<WorkflowChangeAction> rdiff = RuleSets.Diff(originalRules.RuleSets, changedRules.RuleSets);

        //    // quick optimization -- if no condition changes, simply return the ruleset changes
        //    if (cdiff.Count == 0)
        //        return rdiff;

        //    // merge ruleset changes into condition changes
        //    for (int i = 0; i < rdiff.Count; ++i)
        //    {
        //        cdiff.Add(rdiff[i]);
        //    }
        //    return cdiff;
        //}
        #endregion

        internal RuleDefinitions Clone()
        {
            RuleDefinitions newRuleDefinitions = new RuleDefinitions();

            if (this.ruleSets != null)
            {
                newRuleDefinitions.ruleSets = new RuleSetCollection();
                foreach (RuleSet r in this.ruleSets)
                {
                    newRuleDefinitions.ruleSets.Add(r.Clone());
                }
            }

            if (this.conditions != null)
            {
                newRuleDefinitions.conditions = new RuleConditionCollection();
                foreach (RuleCondition r in this.conditions)
                {
                    newRuleDefinitions.conditions.Add(r.Clone());
                }
            }

            return(newRuleDefinitions);
        }
Esempio n. 2
0
        internal static RuleDefinitions GetRuleDefinitionsFromManifest(Type workflowType)
        {
            if (workflowType == null)
            {
                throw new ArgumentNullException("workflowType");
            }

            RuleDefinitions rules = null;

            if (cloneableOrNullRulesResources.ContainsKey(workflowType))
            {
                rules = (RuleDefinitions)cloneableOrNullRulesResources[workflowType];
                if (rules != null)
                {
                    // This should always succeed, since it is coming out of the cloneable cache
                    rules = rules.Clone();
                }
            }
            else
            {
                string resourceName = workflowType.Name + ".rules";
                Stream stream       = workflowType.Module.Assembly.GetManifestResourceStream(workflowType, resourceName);

                // Try just the .rules file name. This is needed for wfc.exe compilation scenarios.
                if (stream == null)
                {
                    stream = workflowType.Module.Assembly.GetManifestResourceStream(resourceName);
                }

                if (stream != null)
                {
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        using (XmlReader xmlReader = XmlReader.Create(reader))
                            rules = new WorkflowMarkupSerializer().Deserialize(xmlReader) as RuleDefinitions;
                    }
                }
                // Don't know yet whether 'rules' is cloneable, give it a try
                if (!uncloneableRulesResources.ContainsKey(workflowType))
                {
                    try
                    {
                        RuleDefinitions originalRules = rules;
                        if (rules != null)
                        {
                            rules = rules.Clone();
                        }
                        lock (cloneableOrNullRulesResources)
                        {
                            cloneableOrNullRulesResources[workflowType] = originalRules;
                        }
                    }
                    catch (Exception)
                    {
                        lock (uncloneableRulesResources)
                        {
                            uncloneableRulesResources[workflowType] = null;
                        }
                    }
                }
            }
            return(rules);
        }