コード例 #1
0
        public static void AppendToStandardTableData(StandardTableDataCM dest, StandardTableDataCM source)
        {
            if (dest == null || dest.Table == null || dest.Table.Count == 0)
            {
                return;
            }

            if (source == null || source.Table == null || source.Table.Count == 0)
            {
                return;
            }

            var columnSet = new HashSet <string>(dest.GetHeaderRow().Row.Select(x => x.Cell.Key));

            for (var i = 1; i < source.Table.Count; ++i)
            {
                var row = new TableRowDTO();

                foreach (var cell in source.Table[i].Row)
                {
                    if (!columnSet.Contains(cell.Cell.Key))
                    {
                        continue;
                    }

                    row.Row.Add(
                        new TableCellDTO()
                    {
                        Cell = cell.Cell.Clone()
                    });
                }

                dest.Table.Add(row);
            }
        }
コード例 #2
0
ファイル: DbRow.cs プロジェクト: delegateas/XrmMockup
        public static DbRow RestoreSerializableDTO(DbTable table, TableRowDTO model)
        {
            var clonedColumns = model.Columns.ToDictionary(x => x.Key, x => Utility.ConvertValueFromSerializableDTO(x.Value));
            var clonedDBRow   = new DbRow(table, model.Id, clonedColumns)
            {
                IsDeleted = model.IsDeleted
            };

            return(clonedDBRow);
        }
コード例 #3
0
        public static StandardTableDataCM StandardTableData_Test1()
        {
            var headerRow = new TableRowDTO()
            {
                Row = new List <TableCellDTO>()
                {
                    new TableCellDTO()
                    {
                        Cell = new KeyValueDTO("1", "Date")
                    },
                    new TableCellDTO()
                    {
                        Cell = new KeyValueDTO("2", "Description")
                    },
                    new TableCellDTO()
                    {
                        Cell = new KeyValueDTO("3", "Phone")
                    },
                    new TableCellDTO()
                    {
                        Cell = new KeyValueDTO("4", "Travelling")
                    }
                }
            };
            var dataRow1 = new TableRowDTO()
            {
                Row = new List <TableCellDTO>()
                {
                    new TableCellDTO()
                    {
                        Cell = new KeyValueDTO("5", "30-Dec-2015")
                    },
                    new TableCellDTO()
                    {
                        Cell = new KeyValueDTO("6", "Trip to Samarkand")
                    },
                    new TableCellDTO()
                    {
                        Cell = new KeyValueDTO("7", "70")
                    },
                    new TableCellDTO()
                    {
                        Cell = new KeyValueDTO("8", "90")
                    }
                }
            };

            return(new StandardTableDataCM
            {
                FirstRowHeaders = true,
                Table = new List <TableRowDTO> {
                    headerRow, dataRow1
                }
            });
        }
コード例 #4
0
        private string[] GetPropertyValuesFromDataRow(TableRowDTO dataRow, HashSet <string> dataProperties)
        {
            var result = dataRow.Row
                         .Select(x => x.Cell)
                         .Where(x => dataProperties == null || dataProperties.Count == 0 || dataProperties.Contains(x.Key))
                         .Select(x => x.Value)
                         .Where(x => !string.IsNullOrWhiteSpace(x))
                         .Select(RemoveStopwords);

            return(result.ToArray());
        }
コード例 #5
0
ファイル: DbRow.cs プロジェクト: delegateas/XrmMockup
        public TableRowDTO ToSerializableDTO()
        {
            var jsonObj = new TableRowDTO
            {
                Id        = this.Id,
                IsDeleted = this.IsDeleted,
                Columns   = this.Columns.ToDictionary(x => x.Key, x => Utility.ConvertValueToSerializableDTO(x.Value))
            };

            return(jsonObj);
        }
コード例 #6
0
        public StandardPayloadDataCM TransformStandardTableDataToStandardPayloadData(string curObjectType, StandardTableDataCM tableDataMS)
        {
            var payloadDataMS = new StandardPayloadDataCM()
            {
                PayloadObjects = new List <PayloadObjectDTO>(),
                ObjectType     = curObjectType,
            };

            int         staringRow;
            TableRowDTO columnHeadersRowDTO = null;

            if (tableDataMS.FirstRowHeaders)
            {
                staringRow          = 1;
                columnHeadersRowDTO = tableDataMS.Table[0];
            }
            else
            {
                staringRow = 0;
            }

            // Rows containing column names
            for (int i = staringRow; i < tableDataMS.Table.Count; ++i) // Since first row is headers; hence i starts from 1
            {
                try
                {
                    var tableRowDTO = tableDataMS.Table[i];
                    var fields      = new List <FieldDTO>();
                    int colNumber   = (tableDataMS.FirstRowHeaders) ? columnHeadersRowDTO.Row.Count : tableRowDTO.Row.Count;
                    for (int j = 0; j < colNumber; ++j)
                    {
                        var tableCellDTO = tableRowDTO.Row[j];
                        var listFieldDTO = new FieldDTO()
                        {
                            Key   = (tableDataMS.FirstRowHeaders) ? columnHeadersRowDTO.Row[j].Cell.Value : tableCellDTO.Cell.Key,
                            Value = tableCellDTO.Cell.Value
                        };
                        fields.Add(listFieldDTO);
                    }
                    payloadDataMS.PayloadObjects.Add(new PayloadObjectDTO()
                    {
                        PayloadObject = fields
                    });
                }
                catch (Exception)
                {
                    //Avoid general failure of the process if there is an error processing individual records in the table
                }
            }

            return(payloadDataMS);
        }
コード例 #7
0
        private void ParseGameResult(TableRowDTO teamResult, GameResult gameResult)
        {
            teamResult.Points += ConvertGameResultToPoints(gameResult);
            switch (gameResult)
            {
            case GameResult.Lost:
                teamResult.Losts++;
                break;

            case GameResult.Draw:
                teamResult.Draws++;
                break;

            case GameResult.Win:
                teamResult.Wins++;
                break;
            }
        }
コード例 #8
0
        protected void ParseAwayTeamResult(GameDTO game)
        {
            var teamResult = tableRows.FirstOrDefault(r => r.TeamName == game.AwayTeam);

            if (teamResult == null)
            {
                teamResult = new TableRowDTO {
                    TeamName = game.AwayTeam, CrestUrl = game.AwayTeamCrestUrl
                };
                tableRows.Add(teamResult);
            }
            teamResult.GoalsLost   += game.HomeTeamGoals.Value;
            teamResult.GoalsScored += game.AwayTeamGoals.Value;
            teamResult.PlayedGames++;
            GameResult gameResult = GetGameResult(game.AwayTeamGoals.Value, game.HomeTeamGoals.Value);

            ParseGameResult(teamResult, gameResult);
        }
コード例 #9
0
        public override Task Run()
        {
            var table = new StandardTableDataCM();

            for (int i = 0; i < int.Parse(ActivityUI.NumberOfRows.Value); i++)
            {
                TableRowDTO row;
                table.Table.Add(row = new TableRowDTO());
                for (int j = 0; j < 5; j++)
                {
                    row.Row.Add(new TableCellDTO
                    {
                        Cell = new KeyValueDTO($"Column {j}", $"Cell [{i}, {j}]")
                    });
                }
            }
            Payload.Add(Crate.FromContent(TableCrateLabel, table));
            return(Task.FromResult(0));
        }
コード例 #10
0
        private Func <object, TableRowDTO> CrateManifestToRowConverter(Type manifestType)
        {
            var accessors = new List <KeyValuePair <string, AutoMapper.IMemberAccessor> >();

            foreach (var member in manifestType.GetMembers(BindingFlags.Instance | BindingFlags.Public).OrderBy(x => x.Name))
            {
                AutoMapper.IMemberAccessor accessor;

                if (member is FieldInfo)
                {
                    accessor = ((FieldInfo)member).ToMemberAccessor();
                }
                else if (member is PropertyInfo && !((PropertyInfo)member).IsSpecialName)
                {
                    accessor = ((PropertyInfo)member).ToMemberAccessor();
                }
                else
                {
                    continue;
                }

                accessors.Add(new KeyValuePair <string, AutoMapper.IMemberAccessor>(member.Name, accessor));
            }

            return(x =>
            {
                var row = new TableRowDTO();

                foreach (var accessor in accessors)
                {
                    row.Row.Add(
                        new TableCellDTO()
                    {
                        Cell = new KeyValueDTO(accessor.Key, string.Format(CultureInfo.InvariantCulture, "{0}", accessor.Value.GetValue(x)))
                    }
                        );
                }

                return row;
            });
        }
コード例 #11
0
        public override Task Run()
        {
            Log($"Table {ActivityPayload.Label} [{ActivityId}] started");

            var tableCm = new StandardTableDataCM();

            for (int i = 0; i < int.Parse(ActivityUI.NumberOfRows.Value); i++)
            {
                TableRowDTO row;
                tableCm.Table.Add(row = new TableRowDTO());

                for (int j = 0; j < 5; j++)
                {
                    row.Row.Add(new TableCellDTO
                    {
                        Cell = new KeyValueDTO("Column " + j, $"Cell [{i}, {j}]")
                    });
                }
            }

            Payload.Add(Crate.FromContent("Table", tableCm));

            return(Task.FromResult(0));
        }
コード例 #12
0
        public static StandardTableDataCM ExtractPayloadCrateDataToStandardTableData(Crate crate)
        {
            if (crate.ManifestType.Id == (int)MT.StandardTableData)
            {
                return(crate.Get <StandardTableDataCM>());
            }
            if (crate.ManifestType.Id == (int)MT.FieldDescription)
            {
                var fields = crate.Get <FieldDescriptionsCM>();
                return(new StandardTableDataCM
                {
                    FirstRowHeaders = true,
                    Table = new List <TableRowDTO>
                    {
                        //Keys of fields will become column headers
                        new TableRowDTO {
                            Row = fields.Fields.Select(x => new TableCellDTO {
                                Cell = new FieldDTO(x.Key, x.Key)
                            }).ToList()
                        },
                        new TableRowDTO {
                            Row = fields.Fields.Select(x => new TableCellDTO {
                                Cell = x
                            }).ToList()
                        }
                    }
                });
            }
            var tableData = new StandardTableDataCM
            {
                FirstRowHeaders = true,
                Table           = new List <TableRowDTO>()
            };
            var headerIsAdded = false;


            var item = CrateStorageSerializer.Default.ConvertToDto(crate);

            var token = JToken.Parse(item.Contents.ToString());

            var jObject = token as JObject;

            if (jObject != null)
            {
                //check if jObject has some JArray properties
                var arrayProperty = jObject.Properties().FirstOrDefault(x => x.Value is JArray);

                //check how StandardPayloadDataCM is structured
                if (arrayProperty != null)
                {
                    foreach (var arrayItem in arrayProperty.Value)
                    {
                        //arrayItem is PayloadObjectDTO which on has an List<FieldDTO>
                        var innerArrayProperty = ((JObject)arrayItem).Properties().FirstOrDefault(x => x.Value is JArray);
                        if (innerArrayProperty != null)
                        {
                            var headerRow = new TableRowDTO();
                            var dataRow   = new TableRowDTO();

                            foreach (var innerArrayItem in innerArrayProperty.Value)
                            {
                                //try to parse the property as FieldDTO
                                if (innerArrayItem is JObject)
                                {
                                    var fieldObj = (JObject)innerArrayItem;
                                    if (fieldObj.Property("key") != null && fieldObj.Property("value") != null)
                                    {
                                        headerRow.Row.Add(new TableCellDTO
                                        {
                                            Cell = new FieldDTO(fieldObj["key"].ToString(), fieldObj["key"].ToString())
                                        });
                                        dataRow.Row.Add(new TableCellDTO
                                        {
                                            Cell =
                                                new FieldDTO(fieldObj["key"].ToString(), fieldObj["value"].ToString())
                                        });
                                    }
                                }
                            }

                            if (!headerIsAdded)
                            {
                                tableData.Table.Add(headerRow);
                                headerIsAdded = true;
                            }
                            tableData.Table.Add(dataRow);
                        }

                        // StandardFileListCM manifest has structure like this.
                        else
                        {
                            var headerRow = new TableRowDTO();
                            var dataRow   = new TableRowDTO();

                            foreach (var property in ((JObject)arrayItem).Properties())
                            {
                                //try to parse the property as FieldDTO
                                if (property.Name != null && property.Value != null)
                                {
                                    headerRow.Row.Add(new TableCellDTO
                                    {
                                        Cell = new FieldDTO(property.Name, property.Name)
                                    });
                                    dataRow.Row.Add(new TableCellDTO
                                    {
                                        Cell =
                                            new FieldDTO(property.Name, property.Value.ToString())
                                    });
                                }
                            }
                            if (!headerIsAdded)
                            {
                                tableData.Table.Add(headerRow);
                                headerIsAdded = true;
                            }
                            tableData.Table.Add(dataRow);
                        }
                    }
                }
                else
                {
                    var headerRow = new TableRowDTO();
                    var dataRow   = new TableRowDTO();

                    foreach (JProperty property in jObject.Properties())
                    {
                        //try to parse the property as FieldDTO
                        if (property.Value is JObject)
                        {
                            var fieldObj = (JObject)property.Value;
                            if (fieldObj.Property("key") != null && fieldObj.Property("value") != null)
                            {
                                headerRow.Row.Add(new TableCellDTO {
                                    Cell = new FieldDTO(fieldObj["key"].ToString(), fieldObj["key"].ToString())
                                });
                                dataRow.Row.Add(new TableCellDTO {
                                    Cell = new FieldDTO(fieldObj["key"].ToString(), fieldObj["value"].ToString())
                                });
                            }
                        }
                        else
                        {
                            headerRow.Row.Add(new TableCellDTO {
                                Cell = new FieldDTO(property.Name, property.Name)
                            });
                            dataRow.Row.Add(new TableCellDTO {
                                Cell = new FieldDTO(property.Name, property.Value.ToString())
                            });
                        }
                    }
                    if (!headerIsAdded)
                    {
                        tableData.Table.Add(headerRow);
                        headerIsAdded = true;
                    }
                    tableData.Table.Add(dataRow);
                }
            }
            return(tableData);
        }
コード例 #13
0
        public override async Task Run()
        {
            using (var uow = _container.GetInstance <IUnitOfWork>())
            {
                var selectedObjectId = Guid.Parse(ActivityUI.AvailableObjects.Value);
                var mtType           = uow.MultiTenantObjectRepository.FindTypeReference(selectedObjectId);
                if (mtType == null)
                {
                    throw new ApplicationException("Invalid object selected.");
                }

                var conditions = JsonConvert.DeserializeObject <List <FilterConditionDTO> >(
                    ActivityUI.QueryBuilder.Value
                    );

                //////////DIRTY DIRTY NASTY HACK////////////
                //cause we can't select upstream value on //
                //these controls yet                      //

                foreach (var condition in conditions)
                {
                    if (condition.Value == "FromPayload")
                    {
                        foreach (var crate in Payload)
                        {
                            // skip system crates
                            if (crate.IsOfType <OperationalStateCM>() || crate.IsOfType <CrateDescriptionCM>() || crate.IsOfType <ValidationResultsCM>())
                            {
                                continue;
                            }

                            //GetValue() method is a copy of UpstreamValueExtractorBase<T>.GetValue
                            var foundValue = GetValue(crate, condition.Field);

                            if (foundValue != null)
                            {
                                condition.Value = Convert.ToString(foundValue);
                            }
                        }
                    }
                }

                ////////////END OF HACK/////////////////////


                var manifestType = mtType.ClrType;
                var queryBuilder = MTSearchHelper.CreateQueryProvider(manifestType);
                var converter    = CrateManifestToRowConverter(manifestType);

                var foundObjects = queryBuilder
                                   .Query(
                    uow,
                    CurrentUserId,
                    conditions
                    )
                                   .ToArray();

                var searchResult = new StandardTableDataCM();

                if (foundObjects.Length > 0)
                {
                    searchResult.FirstRowHeaders = true;

                    var headerRow = new TableRowDTO();

                    var properties = uow.MultiTenantObjectRepository.ListTypePropertyReferences(mtType.Id);
                    foreach (var mtTypeProp in properties)
                    {
                        headerRow.Row.Add(
                            new TableCellDTO()
                        {
                            Cell = new KeyValueDTO(mtTypeProp.Name, mtTypeProp.Name)
                        });
                    }

                    searchResult.Table.Add(headerRow);
                }

                foreach (var foundObject in foundObjects)
                {
                    searchResult.Table.Add(converter(foundObject));
                }

                Payload.Add(
                    Crate.FromContent(
                        RunTimeCrateLabel,
                        searchResult
                        )
                    );
            }

            await Task.Yield();
        }
        public override async Task Run()
        {
            var eventCrate = Payload.CratesOfType <EventReportCM>().FirstOrDefault()
                             ?.Get <EventReportCM>()
                             ?.EventPayload;

            KeyValueListCM changedFiles = null;

            if (eventCrate != null)
            {
                changedFiles = eventCrate
                               .CrateContentsOfType <KeyValueListCM>(x => x.Label == "ChangedFiles")
                               .SingleOrDefault();
            }

            if (changedFiles == null)
            {
                RequestPlanExecutionTermination("File list was not found in the payload.");
            }

            if (ActivityUI.AllSpreadsheetsOption.Selected)
            {
                var rows = new List <TableRowDTO>();
                foreach (var changedFile in changedFiles.Values)
                {
                    var row = new TableRowDTO();
                    row.Row.Add(TableCellDTO.Create(SpreadsheetIdLabel, changedFile.Key));
                    row.Row.Add(TableCellDTO.Create(SpreadsheetNameLabel, changedFile.Value));

                    rows.Add(row);
                }

                var tableData = new StandardTableDataCM(false, rows);

                Payload.Add(Crate.FromContent(RunTimeCrateLabel, tableData));
                Success();
            }
            else
            {
                var hasFileId = changedFiles.Values.Any(x => x.Key == ActivityUI.SpreadsheetList.Value);
                if (!hasFileId)
                {
                    RequestPlanExecutionTermination();
                }
                else
                {
                    var rows        = new List <TableRowDTO>();
                    var changedFile = changedFiles.Values.Where(x => x.Key == ActivityUI.SpreadsheetList.Value).First();

                    var row = new TableRowDTO();
                    row.Row.Add(TableCellDTO.Create(SpreadsheetIdLabel, changedFile.Key));
                    row.Row.Add(TableCellDTO.Create(SpreadsheetNameLabel, changedFile.Value));
                    rows.Add(row);

                    var tableData = new StandardTableDataCM(false, rows);

                    Payload.Add(Crate.FromContent(RunTimeCrateLabel, tableData));
                    Success();
                }
            }
        }
コード例 #15
0
        private static FieldDTO FindField(OperationalStateCM operationalState, Crate crate, string fieldKey)
        {
            object searchArea;
            //let's check if we are in a loop
            //and this is a loop data?
            //check if this crate is loop related
            var loopState = operationalState.CallStack.FirstOrDefault(x =>
            {
                if (x.LocalData?.Type == "Loop")
                {
                    var loopStatus = x.LocalData.ReadAs <OperationalStateCM.LoopStatus>();

                    if (loopStatus != null && loopStatus.CrateManifest.CrateDescriptions[0].Label == crate.Label && loopStatus.CrateManifest.CrateDescriptions[0].ManifestType == crate.ManifestType.Type)
                    {
                        return(true);
                    }
                }

                return(false);
            });

            if (loopState != null) //this is a loop related data request
            {
                searchArea = GetDataListItem(crate, loopState.LocalData.ReadAs <OperationalStateCM.LoopStatus>().Index);
            }
            else
            {
                //hmmm this is a regular data request
                //lets search in complete crate
                searchArea = crate;
                //if we have a StandardTableDataCM and we are not in the loop and crate has Headers - we should search next row
                if (crate.IsOfType <StandardTableDataCM>())
                {
                    var tableCrate = crate.Get <StandardTableDataCM>();
                    if (tableCrate.FirstRowHeaders && tableCrate.Table.Count > 1)
                    {
                        //TODO it is weird to get just first row of table data while searching for a field
                        //note: GetDataListItem function skips header
                        TableRowDTO row = GetDataListItem(crate, 0) as TableRowDTO;
                        if (row != null)
                        {
                            return(row.Row.FirstOrDefault(a => a.Cell.Key == fieldKey)?.Cell);
                        }
                    }
                }
            }

            if (searchArea is Crate)
            {
                if (((Crate)searchArea).IsKnownManifest)
                {
                    searchArea = ((Crate)searchArea).Get();
                }
                else
                {
                    return(null);
                }
            }

            //we should find first related field and return
            var fields     = Fr8ReflectionHelper.FindFieldsRecursive(searchArea);
            var fieldMatch = fields.FirstOrDefault(f => f.Key == fieldKey);

            //let's return first match
            return(fieldMatch);
        }