コード例 #1
0
        public async Task <IEnumerable <SourceCatalog> > AddRecentFile(SourceCatalog sourceCatalog)
        {
            var catalog = await _dbContext.SourceCatalogs.FirstOrDefaultAsync(o => o.DocumentId == sourceCatalog.DocumentId);

            if (catalog == null)
            {
                catalog = new SourceCatalog()
                {
                    Name = sourceCatalog.Name, DocumentId = sourceCatalog.DocumentId
                };
                _dbContext.SourceCatalogs.Add(catalog);
            }
            var recentFile = new RecentFile();

            recentFile.User      = _userProfileService.GetCurrentUser().Username;
            recentFile.Date      = DateTime.Now.ToUniversalTime().ToPSTDateTime();
            recentFile.CatalogId = catalog.Id;
            _dbContext.RecentFiles.Add(recentFile);

            await _dbContext.SaveChangesAsync();

            return(await GetRecentFiles());
        }
コード例 #2
0
        public async Task <SourcePoint> AddSourcePoint(string fileName, string documentId, SourcePoint sourcePoint)
        {
            try
            {
                var  sourceCatalog    = _dbContext.SourceCatalogs.FirstOrDefault(o => o.DocumentId == documentId);
                bool addSourceCatalog = (sourceCatalog == null);
                if (addSourceCatalog)
                {
                    try
                    {
                        sourceCatalog = new SourceCatalog()
                        {
                            Name = fileName, DocumentId = documentId
                        };
                        _dbContext.SourceCatalogs.Add(sourceCatalog);
                    }
                    catch (Exception ex)
                    {
                        var entity = new LogEntity()
                        {
                            LogId      = "30006",
                            Action     = Constant.ACTIONTYPE_ADD,
                            ActionType = ActionTypeEnum.ErrorLog,
                            PointType  = Constant.POINTTYPE_SOURCECATALOG,
                            Message    = ".Net Error",
                        };
                        entity.Subject = $"{entity.LogId} - {entity.Action} - {entity.PointType} - Error";
                        await _logService.WriteLog(entity);

                        throw new ApplicationException("Add Source Catalog failed", ex);
                    }
                }

                sourcePoint.Created = DateTime.Now.ToUniversalTime().ToPSTDateTime();
                sourcePoint.Creator = _userProfileService.GetCurrentUser().Username;

                sourceCatalog.SourcePoints.Add(sourcePoint);

                _dbContext.PublishedHistories.Add(new PublishedHistory()
                {
                    Name          = sourcePoint.Name,
                    Position      = sourcePoint.Position,
                    Value         = sourcePoint.Value,
                    PublishedDate = sourcePoint.Created,
                    PublishedUser = sourcePoint.Creator,
                    SourcePointId = sourcePoint.Id
                });

                await _dbContext.SaveChangesAsync();

                if (addSourceCatalog)
                {
                    await _logService.WriteLog(new LogEntity()
                    {
                        LogId      = "30003",
                        Action     = Constant.ACTIONTYPE_ADD,
                        PointType  = Constant.POINTTYPE_SOURCECATALOG,
                        ActionType = ActionTypeEnum.AuditLog,
                        Message    = $"Add Source Catalog named {sourceCatalog.Name}."
                    });
                }
                await _logService.WriteLog(new LogEntity()
                {
                    LogId      = "10001",
                    Action     = Constant.ACTIONTYPE_ADD,
                    PointType  = Constant.POINTTYPE_SOURCEPOINT,
                    ActionType = ActionTypeEnum.AuditLog,
                    Message    = $"Create source point named {sourcePoint.Name} in the location: {sourcePoint.Position}, value: {sourcePoint.Value} in the excel file named: {sourceCatalog.FileName} by {sourcePoint.Creator}"
                });
            }
            catch (ApplicationException ex)
            {
                throw ex.InnerException;
            }
            catch (Exception ex)
            {
                var logEntity = new LogEntity()
                {
                    LogId      = "10005",
                    Action     = Constant.ACTIONTYPE_ADD,
                    ActionType = ActionTypeEnum.ErrorLog,
                    PointType  = Constant.POINTTYPE_SOURCEPOINT,
                    Message    = ".Net Error",
                    Detail     = ex.ToString()
                };
                logEntity.Subject = $"{logEntity.LogId} - {logEntity.Action} - {logEntity.PointType} - Error";
                await _logService.WriteLog(logEntity);

                throw ex;
            }
            return(sourcePoint);
        }
コード例 #3
0
        public async Task <DestinationPoint> AddDestinationPoint(string fileName, string documentId, DestinationPoint destinationPoint)
        {
            try
            {
                var  destinationCatalog    = _dbContext.DestinationCatalogs.FirstOrDefault(o => o.DocumentId == documentId);
                bool addDestinationCatalog = (destinationCatalog == null);
                if (addDestinationCatalog)
                {
                    try
                    {
                        destinationCatalog = new DestinationCatalog()
                        {
                            Name = fileName, DocumentId = documentId
                        };
                        _dbContext.DestinationCatalogs.Add(destinationCatalog);
                    }
                    catch (Exception ex)
                    {
                        var entity = new LogEntity()
                        {
                            LogId      = "40002",
                            Action     = Constant.ACTIONTYPE_ADD,
                            ActionType = ActionTypeEnum.ErrorLog,
                            PointType  = Constant.POINTYTPE_DESTINATIONCATALOG,
                            Message    = ".Net Error",
                        };
                        entity.Subject = $"{entity.LogId} - {entity.Action} - {entity.PointType} - Error";
                        await _logService.WriteLog(entity);

                        throw new ApplicationException("Add Source Catalog failed", ex);
                    }
                }

                destinationPoint.Created = DateTime.Now.ToUniversalTime().ToPSTDateTime();
                destinationPoint.Creator = _userProfileService.GetCurrentUser().Username;

                destinationCatalog.DestinationPoints.Add(destinationPoint);

                _dbContext.SourcePoints.Attach(destinationPoint.ReferencedSourcePoint);
                _dbContext.DestinationPoints.Add(destinationPoint);

                await _dbContext.Entry(destinationPoint.ReferencedSourcePoint).ReloadAsync();

                // Add recent files
                var recentFile = new RecentFile();
                recentFile.User      = _userProfileService.GetCurrentUser().Username;
                recentFile.Date      = DateTime.Now.ToUniversalTime().ToPSTDateTime();
                recentFile.CatalogId = (await _dbContext.SourcePoints.FirstOrDefaultAsync(o => o.Id == destinationPoint.ReferencedSourcePoint.Id)).CatalogId;
                _dbContext.RecentFiles.Add(recentFile);

                foreach (var formatId in destinationPoint.CustomFormats)
                {
                    _dbContext.CustomFormats.Attach(formatId);
                }

                await _dbContext.SaveChangesAsync();

                foreach (var customFormatItem in destinationPoint.CustomFormats)
                {
                    await _dbContext.Entry(customFormatItem).ReloadAsync();
                }

                if (addDestinationCatalog)
                {
                    await _logService.WriteLog(new LogEntity()
                    {
                        LogId      = "40001",
                        Action     = Constant.ACTIONTYPE_ADD,
                        PointType  = Constant.POINTYTPE_DESTINATIONCATALOG,
                        ActionType = ActionTypeEnum.AuditLog,
                        Message    = $"Add destination catalog {destinationCatalog.Name}."
                    });
                }
                await _logService.WriteLog(new LogEntity()
                {
                    LogId      = "20001",
                    Action     = Constant.ACTIONTYPE_ADD,
                    PointType  = Constant.POINTTYPE_DESTINATIONPOINT,
                    ActionType = ActionTypeEnum.AuditLog,
                    Message    = $"Create destination point value: {destinationPoint.ReferencedSourcePoint.Value} in the word file named:{destinationCatalog.FileName} by {_userProfileService.GetCurrentUser().Username}"
                });

                destinationPoint = await _dbContext.DestinationPoints
                                   .Include(o => o.ReferencedSourcePoint)
                                   .Include(o => o.ReferencedSourcePoint.Catalog)
                                   .Include(o => o.CustomFormats).FirstAsync(o => o.Id == destinationPoint.Id);

                destinationPoint.ReferencedSourcePoint.PublishedHistories            = (await _dbContext.PublishedHistories.Where(o => o.SourcePointId == destinationPoint.ReferencedSourcePoint.Id).ToArrayAsync()).OrderByDescending(p => p.PublishedDate).ToArray();
                destinationPoint.ReferencedSourcePoint.SerializeCatalog              = true;
                destinationPoint.ReferencedSourcePoint.Catalog.SerializeSourcePoints = false;
                destinationPoint.CustomFormats = destinationPoint.CustomFormats.OrderBy(c => c.GroupOrderBy).ToArray();

                await _logService.WriteLog(new LogEntity()
                {
                    LogId      = "30002",
                    Action     = Constant.ACTIONTYPE_GET,
                    PointType  = Constant.POINTTYPE_SOURCECATALOGLIST,
                    ActionType = ActionTypeEnum.AuditLog,
                    Message    = $"Get source catalogs."
                });

                return(destinationPoint);
            }
            catch (ApplicationException ex)
            {
                throw ex.InnerException;
            }
            catch (Exception ex)
            {
                var logEntity = new LogEntity()
                {
                    LogId      = "20003",
                    Action     = Constant.ACTIONTYPE_ADD,
                    ActionType = ActionTypeEnum.ErrorLog,
                    PointType  = Constant.POINTTYPE_DESTINATIONPOINT,
                    Message    = ".Net Error",
                    Detail     = ex.ToString()
                };
                logEntity.Subject = $"{logEntity.LogId} - {logEntity.Action} - {logEntity.PointType} - Error";
                await _logService.WriteLog(logEntity);

                throw ex;
            }
        }