コード例 #1
0
        public static int WriteFileRouter(int PortalId, int ContentItemId, string CultureCode, bool Discontinued, string HomeDirectory, string RouterPath, string RouterFile)
        {
            List<aspnet_Routes> lst = RouteController.GetListByPortalIdCultureCodeStatus(PortalId, ContentItemId, CultureCode, Discontinued);

            if (!Directory.Exists(HomeDirectory))
                Directory.CreateDirectory(HomeDirectory);

            if (!Directory.Exists(RouterPath))
                Directory.CreateDirectory(RouterPath);

            string FileRouterPath = Path.Combine(RouterPath, RouterFile);
            if (!System.IO.File.Exists(FileRouterPath))
                System.IO.File.Create(FileRouterPath);

            GC.Collect();
            GC.WaitForPendingFinalizers();

            FileHandleClass file_obj = new FileHandleClass();
            FileInfo fileInfo = new FileInfo(FileRouterPath);
            string n = file_obj.ReadFile(fileInfo.FullName);
            int start = 0; int end = 0;

            if (n.IndexOf("//start") > -1)
                start = n.IndexOf("//start");

            if (n.IndexOf("//end") > -1)
                end = n.IndexOf("//end");

            string content = n.Replace(n.Substring(start + 7, end - start - 7), "\r\n            ");
            file_obj.UpDateFile(fileInfo.FullName, content);
            n = file_obj.ReadFile(fileInfo.FullName);
            string optionparams = string.Empty;
            for (int i = 0; i < lst.Count; i++)
            {
                string RouteName = lst[i].RouteName;
                string RouteUrl = lst[i].RouteUrl;
                string PhysicalFile = lst[i].PhysicalFile;
                bool CheckPhysicalUrlAccess = lst[i].CheckPhysicalUrlAccess;
                string RouteValueDictionary = StringDirectionProcess(lst[i].RouteValueDictionary);
                if (RouteValueDictionary != "")
                    RouteValueDictionary = ", new System.Web.Routing.RouteValueDictionary { " + RouteValueDictionary + " })";
                else
                    RouteValueDictionary = ")";
                string newrow = "routes.MapPageRoute(\"" + RouteName + "\", \"" + RouteUrl + "\", \"" + PhysicalFile + "\"," + CheckPhysicalUrlAccess.ToString().ToLower() + RouteValueDictionary + ";";
                n = n.Replace("//end", newrow + System.Environment.NewLine + "            //end");
                file_obj.UpDateFile(fileInfo.FullName, n);
            }

            return 1;
        }