Ejemplo n.º 1
0
        private void Init()
        {
            try {
                string basepath = System.Reflection.Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", "").Replace("/", @"\");
                basepath = System.IO.Path.GetDirectoryName(basepath) + @"\";

                GameCatalogSerializer  gcs = new GameCatalogSerializer();
                System.Xml.XmlDocument doc = gcs.Serialize(games);

                System.Xml.XPath.XPathNavigator nav    = doc.CreateNavigator();
                System.Xml.Xsl.XslTransform     xt     = new System.Xml.Xsl.XslTransform();
                System.Xml.XmlResolver          res    = new System.Xml.XmlUrlResolver();
                System.IO.StringWriter          writer = new System.IO.StringWriter();
                System.Xml.Xsl.XsltArgumentList args   = new System.Xml.Xsl.XsltArgumentList();

                System.Xml.XmlNameTable xnt  = new System.Xml.NameTable();
                System.Xml.XmlReader    xslt = new System.Xml.XmlTextReader(new System.IO.StreamReader(basepath + "GameList.xslt"), xnt);

                xt.Load(xslt, res, new System.Security.Policy.Evidence());
                xt.Transform(nav, args, writer, res);

                string html = writer.ToString();

                WriteHTML(html);
            } catch (Exception ex) {
                string    error = "There was an error generating HTML";
                Exception xe    = ex;
                while (xe != null)
                {
                    error += "<p><b>" + xe.Message + "</b><br><pre>" + xe.StackTrace + "</pre></p>\r\n";
                }
                WriteHTML(error);
            }
        }
 internal static void Preprocess(XmlSchema schema)
 {
     if (!schema.IsPreprocessed)
     {
         try {
             XmlNameTable nameTable = new System.Xml.NameTable();
             Preprocessor prep      = new Preprocessor(nameTable, new SchemaNames(nameTable), null);
             prep.SchemaLocations = new Hashtable();
             prep.Execute(schema, schema.TargetNamespace, false);
         }
         catch (XmlSchemaException e) {
             throw CreateValidationException(e, e.Message);
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Validates the given XML document.
        /// </summary>
        /// <param name="input">XML document as stream.</param>
        /// <param name="ser">Serialiser.</param>
        /// <exception cref="InvalidOperationException">Thrown if the document is invalid.</exception>
        public void Validate(System.IO.Stream input, Type type)
        {
            var settings = GetSettings();

            // Adding the event handler of this object
            settings.ValidationEventHandler += Settings_ValidationEventHandler;

            // Clearing validation messages
            m_validationMessages.Clear();

            // Out of the box, XLink attributes have not worked as they should.
            // They exist as default attributes in some places (have forgotten if
            // this is in the XML schemata or added manually in MessageSerialiser).
            // Anyway, because XLink attributes come from a namespace unknown to the parser,
            // there must be a namespace manager to explicitly declare the XLink namespace.
            var nametable    = new System.Xml.NameTable();
            var xmlNsManager = new System.Xml.XmlNamespaceManager(nametable);

            xmlNsManager.AddNamespace("xlink", "http://www.w3.org/1999/xlink");

            // This context object is mandatory to pass the namespace manager to the parser.
            var parserContext = new System.Xml.XmlParserContext(null, xmlNsManager, null, System.Xml.XmlSpace.None);

            using (var reader = System.Xml.XmlReader.Create(input, settings, parserContext))
            {
                // Deserialising the document
                var serializer = new System.Xml.Serialization.XmlSerializer(type);
                serializer.Deserialize(reader);
            }

            // Removing the event handler of this object (this would
            // otherwise cause conflicts when multiple documents are validated)
            settings.ValidationEventHandler -= Settings_ValidationEventHandler;

            if (m_validationMessages.Count > 0)
            {
                var msg = string.Format("The XML document has {0} errors. First error: {1}", m_validationMessages.Count, m_validationMessages[0]);
                throw new InvalidOperationException(msg);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Validates the given XML document.
        /// </summary>
        /// <param name="input">XML document as stream.</param>
        /// <param name="ser">Serialiser.</param>
        /// <exception cref="InvalidOperationException">Thrown if the document is invalid.</exception>
        public void Validate(System.IO.Stream input, Type type)
        {
            var settings = GetSettings();

            // Adding the event handler of this object
            settings.ValidationEventHandler += Settings_ValidationEventHandler;

            // Clearing validation messages
            m_validationMessages.Clear();

            // Declaring a prefix for the XLink namespace explicitly.
            // This is necessary to support scheduling parameters of type
            // Item_DataRecord from the library "Cocop.MessageSerialiser.Meas".
            var nametable    = new System.Xml.NameTable();
            var xmlNsManager = new System.Xml.XmlNamespaceManager(nametable);

            xmlNsManager.AddNamespace("xlink", "http://www.w3.org/1999/xlink");

            // Declaring a context object to pass the namespace manager to the parser
            var parserContext = new System.Xml.XmlParserContext(null, xmlNsManager, null, System.Xml.XmlSpace.None);

            using (var reader = System.Xml.XmlReader.Create(input, settings, parserContext))
            {
                // Deserialising the document
                var serializer = new System.Xml.Serialization.XmlSerializer(type);
                serializer.Deserialize(reader);
            }

            // Removing the event handler of this object (the event handler would
            // otherwise cause conflicts when multiple documents are validated)
            settings.ValidationEventHandler -= Settings_ValidationEventHandler;

            if (m_validationMessages.Count > 0)
            {
                var msg = string.Format("The XML document has {0} errors. First error: {1}", m_validationMessages.Count, m_validationMessages[0]);
                throw new InvalidOperationException(msg);
            }
        }
Ejemplo n.º 5
0
        private System.Xml.XmlNamespaceManager GetNamespaceManager()
        {
            System.Xml.NameTable           nt               = new System.Xml.NameTable();
            System.Xml.XmlNamespaceManager mgr              = new System.Xml.XmlNamespaceManager(nt);
            IPDFRemoteComponent            parsed           = this.GetParsedParent();
            IDictionary <string, string>   parsedNamespaces = null;

            //add the namespaces of the last parsed document so we can infer any declarations
            if (null != parsed)
            {
                parsedNamespaces = parsed.GetDeclaredNamespaces();

                if (null != parsedNamespaces)
                {
                    foreach (string prefix in parsedNamespaces.Keys)
                    {
                        mgr.AddNamespace(prefix, parsedNamespaces[prefix]);
                    }
                }
            }

            if (null != this._nss)
            {
                string found;
                foreach (XmlNamespaceDeclaration dec in _nss)
                {
                    //makes sure this overrides any existing namespace declaration
                    if (null != parsedNamespaces && parsedNamespaces.TryGetValue(dec.Prefix, out found))
                    {
                        mgr.RemoveNamespace(dec.Prefix, found);
                    }

                    mgr.AddNamespace(dec.Prefix, dec.NamespaceURI);
                }
            }
            return(mgr);
        }
Ejemplo n.º 6
0
        public void Compile(ValidationEventHandler handler, bool fullCompile)
        {
            if (_isCompiled)
            {
                return;
            }

            foreach (XmlSchema s in delayedSchemas.Values)
            {
                Merge(s);
            }
            delayedSchemas.Clear();

            if (fullCompile)
            {
                _schemaSet                         = new XmlSchemaSet();
                _schemaSet.XmlResolver             = null;
                _schemaSet.ValidationEventHandler += handler;

                foreach (XmlSchema s in References.Values)
                {
                    _schemaSet.Add(s);
                }
                int schemaCount = _schemaSet.Count;

                foreach (XmlSchema s in List)
                {
                    if (!SchemaSet.Contains(s))
                    {
                        _schemaSet.Add(s);
                        schemaCount++;
                    }
                }

                if (!SchemaSet.Contains(XmlSchema.Namespace))
                {
                    AddReference(XsdSchema);
                    _schemaSet.Add(XsdSchema);
                    schemaCount++;
                }

                if (!SchemaSet.Contains(XmlReservedNs.NsXml))
                {
                    AddReference(XmlSchema);
                    _schemaSet.Add(XmlSchema);
                    schemaCount++;
                }
                _schemaSet.Compile();
                _schemaSet.ValidationEventHandler -= handler;
                _isCompiled = _schemaSet.IsCompiled && schemaCount == _schemaSet.Count;
            }
            else
            {
                try
                {
                    XmlNameTable nameTable = new System.Xml.NameTable();
                    Preprocessor prep      = new Preprocessor(nameTable, new SchemaNames(nameTable), null);
                    prep.XmlResolver      = null;
                    prep.SchemaLocations  = new Hashtable();
                    prep.ChameleonSchemas = new Hashtable();
                    foreach (XmlSchema schema in SchemaSet.Schemas())
                    {
                        prep.Execute(schema, schema.TargetNamespace, true);
                    }
                }
                catch (XmlSchemaException e)
                {
                    throw CreateValidationException(e, e.Message);
                }
            }
        }
Ejemplo n.º 7
0
 protected XsltContext(System.Xml.NameTable table) : base(default(System.Xml.XmlNameTable))
 {
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Loads a list of .addin files, ensuring that dependencies are satisfied.
        /// This method is normally called by <see cref="CoreStartup.RunInitialization"/>.
        /// </summary>
        /// <param name="addInFiles">
        /// The list of .addin file names to load.
        /// </param>
        /// <param name="disabledAddIns">
        /// The list of disabled AddIn identity names.
        /// </param>
        public void Load(List <string> addInFiles, List <string> disabledAddIns)
        {
            List <AddIn> list = new List <AddIn>();
            Dictionary <string, Version> dict      = new Dictionary <string, Version>();
            Dictionary <string, AddIn>   addInDict = new Dictionary <string, AddIn>();
            var nameTable = new System.Xml.NameTable();

            foreach (string fileName in addInFiles)
            {
                AddIn addIn;
                try {
                    addIn = AddIn.Load(this, fileName, nameTable);
                } catch (AddInLoadException ex) {
                    LoggingService.Error(ex);
                    if (ex.InnerException != null)
                    {
                        MessageService.ShowError("Error loading AddIn " + fileName + ":\n"
                                                 + ex.InnerException.Message);
                    }
                    else
                    {
                        MessageService.ShowError("Error loading AddIn " + fileName + ":\n"
                                                 + ex.Message);
                    }
                    addIn = new AddIn(this);
                    addIn.addInFileName      = fileName;
                    addIn.CustomErrorMessage = ex.Message;
                }
                if (addIn.Action == AddInAction.CustomError)
                {
                    list.Add(addIn);
                    continue;
                }
                addIn.Enabled = true;
                if (disabledAddIns != null && disabledAddIns.Count > 0)
                {
                    foreach (string name in addIn.Manifest.Identities.Keys)
                    {
                        if (disabledAddIns.Contains(name))
                        {
                            addIn.Enabled = false;
                            break;
                        }
                    }
                }
                if (addIn.Enabled)
                {
                    foreach (KeyValuePair <string, Version> pair in addIn.Manifest.Identities)
                    {
                        if (dict.ContainsKey(pair.Key))
                        {
                            MessageService.ShowError("Name '" + pair.Key + "' is used by " +
                                                     "'" + addInDict[pair.Key].FileName + "' and '" + fileName + "'");
                            addIn.Enabled = false;
                            addIn.Action  = AddInAction.InstalledTwice;
                            break;
                        }
                        else
                        {
                            dict.Add(pair.Key, pair.Value);
                            addInDict.Add(pair.Key, addIn);
                        }
                    }
                }
                list.Add(addIn);
            }
checkDependencies:
            for (int i = 0; i < list.Count; i++)
            {
                AddIn addIn = list[i];
                if (!addIn.Enabled)
                {
                    continue;
                }

                Version versionFound;

                foreach (AddInReference reference in addIn.Manifest.Conflicts)
                {
                    if (reference.Check(dict, out versionFound))
                    {
                        MessageService.ShowError(addIn.Name + " conflicts with " + reference.ToString()
                                                 + " and has been disabled.");
                        DisableAddin(addIn, dict, addInDict);
                        goto checkDependencies;                         // after removing one addin, others could break
                    }
                }
                foreach (AddInReference reference in addIn.Manifest.Dependencies)
                {
                    if (!reference.Check(dict, out versionFound))
                    {
                        if (versionFound != null)
                        {
                            MessageService.ShowError(addIn.Name + " has not been loaded because it requires "
                                                     + reference.ToString() + ", but version "
                                                     + versionFound.ToString() + " is installed.");
                        }
                        else
                        {
                            MessageService.ShowError(addIn.Name + " has not been loaded because it requires "
                                                     + reference.ToString() + ".");
                        }
                        DisableAddin(addIn, dict, addInDict);
                        goto checkDependencies;                         // after removing one addin, others could break
                    }
                }
            }
            foreach (AddIn addIn in list)
            {
                try {
                    InsertAddIn(addIn);
                } catch (AddInLoadException ex) {
                    LoggingService.Error(ex);
                    MessageService.ShowError("Error loading AddIn " + addIn.FileName + ":\n"
                                             + ex.Message);
                }
            }
        }
 public XPathMessageContext(System.Xml.NameTable table)
 {
 }
        public HttpResponseMessage SSOLogin(JObject ticketInfo)
        {
            var    jsonParams = HttpUtil.Deserialize(ticketInfo);
            string ticket     = jsonParams.ticket;

            string url = SSOServer + "serviceValidate?ticket=" + ticket + "&" +
                         "service=" + MyServer;

            System.IO.StreamReader Reader = new System.IO.StreamReader(new System.Net.WebClient().OpenRead(url));
            string resp = Reader.ReadToEnd();

            Reader.Close();

            System.Xml.NameTable           nt      = new System.Xml.NameTable();
            System.Xml.XmlNamespaceManager nsmgr   = new System.Xml.XmlNamespaceManager(nt);
            System.Xml.XmlParserContext    context = new System.Xml.XmlParserContext(null, nsmgr, null, System.Xml.XmlSpace.None);
            System.Xml.XmlTextReader       reader1 = new System.Xml.XmlTextReader(resp, System.Xml.XmlNodeType.Element, context);
            string netid    = null;
            string debugMsg = "";

            while (reader1.Read())
            {
                debugMsg += reader1.LocalName + reader1.ReadString();
                if (reader1.IsStartElement())
                {
                    string tag = reader1.LocalName;

                    if (tag == "employeeNumber")
                    {
                        netid = reader1.ReadString();
                    }
                }
            }
            if (netid == null)
            {
                LogUtil.Log(Request, "登录", "Unknown", "Unknown", 0, "Fail", debugMsg, DateTime.Now.ToString());
                return(new Response(2002, "请重试").Convert());
            }
            User user = UserDao.GetUserById(netid.ToUpper());

            if (user != null)
            {
                bool login = redis.IsSet(user.id);
                if (login)
                {
                    string expiredToken = redis.Get <string>(user.id);
                    redis.Delete(expiredToken);
                    redis.Delete(user.id);
                }
                string uuid = System.Guid.NewGuid().ToString();
                redis.Set(uuid, user.id, 15);
                redis.Set(user.id, uuid, 15);
                Dictionary <string, string> retData = new Dictionary <string, string>
                {
                    { "authorization", uuid },
                    { "userId", user.id },
                    { "role", user.role.ToString() },
                    { "name", user.name },
                    { "is_accept", user.is_accept.ToString() }
                };
                LogUtil.Log(Request, "登录", user.id, user.id, user.role, "", "SSO登录" + SSOServer, DateTime.Now.ToString());
                return(new Response(1001, "登录成功", retData).Convert());
            }
            return(new Response(2002, "ID不存在").Convert());
        }