示例#1
0
 private void SetDestinations(
     Context context,
     SiteSettings ss,
     IExportModel exportModel,
     List <DataRow> dataRows)
 {
     ss.Destinations?.Values.ForEach(currentSs =>
     {
         currentSs.JoinStacks.ForEach(joinStack =>
         {
             var tableAlias = joinStack.TableName();
             var idColumn   = tableAlias + "," + Rds.IdColumn(currentSs.ReferenceType);
             dataRows
             .GroupBy(o => o.Long(idColumn))
             .Where(o => o.Key > 0)
             .Select(o => o.ToList())
             .ForEach(groupedDataRows =>
             {
                 exportModel.AddDestination(
                     exportModel: JsonStacks(
                         context: context,
                         ss: currentSs,
                         idColumn: idColumn,
                         dataRows: groupedDataRows,
                         tableAlias: tableAlias),
                     columnName: joinStack.ColumnName);
             });
         });
     });
 }
示例#2
0
 private void SetSources(
     Context context,
     SiteSettings ss,
     IExportModel exportModel,
     List <DataRow> dataRows)
 {
     ss.Sources?.Values.ForEach(currentSs =>
     {
         var tableAlias = currentSs.JoinStacks.FirstOrDefault()?.TableName();
         if (tableAlias != null)
         {
             var idColumn = tableAlias + "," + Rds.IdColumn(currentSs.ReferenceType);
             dataRows
             .GroupBy(o => o.Long(idColumn))
             .Where(o => o.Key > 0)
             .Select(o => o.ToList())
             .ForEach(groupedDataRows =>
                      exportModel.AddSource(
                          exportModel: JsonStacks(
                              context: context,
                              ss: currentSs,
                              idColumn: idColumn,
                              dataRows: groupedDataRows,
                              tableAlias: tableAlias)));
         }
     });
 }
 public void AddSource(IExportModel exportModel)
 {
     if (Sources == null)
     {
         Sources = new List <IExportModel>();
     }
     Sources.Add(exportModel);
 }
        public void AddDestination(IExportModel exportModel, string columnName)
        {
            switch (columnName)
            {
            case "ClassA": ClassA = exportModel; break;

            case "ClassB": ClassB = exportModel; break;

            case "ClassC": ClassC = exportModel; break;

            case "ClassD": ClassD = exportModel; break;

            case "ClassE": ClassE = exportModel; break;

            case "ClassF": ClassF = exportModel; break;

            case "ClassG": ClassG = exportModel; break;

            case "ClassH": ClassH = exportModel; break;

            case "ClassI": ClassI = exportModel; break;

            case "ClassJ": ClassJ = exportModel; break;

            case "ClassK": ClassK = exportModel; break;

            case "ClassL": ClassL = exportModel; break;

            case "ClassM": ClassM = exportModel; break;

            case "ClassN": ClassN = exportModel; break;

            case "ClassO": ClassO = exportModel; break;

            case "ClassP": ClassP = exportModel; break;

            case "ClassQ": ClassQ = exportModel; break;

            case "ClassR": ClassR = exportModel; break;

            case "ClassS": ClassS = exportModel; break;

            case "ClassT": ClassT = exportModel; break;

            case "ClassU": ClassU = exportModel; break;

            case "ClassV": ClassV = exportModel; break;

            case "ClassW": ClassW = exportModel; break;

            case "ClassX": ClassX = exportModel; break;

            case "ClassY": ClassY = exportModel; break;

            case "ClassZ": ClassZ = exportModel; break;
            }
        }
示例#5
0
        public async Task ExportAsync_WhenCalled_ReturnsResultFromDoExportAsyncOnModelExporter()
        {
            IExportModel exportModel = new Mock <IExportModel>().Object;
            IModelExporter <IExportModel, object> sut = CreateSut(exportModel);

            IExportModel result = await sut.ExportAsync(new object());

            Assert.AreEqual(exportModel, result);
        }
示例#6
0
        private IModelExporter <IExportModel, object> CreateSut(IExportModel exportModel = null, IExportModel emptyExportModel = null, Exception exception = null)
        {
            _exceptionHandlerMock.Setup(m => m.HandleAsync(It.IsAny <AggregateException>()))
            .Returns(Task.CompletedTask);
            _exceptionHandlerMock.Setup(m => m.HandleAsync(It.IsAny <Exception>()))
            .Returns(Task.CompletedTask);

            return(new MyModelExporter(_exceptionHandlerMock.Object, exportModel ?? new Mock <IExportModel>().Object, emptyExportModel ?? new Mock <IExportModel>().Object, exception));
        }
示例#7
0
        public async Task ExportAsync_WhenExceptionWasThrown_ReturnsResultFromEmptyOnModelExporter()
        {
            IExportModel emptyExportModel             = new Mock <IExportModel>().Object;
            Exception    exception                    = new Exception();
            IModelExporter <IExportModel, object> sut = CreateSut(emptyExportModel: emptyExportModel, exception: exception);

            IExportModel result = await sut.ExportAsync(new object());

            Assert.AreEqual(emptyExportModel, result);
        }
 public void AddDestination(IExportModel exportModel, string columnName)
 {
     switch (Def.ExtendedColumnTypes.Get(columnName))
     {
     case "Class":
         Class(
             columnName: columnName,
             value: exportModel);
         break;
     }
 }
示例#9
0
        private IExportModel JsonStacks(
            Context context,
            SiteSettings ss,
            string idColumn,
            List <DataRow> dataRows,
            string tableAlias = null)
        {
            IExportModel exportModel = null;

            switch (ss.ReferenceType)
            {
            case "Issues":
                exportModel = new IssueExportModel(
                    context: context,
                    ss: ss,
                    dataRow: dataRows.First(),
                    tableAlias: tableAlias);
                break;

            case "Results":
                exportModel = new ResultExportModel(
                    context: context,
                    ss: ss,
                    dataRow: dataRows.First(),
                    tableAlias: tableAlias);
                break;
            }
            SetDestinations(
                context: context,
                ss: ss,
                exportModel: exportModel,
                dataRows: dataRows);
            SetSources(
                context: context,
                ss: ss,
                exportModel: exportModel,
                dataRows: dataRows);
            return(exportModel);
        }
示例#10
0
        private static void ImportResults(Context context, Dictionary <long, long> idHash, IExportModel exportModel)
        {
            var model       = exportModel as ResultExportModel;
            var siteId      = idHash.Get(model.SiteId.ToLong());
            var referenceId = idHash.Get(model.ResultId.ToLong());
            var param       = Rds.ResultsParam()
                              .SiteId(siteId)
                              .ResultId(referenceId)
                              .Title(model.Title?.ToString(), _using: model.Title != null)
                              .Body(model.Body, _using: model.Body != null)
                              .Status(model.Status?.Value, _using: model.Status != null)
                              .Manager(model.Manager?.Id, _using: model.Manager != null)
                              .Owner(model.Owner?.Id, _using: model.Owner != null)
                              .Comments(model.Comments?.ToJson(), _using: model.Comments?.Any() == true);

            model.ClassHash?.ForEach(o =>
                                     param.Add(
                                         columnBracket: o.Key,
                                         name: o.Key,
                                         value: o.Value.ToString().MaxLength(1024)));
            model.NumHash?.ForEach(o =>
                                   param.Add(
                                       columnBracket: o.Key,
                                       name: o.Key,
                                       value: o.Value));
            model.DateHash?.ForEach(o =>
                                    param.Add(
                                        columnBracket: o.Key,
                                        name: o.Key,
                                        value: o.Value));
            model.DescriptionHash?.ForEach(o =>
                                           param.Add(
                                               columnBracket: o.Key,
                                               name: o.Key,
                                               value: o.Value));
            model.CheckHash?.ForEach(o =>
                                     param.Add(
                                         columnBracket: o.Key,
                                         name: o.Key,
                                         value: o.Value));
            Rds.ExecuteScalar_response(
                context: context,
                selectIdentity: false,
                statements: Rds.InsertResults(param: param));
            var ss = new SiteModel(
                context: context,
                siteId: siteId)
                     .ResultsSiteSettings(
                context: context,
                referenceId: referenceId);
            var resultModel = new ResultModel(
                context: context,
                ss: ss,
                resultId: referenceId);

            resultModel.UpdateRelatedRecords(
                context: context,
                ss: ss,
                extendedSqls: false,
                updateItems: true);
        }
示例#11
0
        private static void ImportIssues(Context context, IDictionary <long, long> idHash, IExportModel exportModel)
        {
            var model       = exportModel as IssueExportModel;
            var siteId      = idHash.Get(model.SiteId.ToLong());
            var referenceId = idHash.Get(model.IssueId.ToLong());
            var param       = Rds.IssuesParam()
                              .SiteId(siteId)
                              .IssueId(referenceId)
                              .Title(model.Title?.ToString() ?? string.Empty)
                              .Body(model.Body, _using: model.Body != null)
                              .StartTime(model.StartTime, _using: model.StartTime != null)
                              .CompletionTime(value: model.CompletionTime?.Value, _using: model.CompletionTime != null)
                              .WorkValue(value: model.WorkValue?.Value, _using: model.WorkValue != null)
                              .ProgressRate(value: model.ProgressRate?.Value, _using: model.ProgressRate != null)
                              .Status(model.Status?.Value, _using: model.Status != null)
                              .Manager(model.Manager?.Id, _using: model.Manager != null)
                              .Owner(model.Owner?.Id, _using: model.Owner != null)
                              .Comments(model.Comments?.ToJson(), _using: model.Comments?.Any() == true);

            model.ClassHash?.ForEach(o =>
                                     param.Add(
                                         columnBracket: $"\"{o.Key}\"",
                                         name: o.Key,
                                         value: o.Value.ToString().MaxLength(1024)));
            model.NumHash?.ForEach(o =>
                                   param.Add(
                                       columnBracket: $"\"{o.Key}\"",
                                       name: o.Key,
                                       value: o.Value));
            model.DateHash?.ForEach(o =>
                                    param.Add(
                                        columnBracket: $"\"{o.Key}\"",
                                        name: o.Key,
                                        value: o.Value));
            model.DescriptionHash?.ForEach(o =>
                                           param.Add(
                                               columnBracket: $"\"{o.Key}\"",
                                               name: o.Key,
                                               value: o.Value));
            model.CheckHash?.ForEach(o =>
                                     param.Add(
                                         columnBracket: $"\"{o.Key}\"",
                                         name: o.Key,
                                         value: o.Value));
            Repository.ExecuteScalar_response(
                context: context,
                selectIdentity: false,
                statements: Rds.InsertIssues(param: param));
            var ss = new SiteModel(
                context: context,
                siteId: siteId)
                     .IssuesSiteSettings(
                context: context,
                referenceId: referenceId);
            var issueModel = new IssueModel(
                context: context,
                ss: ss,
                issueId: referenceId);

            issueModel.UpdateRelatedRecords(
                context: context,
                ss: ss,
                extendedSqls: false,
                updateItems: true);
        }