Beispiel #1
0
        public int Index(Document doc, bool deleteold)
        {
            checkloaded();
            _log.Info("indexing doc : " + doc.FileName);
            DateTime dt = FastDateTime.Now;

            if (deleteold && doc.DocNumber > -1)
            {
                _deleted.Set(true, doc.DocNumber);
            }

            if (deleteold == true || doc.DocNumber == -1)
            {
                doc.DocNumber = _lastDocNum++;//新增编号
            }
            // save doc to disk
            //string dstr = fastJSON.JSON.ToJSON(doc, new fastJSON.JSONParameters { UseExtensions = false });//fastJSON
            string dstr = _json.SerializeObject(doc);

            //存储doc模型对象
            _docs.Set(doc.FileName.ToLower(), Encoding.Unicode.GetBytes(dstr));

            _log.Info("writing doc to disk (ms) = " + FastDateTime.Now.Subtract(dt).TotalMilliseconds);

            dt = FastDateTime.Now;
            // index doc
            AddtoIndex(doc.DocNumber, doc.Text);
            _log.Info("indexing time (ms) = " + FastDateTime.Now.Subtract(dt).TotalMilliseconds);

            return(_lastDocNum);
        }
Beispiel #2
0
        public long WriteObject(T key, object obj)
        {
            StorageItem <T> meta = new StorageItem <T>();

            meta.key = key;
            //meta.typename = fastJSON.Reflection.Instance.GetTypeAssemblyName(obj.GetType());//fastJSON
            meta.typename = Reflection.Instance.GetTypeAssemblyName(obj.GetType());

            byte[] data;
            if (_saveFormat == SF_FORMAT.BSON)
            {
                //data = fastBinaryJSON.BJSON.ToBJSON(obj);//fastBinaryJSON
                data = _bson.SerializeObject(obj);
            }
            else
            {
                //data = Helper.GetBytes(fastJSON.JSON.ToJSON(obj));//fastJSON
                data = Helper.GetBytes(_json.SerializeObject(obj));
            }
            //超过压缩最大值界限就开启压缩
            if (data.Length > (int)Global.CompressDocumentOverKiloBytes * _KILOBYTE)
            {
                meta.isCompressed = 1;
                data = MiniLZO.Compress(data); //MiniLZO
            }
            return(internalWriteData(meta, data, false));
        }
 public async Task Invoke(HttpContext context)
 {
     try
     {
         await next(context);
     }
     //catch (ValidationException ex)
     //{
     //    var problem = HandleValidationException(ex, context) ;
     //    context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
     //    context.Response.ContentType = "application/problem+json";
     //    await context.Response.WriteAsync(json.SerializeObject(problem));
     //}
     catch (Exception ex)
     {
         var problem = HandleUnknownException(ex, context);
         context.Response.StatusCode  = (int)HttpStatusCode.BadRequest;
         context.Response.ContentType = "application/problem+json";
         await context.Response.WriteAsync(json.SerializeObject(problem));
     }
 }