Ejemplo n.º 1
0
        public static List <AlarmHistoryDocData> getFileInformation(string alarmNo, string colName, string machineid, string company, string plant, string cncCause, string cncSolution)
        {
            List <AlarmHistoryDocData> listDoc = new List <AlarmHistoryDocData>();

            try
            {
                string mtb = DBAccess.getMTBForMachine(company, plant, machineid);
                List <AlarmHistoryDocData> documentIdList = MongoDBAccess.getAlarmHistoryDocumentList(alarmNo, colName, machineid, company, plant, cncCause, cncSolution, mtb);

                byte[] fileByte = null;
                foreach (var fileObjId in documentIdList)
                {
                    AlarmHistoryDocData data = new AlarmHistoryDocData();
                    string fileid            = fileObjId.FileID;
                    string filenameStr       = fileObjId.FileName;


                    string   fileBase64 = "";
                    ObjectId id         = new ObjectId(fileid);
                    Logger.WriteDebugLog("Download alarm doc File: Before: " + DateTime.Now);
                    fileByte = MongoDBAccess.getAlarmFilesInByte(fileid, colName);
                    Logger.WriteDebugLog("Download alarm doc File: After: " + DateTime.Now);
                    if (fileByte != null)
                    {
                        fileBase64 = Convert.ToBase64String(fileByte);
                    }
                    Logger.WriteDebugLog("Download eDoc File: After base64: " + DateTime.Now);
                    string fileName = filenameStr;
                    if (!string.IsNullOrEmpty(fileBase64))
                    {
                        string extension = "";
                        if (filenameStr != "")
                        {
                            var list = filenameStr.Split('.').ToList();
                            extension = list[list.Count - 1].ToLower();
                        }
                        string filetype = "";
                        if ((extension == "mp4") || (extension == "wmv") || (extension == "avi") || (extension == "mov") || (extension == "qt") || (extension == "yuv") || (extension == "mkv") || (extension == "webm") || (extension == "flv") || (extension == "ogg") || (extension == "gif"))
                        {
                            filetype = "video";
                        }
                        else if (extension == "png" || extension == "jpg" || extension == "tif" || extension == "tiff" || extension == "bmp" || extension == "jpeg" || extension == "gif" || extension == "eps" || extension == "tif" || extension == "tif" || extension == "tif")
                        {
                            filetype = "image";
                        }
                        else if (extension == "pdf")
                        {
                            filetype = "pdf";
                        }
                        else if (extension == "xlsx" || extension == "xlsm" || extension == "xlsb" || extension == "xltx" || extension == "xltm" || extension == "xls" || extension == "xlt" || extension == "xml" || extension == "xlam" || extension == "xlw" || extension == "xlr")
                        {
                            filetype = "excel";
                        }
                        else
                        {
                            filetype = "other";
                        }
                        data.FileName      = filenameStr;
                        data.FileInBase64  = fileBase64;
                        data.FileType      = filetype;
                        data.FileExtension = extension;
                        listDoc.Add(data);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteDebugLog("Download alarm doc File: Error: " + DateTime.Now + "   --- " + ex.Message);
            }
            Logger.WriteDebugLog("Download alarm doc File: data return: " + DateTime.Now);
            return(listDoc);
        }