Ejemplo n.º 1
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);
        }