示例#1
0
        /// <method>
        /// Update file information
        /// </method>
        public bool UpdateFileInformation(FileInformationModal fileInfo)
        {
            string query = string.Format("UPDATE tblFileInformation SET PathID=@PathId, XMLFileCount=@XMLFileCount, ImageCount=@ImageCount, UpdatedDate=@UpdatedDate WHERE DPSI = @DPSI");

            SqlParameter[] sqlParameters = new SqlParameter[5];
            sqlParameters[0]       = new SqlParameter("@DPSI", SqlDbType.VarChar);
            sqlParameters[0].Value = fileInfo.DPSI;
            sqlParameters[1]       = new SqlParameter("@PathId", SqlDbType.VarChar);
            sqlParameters[1].Value = fileInfo.PathID;
            sqlParameters[2]       = new SqlParameter("@XMLFileCount", SqlDbType.Int);
            sqlParameters[2].Value = fileInfo.XMLFileCount;
            sqlParameters[3]       = new SqlParameter("@ImageCount", SqlDbType.Int);
            sqlParameters[3].Value = fileInfo.ImageCount;
            sqlParameters[4]       = new SqlParameter("@UpdatedDate", SqlDbType.DateTime);
            sqlParameters[4].Value = fileInfo.UpdatedDate;
            return(con.executeUpdateQuery(query, sqlParameters));
        }
示例#2
0
        /// <method>
        /// Add file information
        /// </method>
        public bool AddFileInformation(FileInformationModal fileInfo)
        {
            string query = string.Format("INSERT INTO tblFileInformation(DPSI,PathID,XMLFileCount,ImageCount,CreatedDate,UpdatedDate) VALUES (@DPSI, @PathId, @XMLFileCount, @ImageCount, @CreatedDate, @UpdatedDate)");

            SqlParameter[] sqlParameters = new SqlParameter[6];
            sqlParameters[0]       = new SqlParameter("@DPSI", SqlDbType.VarChar);
            sqlParameters[0].Value = fileInfo.DPSI;
            sqlParameters[1]       = new SqlParameter("@PathId", SqlDbType.Int);
            sqlParameters[1].Value = fileInfo.PathID;
            sqlParameters[2]       = new SqlParameter("@XMLFileCount", SqlDbType.Int);
            sqlParameters[2].Value = fileInfo.XMLFileCount;
            sqlParameters[3]       = new SqlParameter("@ImageCount", SqlDbType.Int);
            sqlParameters[3].Value = fileInfo.ImageCount;
            sqlParameters[4]       = new SqlParameter("@CreatedDate", SqlDbType.DateTime);
            sqlParameters[4].Value = fileInfo.CreatedDate;
            sqlParameters[5]       = new SqlParameter("@UpdatedDate", SqlDbType.DateTime);
            sqlParameters[5].Value = fileInfo.UpdatedDate;
            return(con.executeInsertQuery(query, sqlParameters));
        }
示例#3
0
        /// <method>
        /// Read file information
        /// </method>
        public void ReadFileInformation(string path, int pathId = 0, bool isPathExist = false)
        {
            var xmlFiles   = Directory.EnumerateFiles(path, "*.*", SearchOption.TopDirectoryOnly).Where(s => s.EndsWith(".xml"));
            var imageFiles = Directory.EnumerateFiles(path, "*.*", SearchOption.TopDirectoryOnly).Where(s => s.EndsWith(".jpeg") || s.EndsWith(".gif") || s.EndsWith(".pdf"));
            var zipFiles   = Directory.EnumerateFiles(path, "*.*", SearchOption.TopDirectoryOnly).Where(s => s.EndsWith(".zip"));

            /* Insert input path into table */
            PathModal addPath = new PathModal()
            {
                PathName    = path.Trim(),
                CreatedDate = DateTime.Now
            };

            if (!isPathExist)
            {
                bool pathResult = _fileProcessDL.AddFilePath(addPath);
                pathId = GetFilePath(path).PathID;
            }

            List <FileInformationModal> fileInfoList = new List <FileInformationModal>();
            List <FileInformationModal> finalList    = new List <FileInformationModal>();

            /* Get XMl files information */
            foreach (string xmlFile in xmlFiles)
            {
                string dpsiValue = GetDPSIValue(xmlFile);
                FileInformationModal addFileInfo = new FileInformationModal()
                {
                    DPSI         = dpsiValue,
                    PathID       = pathId,
                    XMLFileCount = 1         // Handling with single file
                };
                fileInfoList.Add(addFileInfo);
            }

            /*Get other files information like image, pdf and etc */
            foreach (string imgFile in imageFiles)
            {
                string dpsiValue = GetDPSIValue(imgFile);
                FileInformationModal addFileInfo = new FileInformationModal()
                {
                    DPSI       = dpsiValue,
                    PathID     = pathId,
                    ImageCount = 1         // Handling with single file
                };
                fileInfoList.Add(addFileInfo);
            }

            /*Get zip files information */
            foreach (string zipFile in zipFiles)
            {
                string dpsiValue  = GetDPSIValue(zipFile);
                int    xmlCount   = 0;
                int    otherCount = 0;
                using (ZipArchive archive = ZipFile.OpenRead(zipFile))
                {
                    foreach (ZipArchiveEntry entry in archive.Entries)
                    {
                        if (entry.FullName.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
                        {
                            xmlCount++;
                        }
                        else
                        {
                            otherCount++;
                        }
                    }
                    FileInformationModal addFileInfo = new FileInformationModal()
                    {
                        DPSI         = dpsiValue,
                        PathID       = pathId,
                        XMLFileCount = xmlCount,
                        ImageCount   = otherCount
                    };
                    fileInfoList.Add(addFileInfo);
                }
            }

            finalList = (from rec in fileInfoList
                         group rec by rec.DPSI into g
                         select new FileInformationModal
            {
                PathID = g.Select(x => x.PathID).First(),
                DPSI = g.Key,
                XMLFileCount = g.Sum(x => x.XMLFileCount),
                ImageCount = g.Sum(x => x.ImageCount)
            }).ToList();

            List <FileInformationModal> existFileInfoList = GetFileInformation();

            /* Insert or update fileinfo based on availability in database */
            foreach (FileInformationModal info in finalList)
            {
                var existFileInfo = existFileInfoList.Where(x => x.DPSI == info.DPSI && x.PathID == pathId).FirstOrDefault();
                if (existFileInfo == null)
                {
                    info.CreatedDate = DateTime.Now;
                    info.UpdatedDate = DateTime.Now;
                    var fileInfoResult = _fileProcessDL.AddFileInformation(info);
                }
                else
                {
                    info.XMLFileCount += existFileInfo.XMLFileCount;
                    info.ImageCount   += existFileInfo.ImageCount;
                    info.UpdatedDate   = DateTime.Now;
                    var fileInfoResult = _fileProcessDL.UpdateFileInformation(info);
                }
            }
        }