Example #1
0
        private void FormMain_Shown(object sender, EventArgs e)
        {
            System.Timers.Timer Timer = new System.Timers.Timer(300000);

            Timer.Elapsed  += new System.Timers.ElapsedEventHandler(LoginKeep);
            Timer.AutoReset = true;
            Timer.Start();

            ListViewDataLoad();

            AppCommon.ProcessExecute(AppCommon.PathCombine(AppConfig.AppPath, "dboxSyncer.Task.exe"), "", -1);
        }
Example #2
0
        /// <summary>
        /// 同步设置按钮点击事件
        /// </summary>
        private void ButtonSetting_Click(object sender, EventArgs e)
        {
            XmlDocument XDocument     = new XmlDocument();
            XmlNode     XNode         = default(XmlNode);
            string      XPath         = "/configuration/appSettings/add[@key=\"{key}\"]";
            string      ConfigPath    = AppCommon.PathCombine(AppConfig.AppPath, "dboxSyncer.exe.config");
            string      IntervalTime  = listBoxIntervalTime.Text;
            string      UploadSpeed   = textBoxUploadSpeed.Text;
            string      DownloadSpeed = textBoxDownloadSpeed.Text;

            if (UploadSpeed.TypeInt() < 0 || UploadSpeed.TypeInt() > 1000)
            {
                MessageBox.Show(LangTable["tipsUploadSpeedError"].TypeString());
                return;
            }

            if (DownloadSpeed.TypeInt() < 0 || DownloadSpeed.TypeInt() > 1000)
            {
                MessageBox.Show(LangTable["tipsDownloadSpeedError"].TypeString());
                return;
            }

            XDocument.Load(ConfigPath);

            XNode = (XmlNode)XDocument.SelectSingleNode(XPath.Replace("{key}", "IntervalTime"));

            if (AppCommon.IsNothing(XNode) == false)
            {
                XNode.Attributes["value"].InnerText = IntervalTime;
            }

            XNode = (XmlNode)XDocument.SelectSingleNode(XPath.Replace("{key}", "UploadSpeed"));

            if (AppCommon.IsNothing(XNode) == false)
            {
                XNode.Attributes["value"].InnerText = UploadSpeed;
            }

            XNode = (XmlNode)XDocument.SelectSingleNode(XPath.Replace("{key}", "DownloadSpeed"));

            if (AppCommon.IsNothing(XNode) == false)
            {
                XNode.Attributes["value"].InnerText = DownloadSpeed;
            }

            XDocument.Save(ConfigPath);

            AppCommon.ProcessExit("dboxSyncer.Task");
            AppCommon.ProcessExecute(AppCommon.PathCombine(AppConfig.AppPath, "dboxSyncer.Task.exe"), "", -1);
        }
Example #3
0
        /// <summary>
        /// 加载语言
        /// </summary>
        private void LoadLanguage(ref Hashtable LangTable)
        {
            XmlDocument XDocument = new XmlDocument();
            XmlNode     XNodes    = default(XmlNode);
            string      FilePath  = AppCommon.PathCombine(AppConfig.AppPath, "language.xml");

            XDocument.Load(FilePath);

            XNodes = XDocument.SelectSingleNode("/language/formMain");

            foreach (XmlNode XNode in XNodes.ChildNodes)
            {
                LangTable.Add(XNode.Name, XNode.InnerText);
            }
        }
Example #4
0
        /// <summary>
        /// 手工同步菜单点击事件
        /// </summary>
        private void ToolStripMenuItemSync_Click(object sender, EventArgs e)
        {
            if (AppCommon.ProcessExist("dboxSyncer.Process") == true)
            {
                MessageBox.Show(LangTable["tipsProcessing"].TypeString());
            }
            else
            {
                buttonSync.Enabled = false;
                buttonSync.Text    = LangTable["buttonProcessing"].TypeString();

                AppCommon.ProcessExecute(AppCommon.PathCombine(AppConfig.AppPath, "dboxSyncer.Process.exe"), "", -1);

                buttonSync.Enabled = true;
                buttonSync.Text    = LangTable["buttonSync"].TypeString();
            }
        }
Example #5
0
        /// <summary>
        /// 用户登录数据保存
        /// </summary>
        private void LoginDataSave()
        {
            XmlDocument XDocument  = new XmlDocument();
            XmlNode     XNode      = default(XmlNode);
            string      XPath      = "/configuration/appSettings/add[@key=\"{key}\"]";
            string      ConfigPath = AppCommon.PathCombine(AppConfig.AppPath, "dboxSyncer.exe.config");

            XDocument.Load(ConfigPath);

            XNode = (XmlNode)XDocument.SelectSingleNode(XPath.Replace("{key}", "ServerHost"));

            if (AppCommon.IsNothing(XNode) == false)
            {
                XNode.Attributes["value"].InnerText = AppConfig.ServerHost;
            }

            XNode = (XmlNode)XDocument.SelectSingleNode(XPath.Replace("{key}", "LoginId"));

            if (AppCommon.IsNothing(XNode) == false)
            {
                XNode.Attributes["value"].InnerText = AppConfig.LoginId;
            }

            XNode = (XmlNode)XDocument.SelectSingleNode(XPath.Replace("{key}", "Password"));

            if (AppCommon.IsNothing(XNode) == false)
            {
                XNode.Attributes["value"].InnerText = AppConfig.Password;
            }

            XNode = (XmlNode)XDocument.SelectSingleNode(XPath.Replace("{key}", "UserSession"));

            if (AppCommon.IsNothing(XNode) == false)
            {
                XNode.Attributes["value"].InnerText = AppConfig.UserSession;
            }

            XNode = (XmlNode)XDocument.SelectSingleNode(XPath.Replace("{key}", "AutoLogin"));

            if (AppCommon.IsNothing(XNode) == false)
            {
                XNode.Attributes["value"].InnerText = AppConfig.AutoLogin;
            }

            XDocument.Save(ConfigPath);
        }
Example #6
0
        /// <summary>
        /// 获取配置文件参数值
        /// </summary>
        private static string ConfigValue(string Name)
        {
            System.Configuration.Configuration Config = default(System.Configuration.Configuration);
            AppSettingsSection AppSetting             = default(AppSettingsSection);

            Config = ConfigurationManager.OpenExeConfiguration(AppCommon.PathCombine(AppConfig.AppPath, "dboxSyncer.exe"));

            AppSetting = (System.Configuration.AppSettingsSection)Config.GetSection("appSettings");

            if (AppCommon.IsNothing(AppSetting.Settings[Name]) == true)
            {
                return(string.Empty);
            }
            else
            {
                return(AppSetting.Settings[Name].Value);
            }
        }
Example #7
0
        /// <summary>
        /// 同步日志
        /// </summary>
        private static void SyncLog(string Action, string FilePath)
        {
            string[] Files = {};

            if (Directory.Exists(AppCommon.PathCombine(AppConfig.AppPath, "log")) == false)
            {
                Directory.CreateDirectory(AppCommon.PathCombine(AppConfig.AppPath, "log"));
            }

            Files = Directory.GetFiles(AppCommon.PathCombine(AppConfig.AppPath, "log"));

            foreach (string SubFile in Files)
            {
                if (DateTime.Compare(File.GetLastWriteTime(SubFile), DateTime.Now.AddDays(-14)) < 0)
                {
                    File.Delete(SubFile);
                }
            }

            File.AppendAllText(AppCommon.PathCombine(AppConfig.AppPath, "log", "" + DateTime.Now.ToString("yyyy-MM-dd") + ".log"), "" + DateTime.Now.ToString() + " " + Action + " " + FilePath + "\n");
        }
Example #8
0
        public static void Main()
        {
            if (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length - 1 > 0)
            {
                Application.Exit();
            }

            try
            {
                TaskQueue();
            }
            catch (Exception ex)
            {
                File.AppendAllText(AppCommon.PathCombine(AppConfig.AppPath, "error.log"), "" + DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n");
            }
            finally
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
Example #9
0
        public static void Main()
        {
            if (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length - 1 > 0)
            {
                Application.Exit();
            }

            TimeSpan TS = new TimeSpan();

            try
            {
                do
                {
                    TS = DateTime.Now.AddMinutes(AppConfig.IntervalTime.TypeInt()) - DateTime.Now;

                    Thread.Sleep((int)TS.TotalMilliseconds);

                    if (AppCommon.ProcessExist("dboxSyncer") == false)
                    {
                        Application.Exit();
                    }

                    if (AppCommon.ProcessExist("dboxSyncer.Process") == false)
                    {
                        AppCommon.ProcessExecute(AppCommon.PathCombine(AppConfig.AppPath, "dboxSyncer.Process.exe"), "", 0);
                    }
                } while (true);
            }
            catch (Exception ex)
            {
                File.AppendAllText(AppCommon.PathCombine(AppConfig.AppPath, "error.log"), "" + DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n");
            }
            finally
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
Example #10
0
        /// <summary>
        /// 文件下载
        /// </summary>
        private static void FileDownload(int FileId, string FileCodeId, string FileName, string LocalFolderPath)
        {
            WebClient  WebClient    = new WebClient();
            FileStream FileStream   = default(FileStream);
            Stream     WebStream    = default(Stream);
            string     DownloadUrl  = "";
            string     TempFilePath = "";
            string     SaveFilePath = "";

            byte[] ByteBuffer   = {};
            int    ByteRead     = 0;
            int    IntervalTime = 0;

            try
            {
                DownloadUrl = "" + AppConfig.ServerHost + "/sync/file-download.ashx?id=" + FileId + "&codeid=" + FileCodeId + "&timestamp=" + DateTime.Now.ToString("yyyyMMddHHmmssfffffff") + "";

                if (Directory.Exists(AppCommon.PathCombine(AppConfig.AppPath, "temp")) == false)
                {
                    Directory.CreateDirectory(AppCommon.PathCombine(AppConfig.AppPath, "temp"));
                }

                TempFilePath = AppCommon.PathCombine(AppConfig.AppPath, "temp", FileName);

                SaveFilePath = AppCommon.PathCombine(LocalFolderPath, FileName);

                if (File.Exists(TempFilePath) == true)
                {
                    File.Delete(TempFilePath);
                }

                if (AppConfig.DownloadSpeed.TypeInt() == 0)
                {
                    IntervalTime = 0;
                }
                else
                {
                    IntervalTime = (int)1000 / (AppConfig.DownloadSpeed.TypeInt());
                }

                FileStream = new FileStream(TempFilePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite, 4096, true);

                WebClient.Proxy = null;

                WebClient.Headers.Add("Cookie", AppConfig.UserSession);

                WebStream = WebClient.OpenRead(DownloadUrl);

                ByteBuffer = new byte[1024];

                ByteRead = WebStream.Read(ByteBuffer, 0, 1024);

                while (ByteRead > 0)
                {
                    FileStream.Write(ByteBuffer, 0, ByteRead);

                    ByteRead = WebStream.Read(ByteBuffer, 0, 1024);

                    Application.DoEvents();

                    if (IntervalTime > 0)
                    {
                        Thread.Sleep(IntervalTime);
                    }
                }

                WebClient.Dispose();

                WebStream.Close();
                WebStream.Dispose();

                FileStream.Close();
                FileStream.Dispose();

                File.Copy(TempFilePath, SaveFilePath, true);

                SyncLog("download", SaveFilePath);
            }
            catch (Exception ex)
            {
                File.AppendAllText(AppCommon.PathCombine(AppConfig.AppPath, "error.log"), "" + DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n");
            }
            finally
            {
                if (AppCommon.IsNothing(WebClient) == false)
                {
                    WebClient.Dispose();
                }

                if (AppCommon.IsNothing(WebStream) == false)
                {
                    WebStream.Close();
                    WebStream.Dispose();
                }

                if (AppCommon.IsNothing(FileStream) == false)
                {
                    FileStream.Close();
                    FileStream.Dispose();
                }

                File.Delete(TempFilePath);
            }
        }
Example #11
0
        /// <summary>
        /// 新版本上传
        /// </summary>
        private static void FileUpversion(string FilePath, string FileSize, string FileHash, int FileId)
        {
            WebClient  WebClient    = new WebClient();
            FileStream FileStream   = default(FileStream);
            Stream     WebStream    = default(Stream);
            string     UpversionUrl = "";

            byte[] ByteBuffer   = {};
            int    ByteRead     = 0;
            int    IntervalTime = 0;

            try
            {
                UpversionUrl = "" + AppConfig.ServerHost + "/sync/file-upversion.ashx?guid=" + System.Guid.NewGuid().ToString("N") + "&fileid=" + FileId + "&filepath=" + HttpUtility.UrlEncode(FilePath) + "&filesize=" + FileSize + "&filehash=" + FileHash + "&timestamp=" + DateTime.Now.ToString("yyyyMMddHHmmssfffffff") + "";

                if (AppConfig.UploadSpeed.TypeInt() == 0)
                {
                    IntervalTime = 0;
                }
                else
                {
                    IntervalTime = (int)1000 / (AppConfig.UploadSpeed.TypeInt());
                }

                FileStream = new FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 4096, true);

                WebClient.Proxy = null;

                WebClient.Headers.Add("Cookie", AppConfig.UserSession);

                WebStream = WebClient.OpenWrite(UpversionUrl);

                ByteBuffer = new byte[1024];

                ByteRead = FileStream.Read(ByteBuffer, 0, 1024);

                while (ByteRead > 0)
                {
                    WebStream.Write(ByteBuffer, 0, ByteRead);

                    ByteRead = FileStream.Read(ByteBuffer, 0, 1024);

                    Application.DoEvents();

                    if (IntervalTime > 0)
                    {
                        Thread.Sleep(IntervalTime);
                    }
                }

                WebClient.Dispose();

                WebStream.Close();
                WebStream.Dispose();

                FileStream.Close();
                FileStream.Dispose();

                SyncLog("upversion", FilePath);
            }
            catch (Exception ex)
            {
                File.AppendAllText(AppCommon.PathCombine(AppConfig.AppPath, "error.log"), "" + DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n");
            }
            finally
            {
                if (AppCommon.IsNothing(WebClient) == false)
                {
                    WebClient.Dispose();
                }

                if (AppCommon.IsNothing(WebStream) == false)
                {
                    WebStream.Close();
                    WebStream.Dispose();
                }

                if (AppCommon.IsNothing(FileStream) == false)
                {
                    FileStream.Close();
                    FileStream.Dispose();
                }
            }
        }
Example #12
0
        /// <summary>
        /// 读取网络文件夹获取文件集合返回list<hashtable>
        /// </summary>
        private static void NetDataToList(int NetFolderId, ref List <Hashtable> NetDataList, ref Hashtable NetFolderTable)
        {
            WebClient WebClient = new WebClient();
            Uri       HttpUri   = default(Uri);

            byte[] ResponseData = {};
            string XData        = "";

            try
            {
                HttpUri = new Uri("" + AppConfig.ServerHost + "/sync/file-list-xml.ashx?folderid=" + NetFolderId + "&timestamp=" + DateTime.Now.ToString("yyyyMMddHHmmssfffffff") + "");

                WebClient.Proxy = null;

                WebClient.Headers.Add("Cookie", AppConfig.UserSession);

                ResponseData = WebClient.DownloadData(HttpUri);

                WebClient.Dispose();

                XData = Encoding.UTF8.GetString(ResponseData);

                if (XData.IndexOf("<item>") == -1 || XData.IndexOf("</item>") == -1)
                {
                    return;
                }

                XmlDocument XDocument = new XmlDocument();
                XmlNodeList XNodes    = default(XmlNodeList);

                XDocument.LoadXml(XData);

                XNodes = XDocument.SelectNodes("/root/folder");

                foreach (XmlNode XNode in XNodes)
                {
                    NetFolderTable.Add("Share", XNode.SelectSingleNode("share").InnerText);
                    NetFolderTable.Add("Lock", XNode.SelectSingleNode("lock").InnerText);
                    NetFolderTable.Add("Purview", XNode.SelectSingleNode("purview").InnerText);
                }

                XNodes = XDocument.SelectNodes("/root/files/item");

                foreach (XmlNode XNode in XNodes)
                {
                    Hashtable Table = new Hashtable();

                    Table.Add("Id", XNode.SelectSingleNode("id").InnerText);
                    Table.Add("VersionId", XNode.SelectSingleNode("versionId").InnerText);
                    Table.Add("CodeId", XNode.SelectSingleNode("codeId").InnerText);
                    Table.Add("Hash", XNode.SelectSingleNode("hash").InnerText);
                    Table.Add("Name", XNode.SelectSingleNode("name").InnerText);
                    Table.Add("Size", XNode.SelectSingleNode("size").InnerText);
                    Table.Add("Lock", XNode.SelectSingleNode("lock").InnerText);
                    Table.Add("UpdateTime", XNode.SelectSingleNode("updateTime").InnerText);

                    NetDataList.Add(Table);
                }
            }
            catch (Exception ex)
            {
                File.AppendAllText(AppCommon.PathCombine(AppConfig.AppPath, "error.log"), "" + DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n");
            }
            finally
            {
                if (AppCommon.IsNothing(WebClient) == false)
                {
                    WebClient.Dispose();
                }
            }
        }
Example #13
0
 /// <summary>
 /// 获取数据文件路径
 /// </summary>
 private static string GetDataPath()
 {
     return(AppCommon.PathCombine(AppConfig.AppPath, "data.xml"));
 }