/// <summary>
    /// Запускает процесс обработки данных курсора и возвращает строку в виде JSON-объекта.
    /// </summary>
    /// <param name="cursor">Созданный курсор.</param>
    /// <param name="logFile"></param>
    /// <returns>CJsonStoreData</returns>
    public JsonStoreData Process(CJSCursor cursor, Logger logger = null) {
      if (logger != null) logger.WriteLn("CSQLtoJSON.Process - start");
      var result = new JsonStoreData {
        EndReached = cursor.rqPacket.EndReached,
        Start = 0
      };

      result.MetaData = JsonStoreMetadata.ConstructMetadata(cursor.bioCode, cursor.CursorIniDoc);
      result.Rows = new JsonStoreRows();
      var rowCount = 0;
      result.Start = cursor.rqPacket.Start;
      result.Limit = cursor.rqPacket.Limit;
      result.TotalCount = cursor.rqPacket.TotalCount;
      // перебираем все записи в курсоре
      //throw new Exception("FTW!!!");
      if (logger != null) logger.WriteLn("CSQLtoJSON.Process - cursor - fettching - start");
      while (cursor.Next()) {
        if (result.Limit == 0 || ++rowCount <= result.Limit) {
          var newRow = result.AddRow();
          // перебираем все поля одной записи
          if (logger != null) logger.WriteLn("CSQLtoJSON.Process - cursor - fields - fettching - start");
          foreach (var fld in cursor.Fields) {
            var fieldName = fld.FieldName;
            var v_field = fld;
            var process = true;
            if (this.ProcessField != null)
              process = this.ProcessField(ref fieldName, ref v_field);
            if (process) {
              var doEncodeFromAnsi = (v_field.DataType == JSFieldType.Clob) && (v_field.Encoding == FieldEncoding.WINDOWS1251);
              newRow.Values[result.MetaData.IndexOf(fieldName)] = doEncodeFromAnsi ? Utl.EncodeANSI2UTF(v_field.AsObject as String) : v_field.AsObject;
            }
          }
          if (logger != null) logger.WriteLn("CSQLtoJSON.Process - cursor - fields - fettching - end");
        }
      }
      if (logger != null) logger.WriteLn("CSQLtoJSON.Process - cursor - fettching - end");
      result.EndReached = result.Limit == 0 || rowCount <= result.Limit;
      result.TotalCount = result.Start + rowCount;
      if (logger != null) logger.WriteLn("CSQLtoJSON.Process - end");
      return result;
    }
    private void processData(CJSCursor pCursor, StringBuilder vDoc, ref EBioException vEx) {
      try {
        var needClose = false;
        if(!pCursor.IsActive && (pCursor.Connection != null)) {
          pCursor.Open(120);
          needClose = true;
        }
      // перебираем все записи в курсоре
        while(pCursor.Next()) {
          // перебираем все поля одной записи
          var fRow = new StringBuilder();
          foreach(DictionaryEntry vCur in pCursor.RowValues) {
            fRow.Append(SQLUtils.ObjectAsString(vCur.Value));
          }
          vDoc.Append(fRow);
        }
        if(needClose)
          pCursor.Close();
      } catch(Exception ex) {
        vEx = EBioException.CreateIfNotEBio(ex);
      }

    }
 private void _doProcessCursor() {
   var conn = this.dbSess.GetConnection();
   var vCursor = new CJSCursor(conn, this._cursor_ds, this.bioCode);
   vCursor.Init(null, this._request.BioParams, this._request.Filter, this._request.Sort, this._request.Selection, 120);
   vCursor.Open(120);
   try {
     while (vCursor.Next()) {
       if (this._state == RemoteProcState.Breaking)
         break;
       var newRow = vCursor.rqPacket.MetaData.CreateNewRow();
       // перебираем все поля одной записи
       foreach (Field vCur in vCursor.Fields) {
         var vFName = vCur.FieldName;
         var vFVal = vCur;
         newRow.Values[vCursor.rqPacket.MetaData.IndexOf(vFName)] = vCur.AsObject;
       }
       this._doProcessRecord(vCursor.rqPacket.MetaData, newRow);
     }
   } finally {
     vCursor.Close();
     if (conn != null)
       conn.Close();
   }
 }
Exemple #4
0
    private void _doGetSelectionPks(IDbConnection conn, XmlElement ds) {
      var v_cursor = new CJSCursor(conn, ds, this.bioCode);
      var rqst = this.BioRequest<JsonStoreRequestGet>();
      v_cursor.Init(rqst);
      v_cursor.Open(rqst.Timeout);
      try {
        String pks = null;
        while (v_cursor.Next()) 
          Utl.AppendStr(ref pks, v_cursor.PKValue, ";");
        var rsp = new JsonStoreResponse {
          BioParams = this.bioParams,
          Ex = null,
          Success = true,
          TransactionID = this.TransactionID,
          selectedPkList = pks
        };

        this.Context.Response.Write(rsp.Encode());
      } finally {
        v_cursor.Close();
      }
    }