Esempio n. 1
0
        /// <summary>
        /// get the search reader
        /// </summary>
        /// <param name="monitorFileName"></param>
        /// <param name="monitorServerID"></param>
        /// <returns></returns>
        public SqlDataReader GetSearchReaderPathBk(string monitorFileName, string msidCond)
        {
            SqlDataReader sdr = null;

            try
            {
                string connstr = ConfigUtil.AppSetting("ConnStringFordownload");
                if (string.IsNullOrWhiteSpace(connstr))
                {
                    return(null);
                }

                string sql = "select msid as [monitorServerID],[relativePath] as [monitorFileRelativeFullPath] from [dbo].[pathBk] where 1=1  ";
                if (!string.IsNullOrWhiteSpace(msidCond))
                {
                    sql += " and [msid]  " + msidCond;
                }

                sql += " and relativePath like N'%" + monitorFileName + "%'";
                sdr  = DBHelper.ExecuteReader(connstr, CommandType.Text, sql);
            }
            catch (Exception ex)
            {
                logger.Error(MessageUtil.GetExceptionMsg(ex, ""));
            }
            return(sdr);
        }
Esempio n. 2
0
        public ServerShareInfo GetSSI()
        {
            ServerShareInfo ssi = null;

            //get the config
            string configValue = ConfigUtil.AppSetting("backupServerInfo");

            //please guarantee the correctness of the config
            if (!string.IsNullOrWhiteSpace(configValue))
            {
                string[] valueS = configValue.Split(';');
                if (valueS.Count() == 3)
                {
                    ssi = new ServerShareInfo();
                    foreach (string item in valueS)
                    {
                        string[] kv = item.Split('=');
                        if (kv.Count() == 2)
                        {
                            string key = kv[0];
                            switch (key)
                            {
                            case "UNCBase": ssi.UNCBase = kv[1]; break;

                            case "username": ssi.Username = kv[1]; break;

                            case "passwd": ssi.Passwd = kv[1]; break;
                            }
                        }
                    }
                }
            }

            return(ssi);
        }
Esempio n. 3
0
        /// <summary>
        /// get the search reader
        /// </summary>
        /// <param name="monitorFileName"></param>
        /// <param name="monitorServerID"></param>
        /// <returns></returns>
        public SqlDataReader GetSearchReader(string monitorFileName, string msidCond)
        {
            SqlDataReader sdr = null;

            try
            {
                string connstr = ConfigUtil.AppSetting("ConnStringFordownload");
                if (string.IsNullOrWhiteSpace(connstr))
                {
                    return(null);
                }

                string sql = "select [monitorServerID],[monitorServerIP],[sharePoint],[monitorLocalPath],[monitorFileName],[monitorFileRelativeFullPath],[updateDate] from [dbo].[monitorFileListen] where deleteFlg=0 ";
                if (!string.IsNullOrWhiteSpace(msidCond))
                {
                    sql += " and [monitorServerID]  " + msidCond;
                }

                sql += " and monitorFileRelativeFullPath like N'%" + monitorFileName + "%'";
                sdr  = DBHelper.ExecuteReader(connstr, CommandType.Text, sql);
            }
            catch (Exception ex)
            {
                logger.Error(MessageUtil.GetExceptionMsg(ex, ""));
            }
            return(sdr);
        }
Esempio n. 4
0
        /// <summary>
        /// 用于每天同步 删除pathBk表中job已删除的文件
        /// </summary>
        public void DaySync()
        {
            lock (_lock)
            {
                //获取配置时间
                string syncTime = ConfigUtil.AppSetting("daysyncTime");
                if (TimeCheckHelper.CheckTime("daysyncTime", syncTime))
                {
                    try
                    {
                        #region 判断是否有顶级文件夹未传送
                        new System.Threading.Thread(() =>
                        {
                            CheckTopFolder();
                        }).Start();
                        #endregion
                        #region delete pathBk overdue entry
                        Common.LogManager.WriteLog(Common.LogFile.Trace, "delete pathBk overdue entry start:" + DateTime.Now.ToString());

                        //获取今天产生的delete event entry log文件名
                        string       path = AppDomain.CurrentDomain.BaseDirectory + @"log\FSWDeleteEvent" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
                        StreamReader sr   = new StreamReader(path);
                        while (!sr.EndOfStream)
                        {
                            string entry = sr.ReadLine();
                            if (entry.Contains("msID:"))
                            {
                                int firstIndex  = entry.IndexOf("msID:") + 5;
                                int secondIndex = entry.IndexOf(";relativePath:");
                                //获取msid
                                string msid = entry.Substring(firstIndex, secondIndex - firstIndex);
                                //获取relativePath
                                string relativePath = entry.Substring(secondIndex + 14);
                                try
                                {
                                    //删除pathBk里相同的项
                                    SyncDAL sd = new SyncDAL();
                                    sd.DeletePath(msid, relativePath);
                                }
                                catch (Exception ex)
                                {
                                    Common.LogManager.WriteLog(Common.LogFile.Error, MessageUtil.GetExceptionMsg(ex, ""));
                                }
                            }
                        }

                        sr.Close();


                        Common.LogManager.WriteLog(Common.LogFile.Trace, "delete pathBk overdue entry end:" + DateTime.Now.ToString());
                        #endregion
                    }
                    catch (Exception ex)
                    {
                        Common.LogManager.WriteLog(Common.LogFile.Error, MessageUtil.GetExceptionMsg(ex, ""));
                    }
                }
            }
        }
Esempio n. 5
0
        public ActionResult Index()
        {
            if (Session["LoginId"] == null)
            {
                if (CommonUtil.LoginId != string.Empty)
                {
                    Session["LoginId"] = CommonUtil.LoginId;
                    CommonUtil.LoginId = string.Empty;
                }
                else
                {
                    return(RedirectToAction("Account", "Account/LogOn", new { url = Request.Url }));
                }
            }

            object loginId  = Session["LoginId"];
            string username = loginId as string;

            try
            {
                FileDownloadService fds = new FileDownloadService();
                string dbServerip       = ConfigUtil.AppSetting("remoteIP");

                List <Models.MonitorServer> mslist = fds.GetRemoteMSList(dbServerip) ?? new List <Models.MonitorServer>();

                if ("soumu".Equals(username))
                {
                    mslist = mslist.FindAll(x => x.MonitorServerName.Equals("soumu"));
                }
                else if ("mac".Equals(username))
                {
                    mslist = mslist.FindAll(x => !x.MonitorServerName.Equals("soumu"));
                }

                ViewData["msList"] = mslist;
            }
            catch (Exception ex)
            {
                ViewData["msList"] = new List <Models.MonitorServer>();
                logger.Error(ex.Message);
            }

            if (loginId != null)
            {
                if ("admin".Equals(username))
                {
                    return(View());
                }
            }

            return(View("NmIndex"));
        }
Esempio n. 6
0
 /// <summary>
 /// 同步
 /// </summary>
 public void Sync()
 {
     lock (_lock)
     {
         //获取配置时间
         string syncTime = ConfigUtil.AppSetting("syncTime");
         if (TimeCheckHelper.CheckTime("syncTime", syncTime))
         {
             Common.LogManager.WriteLog(Common.LogFile.Trace, "Sync start:" + DateTime.Now.ToString());
             //同步数据库 SSH输出 Mac (特殊字符文件)
             StartSync();
             Common.LogManager.WriteLog(Common.LogFile.Trace, "Sync end:" + DateTime.Now.ToString());
         }
     }
 }
Esempio n. 7
0
        /// <summary>
        /// 同步 此同步只用于下载查询
        /// </summary>
        public void WeekendSync()
        {
            //获取同步设置dayofweek
            string dayOfWeek = ConfigUtil.AppSetting("dayOfWeek");

            if (!string.IsNullOrWhiteSpace(dayOfWeek) && Regex.IsMatch(dayOfWeek, @"^[0-6]$"))
            {
                DayOfWeek dow = (DayOfWeek)int.Parse(dayOfWeek);
                if (DateTime.Now.DayOfWeek != dow)
                {
                    return;
                }
            }
            else
            {
                Common.LogManager.WriteLog(Common.LogFile.Trace, "please set dayOfWeek correctly  :" + DateTime.Now.ToString());
                return;
            }

            lock (_lock)
            {
                //获取配置时间
                string syncTime = ConfigUtil.AppSetting("syncTime");
                if (TimeCheckHelper.CheckTime("syncTime", syncTime))
                {
                    Common.LogManager.WriteLog(Common.LogFile.Trace, "Sync start:" + DateTime.Now.ToString());
                    ////同步数据库 SSH输出 Mac (特殊字符文件)
                    //StartSync();

                    /**
                     * xiecongwen 20150102
                     * 由于获取文件信息,及进行数据库校验速度过慢,特进行如下修改:
                     *
                     * 1.将ignore日志文件中的文件路径规整到相关数据库表 filelisten log (暂时忽略)
                     * 2.删除pathBK表中所有数据(truncate),将监控目录路径信息备份到此数据库(类似于快照)
                     *   每周执行一次 20150111
                     */
                    //ResolveIgnoreList();

                    BackupPath();
                    //重置monitorfilelisten表
                    TruncateFileListen();
                    Common.LogManager.WriteLog(Common.LogFile.Trace, "Sync end:" + DateTime.Now.ToString());
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// get monitor server list
        /// </summary>
        /// <param name="dbServerip"></param>
        /// <param name="monitorServerID"></param>
        /// <returns></returns>
        public List <MonitorServer> GetMSList(string dbServerip, string msidCond)
        {
            List <MonitorServer> list = new List <MonitorServer>();

            try
            {
                string connstr = ConfigUtil.AppSetting("ConnStringFordownload");
                if (string.IsNullOrWhiteSpace(connstr))
                {
                    return(null);
                }

                string sql = "select [id],'" + dbServerip + "' as [DBServerIP],[monitorServerIP],[startFile],[monitorLocalPath] from [dbo].[monitorServer] where [deleteFlg] = 0  ";
                if (!string.IsNullOrWhiteSpace(msidCond))
                {
                    sql += " and id " + msidCond;
                }

                DataSet ds = DBHelper.ExecuteDataset(connstr, CommandType.Text, sql);
                if (ds != null && ds.Tables.Count > 0)
                {
                    DataTable dt = ds.Tables[0];
                    if (dt.Rows.Count > 0)
                    {
                        foreach (DataRow row in dt.Rows)
                        {
                            list.Add(new MonitorServer()
                            {
                                ID               = Convert.ToString(row["id"]),
                                DBServerIP       = Convert.ToString(row["DBServerIP"]),
                                MonitorLocalPath = Convert.ToString(row["monitorLocalPath"]),
                                MonitorServerIP  = Convert.ToString(row["monitorServerIP"]),
                                StartFile        = Convert.ToString(row["startFile"]),
                            });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(MessageUtil.GetExceptionMsg(ex, ""));
                throw;
            }

            return(list);
        }
Esempio n. 9
0
        public DownloadSearchResult GetMatchList(string searchPattern, string monitorServerID, int maxsize, string username)
        {
            SqlDataReader        sdr       = null;
            SqlDataReader        sdrPathBk = null;
            DownloadSearchResult ds        = null;

            //the max size
            try
            {
                #region get the monitor server id
                string msid = string.Empty;
                if (monitorServerID == "-1")
                {
                    msid = monitorServerID;
                }
                else
                {
                    msid = monitorServerID.Split('|')[1];
                }
                #endregion

                FileDownloadDAL fdal = new FileDownloadDAL();

                //get monitor Server
                string dbServerip = ConfigUtil.AppSetting("remoteIP");
                string msidCond   = GetMsidCond(username, dbServerip, msid);

                List <MonitorServer> mslist = fdal.GetMSList(dbServerip, msidCond);
                if (mslist != null && mslist.Count > 0)
                {
                    //use this to check whether the folder exists
                    HashSet <string> folderSet = new HashSet <string>();
                    HashSet <string> fileSet   = new HashSet <string>();
                    #region  from filelisten
                    #region get reader
                    sdr = fdal.GetSearchReader(searchPattern, msidCond);
                    #endregion

                    #region get the match list
                    if (sdr != null)
                    {
                        ds = new DownloadSearchResult();
                        while (sdr.Read())
                        {
                            string relativePath = Convert.ToString(sdr["monitorFileRelativeFullPath"]);

                            if (fileSet.Add(relativePath))
                            {
                                #region analyse  the rows
                                //get the monitor server
                                string        msID = Convert.ToString(sdr["monitorServerID"]);
                                MonitorServer ms   = mslist.Find((x) => x.ID.Equals(msID));

                                //get the filename
                                string fileName      = Convert.ToString(sdr["monitorFileName"]);
                                string macbasePath   = @"\\" + Convert.ToString(sdr["monitorServerIP"]) + @"\" + Convert.ToString(sdr["sharePoint"]);
                                string winbasePath   = ms.DBServerIP + ms.MonitorLocalPath.Substring(ms.MonitorLocalPath.IndexOf(':') + 1);
                                string lastWriteTime = Convert.ToString(sdr["updateDate"]);

                                //check filename or subdir contains the search pattern
                                if (fileName.Contains(searchPattern))
                                {
                                    #region file

                                    ds.FileInfoList.Add(new DFileInfo()
                                    {
                                        Name          = fileName,
                                        WinPath       = winbasePath + relativePath,
                                        MacPath       = macbasePath + relativePath,
                                        LastWriteTime = lastWriteTime
                                    });

                                    #endregion
                                }

                                #region check folder

                                //check the count match the needle
                                string[] subdirs = relativePath.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
                                for (int i = 0; i < subdirs.Count() - 1; i++)
                                {
                                    string subdir = subdirs[i];
                                    if (subdir.Contains(searchPattern))
                                    {
                                        string temp = string.Empty;
                                        for (int j = 0; j <= i; j++)
                                        {
                                            temp += @"\" + subdirs[j];
                                        }
                                        string folderMacPath = macbasePath + temp;
                                        if (folderSet.Add(folderMacPath))
                                        {
                                            ds.FolderInfoList.Add(new DFolderInfo()
                                            {
                                                Name          = subdir,
                                                WinPath       = winbasePath + temp,
                                                MacPath       = folderMacPath,
                                                LastWriteTime = lastWriteTime
                                            });
                                        }
                                    }
                                }
                                #endregion

                                #endregion
                                //check the count
                                if (ds.Count >= maxsize)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    #endregion
                    #endregion

                    #region from pathBk
                    if (ds.Count <= maxsize)
                    {
                        #region get reader
                        sdrPathBk = fdal.GetSearchReaderPathBk(searchPattern, msidCond);

                        #endregion
                        #region get the match list

                        if (sdrPathBk != null)
                        {
                            while (sdrPathBk.Read())
                            {
                                //get the filename
                                string relativePath = Convert.ToString(sdrPathBk["monitorFileRelativeFullPath"]);
                                if (fileSet.Add(relativePath))
                                {
                                    #region analyse  the rows
                                    //get the monitor server
                                    string        msID = Convert.ToString(sdrPathBk["monitorServerID"]);
                                    MonitorServer ms   = mslist.Find((x) => x.ID.Equals(msID));


                                    int    lastIndex     = relativePath.LastIndexOf(Path.DirectorySeparatorChar);
                                    string fileName      = relativePath.Substring(lastIndex + 1);
                                    string macbasePath   = @"\\" + ms.MonitorServerIP + @"\" + ms.StartFile;
                                    string winbasePath   = ms.DBServerIP + ms.MonitorLocalPath.Substring(ms.MonitorLocalPath.IndexOf(':') + 1);
                                    string lastWriteTime = "";

                                    #endregion

                                    //check filename or subdir contains the search pattern
                                    if (fileName.Contains(searchPattern))
                                    {
                                        #region file
                                        ds.FileInfoList.Add(new DFileInfo()
                                        {
                                            Name          = fileName,
                                            WinPath       = winbasePath + relativePath,
                                            MacPath       = macbasePath + relativePath,
                                            LastWriteTime = lastWriteTime
                                        });
                                        #endregion
                                    }

                                    #region check folder

                                    //check the count match the needle
                                    string[] subdirs = relativePath.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
                                    for (int i = 0; i < subdirs.Count() - 1; i++)
                                    {
                                        string subdir = subdirs[i];
                                        if (subdir.Contains(searchPattern))
                                        {
                                            string temp = string.Empty;
                                            for (int j = 0; j <= i; j++)
                                            {
                                                temp += @"\" + subdirs[j];
                                            }
                                            string folderMacPath = macbasePath + temp;
                                            if (folderSet.Add(folderMacPath))
                                            {
                                                ds.FolderInfoList.Add(new DFolderInfo()
                                                {
                                                    Name          = subdir,
                                                    WinPath       = winbasePath + temp,
                                                    MacPath       = folderMacPath,
                                                    LastWriteTime = lastWriteTime
                                                });
                                            }
                                        }
                                    }
                                    #endregion

                                    //check the count
                                    if (ds.Count >= maxsize)
                                    {
                                        break;
                                    }
                                }
                            }
                        }

                        #endregion
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }
            finally
            {
                if (sdr != null)
                {
                    sdr.Close();
                }

                if (sdrPathBk != null)
                {
                    sdr.Close();
                }
            }
            return(ds);
        }