Example #1
0
        /// <summary>
        /// 将现在文件复制到新文件里 (如果有同名的文件,则就将其删除)
        /// </summary>
        /// <param name="sourceFilePath"></param>
        /// <param name="targetFilePath"></param>
        /// <returns></returns>
        public static bool FileCopy(string sourceFilePath, string targetFilePath)
        {
            if (!File.Exists(sourceFilePath))
            {
                return(false);
            }
            string targetPath = Path.GetDirectoryName(targetFilePath);

            if (!Directory.Exists(targetPath))
            {
                Directory.CreateDirectory(targetPath);
            }
            try
            {
                if (File.Exists(targetFilePath))
                {
                    File.Delete(targetFilePath);
                }
                File.Copy(sourceFilePath, targetFilePath); //不提供目录的创建,只能在同一目录下
                return(true);
            }
            catch (Exception e)
            {
                ExceptionService.WriteExceptionLog(e);
                return(false);
            }
        }
Example #2
0
        /// <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);
            }
        }
Example #3
0
 public static bool FileDelete(string filePath)
 {
     try
     {
         File.Delete(filePath);
         return(true);
     }
     catch (Exception e)
     {
         ExceptionService.WriteExceptionLog(e);
         return(false);
     }
 }
Example #4
0
 public static bool FolderDelete(string directoryPath)
 {
     try
     {
         Directory.Delete(directoryPath, true);
         return(true);
     }
     catch (Exception e)
     {
         ExceptionService.WriteExceptionLog(e);
         return(false);
     }
 }
Example #5
0
 public static bool FolderMove(string sourceDirectoryPath, string targetDirectoryPath)
 {
     try
     {
         //当sourceDirectoryPath 与targetDirectoryPath路径相同时,则会出现问题
         Directory.Move(sourceDirectoryPath, targetDirectoryPath);
         return(true);
     }
     catch (Exception e)
     {
         ExceptionService.WriteExceptionLog(e);
         return(false);
     }
 }
Example #6
0
 public static bool FileSave(byte[] content, string filePath)
 {
     try
     {
         string fileUrlPath = Path.GetDirectoryName(filePath);
         Directory.CreateDirectory(fileUrlPath);
         File.WriteAllBytes(filePath, content);
         return(true);
     }
     catch (Exception e)
     {
         ExceptionService.WriteExceptionLog(e);
         return(false);
     }
 }
Example #7
0
 /// <summary>
 /// 发送无消息体的消息到客户端
 /// </summary>
 /// <param name="type"></param>
 private void ResponseMessage(NetworkStream stream, MessageType type, int state)
 {
     try
     {
         MessageHead head   = new MessageHead((int)type, 0, state);
         MessageBag  bag    = new MessageBag(head);
         byte[]      buffer = bag.ToBytes();
         stream.Write(buffer, 0, buffer.Length);
     }
     catch (Exception e)
     {
         ExceptionService.WriteExceptionLog(e);
         DisposeUserMethod.DeleteUser();
         Client.Client.Close();
     }
 }
Example #8
0
        /// <summary>
        /// 监听并处理客户端请求
        /// </summary>
        public void Listen()
        {
            ///读取配置文件,获取端口号
            Configuration config     = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            string        serverPort = config.AppSettings.Settings["ServerPort"].Value;

            Port = Convert.ToInt32(serverPort);

            ///初始化PathService
            SimplusD.PathService.Initialize(Application.StartupPath);

            try
            {
                ///初始化Tcp服务端
                _listener = new TcpListener(IPAddress.Any, Port);
                _listener.Start();

                while (true)
                {
                    ///接收客户端请求
                    TcpClient tcpClient = _listener.AcceptTcpClient();

                    ///启动一个线程来处理这此客户端请求
                    ClientThread clientThread = new ClientThread(tcpClient);
                    clientThread._publisherIP = ((IPEndPoint)tcpClient.Client.RemoteEndPoint).Address.ToString();

                    Thread thread = new Thread(new ThreadStart(clientThread.ThreadCallback));
                    thread.Start();

                    LogService.WriteServerRunLog(LogLevel.Info, "接收来自" + clientThread._publisherIP + "一个请求,线程启动");
                }
            }
            catch (Exception e)
            {
                ExceptionService.WriteExceptionLog(e);
                MessageService.Show(e.Message);
                Application.Exit();
            }
        }
Example #9
0
        /// <summary>
        /// 保存文件
        /// </summary>
        /// <param name="fileContent"></param>
        /// <returns></returns>
        private bool FileSave(byte[] fileContent, string fileUrl)
        {
            try
            {
                ///保存到临时文件夹
                ///modified by zhangling on 2008年6月12日
                string _fileUrl = Path.Combine(AnyFilePath.GetTempFolderAbsolutePath(_userFilePath), fileUrl);
                FileService.FileSave(fileContent, _fileUrl);

                ///接收到的文件数+1
                _fileCount += 1;

                ///总结接收文件的字节数
                _uploadFileBytesAmount += fileContent.Length;
                return(true);
            }
            catch (Exception e)
            {
                ExceptionService.WriteExceptionLog(e);
                return(false);
            }
        }
Example #10
0
        //SdsiteXmlDocument sdsiteDocument;

        /// <summary>
        /// 开始生成网站
        /// </summary>
        /// <returns></returns>
        public bool StartBuild(string partPath, string projName)
        {
            string sdPath    = AnyFilePath.GetSdsitesFolderAbsolutePath(partPath);
            string buildPath = AnyFilePath.GetWebAbsolutePath(partPath);

            toHtmlHelperObj = new ToHtmlHelper(sdPath, buildPath);

            resStartPath = sdPath + @"Root\" + @"Resource";
            resToPath    = buildPath + @"\Resource";

            buildFile = new BuildFile();
            buildFile.SdsiteDocument  = toHtmlHelperObj.SdsiteXmlDocument;
            buildFile.ToHtmlHelperObj = toHtmlHelperObj;

            FolderXmlElement channelRootEle = toHtmlHelperObj.SdsiteXmlDocument.RootChannel;

            //string sdPath = AnyFilePath.GetSdsitesFolderAbsolutePath(partPath) + projName + ".sdsite";
            ////打开网站
            //this.sdsiteDocument = new SdsiteXmlDocument(sdPath);
            //this.sdsiteDocument.Load();
            //buildFile = new BuildFile();
            //buildFile.SdsiteDocument = this.sdsiteDocument;
            //buildFile.BuildFilePath = partPath;
            //FolderXmlElement channelRootEle = this.sdsiteDocument.RootChannel;

            try
            {
                SearchAndProcess(channelRootEle);

                return(true);
            }
            catch (Exception Ex)
            {
                ExceptionService.WriteExceptionLog(Ex);
                return(false);
            }
        }