public void TestPost() { Response response = _dataLayer.RefreshAll(); IList <IDataObject> dataObjects = _dataLayer.Get("Spools", new DataFilter(), 25, 0); dataObjects = new List <IDataObject>(); IDataObject dataObject = new GenericDataObject() { ObjectType = "Spools" }; dataObject.SetPropertyValue("Spool", "01EKG11PS02001"); dataObject.SetPropertyValue("WorkPackage", "WP1"); dataObject.SetPropertyValue("ConstructionStatus", "Go!"); dataObjects.Add(dataObject); response = _dataLayer.Post(dataObjects); //string orgIdentifier = GetIdentifier(dataObjects[0]); //string orgPropValue = Convert.ToString(dataObjects[0].GetPropertyValue(_modifiedProperty)) ?? String.Empty; //int newPropValue = 101; //// post data object with modified property //dataObjects[0].SetPropertyValue(_modifiedProperty, newPropValue); //Response response = _dataLayer.Post(dataObjects); //Assert.AreEqual(response.Level, StatusLevel.Success); //// verify post result //dataObjects = _dataLayer.Get(_objectType, new List<string> { orgIdentifier }); //Assert.AreEqual(dataObjects[0].GetPropertyValue(_modifiedProperty), newPropValue); //// reset property to its orginal value //dataObjects[0].SetPropertyValue(_modifiedProperty, orgPropValue); //response = _dataLayer.Post(dataObjects); //Assert.AreEqual(response.Level, StatusLevel.Success); }
private IDataObject FormDataObject(string objectType, string csvRow) { try { IDataObject dataObject = new GenericDataObject { ObjectType = objectType, }; XElement commodityElement = new XElement("a"); //GetCommodityConfig(objectType); if (!String.IsNullOrEmpty(csvRow)) { IEnumerable<XElement> attributeElements = commodityElement.Element("attributes").Elements("attribute"); string[] csvValues = csvRow.Split(','); int index = 0; foreach (var attributeElement in attributeElements) { string name = attributeElement.Attribute("name").Value; string dataType = attributeElement.Attribute("dataType").Value.ToLower(); string value = csvValues[index++].Trim(); // if data type is not nullable, make sure it has a value if (!(dataType.EndsWith("?") && value == String.Empty)) { if (dataType.Contains("bool")) { if (value.ToUpper() == "TRUE" || value.ToUpper() == "YES") { value = "1"; } else { value = "0"; } } else if (value == String.Empty && ( dataType.StartsWith("int") || dataType == "double" || dataType == "single" || dataType == "float" || dataType == "decimal")) { value = "0"; } } dataObject.SetPropertyValue(name, value); } } return dataObject; } catch (Exception ex) { _logger.Error("Error in FormDataObject: " + ex); throw new Exception( "Error while forming a dataObject of type [" + objectType + "] from SPPID.", ex ); } }
protected IDataObject CreateEmptyDataObject(string objectType, DataObject objDef) { IDataObject dataObject = new GenericDataObject() { ObjectType = objectType }; foreach (DataProperty prop in objDef.dataProperties) { dataObject.SetPropertyValue(prop.propertyName, null); } return dataObject; }
private IDataObject FormDataObject(Widget widget) { IDataObject dataObject = new GenericDataObject(); try { dataObject.SetPropertyValue("Id", widget.Id); dataObject.SetPropertyValue("Name", widget.Name); dataObject.SetPropertyValue("Description", widget.Description); dataObject.SetPropertyValue("Length", widget.Length); dataObject.SetPropertyValue("Width", widget.Width); dataObject.SetPropertyValue("Height", widget.Height); dataObject.SetPropertyValue("Weight", widget.Weight); dataObject.SetPropertyValue("LengthUOM", widget.LengthUOM); dataObject.SetPropertyValue("WeightUOM", widget.WeightUOM); dataObject.SetPropertyValue("Material", widget.Material); dataObject.SetPropertyValue("Color", widget.Color); } catch (Exception ex) { _logger.ErrorFormat("Error while marshalling a widget into a data object: {1}", ex); throw new Exception("Error while marshalling a widget into a data object.", ex); } return dataObject; }
protected IDataObject ToDataObject(DataRow dataRow, DataObject objectDefinition) { IDataObject dataObject = null; if (dataRow != null) { try { dataObject = new GenericDataObject() { ObjectType = objectDefinition.objectName }; } catch (Exception e) { throw e; } if (dataObject != null && objectDefinition.dataProperties != null) { foreach (DataProperty prop in objectDefinition.dataProperties) { try { string value = string.Empty; if (dataRow.Table.Columns.Contains(prop.propertyName)) { value = Convert.ToString(dataRow[prop.propertyName]); } dataObject.SetPropertyValue(prop.propertyName, value); } catch (Exception e) { throw e; } } } } return dataObject; }
private IDataObject ToDataObject(DataRow dataRow, DataObject objectDefinition) { IDataObject dataObject = null; if (dataRow != null) { try { dataObject = new GenericDataObject() { ObjectType = objectDefinition.objectName }; } catch (Exception ex) { _logger.Error("Error instantiating data object: " + ex); throw ex; } if (dataObject != null && objectDefinition.dataProperties != null) { foreach (DataProperty objectProperty in objectDefinition.dataProperties) { try { if (dataRow.Table.Columns.Contains(objectProperty.columnName)) { object value = dataRow[objectProperty.columnName]; if (value.GetType() == typeof(System.DBNull)) { value = null; } dataObject.SetPropertyValue(objectProperty.propertyName, value); } else { _logger.Warn(String.Format("Value for column [{0}] not found in data row of table [{1}]", objectProperty.columnName, objectDefinition.tableName)); } } catch (Exception ex) { _logger.Error("Error getting data row value: " + ex); throw ex; } } } } else { dataObject = new GenericDataObject() { ObjectType = objectDefinition.objectName }; foreach (DataProperty objectProperty in objectDefinition.dataProperties) { dataObject.SetPropertyValue(objectProperty.propertyName, null); } } return dataObject; }
private IList <IDataObject> LoadDataObjects(string objectType, DataFilter filter) { try { bool addDataObject = true, containFilterProperty = false; IList <IDataObject> dataObjects = new List <IDataObject>(); int index = 0; SpreadsheetTable cfTable = _provider.GetConfigurationTable(objectType); SpreadsheetReference tableReference = cfTable.GetReference(); WorksheetPart worksheetPart = _provider.GetWorksheetPart(tableReference.SheetName); IEnumerable <Row> rows = worksheetPart.Worksheet.Descendants <Row>().Where(r => r.RowIndex > tableReference.StartRow && r.RowIndex <= tableReference.EndRow); foreach (Row row in rows) { index = 0; addDataObject = true; containFilterProperty = false; IDataObject dataObject = new GenericDataObject { ObjectType = objectType, }; foreach (Cell col in row.ChildElements) { index++; string columnIdx = SpreadsheetReference.GetColumnName(col.CellReference); SpreadsheetColumn column = cfTable.Columns.First <SpreadsheetColumn>(c => columnIdx.Equals(c.ColumnIdx)); if (column != null) { if (index == 1) { if (_provider.GetValue(col) == null) { addDataObject = false; break; } } if (filter != null) { foreach (Expression expression in filter.Expressions) { if (expression.PropertyName.ToLower().Equals(column.Name.ToLower())) { containFilterProperty = true; if (_provider.GetValue(col) == null) { addDataObject = false; break; } } } if (filter.Expressions.Count == 0) { addDataObject = true; } } if (addDataObject) { dataObject.SetPropertyValue(column.Name, _provider.GetValue(col)); } } } if (!containFilterProperty && filter != null) { if (filter.Expressions.Count > 0) { addDataObject = false; } } if (addDataObject) { dataObjects.Add(dataObject); } //foreach (var col in cfTable.Columns) //{ // if (!((GenericDataObject)dataObject).Dictionary.ContainsKey(col.Name)) // dataObject.SetPropertyValue(col.Name, null); //} } return(dataObjects); } catch (Exception ex) { _logger.Error("Error in LoadDataObjects: " + ex); throw new Exception("Error while loading data objects of type [" + objectType + "].", ex); } finally { // _provider.Dispose(); } }
private IDataObject FormDataObject(string objectType, string csvRow) { try { IDataObject dataObject = new GenericDataObject { ObjectType = objectType, }; XElement commodityElement = new XElement("a"); //GetCommodityConfig(objectType); if (!String.IsNullOrEmpty(csvRow)) { IEnumerable <XElement> attributeElements = commodityElement.Element("attributes").Elements("attribute"); string[] csvValues = csvRow.Split(','); int index = 0; foreach (var attributeElement in attributeElements) { string name = attributeElement.Attribute("name").Value; string dataType = attributeElement.Attribute("dataType").Value.ToLower(); string value = csvValues[index++].Trim(); // if data type is not nullable, make sure it has a value if (!(dataType.EndsWith("?") && value == String.Empty)) { if (dataType.Contains("bool")) { if (value.ToUpper() == "TRUE" || value.ToUpper() == "YES") { value = "1"; } else { value = "0"; } } else if (value == String.Empty && ( dataType.StartsWith("int") || dataType == "double" || dataType == "single" || dataType == "float" || dataType == "decimal")) { value = "0"; } } dataObject.SetPropertyValue(name, value); } } return(dataObject); } catch (Exception ex) { _logger.Error("Error in FormDataObject: " + ex); throw new Exception( "Error while forming a dataObject of type [" + objectType + "] from SPPID.", ex ); } }
private IDataObject FormDataObject(Widget widget) { IDataObject dataObject = new GenericDataObject(); try { dataObject.SetPropertyValue("Id", widget.Id); dataObject.SetPropertyValue("Name", widget.Name); dataObject.SetPropertyValue("Description", widget.Description); dataObject.SetPropertyValue("Length", widget.Length); dataObject.SetPropertyValue("Width", widget.Width); dataObject.SetPropertyValue("Height", widget.Height); dataObject.SetPropertyValue("Weight", widget.Weight); dataObject.SetPropertyValue("LengthUOM", widget.LengthUOM); dataObject.SetPropertyValue("WeightUOM", widget.WeightUOM); dataObject.SetPropertyValue("Material", widget.Material); dataObject.SetPropertyValue("Color", widget.Color); } catch (Exception ex) { _logger.ErrorFormat("Error while marshalling a widget into a data object: {1}", ex); throw new Exception("Error while marshalling a widget into a data object.", ex); } return(dataObject); }
public void TestPost() { Response response = _dataLayer.RefreshAll(); IList<IDataObject> dataObjects = _dataLayer.Get("Spools", new DataFilter(), 25, 0); dataObjects = new List<IDataObject>(); IDataObject dataObject = new GenericDataObject() { ObjectType = "Spools" }; dataObject.SetPropertyValue("Spool", "01EKG11PS02001"); dataObject.SetPropertyValue("WorkPackage", "WP1"); dataObject.SetPropertyValue("ConstructionStatus", "Go!"); dataObjects.Add(dataObject); response = _dataLayer.Post(dataObjects); //string orgIdentifier = GetIdentifier(dataObjects[0]); //string orgPropValue = Convert.ToString(dataObjects[0].GetPropertyValue(_modifiedProperty)) ?? String.Empty; //int newPropValue = 101; //// post data object with modified property //dataObjects[0].SetPropertyValue(_modifiedProperty, newPropValue); //Response response = _dataLayer.Post(dataObjects); //Assert.AreEqual(response.Level, StatusLevel.Success); //// verify post result //dataObjects = _dataLayer.Get(_objectType, new List<string> { orgIdentifier }); //Assert.AreEqual(dataObjects[0].GetPropertyValue(_modifiedProperty), newPropValue); //// reset property to its orginal value //dataObjects[0].SetPropertyValue(_modifiedProperty, orgPropValue); //response = _dataLayer.Post(dataObjects); //Assert.AreEqual(response.Level, StatusLevel.Success); }