コード例 #1
0
        /*SP.GlobalTopMenu*/
        /// <summary>
        /// Builds the xDocument of the specific color and Fiscal Year.
        /// </summary>
        /// <param name="strFiscalYearTitle">Fiscal Year title from the Fiscal Year Custom list.</param>
        /// <param name="strColorTitle">Color title from the Color custom list.</param>
        /// <returns></returns>
        public static XDocument GetXDocument(XMLType eXMLName)
        {
            try
            {
                using (SPSite oSite = new SPSite(SiteRootUrl))
                {
                    using (SPWeb oWeb = oSite.OpenWeb())
                    {
                        SPFolder oTargetFolder = oWeb.Folders[XML_LIBRARY];
                        SPFile spFile;

                        if (oWeb.GetFolder(oTargetFolder.Url + "/" + XML_FOLDER).Exists)
                        {
                            if (oWeb.GetFile(oTargetFolder.SubFolders[XML_FOLDER].Url + "/" + eXMLName + ".xml").Exists)
                            {
                                spFile = oTargetFolder.SubFolders[XML_FOLDER].Files[eXMLName + ".xml"];

                                StreamReader sr = new StreamReader(spFile.OpenBinaryStream());

                                return XDocument.Parse(sr.ReadToEnd());
                            }
                        }
                        return emptyXMLFile(eXMLName);
                    }
                }
            }
            catch (Exception ex)
            {
                return emptyXMLFile(eXMLName);
            }
        }
コード例 #2
0
        public ICFTInputFileInfo GetFakeFileInfo(XMLType type)
        {
            var content = string.Empty;

            switch (type)
            {
            case XMLType.ATTRIBUTES:
                content = CONTENT_XML_ATTRIBUTES;
                break;

            case XMLType.NAMESPACE:
                content = CONTENT_XML_NAMESPACE;
                break;

            case XMLType.SIMPLE:
                content = CONTENT_XML;
                break;

            case XMLType.DTD_NAMESPACE:
                content = CONTENT_XML_DTD_NAMESPACE;
                break;
            }
            var fakeFileInfo = A.Fake <ICFTInputFileInfo>();

            A.CallTo(() => fakeFileInfo.FileContent)
            .Returns(Encoding.Default.GetBytes(content));
            return(fakeFileInfo);
        }
コード例 #3
0
        string GetParamsForServiceCall()
        {
            PageSize = GetPropertyValue("pagesize", PageSize, 0);

            StringBuilder sb = new StringBuilder("");

            sb.Append("?method=" + MethodName);
            sb.Append("&siteid=" + SiteId);
            sb.Append("&type=" + XMLType.ToString());

            if (MaxTitleLength > 0)
            {
                sb.Append("&maxtitlelength=" + MaxTitleLength);
            }
            if (MaxDescriptionLength > 0)
            {
                sb.Append("&maxdesclength=" + MaxDescriptionLength);
            }
            if (PageSize > 0)
            {
                sb.Append("&pagesize=" + PageSize);
            }

            return(sb.ToString());
        }
コード例 #4
0
        string GetParamsForServiceCall()
        {
            //BlogId = GetPropertyValue("BlogId", BlogId, DefaultBlogId);

            StringBuilder sb = new StringBuilder("");

            sb.Append("?method=" + MethodName);
            sb.Append("&siteid=" + SiteId);
            sb.Append("&type=" + XMLType.ToString());
            if (BlogId > 0)
            {
                sb.Append("&blogid=" + BlogId);
            }

            if (MethodName == EMethods.GetPostList)
            {
                sb.Append(GetBlogPostList());
            }
            else if (MethodName == EMethods.GetPost)
            {
                sb.Append(GetBlogPost());
            }
            else if (MethodName == EMethods.GetCommentList)
            {
                sb.Append(GetBlogCommentList());
            }
            else if (MethodName == EMethods.GetArchivedPostList)
            {
                sb.Append(GetArchivedPostList());
            }
            else if (MethodName == EMethods.GetPostFileList)
            {
                sb.Append(GetBlogPostFileList());
            }

            if (MaxTitleLength > 0)
            {
                sb.Append("&maxtitlelength=" + MaxTitleLength);
            }
            if (MaxDescriptionLength > 0)
            {
                sb.Append("&maxdesclength=" + MaxDescriptionLength);
            }
            if (Parameters.Trim().Length > 0)
            {
                sb.Append("&prms=" + Parameters);
            }

            sb.Append(GetUriParameters(sb.ToString()));

            return(sb.ToString());
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: oomek/Ego-Engine-Modding
 private static bool IntToXmlType(int conversionType, out XMLType xmlType, int exclude = -1)
 {
     xmlType = XMLType.Text;
     if (exclude == conversionType)
     {
         return false;
     }
     if (Enum.IsDefined(typeof(XMLType), conversionType))
     {
         // Even if the conversion type is not defined, Enum.ToObject does not throw an exception
         xmlType = (XMLType)Enum.ToObject(typeof(XMLType), conversionType);
         return true;
     }
     else
     {
         return false;
     }
 }
コード例 #6
0
        /// <summary>
        /// Updates the XML of the specific color to the XMLs Document Library
        /// </summary>
        /// <param name="document">XML Document to upload to the XMLs Library.</param>
        /// <param name="replaceExistingFile">True: replace the exist document.</param>
        /// <param name="oMetadata">Metadata of the current document.</param>
        public static void UploadXDocumentToDocLib(XDocument document, bool replaceExistingFile, XMLType eXMLName)
        {
            try
            {
                SPFolder oTargetFolder = null;
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite oSite = new SPSite(SiteRootUrl))
                    {
                        using (SPWeb oWeb = oSite.OpenWeb())
                        {
                            oSite.AllowUnsafeUpdates = true;
                            oWeb.AllowUnsafeUpdates = true;

                            SPUtility.ValidateFormDigest();

                            var stream = new MemoryStream();
                            var writer = XmlWriter.Create(stream);
                            document.WriteTo(writer);
                            writer.Flush();

                            if (oWeb.GetFolder(XML_LIBRARY + "\\" + XML_FOLDER).Exists)
                                oTargetFolder = oWeb.Folders[XML_LIBRARY].SubFolders[XML_FOLDER];
                            else
                            {
                                oWeb.Folders[XML_LIBRARY].SubFolders.Add(XML_FOLDER);
                                oWeb.Folders[XML_LIBRARY].Update();
                                oTargetFolder = oWeb.Folders[XML_LIBRARY].SubFolders[XML_FOLDER];
                            }

                            oTargetFolder.Files.Add(eXMLName + ".xml", stream, replaceExistingFile);

                            oWeb.AllowUnsafeUpdates = false;
                            oSite.AllowUnsafeUpdates = false;
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #7
0
        /// <summary>
        /// Begin the Socket Policy Server
        /// </summary>
        /// <param name="xmlType">XML Type to be used</param>
        /// <param name="fileLocation">Location of the policy file</param>
        public static void Begin(XMLType xmlType = XMLType.All, string fileLocation = "")
        {
            string policy = null;

            switch (xmlType)
            {
            case XMLType.All:
                policy = AllPolicy;
                break;

            case XMLType.Local:
                policy = LocalPolicy;
                break;

            case XMLType.File:
                if (fileLocation.Length < 2)
                {
                    UnityEngine.Debug.LogError("Missing policy file name");
                    throw new NetworkException("Missing policy file name");
                }

                if (!File.Exists(fileLocation))
                {
                    UnityEngine.Debug.LogError("Could not find policy file '" + fileLocation + "'.");
                    throw new NetworkException("Could not find policy file '" + fileLocation + "'.");
                }
                using (StreamReader sr = new StreamReader(fileLocation))
                {
                    policy = sr.ReadToEnd();
                }
                break;
            }

            server = new SocketPolicyServer(policy);
            server.Start();
        }
コード例 #8
0
ファイル: XMLAssistant.cs プロジェクト: kaiss78/hustoes
        /// <summary>
        /// XMLAssistance构造函数
        /// </summary>
        /// <param name="s">xml文件名</param>
        /// <param name="x">xml文件类型(一个XMLType的枚举)</param>
        /// <param name="o">文件头属性  试卷XML中需要试卷ID  考生答案XML中需要试卷ID和考生ID   试卷答案XML中需要试卷ID</param>
        public XMLAssistant(String s, XMLType x, Object o)
        {
            fileName = s;
            xmlType = x;
            if (fileName != "")
            {

                XmlElement xmlelem, xmlelem1;
                XmlNode xmlnode;
                if (File.Exists(fileName))
                {
                    try
                    {
                        xd.Load(fileName);
                    }
                    catch
                    {
                        xd.RemoveAll();
                        //加入xml声明
                        xmlnode = xd.CreateNode(XmlNodeType.XmlDeclaration, "", "");
                        xd.AppendChild(xmlnode);
                        //加入一个根元素
                        xmlelem = xd.CreateElement("", "ROOT", "");
                        xd.AppendChild(xmlelem);
                    }
                }
                else
                {
                    //加入xml声明
                    xmlnode = xd.CreateNode(XmlNodeType.XmlDeclaration, "", "");
                    xd.AppendChild(xmlnode);
                    //加入一个根元素
                    xmlelem = xd.CreateElement("", "ROOT", "");
                    xd.AppendChild(xmlelem);
                }
                if (o != null)
                {
                    switch (xmlType)
                    {
                        case XMLType.Log:
                            {
                                break;
                            }
                        case XMLType.Paper:
                            {
                                if (xd.ChildNodes.Item(1).ChildNodes.Count == 0 || Find(xd.ChildNodes.Item(1).ChildNodes.Item(0), "Paper") == null)
                                {
                                    xmlelem = xd.CreateElement("Paper");
                                    XmlAttribute xa = xd.CreateAttribute("id");
                                    xmlelem.Attributes.Append(xa);
                                    xmlelem.SetAttribute("id", ((string)o));
                                    xmlelem1 = xd.CreateElement("Choice");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("Completion");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("Judgment");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("Word");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("Excel");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("PowerPoint");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("CProgramCompletion");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("CProgramModification");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("CProgramFun");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("CppProgramCompletion");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("CppProgramModification");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("CppProgramFun");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("VbProgramCompletion");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("VbProgramModification");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("VbProgramFun");
                                    xmlelem.AppendChild(xmlelem1);
                                    xd.ChildNodes.Item(1).AppendChild(xmlelem);
                                }
                                else { }
                                break;
                            }
                        case XMLType.PaperAnswer:
                            {
                                if (xd.ChildNodes.Item(1).ChildNodes.Count == 0 || Find(xd.ChildNodes.Item(1).ChildNodes.Item(0), "Answer") == null)
                                {
                                    xmlelem = xd.CreateElement("Answer");
                                    XmlAttribute xa = xd.CreateAttribute("id");
                                    xmlelem.Attributes.Append(xa);
                                    xmlelem.SetAttribute("id", ((string[])o)[0]);
                                    xa = xd.CreateAttribute("type");
                                    xmlelem.Attributes.Append(xa);
                                    xmlelem.SetAttribute("type", "Paper");
                                    xmlelem1 = xd.CreateElement("Choice");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("Completion");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("Judgment");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("Word");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("Excel");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("PowerPoint");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("CProgramCompletion");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("CProgramModification");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("CProgramFun");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("CppProgramCompletion");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("CppProgramModification");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("CppProgramFun");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("VbProgramCompletion");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("VbProgramModification");
                                    xmlelem.AppendChild(xmlelem1);
                                    xmlelem1 = xd.CreateElement("VbProgramFun");
                                    xmlelem.AppendChild(xmlelem1);
                                    xd.ChildNodes.Item(1).AppendChild(xmlelem);
                                }
                                else { }
                                break;
                            }
                        case XMLType.StudentAnswer:
                            {
                                xmlelem = xd.CreateElement("Answer");
                                XmlAttribute xa = xd.CreateAttribute("id");
                                xmlelem.Attributes.Append(xa);
                                xmlelem.SetAttribute("id", ((string[])o)[0]);
                                xa = xd.CreateAttribute("type");
                                xmlelem.Attributes.Append(xa);
                                xmlelem.SetAttribute("type", "Student");
                                xa = xd.CreateAttribute("pid");
                                xmlelem.Attributes.Append(xa);
                                xmlelem.SetAttribute("pid", ((string[])o)[1]);
                                xmlelem1 = xd.CreateElement("Choice");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("Completion");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("Judgment");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("Word");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("Excel");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("PowerPoint");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("CProgramCompletion");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("CProgramModification");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("CProgramFun");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("CppProgramCompletion");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("CppProgramModification");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("CppProgramFun");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("VbProgramCompletion");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("VbProgramModification");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("VbProgramFun");
                                xmlelem.AppendChild(xmlelem1);
                                xd.ChildNodes.Item(1).AppendChild(xmlelem);
                                break;
                            }
                        case XMLType.StudentScore:
                            {
                                xmlelem = xd.CreateElement("StudentScore");
                                XmlAttribute xa = xd.CreateAttribute("paperId");
                                xmlelem.Attributes.Append(xa);
                                xmlelem.SetAttribute("paperId", ((string[])o)[0]);
                                xa = xd.CreateAttribute("studentId");
                                xmlelem.Attributes.Append(xa);
                                xmlelem.SetAttribute("studentId", ((string[])o)[1]);
                                xmlelem1 = xd.CreateElement("Choice");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("Completion");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("Judgment");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("Word");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("Excel");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("PowerPoint");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("CProgramCompletion");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("CProgramModification");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("CProgramFun");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("CppProgramCompletion");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("CppProgramModification");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("CppProgramFun");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("VbProgramCompletion");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("VbProgramModification");
                                xmlelem.AppendChild(xmlelem1);
                                xmlelem1 = xd.CreateElement("VbProgramFun");
                                xmlelem.AppendChild(xmlelem1);
                                xd.ChildNodes.Item(1).AppendChild(xmlelem);
                                break;
                            }
                        default:
                            {
                                break;
                            }
                    }
                    xd.Save(fileName);
                }
                else
                {
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// Returns a empty xml.
        /// </summary>
        /// <returns></returns>
        private static XDocument emptyXMLFile(XMLType xmlName)
        {
            try
            {
                XmlTextReader reader=null;
                if(xmlName== XMLType.XMLGROUPNAMES)
                   reader = new XmlTextReader(new StringReader(EMPTYXMLGROUPNAMES));
                else
                    reader = new XmlTextReader(new StringReader(EMPTYXMLGLOBALNAV));

                return XDocument.Load(reader);
            }
            catch (Exception ex)
            {
                throw;
                return null;
            }
        }
コード例 #10
0
ファイル: Content.cs プロジェクト: omeryesil/awapicms
        //public string GetFilePath(string path, bool addParams)
        //{
        //    string strRtn = path;

        //    if (path.IndexOf("http:") < 0)
        //    {
        //        string root = "http://" +
        //                    HttpContext.Current.Request.Url.Host +
        //                    ":" + HttpContext.Current.Request.Url.Port;

        //        strRtn = path.Replace("~", "");
        //        if (!strRtn.StartsWith("/"))
        //            strRtn += "/";

        //        strRtn = root + strRtn;
        //    }

        //    if (addParams)
        //        strRtn += GetParamsForServiceCall();

        //    return strRtn;
        //}


        string GetParamsForServiceCall()
        {
            ContentId = GetPropertyValue("ContentId", ContentId, DefaultContentId);
            Alias     = GetPropertyValue("Alias", Alias, "");
            Lineage   = GetPropertyValue("Lineage", Lineage, "");
            //Where = GetPropertyValue("where", Where, "");
            //SortBy = GetPropertyValue("sortby", SortBy, "");
            PageSize  = GetPropertyValue("pagesize", PageSize, 0);
            PageIndex = GetPropertyValue("pageindex", PageIndex, 0);
            Culture   = GetPropertyValue("culture", Culture, "");

            StringBuilder sb = new StringBuilder("");

            sb.Append("?method=" + MethodName);
            sb.Append("&siteid=" + SiteId);
            sb.Append("&type=" + XMLType.ToString());

            if (ContentId > 0)
            {
                sb.Append("&contentid=" + ContentId);
            }
            if (Culture.Trim() != "")
            {
                sb.Append("&culture=" + Culture);
            }
            if (Alias.Trim().Length > 0)
            {
                sb.Append("&alias=" + Alias);
            }
            if (Lineage.Trim().Length > 0)
            {
                sb.Append("&lineage=" + Lineage);
            }
            if (MaxTitleLength > 0)
            {
                sb.Append("&maxtitlelength=" + MaxTitleLength);
            }
            if (MaxDescriptionLength > 0)
            {
                sb.Append("&maxdesclength=" + MaxDescriptionLength);
            }
            if (PageSize > 0)
            {
                sb.Append("&pagesize=" + PageSize);
            }
            if (PageIndex > 0)
            {
                sb.Append("&pageindex=" + PageIndex);
            }
            if (Parameters.Trim().Length > 0)
            {
                sb.Append("&prms=" + Parameters);
            }
            if (Where.Trim().Length > 0)
            {
                sb.Append("&where=" + Where);
            }
            if (SortBy.Trim().Length > 0)
            {
                sb.Append("&sortby=" + SortBy);
            }

            if (IgnoredUriParameters.Trim() != "*" &&
                HttpContext.Current.Request.Url.Query != null &&
                HttpContext.Current.Request.Url.Query.Length > 0)
            {
                string[] prms = HttpContext.Current.Request.Url.Query.Replace("?", "").Split('&');

                //if paremeter isn't already added to the returning string
                foreach (string prm in prms)
                {
                    if (prm.Trim().Length == 0)
                    {
                        continue;
                    }

                    string prmName = (prm.Split('='))[0];

                    if (!IsInIgnoreList(prmName))
                    {
                        if (sb.ToString().ToLower().IndexOf(prmName.ToLower()) < 0)
                        {
                            sb.Append("&" + prm);
                        }
                    }
                }
            }

            if (HttpContext.Current.Request["currcontentid"] != null)
            {
                sb.Append("&currcontentid=" + HttpContext.Current.Request["currcontentid"].ToString());
            }
            else
            if (HttpContext.Current.Request["contentid"] != null)
            {
                sb.Append("&currcontentid=" + HttpContext.Current.Request["contentid"].ToString());
            }

            return(sb.ToString());
        }
コード例 #11
0
        public void Write(System.IO.Stream fileStream, XMLType convertType)
        {
            if (convertType == XMLType.Text)
            {
                using (fileStream)
                {
                    doc.Save(fileStream);
                }
            }
            else if (convertType == XMLType.BinXML)
            {
                Dictionary<string, int> valuesToID = new Dictionary<string, int>();
                List<BinaryXmlElement> xmlElems = new List<BinaryXmlElement>();
                List<BinaryXmlAttribute> xmlAttrs = new List<BinaryXmlAttribute>();
                List<int> valueLocations = new List<int>();

                BuildBinXml(doc.DocumentElement, valuesToID, xmlElems, xmlAttrs);
                valueLocations.Add(0);

                using (XmlBinaryWriter writer = new XmlBinaryWriter(new LittleEndianBitConverter(), fileStream))
                {
                    writer.Write(0x7252221A);
                    writer.Write(0);

                    // Section 2: Sections 3 and 4 Header and Total Size
                    writer.Write(0x72522217);
                    writer.Write(0); // 16 as Extra, Rest from Section 3 and 4 Length

                    // Section 3: Values/Strings
                    writer.Write(0x7252221D);
                    writer.Write(0);
                    foreach (string s in valuesToID.Keys)
                    {
                        valueLocations.Add(writer.WriteTerminatedString(s) + valueLocations[valueLocations.Count - 1] + 1);
                    }
                    // Write zero bytes to make length the same way CM made it
                    int remainder = (int)writer.BaseStream.Position % 16;
                    byte[] pad = new byte[remainder > 8 ? 24 - remainder : 8 - remainder];
                    writer.Write(pad);

                    // Section 4: Value/String Locations
                    writer.Write(0x7252221E);
                    writer.Write(4 * valuesToID.Count);
                    for (int i = 0; i < valueLocations.Count - 1; i++)
                    {
                        writer.Write(valueLocations[i]);
                    }

                    // Section 5: Element Definitions
                    writer.Write(0x7252221B);
                    writer.Write(24 * xmlElems.Count);
                    for (int i = 0; i < xmlElems.Count; i++)
                    {
                        writer.WriteBinaryXmlElement(xmlElems[i]);
                    }

                    // Section 6: Attribute Definitions
                    writer.Write(0x7252221C);
                    writer.Write(8 * xmlAttrs.Count);
                    for (int i = 0; i < xmlAttrs.Count; i++)
                    {
                        writer.WriteBinaryXmlAttribute(xmlAttrs[i]);
                    }

                    // Update Section Lenghts/Sizes
                    writer.Seek(4, System.IO.SeekOrigin.Begin);
                    writer.Write((int)writer.BaseStream.Length - 8); // Section 1: Total File

                    writer.Seek(12, System.IO.SeekOrigin.Begin);
                    writer.Write(valueLocations[valueLocations.Count - 1] + 4 * valuesToID.Count + 16 + pad.Length); // Section 2

                    writer.Seek(20, System.IO.SeekOrigin.Begin);
                    writer.Write(valueLocations[valueLocations.Count - 1] + pad.Length); // Section 3
                }
            }
            else if (convertType == XMLType.BXMLBig)
            {
                using (XmlBinaryWriter writer = new XmlBinaryWriter(EndianBitConverter.Big, fileStream))
                {
                    writer.Write((byte)0);
                    writer.Write(Encoding.UTF8.GetBytes("BXML"));
                    writer.WriteBxmlElement(doc.DocumentElement);

                    // File Ending: "0004 06000000" x2
                    writer.Write((Int16)0x0004);
                    writer.Write((Int16)0x0600);
                    writer.Write((Int16)0);
                    writer.Write((Int16)0x0004);
                    writer.Write((Int16)0x0600);
                    writer.Write((Int16)0);
                }
            }
            else if (convertType == XMLType.BXMLLittle)
            {
                using (XmlBinaryWriter writer = new XmlBinaryWriter(EndianBitConverter.Little, fileStream))
                {
                    writer.Write((byte)1);
                    writer.Write(Encoding.UTF8.GetBytes("BXML"));
                    writer.WriteBxmlElement(doc.DocumentElement);

                    // File Ending: "0004 06000000" x2
                    writer.Write((Int16)0x0004);
                    writer.Write((Int16)0x0006);
                    writer.Write((Int16)0);
                    writer.Write((Int16)0x0004);
                    writer.Write((Int16)0x0006);
                    writer.Write((Int16)0);
                }
            }
        }
コード例 #12
0
		/// <summary>
		/// Begin the Socket Policy Server
		/// </summary>
		/// <param name="xmlType">XML Type to be used</param>
		/// <param name="fileLocation">Location of the policy file</param>
		public static void Begin(XMLType xmlType = XMLType.All, string fileLocation = "")
		{
			string policy = null;
			switch (xmlType)
			{
				case XMLType.All:
					policy = AllPolicy;
					break;
				case XMLType.Local:
					policy = LocalPolicy;
					break;
				case XMLType.File:
					if (fileLocation.Length < 2)
					{
						UnityEngine.Debug.LogError("Missing policy file name");
						throw new NetworkException("Missing policy file name");
					}

					if (!File.Exists(fileLocation))
					{
						UnityEngine.Debug.LogError("Could not find policy file '" + fileLocation + "'.");
						throw new NetworkException("Could not find policy file '" + fileLocation + "'.");
					}
					using (StreamReader sr = new StreamReader(fileLocation))
					{
						policy = sr.ReadToEnd();
					}
					break;
			}

			server = new SocketPolicyServer(policy);
			server.Start();
		}
コード例 #13
0
        //public string GetFilePath(string path, bool addParams)
        //{
        //    string strRtn = path;

        //    if (path.IndexOf("http:") < 0)
        //    {
        //        string root = "http://" +
        //                    HttpContext.Current.Request.Url.Host +
        //                    ":" + HttpContext.Current.Request.Url.Port;

        //        strRtn = path.Replace("~", "");
        //        if (!strRtn.StartsWith("/"))
        //            strRtn += "/";

        //        strRtn = root + strRtn;
        //    }

        //    if (addParams)
        //        strRtn += GetParamsForServiceCall();

        //    return strRtn;
        //}


        string GetParamsForServiceCall()
        {
            ContestId      = GetPropertyValue("ContestId", ContestId, 0);
            ContestGroupId = GetPropertyValue("ContestGroupId", ContestGroupId, 0);
            UserId         = GetPropertyValue("UserId", UserId, 0);

            PageSize  = GetPropertyValue("pagesize", PageSize, 0);
            PageIndex = GetPropertyValue("pageindex", PageIndex, 0);

            StringBuilder sb = new StringBuilder("");

            sb.Append("?method=" + MethodName);
            sb.Append("&siteid=" + SiteId);
            sb.Append("&type=" + XMLType.ToString());

            if (ContestId > 0)
            {
                sb.Append("&contestid=" + ContestId);
            }
            if (ContestGroupId > 0)
            {
                sb.Append("&groupid=" + ContestGroupId);
            }
            if (UserId > 0)
            {
                sb.Append("&userid=" + UserId);
            }

            if (PageSize > 0)
            {
                sb.Append("&pagesize=" + PageSize);
            }
            if (PageIndex > 0)
            {
                sb.Append("&pageindex=" + PageIndex);
            }
            if (ContestEntryDate.Trim().Length > 0)
            {
                sb.Append("&date=" + ContestEntryDate);
            }
            if (Parameters.Trim().Length > 0)
            {
                sb.Append("&prms=" + Parameters);
            }

            if (IgnoredUriParameters.Trim() != "*" &&
                HttpContext.Current.Request.Url.Query != null &&
                HttpContext.Current.Request.Url.Query.Length > 0)
            {
                string[] prms = HttpContext.Current.Request.Url.Query.Replace("?", "").Split('&');

                //if paremeter isn't already added to the returning string
                foreach (string prm in prms)
                {
                    if (prm.Trim().Length == 0)
                    {
                        continue;
                    }

                    string prmName = (prm.Split('='))[0];

                    if (!IsInIgnoreList(prmName))
                    {
                        if (sb.ToString().ToLower().IndexOf(prmName.ToLower()) < 0)
                        {
                            sb.Append("&" + prm);
                        }
                    }
                }
            }

            return(sb.ToString());
        }
コード例 #14
0
        public XmlFile(System.IO.Stream fileStream)
        {
            // Test for XmlType
            try
            {
                doc = new XmlDocument();
                doc.Load(fileStream);
                type = XMLType.Text;
                foreach (XmlNode child in doc.ChildNodes)
                {
                    if (child.NodeType == XmlNodeType.Comment)
                    {
                        try
                        {
                            type = (XMLType)Enum.Parse(typeof(XMLType), child.Value);
                            break;
                        }
                        catch
                        {
                        }
                    }
                }
                return;
            }
            catch { doc = null; }
            finally
            {
                fileStream.Position = 0;
            }
            XmlBinaryReader r          = new XmlBinaryReader(EndianBitConverter.Little, fileStream);
            byte            headerByte = r.ReadByte();

            if (headerByte == 0x00)
            {
                type = XMLType.BXMLBig;
            }
            else if (headerByte == 0x01)
            {
                type = XMLType.BXMLLittle;
            }
            else
            {
                type = XMLType.BinXML;
            }
            r.BaseStream.Position = 0;
            r = null;

            // Create a text XML file
            if (type == XMLType.BinXML)
            {
                using (XmlBinaryReader reader = new XmlBinaryReader(EndianBitConverter.Little, fileStream))
                {
                    // Section 1
                    reader.ReadByte();   // Unique Byte
                    reader.ReadBytes(3); // Same Magic
                    reader.ReadInt32();  // File Length/Size

                    // Section 2
                    reader.ReadByte();   // Unique Byte
                    reader.ReadBytes(3); // Same Magic
                    reader.ReadInt32();  // Section 3 and 4 Total Length/Size

                    // Section 3 and 4
                    xmlStrings = new BinaryXmlString(reader);

                    // Section 5
                    reader.ReadInt32();
                    xmlElements = new BinaryXmlElement[reader.ReadInt32() / 24];
                    for (int i = 0; i < xmlElements.Length; i++)
                    {
                        xmlElements[i].elementNameID       = reader.ReadInt32();
                        xmlElements[i].elementValueID      = reader.ReadInt32();
                        xmlElements[i].attributeCount      = reader.ReadInt32();
                        xmlElements[i].attributeStartID    = reader.ReadInt32();
                        xmlElements[i].childElementCount   = reader.ReadInt32();
                        xmlElements[i].childElementStartID = reader.ReadInt32();
                    }

                    // Section 6
                    reader.ReadInt32();
                    xmlAttributes = new BinaryXmlAttribute[reader.ReadInt32() / 8];
                    for (int i = 0; i < xmlAttributes.Length; i++)
                    {
                        xmlAttributes[i].nameID  = reader.ReadInt32();
                        xmlAttributes[i].valueID = reader.ReadInt32();
                    }

                    // Build XML
                    doc = new XmlDocument();
                    doc.AppendChild(doc.CreateXmlDeclaration("1.0", "UTF-8", "yes"));
                    doc.AppendChild(doc.CreateComment(type.ToString()));
                    doc.AppendChild(xmlElements[0].CreateElement(doc, this));
                }
            }
            else if (type == XMLType.BXMLBig)
            {
                using (XmlBinaryReader reader = new XmlBinaryReader(EndianBitConverter.Big, fileStream))
                {
                    reader.ReadBytes(5);
                    doc = new XmlDocument();
                    doc.AppendChild(doc.CreateXmlDeclaration("1.0", "UTF-8", "yes"));
                    doc.AppendChild(doc.CreateComment(type.ToString()));
                    doc.AppendChild(reader.ReadBxmlElement(doc));
                }
            }
            else if (type == XMLType.BXMLLittle)
            {
                using (XmlBinaryReader reader = new XmlBinaryReader(EndianBitConverter.Little, fileStream))
                {
                    reader.ReadBytes(5);
                    doc = new XmlDocument();
                    doc.AppendChild(doc.CreateXmlDeclaration("1.0", "UTF-8", "yes"));
                    doc.AppendChild(doc.CreateComment(type.ToString()));
                    doc.AppendChild(reader.ReadBxmlElement(doc));
                }
            }
        }
コード例 #15
0
        public void Write(System.IO.Stream fileStream, XMLType convertType)
        {
            if (convertType == XMLType.Text)
            {
                using (fileStream)
                {
                    doc.Save(fileStream);
                }
            }
            else if (convertType == XMLType.BinXML)
            {
                Dictionary <string, int>  valuesToID = new Dictionary <string, int>();
                List <BinaryXmlElement>   xmlElems   = new List <BinaryXmlElement>();
                List <BinaryXmlAttribute> xmlAttrs   = new List <BinaryXmlAttribute>();
                List <int> valueLocations            = new List <int>();

                BuildBinXml(doc.DocumentElement, valuesToID, xmlElems, xmlAttrs);
                valueLocations.Add(0);

                using (XmlBinaryWriter writer = new XmlBinaryWriter(new LittleEndianBitConverter(), fileStream))
                {
                    writer.Write(0x7252221A);
                    writer.Write(0);

                    // Section 2: Sections 3 and 4 Header and Total Size
                    writer.Write(0x72522217);
                    writer.Write(0); // 16 as Extra, Rest from Section 3 and 4 Length

                    // Section 3: Values/Strings
                    writer.Write(0x7252221D);
                    writer.Write(0);
                    foreach (string s in valuesToID.Keys)
                    {
                        valueLocations.Add(writer.WriteTerminatedString(s) + valueLocations[valueLocations.Count - 1] + 1);
                    }
                    // Write zero bytes to make length the same way CM made it
                    int    remainder = (int)writer.BaseStream.Position % 16;
                    byte[] pad       = new byte[remainder > 8 ? 24 - remainder : 8 - remainder];
                    writer.Write(pad);

                    // Section 4: Value/String Locations
                    writer.Write(0x7252221E);
                    writer.Write(4 * valuesToID.Count);
                    for (int i = 0; i < valueLocations.Count - 1; i++)
                    {
                        writer.Write(valueLocations[i]);
                    }

                    // Section 5: Element Definitions
                    writer.Write(0x7252221B);
                    writer.Write(24 * xmlElems.Count);
                    for (int i = 0; i < xmlElems.Count; i++)
                    {
                        writer.WriteBinaryXmlElement(xmlElems[i]);
                    }

                    // Section 6: Attribute Definitions
                    writer.Write(0x7252221C);
                    writer.Write(8 * xmlAttrs.Count);
                    for (int i = 0; i < xmlAttrs.Count; i++)
                    {
                        writer.WriteBinaryXmlAttribute(xmlAttrs[i]);
                    }

                    // Update Section Lenghts/Sizes
                    writer.Seek(4, System.IO.SeekOrigin.Begin);
                    writer.Write((int)writer.BaseStream.Length - 8); // Section 1: Total File

                    writer.Seek(12, System.IO.SeekOrigin.Begin);
                    writer.Write(valueLocations[valueLocations.Count - 1] + 4 * valuesToID.Count + 16 + pad.Length); // Section 2

                    writer.Seek(20, System.IO.SeekOrigin.Begin);
                    writer.Write(valueLocations[valueLocations.Count - 1] + pad.Length); // Section 3
                }
            }
            else if (convertType == XMLType.BXMLBig)
            {
                using (XmlBinaryWriter writer = new XmlBinaryWriter(EndianBitConverter.Big, fileStream))
                {
                    writer.Write((byte)0);
                    writer.Write(Encoding.UTF8.GetBytes("BXML"));
                    writer.WriteBxmlElement(doc.DocumentElement);

                    // File Ending: "0004 06000000" x2
                    writer.Write((Int16)0x0004);
                    writer.Write((Int16)0x0600);
                    writer.Write((Int16)0);
                    writer.Write((Int16)0x0004);
                    writer.Write((Int16)0x0600);
                    writer.Write((Int16)0);
                }
            }
            else if (convertType == XMLType.BXMLLittle)
            {
                using (XmlBinaryWriter writer = new XmlBinaryWriter(EndianBitConverter.Little, fileStream))
                {
                    writer.Write((byte)1);
                    writer.Write(Encoding.UTF8.GetBytes("BXML"));
                    writer.WriteBxmlElement(doc.DocumentElement);

                    // File Ending: "0004 06000000" x2
                    writer.Write((Int16)0x0004);
                    writer.Write((Int16)0x0006);
                    writer.Write((Int16)0);
                    writer.Write((Int16)0x0004);
                    writer.Write((Int16)0x0006);
                    writer.Write((Int16)0);
                }
            }
        }
コード例 #16
0
ファイル: Poll.cs プロジェクト: omeryesil/awapicms
        string GetParamsForServiceCall()
        {
            PollId    = GetPropertyValue("PollId", PollId, 0);
            PageSize  = GetPropertyValue("pagesize", PageSize, 0);
            PageIndex = GetPropertyValue("pageindex", PageIndex, 0);

            StringBuilder sb = new StringBuilder("");

            sb.Append("?method=" + MethodName);
            sb.Append("&siteid=" + SiteId);
            sb.Append("&type=" + XMLType.ToString());

            if (PollId > 0)
            {
                sb.Append("&blogid=" + PollId);
            }
            if (Culture.Trim() != "")
            {
                sb.Append("&culture=" + Culture);
            }
            if (PageSize > 0)
            {
                sb.Append("&pagesize=" + PageSize);
            }
            if (PageIndex > 0)
            {
                sb.Append("&pageindex=" + PageIndex);
            }
            if (Parameters.Trim().Length > 0)
            {
                sb.Append("&prms=" + Parameters);
            }

            if (IgnoredUriParameters.Trim() != "*" &&
                HttpContext.Current.Request.Url.Query != null &&
                HttpContext.Current.Request.Url.Query.Length > 0)
            {
                string[] prms = HttpContext.Current.Request.Url.Query.Replace("?", "").Split('&');

                //if paremeter isn't already added to the returning string
                foreach (string prm in prms)
                {
                    if (prm.Trim().Length == 0)
                    {
                        continue;
                    }

                    string prmName = (prm.Split('='))[0];

                    if (!IsInIgnoreList(prmName))
                    {
                        if (sb.ToString().ToLower().IndexOf(prmName.ToLower()) < 0)
                        {
                            sb.Append("&" + prm);
                        }
                    }
                }
            }

            if (HttpContext.Current.Request["currpostid"] != null)
            {
                sb.Append("&currpostid=" + HttpContext.Current.Request["currpostid"].ToString());
            }
            else
            if (HttpContext.Current.Request["postid"] != null)
            {
                sb.Append("&currpostid=" + HttpContext.Current.Request["postid"].ToString());
            }

            return(sb.ToString());
        }
コード例 #17
0
 public Element(string type, string name, XMLType xmltype)
 {
     Type    = type;
     Name    = name;
     XmlType = xmltype;
 }
コード例 #18
0
        public XmlFile(System.IO.Stream fileStream)
        {
            // Test for XmlType
            try
            {
                doc = new XmlDocument();
                doc.Load(fileStream);
                type = XMLType.Text;
                return;
            }
            catch { doc = null; }
            finally
            {
                fileStream.Position = 0;
            }
            XmlBinaryReader r = new XmlBinaryReader(EndianBitConverter.Little, fileStream);
            byte headerByte = r.ReadByte();
            if (headerByte == 0x00)
            {
                type = XMLType.BXMLBig;
            }
            else if (headerByte == 0x01)
            {
                type = XMLType.BXMLLittle;
            }
            else
            {
                type = XMLType.BinXML;
            }
            r.BaseStream.Position = 0;
            r = null;

            // Create a text XML file
            if (type == XMLType.BinXML)
            {
                using (XmlBinaryReader reader = new XmlBinaryReader(EndianBitConverter.Little, fileStream))
                {
                    // Section 1
                    reader.ReadByte(); // Unique Byte
                    reader.ReadBytes(3); // Same Magic
                    reader.ReadInt32(); // File Length/Size

                    // Section 2
                    reader.ReadByte(); // Unique Byte
                    reader.ReadBytes(3); // Same Magic
                    reader.ReadInt32(); // Section 3 and 4 Total Length/Size

                    // Section 3 and 4
                    xmlStrings = new BinaryXmlString(reader);

                    // Section 5
                    reader.ReadInt32();
                    xmlElements = new BinaryXmlElement[reader.ReadInt32() / 24];
                    for (int i = 0; i < xmlElements.Length; i++)
                    {
                        xmlElements[i].elementNameID = reader.ReadInt32();
                        xmlElements[i].elementValueID = reader.ReadInt32();
                        xmlElements[i].attributeCount = reader.ReadInt32();
                        xmlElements[i].attributeStartID = reader.ReadInt32();
                        xmlElements[i].childElementCount = reader.ReadInt32();
                        xmlElements[i].childElementStartID = reader.ReadInt32();
                    }

                    // Section 6
                    reader.ReadInt32();
                    xmlAttributes = new BinaryXmlAttribute[reader.ReadInt32() / 8];
                    for (int i = 0; i < xmlAttributes.Length; i++)
                    {
                        xmlAttributes[i].nameID = reader.ReadInt32();
                        xmlAttributes[i].valueID = reader.ReadInt32();
                    }

                    // Build XML
                    doc = new XmlDocument();
                    doc.AppendChild(doc.CreateXmlDeclaration("1.0", "UTF-8", "yes"));
                    doc.AppendChild(xmlElements[0].CreateElement(doc, this));
                }
            }
            else if (type == XMLType.BXMLBig)
            {
                using (XmlBinaryReader reader = new XmlBinaryReader(EndianBitConverter.Big, fileStream))
                {
                    reader.ReadBytes(5);
                    doc = new XmlDocument();
                    doc.AppendChild(doc.CreateXmlDeclaration("1.0", "UTF-8", "yes"));
                    doc.AppendChild(reader.ReadBxmlElement(doc));
                }
            }
            else if (type == XMLType.BXMLLittle)
            {
                using (XmlBinaryReader reader = new XmlBinaryReader(EndianBitConverter.Little, fileStream))
                {
                    reader.ReadBytes(5);
                    doc = new XmlDocument();
                    doc.AppendChild(doc.CreateXmlDeclaration("1.0", "UTF-8", "yes"));
                    doc.AppendChild(reader.ReadBxmlElement(doc));
                }
            }
        }