コード例 #1
0
        public static bool GetHttpRequestPostedFile(HttpContext httpContext, string varName, out string filePath)
        {
            filePath = null;
            if (httpContext != null)
            {
                var pf = GetFormFile(httpContext, varName);
                if (pf != null)
                {
#pragma warning disable SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}'
                    FileInfo fi = new FileInfo(pf.FileName);
#pragma warning restore SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}'
                    string tempDir = Preferences.getTMP_MEDIA_PATH();
                    string ext     = fi.Extension;
                    if (ext != null)
                    {
                        ext = ext.TrimStart('.');
                    }
                    filePath = FileUtil.getTempFileName(tempDir, "BLOB", ext);
                    GXLogging.Debug(log, "cgiGet(" + varName + "), fileName:" + filePath);
                    GxFile file = new GxFile(tempDir, filePath);
#if NETCORE
                    filePath = file.Create(pf.OpenReadStream());
#else
                    filePath = file.Create(pf.InputStream);
#endif
                    GXFileWatcher.Instance.AddTemporaryFile(file);
                    return(true);
                }
            }
            return(false);
        }
コード例 #2
0
        public string getMultimediaFile(int id, string gxdbFileUri)
        {
            if (!GXDbFile.IsFileExternal(gxdbFileUri))
            {
                string fileName = GXDbFile.GetFileNameFromUri(gxdbFileUri);
                if (!String.IsNullOrEmpty(fileName))
                {
                    string filePath = Path.Combine(_gxDbCommand.Conn.MultimediaPath, fileName);

                    try
                    {
                        GxFile file = new GxFile(string.Empty, filePath, GxFileType.PublicAttribute);

                        if (file.Exists())
                        {
                            return(file.GetURI());
                        }
                        else
                        {
                            return(getBLOBFile(id, FileUtil.GetFileType(gxdbFileUri), FileUtil.GetFileName(gxdbFileUri), filePath, false, GxFileType.PublicAttribute));
                        }
                    }
                    catch (ArgumentException)
                    {
                        return("");
                    }
                }
            }

            return("");
        }
コード例 #3
0
 public short Save()
 {
     try
     {
         if (IsReadOnly())
         {
             errCod         = 13;
             errDescription = "Can not modify a readonly document";
             p.Dispose();
         }
         else
         {
             using (var stream = new MemoryStream())
             {
                 p.SaveAs(stream);
                 p.Dispose();
                 GxFile file = new GxFile(Path.GetDirectoryName(xlsFileName), xlsFileName, GxFileType.Private);
                 stream.Position = 0;
                 file.Create(stream);
             }
         }
     }
     catch (Exception e)
     {
         GXLogging.Error(log, "Error saving file " + xlsFileName, e);
         errCod         = 12;
         errDescription = "Could not save file." + e.Message;
         return(-1);
     }
     return(0);
 }
コード例 #4
0
        internal void WcfExecute(Stream istream, string contentType)
        {
            string savedFileName, ext, fName;

            ext = context.ExtensionForContentType(contentType);

            savedFileName = FileUtil.getTempFileName(Preferences.getTMP_MEDIA_PATH(), "BLOB", string.IsNullOrEmpty(ext) ? "tmp" : ext);
            GxFile file = new GxFile(Preferences.getTMP_MEDIA_PATH(), savedFileName);

            file.Create(istream);

            JObject obj = new JObject();

            fName = file.GetURI();
            string fileGuid  = GxUploadHelper.GetUploadFileGuid();
            string fileToken = GxUploadHelper.GetUploadFileId(fileGuid);

            obj.Put("object_id", fileToken);
            localHttpContext.Response.AddHeader("GeneXus-Object-Id", fileGuid);
            localHttpContext.Response.ContentType = MediaTypesNames.ApplicationJson;
            HttpHelper.SetResponseStatus(localHttpContext, ((int)HttpStatusCode.Created).ToString(), string.Empty);
            localHttpContext.Response.Write(obj.ToString());

            GxUploadHelper.CacheUploadFile(fileGuid, savedFileName, fName, ext, file, localHttpContext);
        }
コード例 #5
0
        public void AddTemporaryFile(GxFile FileUploaded)
        {
            if (!DISABLED)
            {
                GXLogging.Debug(log, "AddTemporaryFile ", FileUploaded.Source);
#if !NETCORE
                if (HttpContext.Current != null)
                {
                    try
                    {
                        string sessionId;
                        if (HttpContext.Current.Session != null)
                        {
                            sessionId = HttpContext.Current.Session.SessionID;
                        }
                        else
                        {
                            sessionId = "nullsession";
                        }
                        List <GxFile> sessionTmpFiles;
                        lock (m_SyncRoot)
                        {
                            if (webappTmpFiles.ContainsKey(sessionId))
                            {
                                sessionTmpFiles = (List <GxFile>)webappTmpFiles[sessionId];
                            }
                            else
                            {
                                sessionTmpFiles = new List <GxFile>();
                            }
                            sessionTmpFiles.Add(FileUploaded);
                            webappTmpFiles[sessionId] = sessionTmpFiles;
                        }
                    }
                    catch (Exception exc)
                    {
                        GXLogging.Error(log, "AddTemporaryFile Error", exc);
                    }
                    if (t == null)
                    {
                        GXLogging.Debug(log, "ThreadStart GXFileWatcher.Instance.Run");
                        t = new Thread(new ThreadStart(GXFileWatcher.Instance.Run));
                        t.IsBackground = true;
                        t.Start();
                    }
                }
                else
#endif
                {
                    if (tmpFiles == null)
                    {
                        tmpFiles = new List <GxFile>();
                    }
                    lock (tmpFiles)
                    {
                        tmpFiles.Add(FileUploaded);
                    }
                }
            }
        }
コード例 #6
0
        public short Open(String fileName)
        {
            OpenFromTemplate = false;
            try
            {
                if (!string.IsNullOrWhiteSpace(template))
                {
                    GxFile temp = new GxFile(Path.GetDirectoryName(template), template);
                    if (temp.Exists())
                    {
                        GXLogging.Debug(log, "Opening Template " + template);
                        p = new ExcelPackage(temp.GetStream());
                        OpenFromTemplate = true;
                    }
                    else
                    {
                        errCod         = 4;
                        errDescription = "Invalid template.";
                        return(errCod);
                    }
                }
                else
                {
                    GxFile file = new GxFile(fileName, fileName, GxFileType.Private);

                    if (string.IsNullOrEmpty(Path.GetExtension(fileName)) && !file.Exists())
                    {
                        fileName += Constants.EXCEL2007Extension;
                    }
                    if (file.IsExternalFile)
                    {
                        p = new ExcelPackage(file.GetStream());
                    }
                    else
                    {
                        p = new ExcelPackage(new FileInfo(fileName));
                    }
                }

                workBook          = (ExcelWorkbook)p.Workbook;
                workBook.CalcMode = ExcelCalcMode.Automatic;

                this.selectFirstSheet();
                xlsFileName = fileName.ToString();
            }
            catch (Exception e)
            {
                GXLogging.Error(log, "Error opening " + fileName, e);

                errCod         = 10;
                errDescription = "Could not open file." + e.Message + (e.InnerException != null ? e.InnerException.Message : "");

                return(errCod);
            }
            return(0);
        }
コード例 #7
0
 public bool FromXmlFile(GxFile file, GXBaseCollection <SdtMessages_Message> Messages, string sName, string sNameSpace)
 {
     if (GXUtil.CheckFile(file, Messages))
     {
         return(FromXml(file.ReadAllText(string.Empty), Messages, sName, sNameSpace));
     }
     else
     {
         return(false);
     }
 }
コード例 #8
0
        public short Open(String fileName)
        {
            try
            {
                GXLogging.Debug(log, "GetType " + nmspace + ".ExcelFile");
                Type classType = ass.GetType(nmspace + ".ExcelFile", false, true);
                ef = Activator.CreateInstance(classType);

                GxFile file = new GxFile(Path.GetDirectoryName(fileName), fileName, GxFileType.Private);
                if (!String.IsNullOrEmpty(template))
                {
                    GxFile templateFile = new GxFile(Path.GetDirectoryName(template), template);
                    if (templateFile.Exists())
                    {
                        GXLogging.Debug(log, "Opening Template " + template);
                        var stream = templateFile.GetStream();
                        stream.Position = 0;

                        GxExcelUtils.Invoke(ef, "LoadXls", new object[] { stream });
                    }
                    else
                    {
                        errCod         = 4;
                        errDescription = "Invalid template.";
                        return(errCod);
                    }
                }
                else if (file.Exists())
                {
                    var stream = file.GetStream();
                    stream.Position = 0;

                    GxExcelUtils.Invoke(ef, "LoadXls", new object[] { stream });
                }
                else
                {
                    object worksheets = GxExcelUtils.GetPropValue(ef, "Worksheets");

                    object ws = GxExcelUtils.Invoke(worksheets, "Add", new object[] { "Sheet1" });
                    GxExcelUtils.SetPropValue(worksheets, "ActiveWorksheet", ws);
                }
                xlsFileName = fileName;
            }
            catch (Exception e)
            {
                GXLogging.Error(log, "Error opening " + fileName, e);
                errCod         = 10;
                errDescription = "Could not open file." + e.Message + (e.InnerException != null ? e.InnerException.Message:"");
                return(errCod);
            }
            return(0);
        }
コード例 #9
0
 public bool FromJSonFile(GxFile file, GXBaseCollection <SdtMessages_Message> Messages)
 {
     if (file != null && file.Exists())
     {
         string s = file.ReadAllText(string.Empty);
         return(FromJSonString(s, Messages));
     }
     else
     {
         GXUtil.ErrorToMessages("FromJSon Error", "File does not exist", Messages);
         return(false);
     }
 }
コード例 #10
0
        private IndexRecord GetIndexRecord(object obj, GxContentInfo contentInfo)
        {
            IndexRecord    ir     = null;
            GxFile         file   = obj as GxFile;
            GxSilentTrnSdt silent = obj as GxSilentTrnSdt;
            string         str    = obj as string;

            if (file != null && contentInfo != null)
            {
                ir         = new IndexRecord();
                ir.Uri     = file.GetAbsoluteName();
                ir.Content = DocumentHandler.GetText(file.GetAbsoluteName(), Path.GetExtension(file.GetAbsoluteName()));
                ir.Entity  = contentInfo.Entity == null?file.GetType().ToString() : contentInfo.Entity;

                ir.Title = contentInfo.Title == null?file.GetName() : contentInfo.Title;

                ir.Viewer = contentInfo.Viewer == null?file.GetName() : contentInfo.Viewer;

                ir.Keys = contentInfo.Keys == null || contentInfo.Keys.Count == 0 ? new List <string>() : contentInfo.Keys;
            }
            else if (silent != null)
            {
                IGxSilentTrn  bc   = (silent).getTransaction();
                GxContentInfo info = bc.GetContentInfo();
                if (info != null)
                {
                    ir         = new IndexRecord();
                    ir.Uri     = info.Id;
                    ir.Content = bc.ToString();
                    ir.Entity  = contentInfo.Entity == null ? info.Entity : contentInfo.Entity;
                    ir.Title   = contentInfo.Title == null ? info.Title : contentInfo.Title;
                    ir.Viewer  = contentInfo.Viewer == null ? info.Viewer : contentInfo.Viewer;
                    ir.Keys    = contentInfo.Keys == null || contentInfo.Keys.Count == 0 ? info.Keys : contentInfo.Keys;
                }
            }
            else if (str != null && contentInfo != null)
            {
                ir         = new IndexRecord();
                ir.Uri     = contentInfo.Id == null ? string.Empty : contentInfo.Id;
                ir.Content = str;
                ir.Entity  = contentInfo.Entity == null ? String.Empty : contentInfo.Entity;
                ir.Title   = contentInfo.Title == null ? String.Empty : contentInfo.Title;
                ir.Viewer  = contentInfo.Viewer == null ? String.Empty : contentInfo.Viewer;
                ir.Keys    = contentInfo.Keys == null || contentInfo.Keys.Count == 0 ? new List <string>() : contentInfo.Keys;
            }
            return(ir);
        }
コード例 #11
0
 public bool UploadPrivate(string filefullpath, string storageobjectfullname, GxFile uploadedFile, GXBaseCollection <SdtMessages_Message> messages)
 {
     try
     {
         ValidProvider();
         if (String.IsNullOrEmpty(storageobjectfullname))
         {
             storageobjectfullname = Path.GetFileName(filefullpath);
         }
         string url = provider.Upload(filefullpath, storageobjectfullname, GxFileType.Private);
         uploadedFile.FileInfo = new GxExternalFileInfo(storageobjectfullname, url, provider);
         return(true);
     }
     catch (Exception ex)
     {
         StorageMessages(ex, messages);
         return(false);
     }
 }
コード例 #12
0
 public short Save()
 {
     try
     {
         GxFile       file    = new GxFile(Path.GetDirectoryName(xlsFileName), xlsFileName, GxFileType.Private);
         MemoryStream content = new MemoryStream();
         GxExcelUtils.Invoke(ef, "SaveXls", new object[] { content });
         content.Position = 0;
         file.Create(content);
     }
     catch (Exception e)
     {
         GXLogging.Error(log, "Error saving " + xlsFileName, e);
         errCod         = 12;
         errDescription = "Could not save file." + e.Message;
         return(-1);
     }
     return(0);
 }
コード例 #13
0
 public override void initialize( )
 {
     wcpOAV21tCurrentCode = "";
     gxfirstwebparm       = "";
     gxfirstwebparm_bkp   = "";
     sDynURL               = "";
     FormProcess           = "";
     bodyStyle             = "";
     GXKey                 = "";
     AV7UploadedFiles      = new GXBaseCollection <SdtFileUploadData>(context, "FileUploadData", "DataAnalysisPlatform");
     AV12BR_MedicalImaging = new SdtBR_MedicalImaging(context);
     GX_FocusControl       = "";
     Form              = new GXWebForm();
     sPrefix           = "";
     ucFileupload1     = new GXUserControl();
     sEvt              = "";
     EvtGridId         = "";
     EvtRowId          = "";
     sEvtType          = "";
     AV23cookie        = new GxHttpCookie();
     AV24httpresponse  = new GxHttpResponse(context);
     GXt_dbconnection1 = new GxDataStore();
     AV8FileUploadData = new SdtFileUploadData(context);
     AV18tBaseFile     = new GxFile(context.GetPhysicalPath());
     AV19tLargeHtml    = "";
     AV10tFileNewName  = "";
     AV22Context       = new GeneXus.Programs.wwpbaseobjects.SdtWWPContext(context);
     BackMsgLst        = new msglist();
     LclMsgLst         = new msglist();
     pr_datastore1     = new DataStoreProvider(context, new GeneXus.Programs.br_sduploadimage__datastore1(),
                                               new Object[][] {
     }
                                               );
     pr_default = new DataStoreProvider(context, new GeneXus.Programs.br_sduploadimage__default(),
                                        new Object[][] {
     }
                                        );
     /* GeneXus formulas. */
     context.Gx_err = 0;
 }
コード例 #14
0
 public bool GetPrivate(string storageobjectfullname, GxFile externalFile, int expirationMinutes, GXBaseCollection <SdtMessages_Message> messages)
 {
     try
     {
         ValidProvider();
         string url = provider.Get(storageobjectfullname, GxFileType.Private, expirationMinutes);
         if (String.IsNullOrEmpty(url))
         {
             GXUtil.ErrorToMessages("Get Error", "File doesn't exists", messages);
             return(false);
         }
         else
         {
             externalFile.FileInfo = new GxExternalFileInfo(storageobjectfullname, url, provider, GxFileType.Private);
             return(true);
         }
     }
     catch (Exception ex)
     {
         StorageMessages(ex, messages);
         return(false);
     }
 }
コード例 #15
0
        public bool DownloadPrivate(string storageobjectfullname, GxFile localFile, GXBaseCollection <SdtMessages_Message> messages)
        {
            try
            {
                ValidProvider();
                string destFileName;

                if (Path.IsPathRooted(localFile.GetAbsoluteName()))
                {
                    destFileName = localFile.GetAbsoluteName();
                }
                else
                {
                    destFileName = Path.Combine(GxContext.StaticPhysicalPath(), localFile.Source);
                }
                provider.Download(storageobjectfullname, destFileName, GxFileType.Private);
                return(true);
            }
            catch (Exception ex)
            {
                StorageMessages(ex, messages);
                return(false);
            }
        }
コード例 #16
0
        private string getBLOBFile(int id, string extension, string name, string fileName, bool temporary, GxFileType fileType = GxFileType.PrivateAttribute)
        {
            GxFile       file       = null;
            Stream       fs         = null;
            BinaryWriter bw         = null;
            int          bufferSize = 4096;

            byte[] outbyte = new byte[bufferSize];
            long   retval;
            long   startIndex   = 0;
            bool   streamClosed = false;

            try
            {
                startIndex = 0;

                retval = _gxDbCommand.Db.GetBytes(_gxDbCommand, _DR, id - 1, startIndex, outbyte, 0, bufferSize);

                if (retval == 0)
                {
                    return("");
                }

                using (fs = new MemoryStream())
                {
                    using (bw = new BinaryWriter(fs))
                    {
                        while (retval == bufferSize)
                        {
                            bw.Write(outbyte);
                            bw.Flush();

                            startIndex += bufferSize;
                            retval      = _gxDbCommand.Db.GetBytes(_gxDbCommand, _DR, id - 1, startIndex, outbyte, 0, bufferSize);
                        }

                        bw.Write(outbyte, 0, (int)retval);
                        bw.Flush();

                        fs.Seek(0, SeekOrigin.Begin);

                        file = new GxFile(_gxDbCommand.Conn.BlobPath, fileName, fileType);
                        file.Create(fs);
                    }
                }
                streamClosed = true;

                GXLogging.Debug(log, "GetBlobFile fileName:" + fileName + ", retval bytes:" + retval);

                if (temporary)
                {
                    GXFileWatcher.Instance.AddTemporaryFile(file);
                }

                fileName = file.GetURI();
            }
            catch (IOException e)
            {
                if (!file.Exists())
                {
                    GXLogging.Error(log, "Return getBLOBFile Error Can't read BLOB field into " + fileName, e);
                    throw (new GxADODataException(e));
                }
                else
                {
                    GXLogging.Warn(log, "Return getBLOBFile Error Can't write BLOB field into " + fileName, e);
                }
            }
            finally
            {
                if (!streamClosed)
                {
                    try
                    {
                        if (bw != null)
                        {
                            bw.Close();
                        }
                        if (fs != null)
                        {
                            fs.Close();
                        }
                    }
                    catch (Exception ex)
                    {
                        GXLogging.Error(log, "getBLOBFile Close Stream Error", ex);
                    }
                }
            }
            return(fileName);
        }
コード例 #17
0
 public virtual bool FromJSonFile(GxFile file)
 {
     throw new NotImplementedException();
 }
コード例 #18
0
ファイル: GXRestUtils.cs プロジェクト: jechague/DotNetClasses
 internal static void CacheUploadFile(string fileGuid, string savedFileName, string localfileName, string ext, GxFile file, HttpContext localHttpContext)
 {
     CacheAPI.FilesCache.Set(fileGuid, JSONHelper.Serialize(new UploadCachedFile()
     {
         path = savedFileName, fileExtension = ext, fileName = localfileName
     }), GxRestPrefix.UPLOAD_TIMEOUT);
     GXFileWatcher.Instance.AddTemporaryFile(file, localHttpContext);
 }
コード例 #19
0
        public void AddTemporaryFile(GxFile FileUploaded, HttpContext httpcontext)
        {
            if (!DISABLED)
            {
                GXLogging.Debug(log, "AddTemporaryFile ", FileUploaded.Source);
#if !NETCORE
                if (httpcontext == null)
                {
                    httpcontext = HttpContext.Current;
                }
#endif
                if (httpcontext != null)
                {
                    try
                    {
                        string sessionId;
                        if (httpcontext.Session != null)
                        {
#if NETCORE
                            sessionId = httpcontext.Session.Id;
#else
                            sessionId = httpcontext.Session.SessionID;
#endif
                        }
                        else
                        {
                            sessionId = "nullsession";
                        }
                        List <GxFile> sessionTmpFiles;
                        lock (m_SyncRoot)
                        {
                            if (webappTmpFiles.ContainsKey(sessionId))
                            {
                                sessionTmpFiles = (List <GxFile>)webappTmpFiles[sessionId];
                            }
                            else
                            {
                                sessionTmpFiles = new List <GxFile>();
                            }
                            sessionTmpFiles.Add(FileUploaded);
                            webappTmpFiles[sessionId] = sessionTmpFiles;
                        }
                    }
                    catch (Exception exc)
                    {
                        GXLogging.Error(log, "AddTemporaryFile Error", exc);
                    }
                    lock (m_SyncRoot)
                    {
                        if (!running)
                        {
                            running = true;
                            GXLogging.Debug(log, "ThreadStart GXFileWatcher.Instance.Run");
                            ThreadPool.QueueUserWorkItem(new WaitCallback(GXFileWatcher.Instance.Run), cts.Token);
                        }
                    }
                }
                else
                {
                    if (tmpFiles == null)
                    {
                        tmpFiles = new List <GxFile>();
                    }
                    lock (tmpFiles)
                    {
                        tmpFiles.Add(FileUploaded);
                    }
                }
            }
        }
コード例 #20
0
        public override void webExecute()
        {
            try
            {
                if (context.isMultipartRequest())
                {
                    localHttpContext.Response.ContentType = MediaTypesNames.TextPlain;
                    var r         = new List <UploadFile>();
                    var fileCount = localHttpContext.Request.GetFileCount();
                    for (var i = 0; i < fileCount; i++)
                    {
                        var      hpf      = localHttpContext.Request.GetFile(i);
                        string   fileName = string.Empty;
                        string[] files    = hpf.FileName.Split(new char[] { '\\' });
                        if (files.Length > 0)
                        {
                            fileName = files[files.Length - 1];
                        }
                        else
                        {
                            fileName = hpf.FileName;
                        }

                        string ext           = FileUtil.GetFileType(fileName);
                        string savedFileName = FileUtil.getTempFileName(Preferences.getTMP_MEDIA_PATH(), FileUtil.GetFileName(fileName), string.IsNullOrEmpty(ext) ? "tmp" : ext);
                        GxFile gxFile        = new GxFile(Preferences.getTMP_MEDIA_PATH(), savedFileName);

                        gxFile.Create(hpf.InputStream);

                        GXFileWatcher.Instance.AddTemporaryFile(gxFile);

                        r.Add(new UploadFile()
                        {
                            name         = fileName,
                            size         = gxFile.GetLength(),
                            url          = gxFile.GetPath(),
                            type         = context.GetContentType(ext),
                            extension    = ext,
                            thumbnailUrl = gxFile.GetPath(),
                            path         = savedFileName
                        });
                    }
                    UploadFilesResult result = new UploadFilesResult()
                    {
                        files = r
                    };
                    var jsonObj = JSONHelper.Serialize(result);
                    localHttpContext.Response.Write(jsonObj);
                }
                else
                {
                    Stream istream     = localHttpContext.Request.GetInputStream();
                    String contentType = localHttpContext.Request.ContentType;
                    String ext         = context.ExtensionForContentType(contentType);

                    string fileName = FileUtil.getTempFileName(Preferences.getTMP_MEDIA_PATH(), "BLOB", string.IsNullOrEmpty(ext) ? "tmp" : ext);
                    GxFile file     = new GxFile(Preferences.getTMP_MEDIA_PATH(), fileName);
                    file.Create(istream);

                    Jayrock.Json.JObject obj = new Jayrock.Json.JObject();
                    fileName = file.GetURI();

                    String fileGuid  = Guid.NewGuid().ToString("N");
                    String fileToken = GxRestPrefix.UPLOAD_PREFIX + fileGuid;
                    CacheAPI.FilesCache.Set(fileGuid, fileName, GxRestPrefix.UPLOAD_TIMEOUT);
                    obj.Put("object_id", fileToken);
                    localHttpContext.Response.AddHeader("GeneXus-Object-Id", fileToken);
                    localHttpContext.Response.ContentType = MediaTypesNames.ApplicationJson;
                    localHttpContext.Response.StatusCode  = 201;
                    localHttpContext.Response.Write(obj.ToString());
                }
            }
            catch (Exception e)
            {
                SendResponseStatus(500, e.Message);
                HttpHelper.SetResponseStatusAndJsonError(localHttpContext, HttpStatusCode.InternalServerError.ToString(), e.Message);
            }
            finally
            {
                try
                {
                    context.CloseConnections();
                }
                catch
                {
                }
            }
        }
コード例 #21
0
        public static string HtmlPreview(Object obj, string query, string textType, string preTag, string postTag, int fragmentSize, int maxNumFragments)
        {
            string         text;
            GxSilentTrnSdt silent = obj as GxSilentTrnSdt;
            GxFile         file   = obj as GxFile;

            if (silent != null)
            {
                text = (silent).Transaction.ToString();
            }
            else if (file != null)
            {
                text = DocumentHandler.GetText(file.GetAbsoluteName(), System.IO.Path.GetExtension(file.GetAbsoluteName()));
            }
            else if (textType.ToLower().StartsWith("htm"))
            {
                text = new NTidyHTMLHandler().GetTextFromString(obj.ToString());
            }
            else
            {
                text = obj.ToString();
            }
            if (!string.IsNullOrEmpty(query) && !string.IsNullOrEmpty(text))
            {
                if (qp == null)
                {
                    qp = new QueryParser(Lucene.Net.Util.Version.LUCENE_24, IndexRecord.CONTENTFIELD, Indexer.CreateAnalyzer());
                    qp.DefaultOperator        = QueryParser.Operator.AND;
                    qp.MultiTermRewriteMethod = MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE;
                }
                Query unReWrittenQuery = qp.Parse(query);
                Query q = unReWrittenQuery;
                try
                {
                    if (reader == null)
                    {
                        reader = Indexer.Reader;
                    }
                    if (!queries.TryGetValue(query, out q))
                    {
                        q = unReWrittenQuery.Rewrite(reader);//required to expand search terms (for the usage of highlighting with wildcards)

                        if (queries.Count == int.MaxValue)
                        {
                            queries.Clear();
                        }
                        queries[query] = q;
                    }
                }
                catch (Exception ex)
                {
                    GXLogging.Error(log, "HTMLPreview error", ex);
                }
                QueryScorer scorer = new QueryScorer(q);

                SimpleHTMLFormatter formatter   = new SimpleHTMLFormatter(preTag, postTag);
                Highlighter         highlighter = new Highlighter(formatter, scorer);
                IFragmenter         fragmenter  = new SimpleFragmenter(fragmentSize);

                highlighter.TextFragmenter = fragmenter;
                TokenStream tokenStream = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_24).TokenStream("Content", new StringReader(text));

                String result = highlighter.GetBestFragments(tokenStream, text, maxNumFragments, "...");
                return(result);
            }
            else
            {
                return(text);
            }
        }
コード例 #22
0
 public bool FromJSonFile(GxFile file)
 {
     return(FromJSonFile(file, null));
 }
コード例 #23
0
        public override void webExecute()
        {
            try
            {
                string savedFileName, ext, fName;
                if (context.isMultipartRequest())
                {
                    localHttpContext.Response.ContentType = MediaTypesNames.TextPlain;
                    var r         = new List <UploadFile>();
                    var fileCount = localHttpContext.Request.GetFileCount();
                    for (var i = 0; i < fileCount; i++)
                    {
                        string fileGuid  = GxUploadHelper.GetUploadFileGuid();
                        string fileToken = GxUploadHelper.GetUploadFileId(fileGuid);
                        var    hpf       = localHttpContext.Request.GetFile(i);
                        fName = string.Empty;
                        string[] files = hpf.FileName.Split(new char[] { '\\' });
                        if (files.Length > 0)
                        {
                            fName = files[files.Length - 1];
                        }
                        else
                        {
                            fName = hpf.FileName;
                        }

                        ext           = FileUtil.GetFileType(fName);
                        savedFileName = FileUtil.getTempFileName(Preferences.getTMP_MEDIA_PATH(), FileUtil.GetFileName(fName), string.IsNullOrEmpty(ext) ? "tmp" : ext);
                        GxFile gxFile = new GxFile(Preferences.getTMP_MEDIA_PATH(), savedFileName);

                        gxFile.Create(hpf.InputStream);
                        string uri = gxFile.GetURI();
                        string url = (PathUtil.IsAbsoluteUrl(uri)) ? uri : context.PathToUrl(uri);

                        r.Add(new UploadFile()
                        {
                            name         = fName,
                            size         = gxFile.GetLength(),
                            url          = url,
                            type         = context.GetContentType(ext),
                            extension    = ext,
                            thumbnailUrl = url,
                            path         = fileToken
                        });
                        GxUploadHelper.CacheUploadFile(fileGuid, savedFileName, fName, ext, gxFile, localHttpContext);
                    }
                    UploadFilesResult result = new UploadFilesResult()
                    {
                        files = r
                    };
                    var jsonObj = JSONHelper.Serialize(result);
                    localHttpContext.Response.Write(jsonObj);
                }
                else
                {
                    Stream istream     = localHttpContext.Request.GetInputStream();
                    string contentType = localHttpContext.Request.ContentType;
                    WcfExecute(istream, contentType);
                }
            }
            catch (Exception e)
            {
                SendResponseStatus(500, e.Message);
                HttpHelper.SetResponseStatusAndJsonError(localHttpContext, HttpStatusCode.InternalServerError.ToString(), e.Message);
            }
            finally
            {
                try
                {
                    context.CloseConnections();
                }
                catch
                {
                }
            }
        }
コード例 #24
0
 public virtual bool FromJSonFile(GxFile file, GXBaseCollection <SdtMessages_Message> Messages)
 {
     throw new NotImplementedException();
 }