Beispiel #1
0
        void tmr_Elapsed(object sender, ElapsedEventArgs e)
        {
            const char Delim = '─';

            if (this.mRunning)
            {
                return;
            }
            else
            {
                this.mRunning = true;
            }

            string LogFullPath      = GetLogFullPath();
            string LogFolderForSync = Path.GetDirectoryName(LogFullPath);

            try
            {
                CXmlConfig xc = GetXmlConfig();

                string[] aRootPathSrc = xc.GetSetting("RootPathSrc", "").Split(Delim);

                string[] aFtpHost = xc.GetSetting("FtpHost", "").Split(Delim);
                string[] aFtpId   = xc.GetSetting("FtpId", "").Split(Delim);

                string[] aFtpPassword = xc.GetSetting("FtpPassword", "").Split(Delim);
                for (int i = 0; i < aFtpPassword.Length; i++)
                {
                    aFtpPassword[i] = CEncrypt.DecryptPassword(aFtpPassword[i]);
                }

                string[] aFtpFolder = xc.GetSetting("FtpFolder", "").Split(Delim);

                string[] aSyncType = xc.GetSetting("SyncType", "").Split(Delim);

                string[] aMinifyJs = xc.GetSetting("MinifyJs", "").Split(Delim);

                string[] aFileNameToAppendParam = xc.GetSetting("FileNameToAppendParam", "").Split(Delim);

                string[]   asDateTimeAfter = xc.GetSetting("DateTimeAfter", "").Split(Delim);
                DateTime[] aDateTimeAfter  = new DateTime[asDateTimeAfter.Length];
                for (int i = 0; i < asDateTimeAfter.Length; i++)
                {
                    aDateTimeAfter[i] = CFindRep.IfNotDateTimeThen19000101(asDateTimeAfter[i]);
                }


                for (int i = 0; i < aRootPathSrc.Length; i++)
                {
                    CFtpInfoSync[] aFtpInfo = new CFtpInfoSync[]
                    {
                        new CFtpInfoSync()
                        {
                            Host     = aFtpHost[i],
                            UserId   = aFtpId[i],
                            Password = aFtpPassword[i],
                            Folder   = aFtpFolder[i]
                        }
                    };

                    CSyncFile sf = new CSyncFile(aRootPathSrc[i], aFtpInfo, CEnum.GetValueByName <SyncTypes>(aSyncType[i]), (aMinifyJs[i] == "1"), aFileNameToAppendParam, aDateTimeAfter[i], LogFolderForSync);
                    sf.DisallowedFolder = new string[] { LogFolderForSync };
                    sf.CopyAll();

                    aDateTimeAfter[i] = DateTime.Now;
                }


                for (int i = 0; i < aDateTimeAfter.Length; i++)
                {
                    asDateTimeAfter[i] = aDateTimeAfter[i].ToString(CConst.Format_yyyy_MM_dd_HH_mm_ss);
                }

                xc.SaveSetting("DateTimeAfter", string.Join(Delim.ToString(), asDateTimeAfter));
            }
            catch (Exception ex)
            {
                CFile.AppendTextToFile(LogFullPath, "Error " + DateTime.Now.ToString()
                                       + "\r\n" + ex.Message
                                       + "\r\n" + ex.StackTrace
                                       + "\r\n" + ex.Source);
            }

            this.mRunning = false;
        }
Beispiel #2
0
        private bool IsValid(out SInfo InfoIs, out string ErrMsgIs)
        {
            InfoIs   = new SInfo();
            ErrMsgIs = "";

            DataTable dt = GetTable();

            InfoIs.Name = txtName.Text.Trim();
            if (InfoIs.Name == "")
            {
                ErrMsgIs = "Name not entered.";
                return(false);
            }

            InfoIs.RootFolderSrc = txtRootFolderSrc.Text.Trim();
            if (InfoIs.RootFolderSrc == "")
            {
                ErrMsgIs = "Source Folder not entered.";
                return(false);
            }
            if (!Directory.Exists(InfoIs.RootFolderSrc))
            {
                ErrMsgIs = "Source Folder: " + InfoIs.RootFolderSrc + " is not exists.";
                return(false);
            }

            InfoIs.aRootFolderDest = txtRootFolderDest.Text.Trim().Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string RootFolderDest in InfoIs.aRootFolderDest)
            {
                if (RootFolderDest != "")
                {
                    if (!Directory.Exists(RootFolderDest))
                    {
                        ErrMsgIs = "Destination Folder: " + RootFolderDest + " is not exists.";
                        return(false);
                    }
                }
            }

            if (txtFtpHost.Text.Trim() != "")
            {
                InfoIs.FtpInfo            = new CFtpInfoSync();
                InfoIs.FtpInfo.Host       = txtFtpHost.Text.Trim();
                InfoIs.FtpInfo.Folder     = txtFtpFolder.Text.Trim();
                InfoIs.FtpInfo.Port       = Convert.ToInt32(nudFtpPort.Value);
                InfoIs.FtpInfo.UsePassive = chkFtpUsePassive.Checked;
                InfoIs.FtpInfo.UserId     = txtFtpId.Text.Trim();
                InfoIs.FtpInfo.Password   = txtFtpPassword.Text.Trim();
            }

            if ((InfoIs.aRootFolderDest.Length == 0) && (InfoIs.FtpInfo == null))
            {
                ErrMsgIs = "Both of Destination Folder and FTP Info is empty.";
                return(false);
            }
            else if ((InfoIs.aRootFolderDest.Length != 0) && (InfoIs.FtpInfo != null))
            {
                ErrMsgIs = "Both of Destination Folder and FTP Info is not empty.";
                return(false);
            }

            InfoIs.IntervalMinutes        = Convert.ToInt32(nudIntervalMinutes.Value);
            InfoIs.SyncType               = CEnum.GetValueByName <SyncTypes>((string)cboSyncType.SelectedValue);
            InfoIs.MinifyJs               = chkMinifyJs.Checked;
            InfoIs.EmptyFolderHasNoFile   = chkEmptyFolderHasNoFile.Checked;
            InfoIs.aFullPathReferencingJs = txtFullPathReferencingJs.Text.Trim().Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            InfoIs.aJsFullPathRefered     = txtJsFullPathRefered.Text.Trim().Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            InfoIs.DateTimeAfter          = dtpDateTimeAfter.Value;
            InfoIs.DisallowedExt          = txtDisallowedExt.Text.Trim();
            InfoIs.AllowedOnlyExt         = txtAllowedOnlyExt.Text.Trim();
            InfoIs.DisallowedFolder       = txtDisallowedFolder.Text.Trim();
            InfoIs.AllowedOnlyFolder      = txtAllowedOnlyFolder.Text.Trim();

            InfoIs.LogFolder = txtLogFolder.Text.Trim();
            if (InfoIs.LogFolder == "")
            {
                ErrMsgIs = "Log Folder not entered.";
                return(false);
            }
            if (!Directory.Exists(InfoIs.LogFolder))
            {
                ErrMsgIs = "Log Folder: " + InfoIs.LogFolder + " is not exists.";
                return(false);
            }

            return(true);
        }