コード例 #1
0
        private void LoadDefaultForums(int PortalId, int ModuleId)
        {
            var xDoc = new System.Xml.XmlDocument();

            xDoc.Load(sPath);
            if (xDoc != null)
            {
                System.Xml.XmlNode     xRoot     = xDoc.DocumentElement;
                System.Xml.XmlNodeList xNodeList = xRoot.SelectNodes("//defaultforums/groups/group");
                if (xNodeList.Count > 0)
                {
                    int i;
                    for (i = 0; i < xNodeList.Count; i++)
                    {
                        var gi = new ForumGroupInfo
                        {
                            ModuleId         = ModuleId,
                            ForumGroupId     = -1,
                            GroupName        = xNodeList[i].Attributes["groupname"].Value,
                            Active           = xNodeList[i].Attributes["active"].Value == "1",
                            Hidden           = xNodeList[i].Attributes["hidden"].Value == "1",
                            SortOrder        = i,
                            GroupSettingsKey = "",
                            PermissionsId    = -1
                        };
                        var gc = new ForumGroupController();
                        int groupId;
                        groupId = gc.Groups_Save(PortalId, gi, true);
                        gi      = gc.GetForumGroup(ModuleId, groupId);
                        string sKey       = "G:" + groupId.ToString();
                        string sAllowHTML = "false";
                        if (xNodeList[i].Attributes["allowhtml"] != null)
                        {
                            sAllowHTML = xNodeList[i].Attributes["allowhtml"].Value;
                        }
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.TopicsTemplateId, "0");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.TopicTemplateId, "0");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.EmailAddress, string.Empty);
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.UseFilter, "true");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AllowPostIcon, "true");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AllowEmoticons, "true");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AllowScript, "false");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.IndexContent, "false");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AllowRSS, "true");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AllowAttach, "true");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AttachCount, "3");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AttachMaxSize, "1000");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AttachTypeAllowed, "txt,tiff,pdf,xls,xlsx,doc,docx,ppt,pptx");
                        //Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AttachStore, "FILESYSTEM");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AttachMaxHeight, "450");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AttachMaxWidth, "450");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AttachAllowBrowseSite, "true");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.MaxAttachHeight, "800");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.MaxAttachWidth, "800");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AttachInsertAllowed, "false");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.ConvertingToJpegAllowed, "false");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AllowHTML, sAllowHTML);
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.EditorType, "0");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.EditorHeight, "350");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.EditorWidth, "99%");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.EditorToolbar, "bold,italic,underline,quote");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.EditorStyle, "2");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.TopicFormId, "0");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.ReplyFormId, "0");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.QuickReplyFormId, "0");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.ProfileTemplateId, "0");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.IsModerated, "false");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.DefaultTrustValue, "0");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.AutoTrustLevel, "0");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.ModApproveTemplateId, "0");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.ModRejectTemplateId, "0");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.ModMoveTemplateId, "0");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.ModDeleteTemplateId, "0");
                        Settings.SaveSetting(ModuleId, sKey, ForumSettingKeys.ModNotifyTemplateId, "0");
                        if (groupId != -1)
                        {
                            if (xNodeList[i].HasChildNodes)
                            {
                                System.Xml.XmlNodeList cNodes = xNodeList[i].ChildNodes;
                                for (int c = 0; c < cNodes.Count; c++)
                                {
                                    var fi = new Forum();
                                    var fc = new ForumController();
                                    fi.ForumID          = -1;
                                    fi.ModuleId         = ModuleId;
                                    fi.ForumGroupId     = groupId;
                                    fi.ParentForumId    = 0;
                                    fi.ForumName        = cNodes[c].Attributes["forumname"].Value;
                                    fi.ForumDesc        = cNodes[c].Attributes["forumdesc"].Value;
                                    fi.ForumSecurityKey = "G:" + groupId.ToString();
                                    fi.ForumSettingsKey = "G:" + groupId.ToString();
                                    fi.Active           = cNodes[c].Attributes["active"].Value == "1";
                                    fi.Hidden           = cNodes[c].Attributes["hidden"].Value == "1";
                                    fi.SortOrder        = c;
                                    fi.PermissionsId    = gi.PermissionsId;
                                    fc.Forums_Save(PortalId, fi, true, true);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        private static TestFilter FromXml(XmlNode xmlNode)
        {
            switch (xmlNode.Name)
            {
                case "filter":
                case "and":
                    var andFilter = new AndFilter();
                    foreach (XmlNode childNode in xmlNode.ChildNodes)
                        andFilter.Add(FromXml(childNode));
                    return andFilter;

                case "or":
                    var orFilter = new OrFilter();
                    foreach (System.Xml.XmlNode childNode in xmlNode.ChildNodes)
                        orFilter.Add(FromXml(childNode));
                    return orFilter;

                case "not":
                    return new NotFilter(FromXml(xmlNode.FirstChild));

                case "id":
                    var idFilter = new IdFilter();
                    foreach (string id in xmlNode.InnerText.Split(COMMA))
                        idFilter.Add(int.Parse(id));
                    return idFilter;

                case "tests":
                    var testFilter = new SimpleNameFilter();
                    foreach (XmlNode childNode in xmlNode.SelectNodes("test"))
                        testFilter.Add(childNode.InnerText);
                    return testFilter;

                case "cat":
                    var catFilter = new CategoryFilter();
                    foreach (string cat in xmlNode.InnerText.Split(COMMA))
                        catFilter.AddCategory(cat);
                    return catFilter;

                default:
                    throw new ArgumentException("Invalid filter element: " + xmlNode.Name, "xmlNode");
            }
        }
コード例 #3
0
        static async Task Main(string[] args)
        {
            StreamWriter streamWriter = null;

            try
            {
                // Get the current directory and make it a DirectoryInfo object.
                // Do not use Environment.CurrentDirectory, vistual studio
                // and visual studio code will return different result:
                // Visual studio will return @"projectDir\bin\Release\netcoreapp2.0\", yet
                // vs code will return @"projectDir\"
                var currentDirectory = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);

                // On windows, the current directory is the compiled binary sits,
                // so string like @"bin\Release\netcoreapp2.0\" will follow the project directory.
                // Hense, the project directory is the great grand-father of the current directory.
                string projectDirectory = currentDirectory.Parent.Parent.Parent.FullName;

                string dataDirectory = Path.Combine(projectDirectory, "Data");

                var countriesSourceFilePath      = Path.Combine(dataDirectory, "SeedCountry.csv");
                var countriesDestinationFilePath = Path.Combine(dataDirectory, "SeedCountryWithBoundary.csv");

                if (!File.Exists(countriesSourceFilePath))
                {
                    throw new ArgumentException($"File '{countriesSourceFilePath}' does not exist");
                }

                string kmlFilePath = Path.Combine(dataDirectory, "UIA_World_Countries_Boundaries.kml");

                if (!File.Exists(kmlFilePath))
                {
                    throw new ArgumentException($"File '{kmlFilePath}' does not exist");
                }

                // Read countries from file
                var countries = FileReader.GetCountries(FileReader.GetFileData(dataDirectory, "SeedCountry.csv"));

                streamWriter = new StreamWriter(path: countriesDestinationFilePath, append: false);
                await streamWriter.WriteLineAsync("CountryId,Name,Alpha2,Alpha3,AffiliationId,CountryBoundaries");

                using (var sr = new StreamReader(kmlFilePath))
                {
                    // Read all data from the reader
                    string kml = sr.ReadToEnd();

                    kml = kml.Replace("xmlns=\"http://earth.google.com/kml/2.0\"", ""); // HACK
                    kml = kml.Replace("xmlns='http://earth.google.com/kml/2.0'", "");   // DOUBLE HACK
                    kml = kml.Replace("xmlns=\"http://earth.google.com/kml/2.1\"", ""); // MULTI HACK!
                    kml = kml.Replace("xmlns='http://earth.google.com/kml/2.1'", "");   // M-M-M-M-M-M-M-MONSTER HACK!!!!

                    kml = kml.Replace("xmlns=\"http://www.opengis.net/kml/2.2\"", "");  // HACK
                    kml = kml.Replace("xmlns='http://www.opengis.net/kml/2.2'", "");    // DOUBLE HACK

                    // Open the downloaded xml in an System.Xml.XmlDocument to allow for XPath searching
                    System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                    doc.LoadXml(kml);

                    // Try to find some sort of name for this kml from various places
                    System.Xml.XmlNode node = doc.SelectSingleNode("//Document[name]/name");

                    // Load Placemarks recursively and put them in folders
                    System.Xml.XmlNode documentNode = doc.SelectSingleNode("/kml/Document");
                    if (documentNode == null)
                    {
                        documentNode = doc.SelectSingleNode("/kml");
                    }

                    if (documentNode != null)
                    {
                        // Find Folders and initialize them recursively
                        System.Xml.XmlNodeList folders = documentNode.SelectNodes("Folder");
                        foreach (System.Xml.XmlNode folderNode in folders)
                        {
                            // Parse all Placemarks that have a name and Polygon
                            System.Xml.XmlNodeList placemarkNodes = folderNode.SelectNodes("Placemark");

                            foreach (System.Xml.XmlNode placemarkNode in placemarkNodes)
                            {
                                System.Xml.XmlNodeList simpleDataNodes = placemarkNode.SelectNodes("ExtendedData/SchemaData/SimpleData");

                                var countryCode = simpleDataNodes[2].InnerText;
                                var countryName = simpleDataNodes[1].InnerText;

                                Console.WriteLine($"Parsing {countryName}...");

                                DbGeography geoBorder = null;

                                System.Xml.XmlNodeList polygonNodes = placemarkNode.SelectNodes("Polygon");
                                foreach (System.Xml.XmlNode polygonNode in polygonNodes)
                                {
                                    // Parse Outer Ring
                                    System.Xml.XmlNode outerRingNode = polygonNode.SelectSingleNode("outerBoundaryIs/LinearRing/coordinates");
                                    if (outerRingNode != null)
                                    {
                                        var points     = GeographicCoordinate.ParseCoordinates(outerRingNode);
                                        var geoPolygon = GeographicCoordinate.ConvertGeoCoordinatesToPolygon(points);

                                        if (geoBorder == null)
                                        {
                                            geoBorder = geoPolygon;
                                        }
                                        else
                                        {
                                            try
                                            {
                                                geoBorder = geoBorder.Union(geoPolygon);
                                            }
                                            catch (Exception ex)
                                            {
                                                Console.ForegroundColor = ConsoleColor.Blue;
                                                Console.WriteLine(ex.Message);
                                                Console.ResetColor();
                                            }
                                        }
                                    }
                                }

                                polygonNodes = placemarkNode.SelectNodes("MultiGeometry/Polygon");
                                foreach (System.Xml.XmlNode polygonNode in polygonNodes)
                                {
                                    // Parse Outer Ring
                                    System.Xml.XmlNode outerRingNode = polygonNode.SelectSingleNode("outerBoundaryIs/LinearRing/coordinates");
                                    if (outerRingNode != null)
                                    {
                                        var points     = GeographicCoordinate.ParseCoordinates(outerRingNode);
                                        var geoPolygon = GeographicCoordinate.ConvertGeoCoordinatesToPolygon(points);

                                        if (geoBorder == null)
                                        {
                                            geoBorder = geoPolygon;
                                        }
                                        else
                                        {
                                            try
                                            {
                                                geoBorder = geoBorder.Union(geoPolygon);
                                            }
                                            catch (Exception ex)
                                            {
                                                Console.ForegroundColor = ConsoleColor.Blue;
                                                Console.WriteLine(ex.Message);
                                                Console.ResetColor();
                                            }
                                        }
                                    }
                                }

                                try
                                {
                                    await SaveCountryInDatabase(countryCode, countryName, geoBorder.AsText());
                                    await SaveCountryInFile(countryCode, countries, geoBorder, streamWriter);
                                }
                                catch (Exception ex)
                                {
                                    Console.ForegroundColor = ConsoleColor.Red;
                                    Console.WriteLine($"Country {countryCode} is not added. Error: {ex.Message}");
                                    Console.ResetColor();
                                }
                            }
                        }
                    }
                }

                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Done");
                Console.ResetColor();
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex.Message);
                Console.ResetColor();
            }
            finally
            {
                if (streamWriter != null)
                {
                    streamWriter.Dispose();
                }
            }

            Console.ReadLine();
        }
コード例 #4
0
 protected System.Xml.XmlNodeList GetConvertionTypeNode()
 {
     System.Xml.XmlNode     convertorsXML = (System.Xml.XmlNode)System.Configuration.ConfigurationManager.GetSection("convertionTypes");
     System.Xml.XmlNodeList list          = convertorsXML.SelectNodes(this.convertionType);
     return(list);
 }
コード例 #5
0
        public void GetXMLMenu()
        {
            try
            {
                if (menuHT != null)
                {
                    return;
                }
                if (currentPage == null)
                {
                    return;
                }

                menuHT = new Hashtable();
                string strFile             = currentPage.MapPath("MenuRight.xml");
                System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                doc.Load(strFile);

                #region 加载版本限制Menu (将不会显示)

                System.Xml.XmlNode node = doc.SelectSingleNode(string.Format("//MenuRightVersion"));
                if (node != null)
                {
                    System.Xml.XmlNodeList selectNodes = node.SelectNodes("ModuleCode");
                    if (selectNodes != null && selectNodes.Count > 0)
                    {
                        foreach (System.Xml.XmlNode _childnode in selectNodes)
                        {
                            string disply = _childnode.Attributes["Disply"].Value.Trim().ToUpper();
                            if (disply == "FALSE")
                            {
                                string code = _childnode.Attributes["Code"].Value;
                                if (!menuHT.Contains(code))
                                {
                                    menuHT.Add(code, code);
                                }
                            }
                        }
                    }
                }
                node = null;

                #endregion

                #region 加载限制Menu (只有Admin才可以访问,其它用户不会显示)

                if (this.UserName != null && this.UserName.ToUpper() != "ADMIN")
                {
                    System.Xml.XmlNode node2 = doc.SelectSingleNode(string.Format("//MenuRightAdmin"));
                    if (node2 != null)
                    {
                        System.Xml.XmlNodeList selectNodes = node2.SelectNodes("ModuleCode");
                        if (selectNodes != null && selectNodes.Count > 0)
                        {
                            foreach (System.Xml.XmlNode _childnode in selectNodes)
                            {
                                string disply = _childnode.Attributes["Disply"].Value.Trim().ToUpper();
                                if (disply == "FALSE")
                                {
                                    string code = _childnode.Attributes["Code"].Value;
                                    if (!menuHT.Contains(code))
                                    {
                                        menuHT.Add(code, code);
                                    }
                                }
                            }
                        }
                    }
                    node2 = null;
                }
                #endregion

                doc = null;
            }
            catch
            { }
        }
コード例 #6
0
        internal void Init(System.Xml.XmlNode XMLNode)
        {
            if (XMLNode.SelectSingleNode("Root") != null)
            {
                _root = XMLNode.SelectSingleNode("Root").InnerText;
            }

            if (XMLNode.SelectSingleNode("Port") != null)
            {
                _port = XMLNode.SelectSingleNode("Port").InnerText;
            }

            if (XMLNode.SelectSingleNode("Compatible") != null)
            {
                _compatible = Convert.ToBoolean(XMLNode.SelectSingleNode("Compatible").InnerText);
            }

            if (XMLNode.SelectSingleNode("Theme") != null)
            {
                _theme     = XMLNode.SelectSingleNode("Theme").InnerText;
                _themePath = _theme + '\\';
            }

            if (XMLNode.SelectSingleNode("SessionOutTime") != null)
            {
                _sessionOutTime = Convert.ToInt32(XMLNode.SelectSingleNode("SessionOutTime").InnerText);
            }

            if (XMLNode.SelectSingleNode("EncryptKey") != null)
            {
                _encryptKey = XMLNode.SelectSingleNode("EncryptKey").InnerText;
            }

            if (XMLNode.SelectSingleNode("EncryptIV") != null)
            {
                _encryptIV = XMLNode.SelectSingleNode("EncryptIV").InnerText;
            }

            if (XMLNode.SelectSingleNode("XySessionId") != null)
            {
                _userKeyCookieName = XMLNode.SelectSingleNode("XySessionId").InnerText;
            }
            else
            {
                _userKeyCookieName = "XyFrameSessionId";
            }

            if (XMLNode.SelectSingleNode("DebugMode") != null)
            {
                _debugMode = string.Compare(XMLNode.SelectSingleNode("DebugMode").InnerText, "true", true) == 0;
            }

            if (XMLNode.SelectSingleNode("Encoding") != null)
            {
                switch (XMLNode.SelectSingleNode("Encoding").InnerText.ToLower())
                {
                case "defalut":
                    _encoding = System.Text.Encoding.Default;
                    break;

                case "gb2312":
                    _encoding = System.Text.Encoding.GetEncoding("GB2312");
                    break;

                case "ascii":
                    _encoding = System.Text.Encoding.ASCII;
                    break;

                case "unicode":
                    _encoding = System.Text.Encoding.Unicode;
                    break;

                case "utf8":
                case "utf-8":
                default:
                    _encoding = new System.Text.UTF8Encoding(true);
                    break;
                }
            }

            foreach (System.Xml.XmlNode _xn in XMLNode.SelectNodes("Config/Item"))
            {
                if (_xn.Attributes["Name"] != null)
                {
                    _config[_xn.Attributes["Name"].Value] = _xn.InnerText;
                }
            }

            foreach (System.Xml.XmlNode _xn in XMLNode.SelectNodes("Translate/Item"))
            {
                if (_xn.Attributes["Name"] != null)
                {
                    _translate[_xn.Attributes["Name"].Value] = _xn.InnerText;
                }
            }

            _xsltDir    = Xy.AppSetting.ThemeDir + _themePath + Xy.AppSetting.XSLT_PATH;
            _pageDir    = Xy.AppSetting.ThemeDir + _themePath + Xy.AppSetting.PAGE_PATH;
            _includeDir = Xy.AppSetting.ThemeDir + _themePath + Xy.AppSetting.INCLUDE_PATH;
            _cacheDir   = Xy.AppSetting.CacheDir + _themePath;

            if (!string.IsNullOrEmpty(_config["ScriptPath"]))
            {
                _scriptPath = _config["ScriptPath"];
            }
            else
            {
                _scriptPath = "/Xy_Theme/" + (_themePath + Xy.AppSetting.SCRIPT_PATH).Replace('\\', '/');;
            }

            if (!string.IsNullOrEmpty(_config["CssPath"]))
            {
                _cssPath = _config["CssPath"];
            }
            else
            {
                _cssPath = "/Xy_Theme/" + (_themePath + Xy.AppSetting.CSS_PATH).Replace('\\', '/');;
            }

            if (!string.IsNullOrEmpty(_config["ScriptDir"]))
            {
                _scriptDir = _config["ScriptDir"];
            }
            else
            {
                _scriptDir = Xy.AppSetting.ThemeDir + _themePath + Xy.AppSetting.SCRIPT_PATH;
            }

            if (!string.IsNullOrEmpty(_config["CssDir"]))
            {
                _cssDir = _config["CssDir"];
            }
            else
            {
                _cssDir = Xy.AppSetting.ThemeDir + _themePath + Xy.AppSetting.CSS_PATH;
            }

            CreateFolders();
        }