Example #1
0
        public virtual IList <IDataObject> Create(string objectType, IList <string> identifiers)
        {
            IDataObject         dataObject  = null;
            IList <IDataObject> dataObjects = new List <IDataObject>();

            try
            {
                LoadDataDictionary(objectType);

                if (identifiers == null || identifiers.Count == 0)
                {
                    dataObject = new GenericDataObject
                    {
                        ObjectType = objectType,
                    };

                    SetKeys(dataObject, null);

                    dataObjects.Add(dataObject);
                }
                else
                {
                    dataObjects = Get(objectType, identifiers);

                    foreach (string identifier in identifiers)
                    {
                        var predicate = FormKeyPredicate(identifier);

                        if (predicate != null)
                        {
                            dataObject = dataObjects.AsQueryable().Where(predicate).FirstOrDefault();
                        }

                        if (dataObject == null)
                        {
                            dataObject = new GenericDataObject
                            {
                                ObjectType = objectType,
                            };

                            SetKeys(dataObject, identifier);

                            dataObjects.Add(dataObject);
                        }
                    }
                }

                return(dataObjects);
            }
            catch (Exception ex)
            {
                _logger.Error("Error in Create: " + ex);

                throw new Exception(
                          "Error while creating a list of data objects of type [" + objectType + "].",
                          ex
                          );
            }
        }
        private static IDataObject GetNewObject(IDataObject dataObject, DataObject objectType)
        {
            IDataObject dataObjectNew = new GenericDataObject()
            {
                ObjectType = objectType.objectName
            };
            IDictionary <string, object> dictionary = ((GenericDataObject)dataObjectNew).Dictionary;

            foreach (DataProperty dp in objectType.dataProperties.Where(x => !x.isVirtual))
            {
                dictionary.Add(dp.propertyName, dataObject.GetPropertyValue(dp.propertyName));
            }
            return(dataObjectNew);
        }
Example #3
0
        protected IDataObject ToDataObject(DataRow dataRow, DataObject objectDefinition)
        {
            IDataObject dataObject = null;

            if (dataRow != null)
            {
                try
                {
                    dataObject = new GenericDataObject()
                    {
                        ObjectType = objectDefinition.objectName
                    };
                }
                catch (Exception ex)
                {
                    _logger.Error(string.Format("Error instantiating data object: {0}", ex));
                    throw ex;
                }

                if (dataObject != null && objectDefinition.dataProperties != null)
                {
                    foreach (DataProperty objectProperty in objectDefinition.dataProperties)
                    {
                        try
                        {
                            if (objectProperty.columnName != null)
                            {
                                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(string.Format("Error getting data row value: {0}", ex));
                            throw ex;
                        }
                    }

                    // evaluate has-content expression
                    if (_settings["HasContentExpression"] != null)
                    {
                        string expression = _settings["HasContentExpression"].ToString();

                        foreach (DataProperty prop in objectDefinition.dataProperties)
                        {
                            if (expression.Contains(prop.propertyName))
                            {
                                object value = dataObject.GetPropertyValue(prop.propertyName);

                                if (value != null)
                                {
                                    string valueStr = value.ToString();

                                    if (prop.dataType == DataType.Char || prop.dataType == DataType.String)
                                    {
                                        valueStr = "\"" + valueStr + "\"";
                                    }

                                    expression = expression.Replace(prop.propertyName, valueStr);
                                }
                            }
                        }

                        if ((bool)Utility.Evaluate(expression))
                        {
                            ((GenericDataObject)dataObject).HasContent = true;
                        }
                    }
                }
            }
            else
            {
                dataObject = new GenericDataObject()
                {
                    ObjectType = objectDefinition.objectName
                };

                foreach (DataProperty objectProperty in objectDefinition.dataProperties)
                {
                    dataObject.SetPropertyValue(objectProperty.propertyName, null);
                }
            }

            return(dataObject);
        }
        public static IDataObject ToDataObject(DataObject objectType, DataRow row)
        {
            GenericDataObject dataObject = null;

            if (row != null)
            {
                try
                {
                    dataObject = new GenericDataObject()
                    {
                        ObjectType = objectType.objectName
                    };
                }
                catch (Exception ex)
                {
                    _logger.Error(string.Format("Error instantiating data object: {0}", ex));
                    throw ex;
                }

                if (dataObject != null && objectType.dataProperties != null)
                {
                    foreach (DataProperty objectProperty in objectType.dataProperties)
                    {
                        try
                        {
                            if (objectProperty.propertyName != null)
                            {
                                if (row.Table.Columns.Contains(objectProperty.propertyName))
                                {
                                    object value = row[objectProperty.propertyName];

                                    if (value.GetType() == typeof(System.DBNull))
                                    {
                                        value = null;
                                    }

                                    if (objectProperty.dataType.ToString().ToUpper() == "DECIMAL" ||
                                        objectProperty.dataType.ToString().ToUpper() == "DOUBLE")
                                    {
                                        dataObject.SetPropertyNumericValue(objectProperty.propertyName, value);
                                    }
                                    else
                                    {
                                        dataObject.SetPropertyValue(objectProperty.propertyName, value);
                                    }
                                }
                                else
                                {
                                    _logger.Warn(String.Format("Value for column [{0}] not found in data row of table [{1}]",
                                                               objectProperty.columnName, objectType.tableName));
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            _logger.Error(string.Format("Error getting data row value: {0}", ex));
                            throw ex;
                        }
                    }
                }

                //Extension Properties____Starts
                if (dataObject != null && objectType.extensionProperties != null)
                {
                    foreach (ExtensionProperty extentionProperty in objectType.extensionProperties)
                    {
                        try
                        {
                            if (extentionProperty.propertyName != null)
                            {
                                if (row.Table.Columns.Contains(extentionProperty.propertyName))
                                {
                                    object value = row[extentionProperty.propertyName];

                                    if (value.GetType() == typeof(System.DBNull))
                                    {
                                        value = null;
                                    }

                                    dataObject.SetPropertyValue(extentionProperty.propertyName, value);
                                }
                                else
                                {
                                    _logger.Warn(String.Format("Value for column [{0}] not found in data row of table [{1}]",
                                                               extentionProperty.columnName, objectType.tableName));
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            _logger.Error(string.Format("Error getting data row value: {0}", ex));
                            throw ex;
                        }
                    }
                }
                //Extension Properties____Ends
            }
            else
            {
                dataObject = new GenericDataObject()
                {
                    ObjectType = objectType.objectName
                };

                foreach (DataProperty objectProperty in objectType.dataProperties)
                {
                    dataObject.SetPropertyValue(objectProperty.propertyName, null);
                }
            }

            if (row[HAS_CONTENT] != DBNull.Value && Convert.ToBoolean(row[HAS_CONTENT]))
            {
                dataObject.HasContent = true;
            }

            return(dataObject);
        }