Exemplo n.º 1
0
        public static T BinaryClone <T>(T source)
        {
            try
            {
                if (ReferenceEquals(source, null))
                {
                    return(default(T));
                }

                var type = AnTypes.GetType(source, null);

                if ((type == null) || !type.IsSerializable)
                {
                    throw new ArgumentException(ExceptionError, nameof(source));
                }

                IFormatter formatter = new BinaryFormatter();

                Stream stream = new MemoryStream();

                using (stream)
                {
                    formatter.Serialize(stream, source);
                    stream.Seek(0, SeekOrigin.Begin);
                    return((T)formatter.Deserialize(stream));
                }
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
                throw;
            }
        }
Exemplo n.º 2
0
        protected override List <AnDatabaseCommandData> GenerateDatabaseCommandDataList(bool includeIdColumn)
        {
            List <AnDatabaseCommandData> result = null;

            try
            {
                result = new List <AnDatabaseCommandData>();

                if (includeIdColumn)
                {
                    AnDatabaseCommandData.Add(result, nameof(Id), Id, AnTypes.DataType.Int, AnSerialization.IntSize);
                }

                AnDatabaseCommandData.Add(result, nameof(CustomerId), CustomerId, AnTypes.DataType.VarChar, CustomerIdSize);
                AnDatabaseCommandData.Add(result, nameof(SourceSystemCompanyId), SourceSystemCompanyId, AnTypes.DataType.VarChar, SourceSystemCompanyIdSize);
                AnDatabaseCommandData.Add(result, nameof(UniversalNodeId), UniversalNodeId, AnTypes.DataType.VarChar, UniversalNodeIdSize);
                AnDatabaseCommandData.Add(result, nameof(DataSourceType), DataSourceType, AnTypes.DataType.VarChar, DataSourceTypeSize);
                AnDatabaseCommandData.Add(result, nameof(Organization), Organization, AnTypes.DataType.VarChar, OrganizationSize);
                AnDatabaseCommandData.Add(result, nameof(TableName), TableName, AnTypes.DataType.VarChar, TableNameSize);
                AnDatabaseCommandData.Add(result, nameof(Action), Action, AnTypes.DataType.VarChar, ActionSize);
                AnDatabaseCommandData.Add(result, nameof(ErrorMessage), ErrorMessage, AnTypes.DataType.VarChar, ErrorMessageSize);
                AnDatabaseCommandData.Add(result, nameof(RecordData), RecordData, AnTypes.DataType.VarChar, RecordDataSize);
                AnDatabaseCommandData.Add(result, nameof(EnteredDateTime), EnteredDateTime, AnTypes.DataType.DateTime, AnSerialization.DateTimeSize);
                AnDatabaseCommandData.Add(result, nameof(ProcessedDateTime), ProcessedDateTime, AnTypes.DataType.DateTime, AnSerialization.DateTimeSize);
                AnDatabaseCommandData.Add(result, nameof(Result), Result, AnTypes.DataType.Boolean, AnSerialization.BooleanSize);
                AnDatabaseCommandData.Add(result, nameof(Processed), Processed, AnTypes.DataType.Boolean, AnSerialization.BooleanSize);
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
            }

            return(result ?? new AnList <AnDatabaseCommandData>());
        }
Exemplo n.º 3
0
        public string GetMarkAsProcessedCommand(AnDatabaseTypes.DriverType driverType)
        {
            var result = "";

            try
            {
                if (ProcessedDateTime <= AnTypes.MinDateTimeValue)
                {
                    ProcessedDateTime = DateTime.UtcNow;
                }

                result = AnDatabaseTypes.GenerateUpdateStatement(DbTableName, GeneratePrimaryKeyWhereClause(driverType),
                                                                 new List <AnDatabaseCommandData>
                {
                    new AnDatabaseCommandData(nameof(ProcessedDateTime), ProcessedDateTime, AnTypes.DataType.DateTime, AnSerialization.DateTimeSize),
                    new AnDatabaseCommandData(nameof(ErrorMessage), ErrorMessage, AnTypes.DataType.VarChar, ErrorMessageSize),
                    new AnDatabaseCommandData(nameof(Result), Result, AnTypes.DataType.Boolean, AnSerialization.BooleanSize),
                    new AnDatabaseCommandData(nameof(Processed), true, AnTypes.DataType.Boolean, AnSerialization.BooleanSize)
                },
                                                                 new List <AnDatabaseCommandData>(), driverType, false);
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
            }

            return(result);
        }
Exemplo n.º 4
0
        private void Clear()
        {
            try
            {
                Id                    = 0;
                CustomerId            = "";
                SourceSystemCompanyId = "";
                UniversalNodeId       = "";
                DataSourceType        = "";
                Organization          = "";
                TableName             = "";
                Action                = "";
                ErrorMessage          = "";
                RecordData            = "";
                EnteredDateTime       = AnTypes.MinDateTimeValue;
                ProcessedDateTime     = AnTypes.MinDateTimeValue;
                Result                = false;
                Processed             = false;

                RecordFound = false;
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
            }
        }
Exemplo n.º 5
0
        protected override List <string> GenerateColumnNames(bool includeIdColumn)
        {
            var result = new List <string>();

            try
            {
                if (includeIdColumn)
                {
                    result.Add(nameof(Id));
                }

                result.Add(nameof(CustomerId));
                result.Add(nameof(SourceSystemCompanyId));
                result.Add(nameof(UniversalNodeId));
                result.Add(nameof(DataSourceType));
                result.Add(nameof(Organization));
                result.Add(nameof(TableName));
                result.Add(nameof(Action));
                result.Add(nameof(ErrorMessage));
                result.Add(nameof(RecordData));
                result.Add(nameof(EnteredDateTime));
                result.Add(nameof(ProcessedDateTime));
                result.Add(nameof(Result));
                result.Add(nameof(Processed));
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
            }

            return(result);
        }
Exemplo n.º 6
0
        public string GenerateExistsQuery(AnDatabaseTypes.DriverType driverType)
        {
            var result = "";

            try
            {
                var keyColumnName = GetKeyColumnName();

                if (!string.IsNullOrEmpty(keyColumnName))
                {
                    var whereClause = GeneratePrimaryKeyWhereClause(driverType);

                    if (!string.IsNullOrEmpty(whereClause))
                    {
                        result = AnDatabaseTypes.GenerateSelectQuery(driverType, GetDbTableName(), AnDatabaseTypes.FormatDatabaseColumnName(keyColumnName, GetDbTableName(), AnDatabaseTypes.ExecutionType.Query, driverType), whereClause);
                    }
                }
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
            }

            return(result);
        }
Exemplo n.º 7
0
        public static bool ValidateQueryResults(DataSet dataSet, out DataTable dataTable)
        {
            var result = false;

            dataTable = null;

            try
            {
                if ((dataSet?.Tables.Count > 0) &&
                    (dataSet.Tables[0]?.Columns.Count > 0) &&
                    (dataSet.Tables[0]?.Rows.Count > 0))
                {
                    dataTable = dataSet.Tables[0];

                    result = true;
                }
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
            }

            return(result);
        }
Exemplo n.º 8
0
        public static T FromXml <T>(string xmlString, Type type, Type[] types)
        {
            try
            {
                if (!string.IsNullOrEmpty(xmlString) &&
                    (type != null))
                {
                    if (!type.IsSerializable)
                    {
                        throw new ArgumentException(ExceptionError, nameof(type));
                    }

                    var xmlSerializer = new XmlSerializer(type, types);

                    using (var stream = new MemoryStream())
                    {
                        var writer = new StreamWriter(stream);
                        writer.Write(xmlString);
                        writer.Flush();
                        stream.Seek(0, SeekOrigin.Begin);

                        return((T)xmlSerializer.Deserialize(stream));
                    }
                }
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
                throw;
            }

            return(default(T));
        }
Exemplo n.º 9
0
        public static string GenerateSelectQuery(string customerId, string universalNodeId, string dataSourceType, DateTime beginDateTime, DateTime endDateTime, bool processed, AnDatabaseTypes.DriverType driverType)
        {
            var result = "";

            try
            {
                var whereClause = new StringBuilder();

                whereClause.Append($"{nameof(RawDataRecord.Processed)} = {AnDatabaseTypes.FormatBooleanValue(processed, driverType)}");

                if (!string.IsNullOrEmpty(customerId))
                {
                    whereClause.Append(" AND ");
                    whereClause.Append($"{nameof(RawDataRecord.CustomerId)} = '{AnDatabaseTypes.FormatSingleQuote(AnDatabaseTypes.ValidStringLength(customerId, RawDataRecord.CustomerIdSize))}'");
                }

                if (!string.IsNullOrEmpty(universalNodeId))
                {
                    whereClause.Append(" AND ");
                    whereClause.Append($"{nameof(RawDataRecord.UniversalNodeId)} = '{AnDatabaseTypes.FormatSingleQuote(AnDatabaseTypes.ValidStringLength(universalNodeId, RawDataRecord.UniversalNodeIdSize))}'");
                }

                if (!string.IsNullOrEmpty(dataSourceType))
                {
                    whereClause.Append(" AND ");
                    whereClause.Append($"{nameof(RawDataRecord.DataSourceType)} = '{AnDatabaseTypes.FormatSingleQuote(AnDatabaseTypes.ValidStringLength(dataSourceType, RawDataRecord.DataSourceTypeSize))}'");
                }

                if ((DateTime.Compare(beginDateTime, AnTypes.MinDateTimeValue) > 0) &&
                    (DateTime.Compare(endDateTime, beginDateTime) > 0))
                {
                    whereClause.Append(" AND ");
                    whereClause.Append($"{nameof(RawDataRecord.EnteredDateTime)} > '{AnTypes.SqlDateTimeString(beginDateTime)}'");
                    whereClause.Append(" AND ");
                    whereClause.Append($"{nameof(RawDataRecord.EnteredDateTime)} <= '{AnTypes.SqlDateTimeString(endDateTime)}'");
                }

                whereClause.Append(" ORDER BY ");
                whereClause.Append(AnDatabaseTypes.FormatDatabaseColumnName(nameof(RawDataRecord.Id), RawDataRecord.DbTableName, AnDatabaseTypes.ExecutionType.Query, driverType));

                result = AnDatabaseTypes.GenerateSelectQuery(driverType, RawDataRecord.DbTableName, AnDatabaseTypes.FormatColumnNames(RawDataRecord.DbTableName, new RawDataRecord().GetColumnNames(true), driverType), whereClause.ToString());
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
            }

            return(result);
        }
Exemplo n.º 10
0
        // ReSharper disable once UnusedMethodReturnValue.Global
        public bool Add(RawDataRecord rawDataRecord)
        {
            var result = false;

            try
            {
                if (rawDataRecord != null)
                {
                    if (rawDataRecord.Id > 0)
                    {
                        if (!Exists(rawDataRecord.Id))
                        {
                            List.Add(rawDataRecord);

                            result = Exists(rawDataRecord.Id);
                        }
                    }

                    else
                    {
                        if (!Exists(rawDataRecord.CustomerId,
                                    rawDataRecord.SourceSystemCompanyId,
                                    rawDataRecord.UniversalNodeId,
                                    rawDataRecord.DataSourceType,
                                    rawDataRecord.Organization,
                                    rawDataRecord.TableName,
                                    rawDataRecord.RecordData))
                        {
                            List.Add(rawDataRecord);

                            result = Exists(rawDataRecord.CustomerId,
                                            rawDataRecord.SourceSystemCompanyId,
                                            rawDataRecord.UniversalNodeId,
                                            rawDataRecord.DataSourceType,
                                            rawDataRecord.Organization,
                                            rawDataRecord.TableName,
                                            rawDataRecord.RecordData);
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
            }

            return(result);
        }
Exemplo n.º 11
0
        public List <string> GetColumnNames(bool includeIdColumn)
        {
            List <string> result = null;

            try
            {
                var dbTableName = GetDbTableName();

                if (!string.IsNullOrEmpty(dbTableName))
                {
                    if (!ColumnNamesCache.ContainsKey(dbTableName))
                    {
                        var columnNames = GenerateColumnNames(true);

                        if (columnNames?.Count > 0)
                        {
                            ColumnNamesCache.Add(dbTableName, columnNames);
                        }
                    }

                    if (ColumnNamesCache.ContainsKey(dbTableName))
                    {
                        result = AnCloneUtility.JsonClone(ColumnNamesCache[dbTableName]);

                        if (result?.Count > 0)
                        {
                            if (!includeIdColumn)
                            {
                                var keyColumnName = GetKeyColumnName();

                                if (!string.IsNullOrEmpty(keyColumnName) &&
                                    result.Contains(keyColumnName))
                                {
                                    result.Remove(keyColumnName);
                                }
                            }
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
            }

            return(result ?? new List <string>());
        }
Exemplo n.º 12
0
        public bool Exists(int id)
        {
            var result = false;

            try
            {
                result = (GetById(id) != null);
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
            }

            return(result);
        }
Exemplo n.º 13
0
        public virtual string GenerateInsertStatement(AnDatabaseTypes.DriverType driverType)
        {
            var result = "";

            try
            {
                result = AnDatabaseTypes.GenerateInsertStatement(GetDbTableName(), GenerateDatabaseCommandDataList(false), driverType, false);
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
            }

            return(result);
        }
Exemplo n.º 14
0
        private RawDataRecord GetByData(
            string customerId,
            string sourceSystemCompanyId,
            string universalNodeId,
            string dataSourceType,
            string organization,
            string tableName,
            string recordData)
        {
            try
            {
                if (!string.IsNullOrEmpty(customerId) &&
                    !string.IsNullOrEmpty(sourceSystemCompanyId) &&
                    !string.IsNullOrEmpty(universalNodeId) &&
                    !string.IsNullOrEmpty(dataSourceType) &&
                    !string.IsNullOrEmpty(organization) &&
                    !string.IsNullOrEmpty(tableName) &&
                    !string.IsNullOrEmpty(recordData))
                {
                    foreach (var rawDataRecord in List.Where(rawDataRecord =>
                                                             !string.IsNullOrEmpty(rawDataRecord?.CustomerId) &&
                                                             !string.IsNullOrEmpty(rawDataRecord.SourceSystemCompanyId) &&
                                                             !string.IsNullOrEmpty(rawDataRecord.UniversalNodeId) &&
                                                             !string.IsNullOrEmpty(rawDataRecord.DataSourceType) &&
                                                             !string.IsNullOrEmpty(rawDataRecord.Organization) &&
                                                             !string.IsNullOrEmpty(rawDataRecord.TableName) &&
                                                             !string.IsNullOrEmpty(rawDataRecord.RecordData) &&
                                                             string.Equals(rawDataRecord.CustomerId ?? "", customerId, StringComparison.OrdinalIgnoreCase) &&
                                                             string.Equals(rawDataRecord.SourceSystemCompanyId ?? "", sourceSystemCompanyId, StringComparison.OrdinalIgnoreCase) &&
                                                             string.Equals(rawDataRecord.UniversalNodeId ?? "", universalNodeId, StringComparison.OrdinalIgnoreCase) &&
                                                             string.Equals(rawDataRecord.DataSourceType ?? "", dataSourceType, StringComparison.OrdinalIgnoreCase) &&
                                                             string.Equals(rawDataRecord.Organization ?? "", organization, StringComparison.OrdinalIgnoreCase) &&
                                                             string.Equals(rawDataRecord.TableName ?? "", tableName, StringComparison.OrdinalIgnoreCase) &&
                                                             string.Equals(rawDataRecord.RecordData ?? "", recordData, StringComparison.OrdinalIgnoreCase)))
                    {
                        return(rawDataRecord);
                    }
                }
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
            }

            return(null);
        }
Exemplo n.º 15
0
        public void Remove(int id)
        {
            try
            {
                var removeRawDataRecord = GetById(id);

                if (removeRawDataRecord != null)
                {
                    List.Remove(removeRawDataRecord);
                }
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
            }
        }
Exemplo n.º 16
0
        public RawDataRecord GetById(int id)
        {
            try
            {
                foreach (var rawDataRecord in List.Where(rawDataRecord => (rawDataRecord != null)).Where(rawDataRecord => rawDataRecord.Id == id))
                {
                    return(rawDataRecord);
                }
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
            }

            return(null);
        }
Exemplo n.º 17
0
        public static string GenerateNonActiveNetXmlTypeSchemaFileText(Type baseClassType)
        {
            var result = new StringBuilder();

            try
            {
                if (!string.IsNullOrEmpty(baseClassType?.FullName))
                {
                    var parentClass = new Schema
                    {
                        FieldName     = "Root",
                        ClassName     = baseClassType?.Name ?? "",
                        ClassFullName = baseClassType?.FullName ?? "",
                        Type          = baseClassType
                    };

                    var classes = new List <Schema> {
                        parentClass
                    };

                    GetNonActiveNetClasses(classes, parentClass);

                    var baseElement = new XElement("Tables");

                    foreach (var schema in classes.Where(schema => !string.IsNullOrEmpty(schema?.ClassFullName)))
                    {
                        baseElement.Add(new XElement("Table", new XAttribute("Type", TrimClassName(schema.ClassFullName)), GenerateSchemaElement(schema)));
                    }

                    var xDocument = new XDocument(
                        new XDeclaration("1.0", "utf-8", null),
                        new XComment("ActiveNet Inc. Type Definitions"),
                        baseElement);

                    result.Append(xDocument);
                }
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
            }

            return(result.ToString());
        }
Exemplo n.º 18
0
        public static T JsonClone <T>(T source, List <JsonConverter> jsonConverters = null)
        {
            try
            {
                if (ReferenceEquals(source, null))
                {
                    return(default(T));
                }

                var type = AnTypes.GetType(source, null);

                if ((type == null) || !type.IsSerializable)
                {
                    throw new ArgumentException(ExceptionError, nameof(source));
                }

                var jsonString = new StringBuilder();

                var jsonSerializer = new JsonSerializer();

                if ((jsonConverters != null) && (jsonConverters.Count > 0))
                {
                    foreach (var jsonConverter in jsonConverters.Where(jsonConverter => jsonConverter != null))
                    {
                        jsonSerializer.Converters.Add(jsonConverter);
                    }
                }

                using (var stringWriter = new StringWriter(jsonString))
                {
                    jsonSerializer.Serialize(stringWriter, source);

                    using (var stringReader = new StringReader(jsonString.ToString()))
                    {
                        return((T)jsonSerializer.Deserialize(stringReader, type));
                    }
                }
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
                throw;
            }
        }
Exemplo n.º 19
0
        private static Type GenericOfClassType(string fullClassName)
        {
            Type result = null;

            try
            {
                var subClassName = GenericOfClassName(fullClassName);

                result = AnTypes.GetType(!string.IsNullOrEmpty(subClassName) ? subClassName : fullClassName, null);
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
            }

            return(result);
        }
Exemplo n.º 20
0
        public static List <Dictionary <string, object> > ToDictionaryList <T>(List <T> list)
        {
            var result = new List <Dictionary <string, object> >();

            try
            {
                if (list != null)
                {
                    result = (from t in list where t != null select ToDictionary(t) into dictionary where (dictionary != null) && (dictionary.Count > 0) select dictionary).ToList();
                }
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
            }

            return(result);
        }
Exemplo n.º 21
0
        public static bool Exists <T>(T value, int id)
        {
            try
            {
                if (value != null)
                {
                    var classType = AnTypes.GetType(value, null);

                    if (classType != null)
                    {
                        foreach (var property in classType.GetProperties())
                        {
                            var propertyType = property.PropertyType;

                            if (property.PropertyType.IsEnum)
                            {
                                propertyType = AnReflectionCache.GetUnderlyingType(propertyType);
                            }

                            var key = property.Name.ToLower();

                            if ((Type.GetTypeCode(propertyType) == TypeCode.Int32) && (key == "id"))
                            {
                                var localId = (int)property.GetValue(value, null);

                                if (localId == id)
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
            }

            return(false);
        }
Exemplo n.º 22
0
        public static List <T> FromDictionaryList <T>(List <Dictionary <string, object> > dictionaryList) where T : new()
        {
            var result = new List <T>();

            try
            {
                if ((dictionaryList != null) &&
                    (dictionaryList.Count > 0))
                {
                    result.AddRange(dictionaryList.Where(dictionary => ((dictionary != null) && (dictionary.Count > 0))).Select(FromDictionary <T>));
                }
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
            }

            return(result);
        }
Exemplo n.º 23
0
        public static List <Dictionary <string, object> > ToDictionaryList(DataTable table)
        {
            List <Dictionary <string, object> > result = null;

            try
            {
                if ((table?.Columns.Count > 0) &&
                    (table.Rows?.Count > 0))
                {
                    result = table.Rows.Cast <DataRow>().Where(row => row != null).Select(row => table.Columns.Cast <DataColumn>().Where(column => !string.IsNullOrEmpty(column?.ColumnName)).Where(column => !row.IsNull(column)).ToDictionary(column => column.ColumnName, column => row[column.ColumnName])).ToList();
                }
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
            }

            return(result ?? new List <Dictionary <string, object> >());
        }
Exemplo n.º 24
0
        public RawDataRecord(
            int id,
            string customerId,
            string sourceSystemCompanyId,
            string universalNodeId,
            string dataSourceType,
            string organization,
            string tableName,
            string action,
            string errorMessage,
            string recordData,
            DateTime enteredDateTime,
            DateTime processedDateTime,
            bool result,
            bool processed)
        {
            Clear();

            try
            {
                Id                    = id;
                CustomerId            = customerId ?? "";
                SourceSystemCompanyId = sourceSystemCompanyId ?? "";
                UniversalNodeId       = universalNodeId ?? "";
                DataSourceType        = dataSourceType ?? "";
                Organization          = organization ?? "";
                TableName             = tableName ?? "";
                Action                = action ?? "";
                ErrorMessage          = errorMessage ?? "";
                RecordData            = recordData ?? "";
                EnteredDateTime       = enteredDateTime;
                ProcessedDateTime     = processedDateTime;
                Result                = result;
                Processed             = processed;
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
            }
        }
Exemplo n.º 25
0
        public string GenerateUpdateStatement <T>(AnDatabaseTypes.DriverType driverType, T modelObject)
        {
            var result = "";

            try
            {
                var whereClause = GeneratePrimaryKeyWhereClause(driverType);

                if (!string.IsNullOrEmpty(whereClause))
                {
                    result = AnDatabaseTypes.GenerateUpdateStatement(GetDbTableName(), whereClause, GenerateDatabaseCommandDataList(false), (modelObject as AnModelBase)?.GenerateDatabaseCommandDataList(false) ?? new AnList <AnDatabaseCommandData>(), driverType, false);
                }
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
            }

            return(result);
        }
Exemplo n.º 26
0
        public string GenerateDeleteStatement(AnDatabaseTypes.DriverType driverType)
        {
            var result = "";

            try
            {
                var whereClause = GeneratePrimaryKeyWhereClause(driverType);

                if (!string.IsNullOrEmpty(whereClause))
                {
                    result = $"DELETE FROM {GetDbTableName()} WHERE {whereClause}";
                }
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
            }

            return(result);
        }
Exemplo n.º 27
0
        public static T XmlClone <T>(T source, Type[] types)
        {
            try
            {
                if (ReferenceEquals(source, null))
                {
                    return(default(T));
                }

                var type = AnTypes.GetType(source, null);

                if ((type == null) || !type.IsSerializable)
                {
                    throw new ArgumentException(ExceptionError, nameof(source));
                }

                var xmlSerializer = new XmlSerializer(type, types);

                Stream stream = new MemoryStream();

                using (stream)
                {
                    xmlSerializer.Serialize(stream, source);
                    stream.Seek(0, SeekOrigin.Begin);

                    // Uncomment these for debugging.
                    // var streamReader = new StreamReader(stream);
                    // var xmlContents = streamReader.ReadToEnd();
                    // stream.Seek(0, SeekOrigin.Begin);

                    return((T)xmlSerializer.Deserialize(stream));
                }
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
                throw;
            }
        }
Exemplo n.º 28
0
        public static string GenerateSelectQuery(string customerId, string sourceSystemCompanyId, string universalNodeId, string dataSourceType, string organization, string tableName, string action, AnDatabaseTypes.DriverType driverType)
        {
            var result = "";

            try
            {
                var whereClause = new StringBuilder();

                if (!string.IsNullOrEmpty(customerId) &&
                    !string.IsNullOrEmpty(sourceSystemCompanyId) &&
                    !string.IsNullOrEmpty(universalNodeId) &&
                    !string.IsNullOrEmpty(dataSourceType) &&
                    !string.IsNullOrEmpty(tableName) &&
                    !string.IsNullOrEmpty(action))
                {
                    whereClause.Append($"{nameof(RawDataRecord.CustomerId)} = '{AnDatabaseTypes.FormatSingleQuote(AnDatabaseTypes.ValidStringLength(customerId, RawDataRecord.CustomerIdSize))}'");
                    whereClause.Append(" AND ");
                    whereClause.Append($"{nameof(RawDataRecord.SourceSystemCompanyId)} = '{AnDatabaseTypes.FormatSingleQuote(AnDatabaseTypes.ValidStringLength(sourceSystemCompanyId, RawDataRecord.SourceSystemCompanyIdSize))}'");
                    whereClause.Append(" AND ");
                    whereClause.Append($"{nameof(RawDataRecord.UniversalNodeId)} = '{AnDatabaseTypes.FormatSingleQuote(AnDatabaseTypes.ValidStringLength(universalNodeId, RawDataRecord.UniversalNodeIdSize))}'");
                    whereClause.Append(" AND ");
                    whereClause.Append($"{nameof(RawDataRecord.DataSourceType)} = '{AnDatabaseTypes.FormatSingleQuote(AnDatabaseTypes.ValidStringLength(dataSourceType, RawDataRecord.DataSourceTypeSize))}'");
                    whereClause.Append(" AND ");
                    whereClause.Append($"{nameof(RawDataRecord.Organization)} = '{AnDatabaseTypes.FormatSingleQuote(AnDatabaseTypes.ValidStringLength(organization ?? "", RawDataRecord.OrganizationSize))}'");
                    whereClause.Append(" AND ");
                    whereClause.Append($"{nameof(RawDataRecord.TableName)} = '{AnDatabaseTypes.FormatSingleQuote(AnDatabaseTypes.ValidStringLength(tableName, RawDataRecord.TableNameSize))}'");
                    whereClause.Append(" AND ");
                    whereClause.Append($"{nameof(RawDataRecord.Action)} = '{AnDatabaseTypes.FormatSingleQuote(AnDatabaseTypes.ValidStringLength(action, RawDataRecord.ActionSize))}'");

                    result = AnDatabaseTypes.GenerateSelectQuery(driverType, RawDataRecord.DbTableName, AnDatabaseTypes.FormatColumnNames(RawDataRecord.DbTableName, new RawDataRecord().GetColumnNames(true), driverType), whereClause.ToString());
                }
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
            }

            return(result);
        }
Exemplo n.º 29
0
        public static List <T> ToList <T>(DataTable table, string columnName)
        {
            var result = new List <T>();

            try
            {
                if (!string.IsNullOrEmpty(columnName) &&
                    (table.Rows?.Count > 0))
                {
                    result.AddRange(table.Rows.Cast <DataRow>().Where(row => table.Columns.Contains(columnName) && !row.IsNull(columnName)).Select(row => (T)row[columnName]));

                    //result = (List<T>) table.Rows.Cast<DataRow>().Where(row => row != null).Select(row => table.Columns.Cast<DataColumn>().Where(column => !string.IsNullOrEmpty(column?.ColumnName)).Where(column => !row.IsNull(column)).ToList());
                }
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
            }

            return(result);
        }
Exemplo n.º 30
0
        public static string ToXml <T>(T source, Type[] types)
        {
            var xmlString = "";

            try
            {
                if (!ReferenceEquals(source, null))
                {
                    var type = AnTypes.GetType(source, null);

                    if ((type == null) || !type.IsSerializable)
                    {
                        throw new ArgumentException(ExceptionError, nameof(source));
                    }

                    var xmlSerializer = new XmlSerializer(type, types);

                    Stream stream = new MemoryStream();

                    using (stream)
                    {
                        xmlSerializer.Serialize(stream, source);

                        stream.Seek(0, SeekOrigin.Begin);

                        var streamReader = new StreamReader(stream);
                        xmlString = streamReader.ReadToEnd();
                    }
                }
            }

            catch (Exception ex)
            {
                AnLog.Error(ex);
                throw;
            }

            return(xmlString);
        }