Пример #1
0
        /// <summary>
        /// Returns the cached FileTransformSpec corresponding to the name if it exists.
        /// Otherwise, creates it, caches it, then returns it.
        /// </summary>
        /// <param name="qualifiedName">Must correspond to the wualified name of the XSLT file, which must be an embedded resource.
        /// Example: TDSQASystemAPI.Resources.ItemScoreRequest.xslt</param>
        /// <param name="validate">If true, there must be an embedded resource in name namespace called [qualifiedName].xsd.</param>
        /// <returns></returns>
        public static FileTransformSpec Create(string qualifiedName, bool validate)
        {
            if (String.IsNullOrEmpty(qualifiedName))
            {
                return(null);
            }

            if (!fileTransformSpecs.ContainsKey(qualifiedName))
            {
                lock (lockme)
                {
                    if (!fileTransformSpecs.ContainsKey(qualifiedName))
                    {
                        FileTransformSpec    spec = Create(qualifiedName);
                        DAL.EmbeddedResource embeddedResourceDAL = new DAL.EmbeddedResource();
                        // load the compiled xslt
                        XslCompiledTransform xform = new XslCompiledTransform(true);
                        using (Stream xsltStream = embeddedResourceDAL.GetEmbeddedResourceAsStream(qualifiedName))
                        {
                            XmlReader rdr = new XmlTextReader(xsltStream);
                            xform.Load(rdr);
                        }
                        spec.XsltTransform = xform;

                        if (validate)
                        {
                            // load the XSD schema
                            XmlSchemaSet schemaSet = new XmlSchemaSet();
                            using (XmlReader r = embeddedResourceDAL.GetEmbeddedResourceAsXmlReader(qualifiedName.Replace(".xslt", ".xsd").Replace(".XSLT", ".XSD")))
                            {
                                schemaSet.Add(null, r);
                            }
                            spec.SchemaSet = schemaSet;
                        }

                        fileTransformSpecs[qualifiedName] = spec;
                    }
                }
            }
            return(fileTransformSpecs[qualifiedName]);
        }
Пример #2
0
 public RESTTarget(string targetName, TargetClass targetClass, TargetType type, XMLAdapter.AdapterType xmlVersion, FileTransformSpec transformSpec)
     : base(targetName, targetClass, type, xmlVersion, transformSpec)
 {
 }
Пример #3
0
        private static Target Create(int projectID, string targetName)
        {
            TargetClass targetClass;

            if (!Enum.TryParse <TargetClass>(targetName, true, out targetClass))
            {
                // handscoring targets must have GroupName thats starts with Handscoring (case-insensitive)
                if (targetName.StartsWith("Handscoring", StringComparison.InvariantCultureIgnoreCase))
                {
                    targetClass = TargetClass.Handscoring;
                }
                else
                {
                    targetClass = TargetClass.General;
                }
            }

            MetaDataEntry e = ServiceLocator.Resolve <ConfigurationHolder>().GetFromMetaData(projectID, targetName, Variables.TargetType.ToString());

            TargetType type;

            if (e == null || !Enum.TryParse <TargetType>(e.TextVal ?? "", true, out type))
            {
                type = TargetType.Custom;
            }

            e = ServiceLocator.Resolve <ConfigurationHolder>().GetFromMetaData(projectID, targetName, Variables.XMLVersion.ToString());
            XMLAdapter.AdapterType xmlVersion;
            if (e == null || !Enum.TryParse <XMLAdapter.AdapterType>(e.TextVal, true, out xmlVersion))
            {
                xmlVersion = XMLAdapter.AdapterType.TDS; // default to proprietary
            }
            // if a transform is configured, load it
            FileTransformSpec transformSpec = null;

            e = ServiceLocator.Resolve <ConfigurationHolder>().GetFromMetaData(projectID, targetName, Variables.Transform.ToString());
            if (e != null)
            {
                string xsltName          = e.TextVal;
                bool   validateTransform = Convert.ToBoolean(e.IntVal); // int val can be used to enforce validation.  Default = 0/false.
                transformSpec = FileTransformSpec.Create(xsltName, validateTransform);
            }

            Target t = null;

            ITargetFactory f = ServiceLocator.Resolve <ITargetFactory>();

            if (f == null)
            {
                throw new QAException("There is no ITargetFactory in the service repository.", QAException.ExceptionType.ConfigurationError);
            }
            t = f.Create(targetName, targetClass, type, xmlVersion, transformSpec);
            if (t == null)
            {
                throw new QAException(String.Format("Could not create Target: {0}", targetName), QAException.ExceptionType.ConfigurationError);
            }

            t.CreateDate = DateTime.Now;

            return(t);
        }
Пример #4
0
 protected Target(string targetName, TargetClass targetClass, TargetType type, XMLAdapter.AdapterType xmlVersion, FileTransformSpec transformSpec)
     : this(targetName, targetClass, type, xmlVersion, transformSpec, new NoFileTransformArgs())
 {
 }
Пример #5
0
 protected Target(string targetName, TargetClass targetClass, TargetType type, XMLAdapter.AdapterType xmlVersion, FileTransformSpec transformSpec, IFileTransformArgs transformArgs)
 {
     this.Name          = targetName;
     this.Type          = type;
     this.Class         = targetClass;
     this.XmlVersion    = xmlVersion;
     this.TransformSpec = transformSpec;
     this.TransformArgs = transformArgs ?? new NoFileTransformArgs();
 }
Пример #6
0
 public RESTMultipartTarget(string targetName, TargetClass targetClass, TargetType type, XMLAdapter.AdapterType xmlVersion, FileTransformSpec transformSpec, IFileTransformArgs transformArgs)
     : base(targetName, targetClass, type, xmlVersion, transformSpec, transformArgs)
 {
 }