/// <summary> /// Exports IJSONDocuments to export file. /// </summary> /// <param name="collection"></param> /// <param name="docList"></param> /// <param name="path"></param> /// <param name="dataType"></param> /// <returns></returns> public RecoveryOperationStatus Export(string collection, List<IJSONDocument> docList, string path,string fileName,string database, EXIMDataType dataType) { RecoveryOperationStatus state = new RecoveryOperationStatus(RecoveryStatus.Failure); EXIMBase eximBase = null; switch (dataType) { case EXIMDataType.CSV: eximBase = new CSVEXIMUtil(); break; case EXIMDataType.JSON: eximBase = new JSONEXIMUtil(); break; } if (eximBase != null) { state = eximBase.Write(dataType, path, collection,fileName,database, docList); } return state; }
public RecoveryOperationStatus Import(string database, string collection, string path, bool updateMode, EXIMDataType dataType) { RecoveryOperationStatus state = new RecoveryOperationStatus(RecoveryStatus.Success); EXIMBase eximBase = null; switch (dataType) { case EXIMDataType.CSV: eximBase = new CSVEXIMUtil(); break; case EXIMDataType.JSON: eximBase = new JSONEXIMUtil(); break; } if (eximBase != null) { try { foreach (List<JSONDocument> docList in eximBase.Read(dataType, path)) { if (docList != null) { if (docList.Count > 0) { // create insert operation if mode is update perform replace operation on List<FailedDocument> failedDoc = InsertDocuments(docList); if (failedDoc != null) { if (failedDoc.Count > 0) { if (updateMode) { List<JSONDocument> retryList = new List<JSONDocument>(); foreach (FailedDocument failed in failedDoc) { foreach (JSONDocument orgDoc in docList) { if (orgDoc.Key.Equals(failed.DocumentKey)) { retryList.Add(orgDoc); } } } failedDoc = ReplaceDocuments(retryList); if (failedDoc != null) { if (failedDoc.Count > 0) { if (LoggerManager.Instance.EXIMLogger != null && LoggerManager.Instance.RecoveryLogger.IsErrorEnabled) LoggerManager.Instance.EXIMLogger.Error("Import()", failedDoc.Count + "failed to import in collection" + collection); state.Status = RecoveryStatus.Failure; state.Message = failedDoc.Count + "failed to import in collection" + collection; } } } else { if (LoggerManager.Instance.EXIMLogger != null && LoggerManager.Instance.RecoveryLogger.IsErrorEnabled) LoggerManager.Instance.EXIMLogger.Error("Import()", failedDoc.Count + "failed to import in collection" + collection); state.Status = RecoveryStatus.Failure; state.Message = failedDoc.Count + "failed to import in collection" + collection; } } } } } } } catch (Exception exp) { if (LoggerManager.Instance.EXIMLogger != null && LoggerManager.Instance.RecoveryLogger.IsErrorEnabled) LoggerManager.Instance.EXIMLogger.Error("Import()", exp.ToString()); state.Status = RecoveryStatus.Failure; state.Message = exp.Message.ToString() +" For details kindly review the log file"; } } return state; }