Exemple #1
0
        public Stop ErrorSubmission(Stop stop, SubmissionError submissionError, string stopStatus)
        {
            if (stop.ListSubmission == null)
            {
                stop.ListSubmission = new Common.Models.Submission[0];
                Common.Models.Submission submission = new Common.Models.Submission
                {
                    DateSubmitted = submissionError.DateReported,
                    Id            = submissionError.SubmissionId,
                    Status        = Enum.GetName(typeof(SubmissionStatus), SubmissionStatus.Submitted),
                    FileName      = submissionError.FileName
                };
                var submissions = stop.ListSubmission.ToList();
                submissions.Add(submission);
                stop.ListSubmission = submissions.ToArray();
            }

            var pendingSubmissions = stop.ListSubmission.Where(x => x.FileName.Contains(submissionError.FileName));

            foreach (var submission in pendingSubmissions)
            {
                List <SubmissionError> listSubmissionError = new List <SubmissionError>();
                if (submission.ListSubmissionError != null)
                {
                    listSubmissionError = submission.ListSubmissionError.ToList <SubmissionError>();
                }
                listSubmissionError.Add(submissionError);
                submission.ListSubmissionError = listSubmissionError.ToArray();

                submission.Status = Enum.GetName(typeof(SubmissionStatus), SubmissionStatus.Failed);
            }
            stop.Status = stopStatus;
            return(stop);
        }
        public async Task ProcessRecordLevelErrors(string recordLevelErrors, string type)
        {
            using StringReader reader = new StringReader(recordLevelErrors);
            string line;

            while ((line = reader.ReadLine()) != null)
            {
                var recordLevelError = DeserializeRecordLevelError(line);
                var stop             = await _stopCosmosDbService.GetStopAsync(recordLevelError.LeaRecordId);

                SubmissionError submissionError = new SubmissionError
                {
                    DateReported = DateTime.UtcNow,
                    Code         = type == Enum.GetName(typeof(SubmissionErrorType), SubmissionErrorType.RecordLevelFatalError) ? "RLFE" : recordLevelError.ErrorList.Split("::")[0],
                    ErrorType    = type,
                    Message      = type == Enum.GetName(typeof(SubmissionErrorType), SubmissionErrorType.RecordLevelFatalError) ? recordLevelError.ErrorList : recordLevelError.ErrorList.Split("::")[1],
                    FileName     = recordLevelError.FileName
                };
                await _stopCosmosDbService.UpdateStopAsync(_stopService.ErrorSubmission(stop, submissionError, Enum.GetName(typeof(SubmissionStatus), SubmissionStatus.Failed)));
            }
        }
Exemple #3
0
        private async Task HandleFailedToSubmit(ILogger lod, DateTime date, string fileName, Guid submissionId, Stop stop)
        {
            try
            {
                SubmissionError submissionError = new SubmissionError()
                {
                    Code         = "FTS",
                    Message      = "Failed to submit to DOJ. SFTP connection, Blob Connection failure",
                    DateReported = date,
                    ErrorType    = Enum.GetName(typeof(SubmissionErrorType), SubmissionErrorType.SubmissionError),
                    FileName     = fileName,
                    SubmissionId = submissionId
                };
                await _stopCosmosDbService.UpdateStopAsync(_stopService.ErrorSubmission(stop, submissionError, Enum.GetName(typeof(SubmissionStatus), SubmissionStatus.Unsubmitted)));

                return;
            }
            catch (Exception)
            {
                throw new Exception("Failed to update stop submission error");
            }
        }
Exemple #4
0
        private async Task <bool> HandledDojCastError(ILogger log, Stop stop, DateTime date, string fileName, Guid submissionId, string runId)
        {
            try
            {
                log.LogWarning($"Handling DoJ Cast Error: {stop.Id} : {runId}");
                SubmissionError submissionError = new SubmissionError()
                {
                    Code         = "FTS",
                    Message      = "Failed to submit to DOJ. Stop to DOJ Cast failure",
                    DateReported = date,
                    ErrorType    = Enum.GetName(typeof(SubmissionErrorType), SubmissionErrorType.SubmissionError),
                    FileName     = fileName,
                    SubmissionId = submissionId
                };
                await _stopCosmosDbService.UpdateStopAsync(_stopService.ErrorSubmission(stop, submissionError, Enum.GetName(typeof(SubmissionStatus), SubmissionStatus.Failed)));

                return(true);
            }
            catch (Exception ex)
            {
                log.LogError($"Exception: {ex} --> occurred during HandleDojCastError with stop id {stop.Id}");
                return(false);
            }
        }
        public async Task ProcessFileLevelFatalErrors(string fileLevelFatalErrors)
        {
            using StringReader reader = new StringReader(fileLevelFatalErrors);
            string line;

            while ((line = reader.ReadLine()) != null)
            {
                var fileLevelFatalError = DeserializeFileLevelFatalError(line);
                var stopId = fileLevelFatalError.FileName.Split("_")[2].Replace(".json", string.Empty);
                var stop   = await _stopCosmosDbService.GetStopAsync(stopId);

                SubmissionError submissionError = new SubmissionError
                {
                    DateReported = DateTime.UtcNow,
                    Code         = "FLFE",
                    ErrorType    = Enum.GetName(typeof(SubmissionErrorType), SubmissionErrorType.FileLevelFatalError),
                    Message      = fileLevelFatalError.ErrorMessage,
                    FileName     = fileLevelFatalError.FileName
                };

                // Determine if stop is a duplicate, if so update SubmissionStatus to duplicate.
                await _stopCosmosDbService.UpdateStopAsync(_stopService.ErrorSubmission(stop, submissionError, Enum.GetName(typeof(SubmissionStatus), SubmissionStatus.Failed)));
            }
        }
        /// <summary>
        /// 保存3GX数据到数据库中
        /// </summary>
        /// <param name="boExModelList"></param>
        /// <param name="replaceOrLeave"></param>
        /// <returns></returns>
        private int Save3GX(List <GeoFeature> ftList, string replaceOrLeave = null)
        {
            int  i            = 0;
            int  iInsertCount = 0; //记录添加条数
            int  iUpdateCount = 0; //记录修改条数
            bool IsInsert     = true;

            OracleDBHelper.SQLEntity sqlEntity;
            OracleParameter[]        parameters;
            StringBuilder            strSql = new StringBuilder();

            foreach (GeoFeature bo in ftList)
            {
                subErr = new SubmissionError();
                List <OracleDBHelper.SQLEntity> sqlList = new List <OracleDBHelper.SQLEntity>();
                bool       isBoExist = false;
                GeoFeature seachFt   = GetBoListByName(bo.NAME, bo.FT);
                if (seachFt != null)
                {
                    isBoExist = true;
                    //对象存在则需要把带入库的对象id都换成库中的该对象id
                    bo.BOID = seachFt.BOID;
                }
                else
                {
                    bo.BOID = System.Guid.NewGuid().ToString();
                }

                #region 添加对象
                //存在且保留
                if (isBoExist && replaceOrLeave.ToUpper() == "UNCHANGE")
                {
                    ;
                }
                //覆盖
                else
                {
                    strSql = new StringBuilder();
                    //对象不存在
                    if (!isBoExist)
                    {
                        strSql.Append(" INSERT INTO BO(  ");
                        strSql.Append(" NAME,BOID,BOTID) ");
                        strSql.Append(" VALUES (:NAME,:BOID,:BOTID)");
                        IsInsert = true;
                    }
                    //对象存在
                    else
                    {
                        strSql.Append(" UPDATE BO SET ");
                        strSql.Append(" NAME=:NAME ");
                        strSql.Append(" WHERE BOID=:BOID  AND BOTID= :BOTID ");
                        IsInsert = false;
                    }
                    parameters = new OracleParameter[] {
                        new OracleParameter("NAME", OracleDbType.Varchar2, 50),
                        new OracleParameter("BOID", OracleDbType.Varchar2, 36),
                        new OracleParameter("BOTID", OracleDbType.Varchar2, 36)
                    };
                    parameters[0].Value = bo.NAME;
                    parameters[1].Value = bo.BOID == null?System.Guid.NewGuid().ToString() : bo.BOID;

                    //根据FT查找对象的BOTID没用找到时,添加会出现异常
                    parameters[2].Value = DBUtility.OracleDBHelper.OracleHelper.ExecuteQueryText <string>(string.Format(" SELECT BOTID FROM OBJECTTYPE WHERE FT='{0}'", bo.FT)).FirstOrDefault();
                    if (parameters[2].Value == null)
                    {
                        subErr.BOName     = bo.NAME;
                        subErr.Error      = bo.NAME + "对应的对象类型不存在";
                        result.TotalBO    = ftList.Count;
                        result.UpdatedBO  = iUpdateCount;
                        result.FailedBO   = ListsubErr.Count + 1;
                        result.InsertedBO = iInsertCount;
                        result.Errors.Add(subErr);
                        continue;
                    }
                    sqlEntity                 = new DBUtility.OracleDBHelper.SQLEntity();
                    sqlEntity.Sqlstr          = strSql.ToString();
                    sqlEntity.Oracleparameter = parameters;
                    sqlList.Add(sqlEntity);
                }
                #endregion

                #region 添加坐标数据
                bool isGeometryExist = false;
                //如果对象存在,需要判断坐标是否存在,只要该对象存在一组坐标,就认为该对象坐标存在
                if (isBoExist)
                {
                    bo.GeometryList[0].BOID = bo.BOID;
                    isGeometryExist         = GeometryeExist(bo.GeometryList[0]);
                }
                //坐标且保留
                if (isGeometryExist && replaceOrLeave.ToUpper() == "UNCHANGE")
                {
                    ;
                }
                //覆盖
                else
                {
                    //坐标存在,先删除
                    if (isGeometryExist)
                    {
                        strSql = new StringBuilder();
                        strSql.Append(" DELETE FROM  GEOMETRY  ");
                        strSql.Append(" WHERE BOID =:BOID ");

                        parameters = new OracleParameter[] {
                            new OracleParameter("BOID", OracleDbType.Varchar2, 36)
                        };
                        parameters[0].Value = bo.BOID;

                        sqlEntity                 = new DBUtility.OracleDBHelper.SQLEntity();
                        sqlEntity.Sqlstr          = strSql.ToString();
                        sqlEntity.Oracleparameter = parameters;
                        sqlList.Add(sqlEntity);
                    }

                    foreach (Geometry geometry in bo.GeometryList)
                    {
                        strSql = new StringBuilder();
                        strSql.Append(" INSERT INTO GEOMETRY(  ");
                        strSql.Append(" BOID,NAME,GEOMETRY,SOURCEDB)");
                        strSql.Append(" VALUES (:BOID,:NAME,MDSYS.SDO_GEOMETRY(:GEOMETRY,4326),:SOURCEDB)");

                        parameters = new OracleParameter[] {
                            new OracleParameter("BOID", OracleDbType.Varchar2, 36),
                            new OracleParameter("NAME", OracleDbType.Varchar2, 100),
                            new OracleParameter("GEOMETRY", OracleDbType.Clob),
                            new OracleParameter("SOURCEDB", OracleDbType.Varchar2, 100)
                        };
                        parameters[0].Value = bo.BOID == null?System.Guid.NewGuid().ToString() : bo.BOID;

                        parameters[1].Value = geometry.NAME == null?geometry.GEOMETRY.Split('(')[0] : geometry.NAME;

                        parameters[2].Value = geometry.GEOMETRY;
                        parameters[3].Value = geometry.SOURCEDB;

                        sqlEntity                 = new DBUtility.OracleDBHelper.SQLEntity();
                        sqlEntity.Sqlstr          = strSql.ToString();
                        sqlEntity.Oracleparameter = parameters;
                        sqlList.Add(sqlEntity);
                    }
                }
                #endregion

                #region 添加属性数据
                foreach (Property property in bo.PropertyList)
                {
                    strSql = new StringBuilder();
                    bool isPropertyExist = false;
                    if (isBoExist)
                    {
                        property.BOID   = bo.BOID;
                        isPropertyExist = PropertyExist(property);
                    }
                    //该条属性存在且保留,跳过
                    if (isPropertyExist && replaceOrLeave.ToUpper() == "UNCHANGE")
                    {
                        ;
                    }
                    else
                    {
                        if (!isPropertyExist)
                        {
                            strSql.Append(" INSERT INTO PROPERTY(  ");
                            strSql.Append(" MD,MDSOURCE,BOID,NS)");
                            strSql.Append(" VALUES (:MD,:MDSOURCE,:BOID,:NS)");
                        }
                        else if (isPropertyExist && replaceOrLeave.ToUpper() != "UNCHANGE")
                        {
                            strSql.Append(" UPDATE PROPERTY SET ");
                            strSql.Append(" MD=:MD ,MDSOURCE=:MDSOURCE ");
                            strSql.Append(" WHERE BOID=:BOID AND NS=:NS");
                        }

                        parameters = new OracleParameter[] {
                            new OracleParameter("MD", OracleDbType.XmlType),
                            new OracleParameter("MDSOURCE", OracleDbType.Varchar2, 50),
                            new OracleParameter("BOID", OracleDbType.Varchar2, 36),
                            new OracleParameter("NS", OracleDbType.Varchar2, 50)
                        };
                        parameters[0].Value = property.MD;
                        parameters[1].Value = property.MdSource;
                        parameters[2].Value = bo.BOID;
                        parameters[3].Value = property.NS;

                        sqlEntity                 = new DBUtility.OracleDBHelper.SQLEntity();
                        sqlEntity.Sqlstr          = strSql.ToString();
                        sqlEntity.Oracleparameter = parameters;
                        sqlList.Add(sqlEntity);
                    }
                }
                #endregion

                #region 添加别名
                foreach (AliasName aliasName in bo.AliasNameList)
                {
                    strSql = new StringBuilder();
                    bool isAliasNameExist = false;
                    if (isBoExist)
                    {
                        aliasName.BOID   = bo.BOID;
                        isAliasNameExist = AliasNameExist(aliasName);
                    }
                    //该条属性存在且保留,跳过
                    if (isAliasNameExist && replaceOrLeave.ToUpper() == "UNCHANGE")
                    {
                        ;
                    }
                    else
                    {
                        strSql = new StringBuilder();
                        if (!isAliasNameExist)
                        {
                            strSql.Append(" INSERT INTO ALIASNAME(  ");
                            strSql.Append(" NAME,BOID,APPDOMAIN)");
                            strSql.Append(" VALUES (:NAME,:BOID,:APPDOMAIN)");
                        }
                        else if (isAliasNameExist && replaceOrLeave.ToUpper() != "LEAVE")
                        {
                            strSql.Append(" UPDATE ALIASNAME SET ");
                            strSql.Append(" NAME=:NAME ");
                            strSql.Append(" WHERE BOID=:BOID AND APPDOMAIN=:APPDOMAIN");
                        }
                        parameters = new OracleParameter[] {
                            new OracleParameter("NAME", OracleDbType.Varchar2, 50),
                            new OracleParameter("BOID", OracleDbType.Varchar2, 36),
                            new OracleParameter("APPDOMAIN", OracleDbType.Varchar2, 50)
                        };
                        parameters[0].Value = aliasName.NAME;
                        parameters[1].Value = aliasName.BOID;
                        parameters[2].Value = aliasName.APPDOMAIN;

                        sqlEntity                 = new DBUtility.OracleDBHelper.SQLEntity();
                        sqlEntity.Sqlstr          = strSql.ToString();
                        sqlEntity.Oracleparameter = parameters;
                        sqlList.Add(sqlEntity);
                    }
                }
                #endregion

                try
                {
                    //存在需要执行的sql语句
                    if (sqlList.Count > 0)
                    {
                        i = i + (DBUtility.OracleDBHelper.OracleHelper.ExecuteSql(sqlList) == true ? 1 : 0);
                        if (IsInsert == true)
                        {
                            iInsertCount++;
                        }
                        else
                        {
                            iUpdateCount++;
                        }
                    }
                }
                catch (Exception ex)
                {
                    //记录入库错误信息
                    subErr.BOName = bo.NAME;
                    subErr.Error  = "空间数据有误!";
                    result.Errors.Add(subErr);
                    //continue;
                    //记录完毕
                    throw ex;
                }

                //构造需要返回的SubmissionResult
                result.TotalBO    = ftList.Count;
                result.UpdatedBO  = iUpdateCount;
                result.FailedBO   = ListsubErr.Count;
                result.InsertedBO = iInsertCount;
                //result.Errors.AddRange(ListsubErr);
                //结束
            }
            return(i);
        }