Пример #1
0
            public void ShouldDeserializeToType()
            {
                var values = new List <List <object> >
                {
                    new List <object> {
                        "header1", "header2", "header3", "header4"
                    },
                    new List <object> {
                        "r1v1", "r1v2", "r1v3", 1
                    },
                    new List <object> {
                        "r2v1", "r2v2", "r2v3", 2
                    },
                    new List <object> {
                        "r3v1", "r3v2", "r3v3", 3
                    },
                };

                var result = ExcelMatrix.Deserialize <MockData>(values);

                Assert.Equal("r1v1", result[0].Header1);
                Assert.Equal("r1v2", result[0].Header2);
                Assert.Equal("r1v3", result[0].Header3);
                Assert.Equal(1, result[0].Header4);

                Assert.Equal("r2v1", result[1].Header1);
                Assert.Equal("r2v2", result[1].Header2);
                Assert.Equal("r2v3", result[1].Header3);
                Assert.Equal(2, result[1].Header4);

                Assert.Equal("r3v1", result[2].Header1);
                Assert.Equal("r3v2", result[2].Header2);
                Assert.Equal("r3v3", result[2].Header3);
                Assert.Equal(3, result[2].Header4);
            }
Пример #2
0
        public IEnumerable <CrmOperation> generateCrmOperationRequest(ExcelMatrix dataMatrix)
        {
            int  optionValue;
            bool changeOrder = false;
            int  indexorder  = 0;

            int[] valuesOrder                 = new int[dataMatrix.numberofElements];
            List <CrmOperation> crmOp         = new List <CrmOperation>();
            IEnumerable <int>   currentValues = getDataMatrixValues(dataMatrix);

            for (int i = 0; i < dataMatrix.numberofElements; i++)
            {
                if (int.TryParse(dataMatrix.getElement(i, ExcelColumsDefinition.OPTIONSETVALUEEXCELCOL), out optionValue))
                {
                    int nOptionExcel = currentValues.Where(x => x == optionValue).Count();
                    if (nOptionExcel > 1)
                    {
                        crmOp.Add(new CrmOperation(CrmOperation.CrmOperationType.error, CrmOperation.CrmOperationTarget.none, null, string.Format("Error , duplicate OptionSet Value:{0}", optionValue)));
                    }
                    else if (nOptionExcel == 1)
                    {
                        IEnumerable <OptionMetadata> option = optionMetadata.optionData.Options.Where(x => x.Value.Value == optionValue);
                        if (option.Count() == 0)
                        {
                            addOptionCreateRequest(dataMatrix.getRow(i), crmOp);
                        }
                        else
                        {
                            addOptionUpdateRequest(dataMatrix.getRow(i), crmOp, option.First());
                        }

                        if (optionMetadata.optionData.Options.Count <= i || optionValue != optionMetadata.optionData.Options[i].Value)
                        {
                            changeOrder = true;
                        }
                        valuesOrder[indexorder++] = optionValue;
                    }
                }
                else
                {
                    crmOp.Add(new CrmOperation(CrmOperation.CrmOperationType.error, CrmOperation.CrmOperationTarget.none, null, string.Format("Error converting {0} to int", dataMatrix.getElement(i, ExcelColumsDefinition.OPTIONSETVALUEEXCELCOL))));
                }
            }
            checkOptionToRemove(currentValues, crmOp);
            if (changeOrder)
            {
                addOptionOrderRequestRequest(crmOp, valuesOrder);
            }
            //check revoved option
            return(crmOp);
        }
        public static void getFechAndLayouXml(ExcelMatrix dataMatrix, ViewExcelSheetsInfo sheetView, out string fetchXml, out string viewXml)
        {
            List <ViewFeo> viewFeoList = new List <ViewFeo>();

            for (int i = 0; i < dataMatrix.numberofElements; i++)
            {
                string[] row           = dataMatrix.getRow(i);
                string[] values        = getEntityRelation(row[ExcelColumsDefinition.VIEWATTRIBUTEENTITY]);
                string   attributeName = row[ExcelColumsDefinition.VIEWATTRIBUTENAME];
                if (attributeName.LastIndexOf("-") >= 0)
                {
                    attributeName = attributeName.Substring(attributeName.LastIndexOf("-") + 1, attributeName.Length - attributeName.LastIndexOf("-") - 1);
                    attributeName = attributeName.Trim();
                }
                string attributeEntity            = string.Empty;
                string attributeRelationAttribute = string.Empty;
                if (values != null && values.Count() == 2)
                {
                    attributeEntity            = values[0];
                    attributeRelationAttribute = values[1];
                }
                string            attributewidth = row[ExcelColumsDefinition.VIEWATTRIBUTEWIDTH];
                ViewsRelationsObj obj            = null;
                if (!string.IsNullOrEmpty(attributeEntity))
                {
                    obj = sheetView.relationsList.Where(x => x.relationAlias != null && x.entity.Equals(attributeEntity, StringComparison.InvariantCultureIgnoreCase) &&
                                                        x.relationTo.Equals(attributeRelationAttribute, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
                }
                else
                {
                    obj             = sheetView.relationsList.Where(x => x.relationAlias == null).FirstOrDefault();
                    attributeEntity = obj.entity;
                }

                ViewFeo viewFeo = new ViewFeo()
                {
                    AttributeName   = attributeName,
                    AttributeEntity = attributeEntity,
                    AttributeWidth  = attributewidth,
                    AttributeObj    = obj,
                };
                if (obj == null)
                {
                    setAttributesObj(viewFeo, sheetView.relationsList);
                }
                viewFeoList.Add(viewFeo);
            }
            viewXml = getViewXmlString(viewFeoList, sheetView.viewObj);
            removeUnnecessaryLinksAttributes(sheetView.viewObj, sheetView);
            fetchXml = getFecthXmlString(viewFeoList, sheetView.fetchObj);
        }
Пример #4
0
        public IEnumerable <int> getDataMatrixValues(ExcelMatrix dataMatrix)
        {
            int        optionValue;
            List <int> listValues = new List <int>();

            for (int i = 0; i < dataMatrix.numberofElements; i++)
            {
                if (int.TryParse(dataMatrix.getElement(i, ExcelColumsDefinition.OPTIONSETVALUEEXCELCOL), out optionValue))
                {
                    listValues.Add(optionValue);
                }
            }
            return(listValues);
        }
        public IEnumerable <CrmOperation> generateCrmOperationRequest(ExcelMatrix dataMatrix)
        {
            List <CrmOperation> crmOp = new List <CrmOperation>();

            for (int i = 0; i < dataMatrix.numberofElements; i++)
            {
                IEnumerable <EntityMetadata> attribute = entitySheet.entitiesMetadata.Where(x => x.SchemaName == dataMatrix.getElement(i, ExcelColumsDefinition.ENTITYSCHEMANAMEEXCELCOL));
                if (attribute.Count() == 0)
                {
                    addCreateRequest(dataMatrix.getRow(i), crmOp);
                }
                else if (attribute.Count() == 1)
                {
                    //update Entity
                }
            }
            return(crmOp);
        }
        public IEnumerable <CrmOperation> generateCrmOperationRequest(ExcelMatrix dataMatrix)
        {
            List <CrmOperation> crmOp = new List <CrmOperation>();

            for (int i = 0; i < dataMatrix.numberofElements; i++)
            {
                IEnumerable <AttributeMetadata> attribute = filteredMetadata.Where(x => x.SchemaName == dataMatrix.getElement(i, ExcelColumsDefinition.SCHEMANAMEEXCELCOL));
                if (attribute.Count() == 0)
                {
                    currentOperationCreate = true;
                    addCreateRequest(dataMatrix.getRow(i), crmOp);
                }
                else if (attribute.Count() == 1)
                {
                    currentOperationCreate = false;
                    addUpdateRequest(dataMatrix.getRow(i), crmOp, attribute.First());
                }
            }
            return(crmOp);
        }
Пример #7
0
            public void ShouldHandleStringsAndNumericTypes()
            {
                var values = new List <List <object> >
                {
                    new List <object> {
                        "header1", "header2", "header3", "header4"
                    },
                    new List <object> {
                        "r1v1", "r1v2", "r1v3", 1
                    },
                    new List <object> {
                        "r2v1", "r2v2", "r2v3", 2
                    },
                    new List <object> {
                        "r3v1", "r3v2", "r3v3", 3
                    },
                };

                var result = ExcelMatrix.ToJson(values);

                Assert.Equal(
                    "[{\"header1\":\"r1v1\",\"header2\":\"r1v2\",\"header3\":\"r1v3\",\"header4\":1},{\"header1\":\"r2v1\",\"header2\":\"r2v2\",\"header3\":\"r2v3\",\"header4\":2},{\"header1\":\"r3v1\",\"header2\":\"r3v2\",\"header3\":\"r3v3\",\"header4\":3}]",
                    result);
            }
        public static IEnumerable <CrmOperation> generateCrmOperationRequest(ExcelMatrix dataMatrix, ViewExcelSheetsInfo sheetView)
        {
            List <CrmOperation> crmOp = new List <CrmOperation>();

            try
            {
                string fetchXml;
                string viewXml;
                getFechAndLayouXml(dataMatrix, sheetView, out fetchXml, out viewXml);
                if (sheetView.isNew)
                {
                    crmOp.Add(generateUpdateRequest(viewXml, fetchXml, sheetView.name, sheetView.description, sheetView.entity));
                }
                else
                {
                    crmOp.Add(generateUpdateRequest(viewXml, fetchXml, sheetView.viewId));
                }
            }
            catch (Exception ex)
            {
                crmOp.Add(new CrmOperation(CrmOperation.CrmOperationType.error, CrmOperation.CrmOperationTarget.none, null, "Generic error"));
            }
            return(crmOp);
        }
Пример #9
0
 public void ShouldHandleNullInput()
 {
     Assert.Throws <ArgumentException>(() => ExcelMatrix.Deserialize <MockData>(null));
 }
Пример #10
0
 public void ShouldHandleNullInput()
 {
     Assert.Throws <ArgumentException>(() => ExcelMatrix.ToJson(null));
 }