Example #1
0
        ///////////////////////////////////////////////////////////////////////

        private static IScript PrivateCreate(
            Guid id,
            string name,
            string group,
            string description,
            string type,
            string text,
            string fileName,
            int startLine,
            int endLine,
            bool viaSource,
#if XML
            XmlBlockType blockType,
            DateTime timeStamp,
            string publicKeyToken,
            byte[] signature,
#endif
            EngineMode engineMode,
            ScriptFlags scriptFlags,
            EngineFlags engineFlags,
            SubstitutionFlags substitutionFlags,
            EventFlags eventFlags,
            ExpressionFlags expressionFlags,
            IClientData clientData
            )
        {
            return(new Script(
                       id, name, group, description, type, text, fileName,
                       startLine, endLine, viaSource,
#if XML
                       blockType, timeStamp, publicKeyToken, signature,
#endif
#if CAS_POLICY
                       DefaultEvidence,
                       DefaultHashValue,
                       DefaultHashAlgorithm,
#endif
                       engineMode, scriptFlags, engineFlags, substitutionFlags,
                       eventFlags, expressionFlags, clientData));
        }
Example #2
0
        ///////////////////////////////////////////////////////////////////////

        #region Private Constructors
        private Script(
            Guid id,
            string name,
            string group,
            string description,
            string type,
            string text,
            string fileName,
            int startLine,
            int endLine,
            bool viaSource,
#if XML
            XmlBlockType blockType,
            DateTime timeStamp,
            string publicKeyToken,
            byte[] signature,
#endif
#if CAS_POLICY
            Evidence evidence,
            byte[] hashValue,
            HashAlgorithm hashAlgorithm,
#endif
            EngineMode engineMode,
            ScriptFlags scriptFlags,
            EngineFlags engineFlags,
            SubstitutionFlags substitutionFlags,
            EventFlags eventFlags,
            ExpressionFlags expressionFlags,
            IClientData clientData
            )
        {
            this.kind        = IdentifierKind.Script;
            this.id          = id;
            this.name        = name;
            this.group       = group;
            this.description = description;
            this.type        = type;
            this.parts       = null; /* TODO: If we ever support scripts with multiple
                                      *       parts, change this to be a formal argument
                                      *       to this constructor and remove text? */
            this.text        = text;
            this.fileName    = fileName;
            this.startLine   = startLine;
            this.endLine     = endLine;
            this.viaSource   = viaSource;

#if XML
            this.blockType      = blockType;
            this.timeStamp      = timeStamp;
            this.publicKeyToken = publicKeyToken;
            this.signature      = signature;
#endif

#if CAS_POLICY
            this.evidence      = evidence;
            this.hashValue     = hashValue;
            this.hashAlgorithm = hashAlgorithm;
#endif

            this.engineMode        = engineMode;
            this.scriptFlags       = scriptFlags;
            this.engineFlags       = engineFlags;
            this.substitutionFlags = substitutionFlags;
            this.expressionFlags   = expressionFlags;
            this.eventFlags        = eventFlags;
            this.clientData        = clientData;
        }
Example #3
0
        ///////////////////////////////////////////////////////////////////////

#if XML
        /* INTERNAL STATIC OK */
        internal static IScript CreateFromXmlNode( /* NOTE: Engine use only. */
            string type,
            XmlNode node,
            EngineMode engineMode,
            ScriptFlags scriptFlags,
            EngineFlags engineFlags,
            SubstitutionFlags substitutionFlags,
            EventFlags eventFlags,
            ExpressionFlags expressionFlags,
            IClientData clientData,
            ref Result error
            )
        {
            try
            {
                XmlElement element = node as XmlElement;

                if (element != null)
                {
                    foreach (string attribute in _XmlAttribute.RequiredList)
                    {
                        if ((attribute != null) && !element.HasAttribute(attribute))
                        {
                            error = String.Format(
                                "missing required attribute \"{0}\"",
                                attribute);

                            return(null);
                        }
                    }

                    /* REQUIRED */
                    Guid id = element.HasAttribute(_XmlAttribute.Id) ?
                              new Guid(element.GetAttribute(_XmlAttribute.Id)) : Guid.Empty;

                    /* REQUIRED */
                    XmlBlockType blockType = element.HasAttribute(_XmlAttribute.Type) ?
                                             (XmlBlockType)Enum.Parse(typeof(XmlBlockType),
                                                                      element.GetAttribute(_XmlAttribute.Type), true) :
                                             XmlBlockType.None;

                    /* REQUIRED */
                    string text = element.InnerText;

                    /* OPTIONAL */
                    string name = element.HasAttribute(_XmlAttribute.Name) ?
                                  element.GetAttribute(_XmlAttribute.Name) : null;

                    /* OPTIONAL */
                    string group = element.HasAttribute(_XmlAttribute.Group) ?
                                   element.GetAttribute(_XmlAttribute.Group) : null;

                    /* OPTIONAL */
                    string description = element.HasAttribute(_XmlAttribute.Description) ?
                                         element.GetAttribute(_XmlAttribute.Description) : null;

                    /* OPTIONAL */
                    DateTime timeStamp = element.HasAttribute(_XmlAttribute.TimeStamp) ?
                                         DateTime.Parse(element.GetAttribute(_XmlAttribute.TimeStamp)).ToUniversalTime() :
                                         DateTime.MinValue;

                    /* OPTIONAL */
                    string publicKeyToken = element.HasAttribute(_XmlAttribute.PublicKeyToken) ?
                                            element.GetAttribute(_XmlAttribute.PublicKeyToken) : null;

                    /* OPTIONAL */
                    byte[] signature = element.HasAttribute(_XmlAttribute.Signature) ?
                                       Convert.FromBase64String(
                        element.GetAttribute(_XmlAttribute.Signature)) : null;

                    //
                    // NOTE: Create the script using the values extracted from the XML element.
                    //
                    return(PrivateCreate(
                               id, name, group, description, type, text, null, Parser.UnknownLine,
                               Parser.UnknownLine, false, blockType, timeStamp, publicKeyToken,
                               signature, engineMode, scriptFlags, engineFlags, substitutionFlags,
                               eventFlags, expressionFlags, clientData));
                }
                else
                {
                    error = "xml node is not an element";
                }
            }
            catch (Exception e)
            {
                error = e;
            }

            return(null);
        }