public static DT.Run ToDto(DA.Run source, bool includeBinaryValues, IEnumerable<DT.ValueName> valueNames) { if (source == null) return null; var dto = new DT.Run { Id = source.Id, Algorithm = Convert.ToDto(source.Algorithm), Problem = Convert.ToDto(source.Problem), CreatedDate = source.CreatedDate, ClientId = source.ClientId, UserId = source.UserId }; dto.ParameterValues = source.Values.Where(x => x.ValueName.Category == DA.ValueNameCategory.Parameter && valueNames.Count(y => y.Name == x.ValueName.Name) > 0).Select(x => Convert.ToDto(x, includeBinaryValues)).ToArray(); dto.ResultValues = source.Values.Where(x => x.ValueName.Category == DA.ValueNameCategory.Result && valueNames.Count(y => y.Name == x.ValueName.Name) > 0).Select(x => Convert.ToDto(x, includeBinaryValues)).ToArray(); return dto; }
public static DA.Run ToEntity(DT.Run source, DA.OKBDataContext okb) { if (source == null) return null; List<DA.BinaryData> binCache = new List<DA.BinaryData>(); DA.Run entity = new DA.Run { Id = 0, AlgorithmId = source.AlgorithmId, ProblemId = source.ProblemId, CreatedDate = source.CreatedDate, UserId = source.UserId, ClientId = source.ClientId }; foreach (var value in source.ParameterValues) entity.Values.Add(Convert.ToEntity(value, entity, DA.ValueNameCategory.Parameter, okb, binCache)); foreach (var value in source.ResultValues) entity.Values.Add(Convert.ToEntity(value, entity, DA.ValueNameCategory.Result, okb, binCache)); return entity; }
private static DA.Value ToEntity(DT.Value source, DA.Run run, DA.ValueNameCategory category, DA.OKBDataContext okb, List<DA.BinaryData> binCache) { if (source == null) return null; var entity = new DA.Value(); entity.Run = run; entity.DataType = Convert.ToEntity(source.DataType, okb); if (source is DT.BoolValue) { entity.ValueName = Convert.ToEntity(source.Name, category, DA.ValueNameType.Bool, okb); entity.BoolValue = ((DT.BoolValue)source).Value; } else if (source is DT.IntValue) { entity.ValueName = Convert.ToEntity(source.Name, category, DA.ValueNameType.Int, okb); entity.IntValue = ((DT.IntValue)source).Value; } else if (source is DT.TimeSpanValue) { entity.ValueName = Convert.ToEntity(source.Name, category, DA.ValueNameType.TimeSpan, okb); entity.LongValue = ((DT.TimeSpanValue)source).Value; } else if (source is DT.LongValue) { entity.ValueName = Convert.ToEntity(source.Name, category, DA.ValueNameType.Long, okb); entity.LongValue = ((DT.LongValue)source).Value; } else if (source is DT.FloatValue) { entity.ValueName = Convert.ToEntity(source.Name, category, DA.ValueNameType.Float, okb); entity.FloatValue = ((DT.FloatValue)source).Value; } else if (source is DT.DoubleValue) { entity.ValueName = Convert.ToEntity(source.Name, category, DA.ValueNameType.Double, okb); entity.DoubleValue = ((DT.DoubleValue)source).Value; } else if (source is DT.PercentValue) { entity.ValueName = Convert.ToEntity(source.Name, category, DA.ValueNameType.Percent, okb); entity.DoubleValue = ((DT.PercentValue)source).Value; } else if (source is DT.StringValue) { entity.ValueName = Convert.ToEntity(source.Name, category, DA.ValueNameType.String, okb); entity.StringValue = ((DT.StringValue)source).Value; } else if (source is DT.BinaryValue) { entity.ValueName = Convert.ToEntity(source.Name, category, DA.ValueNameType.Binary, okb); entity.BinaryData = Convert.ToEntity(((DT.BinaryValue)source).Value, okb, binCache); } else { throw new ArgumentException("Unknown value type.", "source"); } return entity; }
private static DT.Value ToDto(DA.Value source, bool includeBinaryValues) { if (source == null) return null; if (source.ValueName.Type == DA.ValueNameType.Bool) { return new DT.BoolValue { Name = source.ValueName.Name, DataType = Convert.ToDto(source.DataType), Value = source.BoolValue.GetValueOrDefault() }; } else if (source.ValueName.Type == DA.ValueNameType.Int) { return new DT.IntValue { Name = source.ValueName.Name, DataType = Convert.ToDto(source.DataType), Value = source.IntValue.GetValueOrDefault() }; } else if (source.ValueName.Type == DA.ValueNameType.TimeSpan) { return new DT.TimeSpanValue { Name = source.ValueName.Name, DataType = Convert.ToDto(source.DataType), Value = source.LongValue.GetValueOrDefault() }; } else if (source.ValueName.Type == DA.ValueNameType.Long) { return new DT.LongValue { Name = source.ValueName.Name, DataType = Convert.ToDto(source.DataType), Value = source.LongValue.GetValueOrDefault() }; } else if (source.ValueName.Type == DA.ValueNameType.Float) { return new DT.FloatValue { Name = source.ValueName.Name, DataType = Convert.ToDto(source.DataType), Value = source.FloatValue.GetValueOrDefault() }; } else if (source.ValueName.Type == DA.ValueNameType.Double) { return new DT.DoubleValue { Name = source.ValueName.Name, DataType = Convert.ToDto(source.DataType), Value = source.DoubleValue.GetValueOrDefault() }; } else if (source.ValueName.Type == DA.ValueNameType.Percent) { return new DT.PercentValue { Name = source.ValueName.Name, DataType = Convert.ToDto(source.DataType), Value = source.DoubleValue.GetValueOrDefault() }; } else if (source.ValueName.Type == DA.ValueNameType.String) { return new DT.StringValue { Name = source.ValueName.Name, DataType = Convert.ToDto(source.DataType), Value = source.StringValue }; } else if (source.ValueName.Type == DA.ValueNameType.Binary) { return new DT.BinaryValue { Name = source.ValueName.Name, DataType = Convert.ToDto(source.DataType), Value = includeBinaryValues ? source.BinaryData.Data.ToArray() : null }; } else { throw new ArgumentException("Unknown value type.", "source"); } }
internal static DA.BinaryData ToEntity(byte[] data, DA.OKBDataContext okb) { if (data == null) return null; byte[] hash; using (SHA1 sha1 = SHA1.Create()) { hash = sha1.ComputeHash(data); } var entity = okb.BinaryDatas.Where(x => x.Hash.Equals(hash)).FirstOrDefault(); if (entity == null) entity = new DA.BinaryData() { Id = 0, Data = data, Hash = hash }; return entity; }
private static DA.DataType ToEntity(string dataTypeName, string dataTypeTypeName, DA.OKBDataContext okb) { if ((dataTypeName == null) || (dataTypeTypeName == null)) return null; var entity = okb.DataTypes.Where(x => (x.Name == dataTypeName) && (x.TypeName == dataTypeTypeName)).FirstOrDefault(); if (entity == null) entity = new DA.DataType() { Id = 0, Name = dataTypeName, TypeName = dataTypeTypeName }; return entity; }
public static DT.ValueName ToDto(DA.ValueName source) { if (source == null) return null; return new DT.ValueName() { Id = source.Id, Category = source.Category, Name = source.Name }; }
private static DA.ValueName ToEntity(string name, DA.ValueNameCategory category, DA.ValueNameType type, DA.OKBDataContext okb) { if (string.IsNullOrEmpty(name)) return null; var entity = okb.ValueNames.Where(x => (x.Name == name) && (x.Category == category) && (x.Type == type)).FirstOrDefault(); if (entity == null) entity = new DA.ValueName() { Id = 0, Name = name, Category = category, Type = type }; return entity; }
public static DT.Problem ToDto(DA.Problem source) { if (source == null) return null; return new DT.Problem { Id = source.Id, Name = source.Name, Description = source.Description, PlatformId = source.PlatformId, ProblemClassId = source.ProblemClassId, DataTypeName = source.DataType.Name, DataTypeTypeName = source.DataType.TypeName }; }
public static DT.ProblemClass ToDto(DA.ProblemClass source) { if (source == null) return null; return new DT.ProblemClass { Id = source.Id, Name = source.Name, Description = source.Description }; }
private static DT.ProblemClass ToDto(DA.ProblemClass source) { if (source == null) return null; return new DT.ProblemClass { Name = source.Name, Description = source.Description }; }
public static DT.Problem ToDto(DA.Problem source) { if (source == null) return null; return new DT.Problem { Id = source.Id, Name = source.Name, Description = source.Description, ProblemClass = Convert.ToDto(source.ProblemClass), DataType = Convert.ToDto(source.DataType) }; }
public static DT.Algorithm ToDto(DA.Algorithm source) { if (source == null) return null; return new DT.Algorithm { Id = source.Id, Name = source.Name, Description = source.Description, AlgorithmClass = Convert.ToDto(source.AlgorithmClass), DataType = Convert.ToDto(source.DataType) }; }
private static DA.BinaryData ToEntity(byte[] data, DA.OKBDataContext okb, List<DA.BinaryData> binCache) { if (data == null) return null; byte[] hash; using (SHA1 sha1 = SHA1.Create()) { hash = sha1.ComputeHash(data); } var cachedBinaryData = binCache.Where(x => x.Hash.SequenceEqual(hash)).FirstOrDefault(); if (cachedBinaryData != null) return cachedBinaryData; var entity = okb.BinaryDatas.Where(x => x.Hash.Equals(hash)).FirstOrDefault(); if (entity == null) { entity = new DA.BinaryData() { Id = 0, Data = data, Hash = hash }; binCache.Add(entity); } return entity; }
public static DT.Platform ToDto(DA.Platform source) { if (source == null) return null; return new DT.Platform { Id = source.Id, Name = source.Name, Description = source.Description }; }
private static DT.Algorithm ToDto(DA.Algorithm source) { if (source == null) return null; return new DT.Algorithm { Id = source.Id, Name = source.Name, Description = source.Description, AlgorithmClass = source.AlgorithmClass.Name, Platform = source.Platform.Name, DataType = Convert.ToDto(source.DataType) }; }
public static void ToEntity(DT.Algorithm source, DA.Algorithm target, DA.OKBDataContext okb) { if ((source != null) && (target != null)) { target.Id = source.Id; target.Name = source.Name; target.Description = source.Description; target.PlatformId = source.PlatformId; target.AlgorithmClassId = source.AlgorithmClassId; target.DataType = Convert.ToEntity(source.DataTypeName, source.DataTypeTypeName, okb); } }
private static DT.Problem ToDto(DA.Problem source) { if (source == null) return null; return new DT.Problem { Name = source.Name, Description = source.Description, ProblemClass = source.ProblemClass.Name, Platform = source.Platform.Name, DataType = Convert.ToDto(source.DataType) }; }
public static void ToEntity(DT.ProblemClass source, DA.ProblemClass target) { if ((source != null) && (target != null)) { target.Id = source.Id; target.Name = source.Name; target.Description = source.Description; } }
private static DT.DataType ToDto(DA.DataType source) { if (source == null) return null; return new DT.DataType { Name = source.Name, TypeName = source.TypeName }; }
public static DA.Problem ToEntity(DT.Problem source, DA.OKBDataContext okb) { if (source == null) return null; return new DA.Problem { Id = source.Id, Name = source.Name, Description = source.Description, PlatformId = source.PlatformId, ProblemClassId = source.ProblemClassId, DataType = Convert.ToEntity(source.DataTypeName, source.DataTypeTypeName, okb) }; }
private static DA.DataType ToEntity(DT.DataType source, DA.OKBDataContext okb) { if (source == null) return null; var entity = okb.DataTypes.Where(x => (x.Name == source.Name) && (x.TypeName == source.TypeName)).FirstOrDefault(); if (entity == null) entity = new DA.DataType() { Id = 0, Name = source.Name, TypeName = source.TypeName }; return entity; }