예제 #1
0
        public FileStream GetDP(string filename)
        {
            if (filename.StartsWith("dp") && filename.Split('.').Length == 2)
            {
                filename = filename.Split('.')[0] + ".jpg";
                string sFilePath = string.Format("StaticFiles/{0}/dp/{1}", ViewBag.cid, filename);
                if (!System.IO.File.Exists(sFilePath))
                {
                    byte[] fileByte = this.ServiceClient.Post <byte[]>(new DownloadFileRequest {
                        FileDetails = new FileMeta {
                            FileName = filename, FileType = "jpg"
                        }
                    });
                    if (fileByte.IsEmpty())
                    {
                        return(System.IO.File.OpenRead("wwwroot/images/proimg.jpg"));
                    }
                    EbFile.Bytea_ToFile(fileByte, sFilePath);
                }
                HttpContext.Response.Headers[HeaderNames.CacheControl] = "private, max-age=604800";

                return(System.IO.File.OpenRead(sFilePath));
            }
            else
            {
                return(null);
            }
        }
예제 #2
0
        public FileStream GetFile(string filename)
        {
            string sFilePath = string.Format("StaticFiles/{0}/{1}", ViewBag.cid, filename);

            if (!System.IO.File.Exists(sFilePath))
            {
                byte[] fileByte = this.ServiceClient.Post <byte[]>
                                      (new DownloadFileRequest
                {
                    FileDetails = new FileMeta
                    {
                        FileName = filename,
                        FileType = filename.Split('.')[1].ToLower()
                    }
                });
                EbFile.Bytea_ToFile(fileByte, sFilePath);
            }

            HttpContext.Response.Headers[HeaderNames.CacheControl] = "private, max-age=31536000";
            if (filename.ToLower().EndsWith(".pdf"))
            {
                HttpContext.Response.Headers[HeaderNames.ContentType] = "application/pdf";
            }
            return(System.IO.File.OpenRead(sFilePath));
        }
        public DownloadFileResponse Get(DownloadLogoExtRequest request)
        {
            DownloadFileResponse dfs = new DownloadFileResponse();
            MemoryStream         ms  = null;

            byte[] fb        = new byte[0];
            string sFilePath = string.Format("../StaticFiles/{0}/logo/{1}", request.SolnId, request.SolnId);

            try
            {
                if (!System.IO.File.Exists(sFilePath))
                {
                    string qry_refId = @"SELECT 
	                                        filestore_sid , V.filedb_con_id
                                        FROM 
	                                        eb_files_ref_variations V 
                                        INNER JOIN 
	                                        eb_solutions S
                                        ON 
	                                        V.eb_files_ref_id = S.logorefid
                                        WHERE 
	                                        S.isolution_id = :solid;"    ;

                    DbParameter[] parameters =
                    {
                        this.InfraConnectionFactory.DataDB.GetNewParameter("solid", EbDbTypes.String, request.SolnId),
                    };

                    var dt = this.InfraConnectionFactory.DataDB.DoQuery(qry_refId, parameters);

                    if (dt.Rows.Count == 0)
                    {
                        throw new Exception("filestore_sid not found - FileRefId:" + request.ImageInfo.FileRefId + " Quality:" + request.ImageInfo.ImageQuality);
                    }
                    else
                    {
                        Console.WriteLine(" Calling FilesDB.DownloadFileById :(InfraconId =" + Convert.ToInt32(dt.Rows[0][1]) + "  ,filestoreid =" + dt.Rows[0][0].ToString());
                        fb = this.InfraConnectionFactory.FilesDB.DownloadFileById(dt.Rows[0][0].ToString(), EbFileCategory.SolLogo, Convert.ToInt32(dt.Rows[0][1]));
                        if (fb != null)
                        {
                            EbFile.Bytea_ToFile(fb, sFilePath);
                        }
                    }
                }
                if (File.Exists(sFilePath))
                {
                    ms = new MemoryStream(File.ReadAllBytes(sFilePath));
                    dfs.StreamWrapper = new MemorystreamWrapper(ms);
                }
                else
                {
                    throw new Exception("File Not Found");
                }
            }
            catch (Exception ee)
            {
                Log.Info("Exception:" + ee.ToString());
            }
            return(dfs);
        }
        public DownloadFileResponse Get(DownloadDpRequest request)
        {
            DownloadFileResponse dfs = new DownloadFileResponse();
            MemoryStream         ms  = null;

            byte[] fb        = new byte[0];
            string sFilePath = string.Format("../StaticFiles/{0}/dp/{1}", request.SolnId, request.ImageInfo.FileName);

            try
            {
                if (!System.IO.File.Exists(sFilePath))
                {
                    string qry_refId = this.EbConnectionFactory.DataDB.EB_DOWNLOAD_DP;
                    //AND V.imagequality_id = 150
                    DbParameter[] parameters =
                    {
                        this.EbConnectionFactory.DataDB.GetNewParameter("userid", EbDbTypes.Int32, Convert.ToInt32(request.ImageInfo.FileName)),
                    };

                    var dt = this.EbConnectionFactory.DataDB.DoQuery(qry_refId, parameters);

                    if (dt.Rows.Count == 0)
                    {
                        throw new Exception("filestore_sid not found - FileRefId:" + request.ImageInfo.FileRefId + " Quality:" + request.ImageInfo.ImageQuality);
                    }
                    else
                    {
                        request.ImageInfo.FileStoreId = dt.Rows[0][0].ToString();
                        request.ImageInfo.InfraConID  = Convert.ToInt32(dt.Rows[0][1]);

                        fb = this.EbConnectionFactory.FilesDB.DownloadFileById(request.ImageInfo.FileStoreId, EbFileCategory.Dp, request.ImageInfo.InfraConID);
                        if (fb != null)
                        {
                            EbFile.Bytea_ToFile(fb, sFilePath);
                        }
                    }
                }

                if (File.Exists(sFilePath))
                {
                    ms = new MemoryStream(File.ReadAllBytes(sFilePath));
                    dfs.StreamWrapper = new MemorystreamWrapper(ms);
                }
                else
                {
                    throw new Exception("File Not Found");
                }
            }
            catch (Exception ee)
            {
                Log.Info("Exception:" + ee.ToString());
            }
            return(dfs);
        }
예제 #5
0
        private void InitDb(string path)
        {
            EbConfiguration e = new EbConfiguration()
            {
                ClientID   = "xyz0007",
                ClientName = "XYZ Enterprises Ltd.",
                LicenseKey = "00288-22558-25558",
            };

            e.DatabaseConfigurations.Add(EbDatabases.EB_OBJECTS, new EbDatabaseConfiguration(EbDatabases.EB_OBJECTS, DatabaseVendors.PGSQL, "eb_objects", "localhost", 5432, "postgres", "infinity", 500));
            e.DatabaseConfigurations.Add(EbDatabases.EB_DATA, new EbDatabaseConfiguration(EbDatabases.EB_DATA, DatabaseVendors.PGSQL, "eb_objects", "localhost", 5432, "postgres", "infinity", 500));
            e.DatabaseConfigurations.Add(EbDatabases.EB_ATTACHMENTS, new EbDatabaseConfiguration(EbDatabases.EB_ATTACHMENTS, DatabaseVendors.PGSQL, "eb_objects", "localhost", 5432, "postgres", "infinity", 500));
            e.DatabaseConfigurations.Add(EbDatabases.EB_LOGS, new EbDatabaseConfiguration(EbDatabases.EB_LOGS, DatabaseVendors.PGSQL, "eb_objects", "localhost", 5432, "postgres", "infinity", 500));

            byte[] bytea = EbSerializers.ProtoBuf_Serialize(e);
            EbFile.Bytea_ToFile(bytea, path);
        }
        public DownloadFileResponse Get(DownloadBotExtImgRequest request)
        {
            DownloadFileResponse dfs = new DownloadFileResponse();
            MemoryStream         ms  = null;

            byte[] fb        = new byte[0];
            string sFilePath = string.Format("../StaticFiles/botExt/{0}", request.RefId);
            EbConnectionFactory ebConnectionFactory = new EbConnectionFactory(request.SolnId, this.Redis);

            try
            {
                if (!System.IO.File.Exists(sFilePath))
                {
                    string qry_refId = @"SELECT 
                                        B.imagequality_id, B.filestore_sid, B.filedb_con_id
                                    FROM 
                                        eb_files_ref A, eb_files_ref_variations B
                                    WHERE 
                                        A.id=B.eb_files_ref_id AND A.id=:fileref
                                    ORDER BY 
                                        B.imagequality_id;";

                    DbParameter[] parameters =
                    {
                        ebConnectionFactory.DataDB.GetNewParameter("fileref", EbDbTypes.Int32, Convert.ToInt32(request.RefId)),
                    };

                    EbDataTable t = ebConnectionFactory.DataDB.DoQuery(qry_refId, parameters);

                    if (t.Rows.Count == 0)
                    {
                        throw new Exception("filestore_sid not found - FileRefId:" + request.ImageInfo.FileRefId + " Quality:" + request.ImageInfo.ImageQuality);
                    }

                    Dictionary <int, ImageMeta> sidAll = new Dictionary <int, ImageMeta>();

                    for (int i = 0; i < t.Rows.Count; i++)
                    {
                        if (!sidAll.ContainsKey(Convert.ToInt32(t.Rows[i][0])))
                        {
                            sidAll.Add(Convert.ToInt32(t.Rows[i][0]), new ImageMeta()
                            {
                                FileStoreId = t.Rows[i][1].ToString(), InfraConID = Convert.ToInt32(t.Rows[i][2])
                            });
                        }
                    }

                    if (sidAll.ContainsKey((int)request.ImageInfo.ImageQuality))
                    {
                        request.ImageInfo.FileStoreId = sidAll[(int)request.ImageInfo.ImageQuality].FileStoreId;
                        request.ImageInfo.InfraConID  = sidAll[(int)request.ImageInfo.ImageQuality].InfraConID;
                    }
                    else
                    {
                        request.ImageInfo.FileStoreId = sidAll[(int)ImageQuality.original].FileStoreId;
                        request.ImageInfo.InfraConID  = sidAll[(int)ImageQuality.original].InfraConID;
                    }

                    fb = ebConnectionFactory.FilesDB.DownloadFileById(request.ImageInfo.FileStoreId, request.ImageInfo.FileCategory, request.ImageInfo.InfraConID);

                    if (fb != null)
                    {
                        EbFile.Bytea_ToFile(fb, sFilePath);
                    }
                }

                if (File.Exists(sFilePath))
                {
                    ms = new MemoryStream(File.ReadAllBytes(sFilePath));

                    dfs.StreamWrapper = new MemorystreamWrapper(ms);
                    dfs.FileDetails   = new FileMeta
                    {
                        FileName           = request.ImageInfo.FileName,
                        FileType           = request.ImageInfo.FileType,
                        Length             = request.ImageInfo.Length,
                        FileStoreId        = request.ImageInfo.FileStoreId,
                        UploadDateTime     = request.ImageInfo.UploadDateTime,
                        MetaDataDictionary = (request.ImageInfo.MetaDataDictionary != null) ? request.ImageInfo.MetaDataDictionary : new Dictionary <String, List <string> >()
                        {
                        },
                    };
                }
                else
                {
                    throw new Exception("File Not Found");
                }
            }
            catch (FormatException e)
            {
                Console.WriteLine("ObjectId not in Correct Format: " + request.ImageInfo.FileName);
                Console.WriteLine("Exception: " + e.ToString());
            }
            catch (Exception e)
            {
                Log.Info("Exception:" + e.ToString());
            }

            return(dfs);
        }
        public DownloadFileResponse Get(DownloadFileByIdRequest request)
        {
            Console.WriteLine("In DownloadFileByIdRequest");
            byte[] fb = new byte[0];

            string sFilePath = string.Format("../StaticFiles/{0}/{1}", request.SolnId, request.FileDetails.FileRefId);

            MemoryStream ms = null;

            DownloadFileResponse dfs = new DownloadFileResponse();

            try
            {
                if (!System.IO.File.Exists(sFilePath))
                {
                    EbFileCategory category = request.FileDetails.FileCategory;

                    string Qry = this.EbConnectionFactory.DataDB.EB_DOWNLOAD_FILE_BY_ID;

                    DbParameter[] parameters =
                    {
                        this.EbConnectionFactory.DataDB.GetNewParameter("fileref", EbDbTypes.Int32, request.FileDetails.FileRefId),
                    };

                    EbDataTable t = this.EbConnectionFactory.DataDB.DoQuery(Qry, parameters);
                    if (t.Rows.Count > 0)
                    {
                        request.FileDetails.FileStoreId = t.Rows[0]["filestore_sid"].ToString();
                        request.FileDetails.InfraConID  = Convert.ToInt32(t.Rows[0]["filedb_con_id"]);
                    }
                    else
                    {
                        throw new Exception("File Not Found in Database , fileref = " + request.FileDetails.FileRefId);
                    }

                    fb = this.EbConnectionFactory.FilesDB.DownloadFileById(request.FileDetails.FileStoreId, category, request.FileDetails.InfraConID);

                    if (fb != null)
                    {
                        EbFile.Bytea_ToFile(fb, sFilePath);
                    }
                }

                if (File.Exists(sFilePath))
                {
                    ms = new MemoryStream(File.ReadAllBytes(sFilePath));

                    dfs.StreamWrapper = new MemorystreamWrapper(ms);
                    dfs.FileDetails   = new FileMeta
                    {
                        FileName           = request.FileDetails.FileName,
                        FileType           = request.FileDetails.FileType,
                        Length             = request.FileDetails.Length,
                        FileStoreId        = request.FileDetails.FileStoreId,
                        UploadDateTime     = request.FileDetails.UploadDateTime,
                        MetaDataDictionary = (request.FileDetails.MetaDataDictionary != null) ? request.FileDetails.MetaDataDictionary : new Dictionary <String, List <string> >()
                        {
                        },
                    };
                }
                else
                {
                    throw new Exception("File Not Found");
                }
            }
            catch (FormatException e)
            {
                Console.WriteLine("ObjectId not in Correct Format: " + request.FileDetails.FileName);
                Console.WriteLine("Exception: " + e.ToString());
            }
            catch (Exception e)
            {
                Log.Info("Exception:" + e.ToString());
            }

            return(dfs);
        }
        public DownloadFileResponse Get(DownloadImageByIdRequest request)
        {
            Console.WriteLine("In DownloadImageByIdRequest");

            byte[] fb = new byte[0];

            string sFilePath = string.Format("../StaticFiles/{0}/{1}/{2}", request.SolnId, request.ImageInfo.ImageQuality, request.ImageInfo.FileRefId);

            MemoryStream ms = null;

            DownloadFileResponse dfs = new DownloadFileResponse();

            Console.WriteLine("Download Image Info: " + request.ImageInfo.ToJson());

            try
            {
                if (!System.IO.File.Exists(sFilePath))
                {
                    Console.WriteLine("Image Not in Cache: " + sFilePath);

                    EbFileCategory category = request.ImageInfo.FileCategory;

                    string Qry = this.EbConnectionFactory.DataDB.EB_DOWNLOAD_IMAGE_BY_ID;

                    DbParameter[] parameters = { this.EbConnectionFactory.DataDB.GetNewParameter("fileref", EbDbTypes.Int32, request.ImageInfo.FileRefId) };
                    EbDataTable   t          = this.EbConnectionFactory.DataDB.DoQuery(Qry, parameters);

                    if (t.Rows.Count == 0)
                    {
                        throw new Exception("filestore_sid not found - FileRefId:" + request.ImageInfo.FileRefId + " Quality:" + request.ImageInfo.ImageQuality);
                    }

                    Dictionary <int, ImageMeta> sidAll = new Dictionary <int, ImageMeta>();

                    for (int i = 0; i < t.Rows.Count; i++)
                    {
                        sidAll.Add(Convert.ToInt32(t.Rows[i][0]), new ImageMeta()
                        {
                            FileStoreId = t.Rows[i][1].ToString(), InfraConID = Convert.ToInt32(t.Rows[i][2])
                        });
                    }
                    if (sidAll.ContainsKey((int)request.ImageInfo.ImageQuality))
                    {
                        request.ImageInfo.FileStoreId = sidAll[(int)request.ImageInfo.ImageQuality].FileStoreId;
                        request.ImageInfo.InfraConID  = sidAll[(int)request.ImageInfo.ImageQuality].InfraConID;
                    }
                    else
                    {
                        request.ImageInfo.FileStoreId = sidAll[(int)ImageQuality.original].FileStoreId;
                        request.ImageInfo.InfraConID  = sidAll[(int)ImageQuality.original].InfraConID;
                    }

                    fb = this.EbConnectionFactory.FilesDB.DownloadFileById(request.ImageInfo.FileStoreId, category, request.ImageInfo.InfraConID);

                    if (fb != null)
                    {
                        EbFile.Bytea_ToFile(fb, sFilePath);
                    }
                    else
                    {
                        Console.WriteLine("No File Found in : FileStoreId: " + request.ImageInfo.FileStoreId);
                    }
                }

                if (File.Exists(sFilePath))
                {
                    ms = new MemoryStream(File.ReadAllBytes(sFilePath));

                    dfs.StreamWrapper = new MemorystreamWrapper(ms);
                    dfs.FileDetails   = new FileMeta
                    {
                        FileName           = request.ImageInfo.FileName,
                        FileType           = request.ImageInfo.FileType,
                        Length             = request.ImageInfo.Length,
                        FileStoreId        = request.ImageInfo.FileStoreId,
                        UploadDateTime     = request.ImageInfo.UploadDateTime,
                        MetaDataDictionary = (request.ImageInfo.MetaDataDictionary != null) ? request.ImageInfo.MetaDataDictionary : new Dictionary <String, List <string> >()
                        {
                        },
                    };
                }
                else
                {
                    throw new Exception("File Not Found");
                }
            }
            catch (FormatException e)
            {
                Console.WriteLine("ObjectId not in Correct Format: " + request.ImageInfo.FileName);
                Console.WriteLine("Exception: " + e.ToString());
            }
            catch (Exception e)
            {
                Log.Info("Exception:" + e.ToString());
            }

            return(dfs);
        }