/// <summary> /// 处理网站的主方法 /// </summary> /// <param name="sdPath">.sdsite的文件夹路径如zha\zhangling\projectname</param> /// <param name="projName">.sdsite的名projName</param> public bool ExecuteSdsite(string partPath, string projName) { try { string sdPath = AnyFilePath.GetTempFolderAbsolutePath(partPath) + projName + ".sdsite"; //打开网站 SdsiteDocument = new SdsiteXmlDocument(sdPath); SdsiteDocument.Load(); _dealwithFileOrFolder = new DealWithFileOrFolder(); _dealwithFileOrFolder.SdsitesPath = partPath; #region add by zhangling on 2008年6月23日 //得到项目的创建时间 string _createTime = SdsiteDocument.DocumentElement.GetAttribute("createTime"); DateTime dt; if (DateTime.TryParse(_createTime, out dt)) { _projCreateTime = DateTime.Parse(_createTime); } _projCreateTime = dt; //得到项目的发布时间 string _pubTime = SdsiteDocument.DocumentElement.GetAttribute("pubTime"); DateTime _publishDt; if (DateTime.TryParse(_pubTime, out _publishDt)) { _publishTime = DateTime.Parse(_pubTime); } _publishTime = _publishDt; #endregion FolderXmlElement channelRootEle = SdsiteDocument.RootChannel; //做相应处理 SearchAndProcess(channelRootEle); ///移动.sdsite ///modified by zhangling on 2008年6月12日 string sourceFilePath = AnyFilePath.GetTempFolderAbsolutePath(partPath) + projName + ".sdsite"; string targetFilePath = AnyFilePath.GetSdsitesFolderAbsolutePath(partPath) + projName + ".sdsite"; FileService.FileMove(sourceFilePath, targetFilePath); //删除时出错 FolderService.FolderDelete(AnyFilePath.GetTempFolderAbsolutePath(partPath)); return(true); } catch (Exception ex) { ExceptionService.WriteExceptionLog(ex); return(false); } }
/// <summary> /// 打开Sdsite网站 /// </summary> /// <param name="sdsiteFilePath">.sdsite的路径</param> static public void OpenSdsite(string sdsiteFilePath, string userName) { if (!CanOpenProject(sdsiteFilePath, userName)) { return; } string folder = Path.GetDirectoryName(sdsiteFilePath); string sdsiteName = Path.GetFileNameWithoutExtension(sdsiteFilePath); string designDataFile = Path.Combine(folder, sdsiteName + ".layout"); ///打开sdsite try { SdsiteXmlDocument sdsiteDoc = new SdsiteXmlDocument(sdsiteFilePath); sdsiteDoc.Load(); CurrentDocument = sdsiteDoc; } catch (System.Exception) { Service.Sdsite.CurrentDocument = null; MessageService.Show(string.Format("载入{0}失败!", Path.GetFileName(sdsiteFilePath)), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ///打开DesignData if (File.Exists(designDataFile)) { DesignDataDocument = new DesignDataXmlDocument(designDataFile); DesignDataDocument.Load(); } else { DesignDataDocument = new DesignDataXmlDocument(designDataFile); DesignDataDocument.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?> <layout> <tree> </tree> <documents> </documents> <productPropertyGroup></productPropertyGroup> <treeOpenItems></treeOpenItems> </layout>"); } OnSdsiteOpened(EventArgs.Empty); }
/// <summary> /// 构造函数。构造一个包含SdsiteXmlDocument对象,及生成的相关参数的实例。 /// </summary> /// <param name="sdsitePath">SdsiteXmlDocument的文件路径。</param> /// <param name="buildPath">生成html源码的目录</param> public ToHtmlHelper(string sdsitePath, string buildPath) { ///初始化一个SdsiteXmlDocument Debug.Assert(File.Exists(sdsitePath), sdsitePath + " isn't Exist!"); SdsiteXmlDocument doc = new SdsiteXmlDocument(sdsitePath); doc.Load(); this.SdsiteXmlDocument = doc; ///初始化生成路径 if (!Directory.Exists(buildPath)) { ///TODO:还没有想好如何处理这个问题。 ///主要是传入的是一个错误的字符串(根本与目录无关)怎么办? Directory.CreateDirectory(buildPath); Debug.Assert(Directory.Exists(GetDir(buildPath)), "网站初始根路径不存在,请检查。\r\n" + buildPath); } _BuildPath = GetDir(buildPath); }
/// <summary> /// 测试此用户名是否可以打开此网站 /// </summary> /// <param name="sdsiteFilePath"></param> /// <param name="userName"></param> /// <returns></returns> static public bool CanOpenProject(string sdsiteFilePath, string userName) { ////得到projectFile的目录信息 //string projectFolder = Path.GetDirectoryName(sdsiteFilePath); ////得到文件名 //string projectName = Path.GetFileNameWithoutExtension(sdsiteFilePath); ////为了得到layout的路径 //string designDataFile = Path.Combine(projectFolder, projectName + ".layout"); SdsiteXmlDocument sdsiteDoc = new SdsiteXmlDocument(sdsiteFilePath); sdsiteDoc.Load(); if (userName != NoValidate) { ///校验用户 if ((!string.IsNullOrEmpty(sdsiteDoc.OwnerUser)) && sdsiteDoc.OwnerUser != userName) { return(false); } } return(true); }