public IEnumerable<DataTransfer.Problem> GetProblems(string platformName) {
      roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser);

      using (OKBDataContext okb = new OKBDataContext()) {
        DataLoadOptions dlo = new DataLoadOptions();
        dlo.LoadWith<Problem>(x => x.ProblemClass);
        dlo.LoadWith<Problem>(x => x.DataType);
        dlo.LoadWith<Problem>(x => x.ProblemUsers);
        okb.LoadOptions = dlo;

        var query = okb.Problems.Where(x => x.Platform.Name == platformName);
        List<Problem> results = new List<Problem>();

        if (roleVerifier.IsInRole(OKBRoles.OKBAdministrator)) {
          results.AddRange(query);
        } else {
          foreach (var problem in query) {
            if (problem.ProblemUsers.Count() == 0 || userManager.VerifyUser(userManager.CurrentUserId, problem.ProblemUsers.Select(y => y.UserGroupId).ToList())) {
              results.Add(problem);
            }
          }
        }
        return results.Select(x => Convert.ToDto(x)).ToArray();
      }
    }
    public IEnumerable<DataTransfer.Platform> GetPlatforms() {
      roleVerifier.AuthenticateForAllRoles(OKBRoles.OKBAdministrator);

      using (OKBDataContext okb = new OKBDataContext()) {
        return okb.Platforms.Select(x => Convert.ToDto(x)).ToArray();
      }
    }
Beispiel #3
0
        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);
        }

        #endregion
    }
    public DataTransfer.AlgorithmClass GetAlgorithmClass(long id) {
      roleVerifier.AuthenticateForAllRoles(OKBRoles.OKBAdministrator);

      using (OKBDataContext okb = new OKBDataContext()) {
        return Convert.ToDto(okb.AlgorithmClasses.FirstOrDefault(x => x.Id == id));
      }
    }
        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.FirstOrDefault(x => x.Hash.SequenceEqual(hash));

            if (cachedBinaryData != null)
            {
                return(cachedBinaryData);
            }

            var entity = okb.BinaryDatas.FirstOrDefault(x => x.Hash.Equals(hash));

            if (entity == null)
            {
                entity = new DA.BinaryData()
                {
                    Id = 0, Data = data, Hash = hash
                };
                binCache.Add(entity);
            }

            return(entity);
        }
Beispiel #6
0
 public static void ToEntity(DT.Problem source, DA.Problem 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.ProblemClassId = source.ProblemClassId; target.DataType = Convert.ToEntity(source.DataTypeName, source.DataTypeTypeName, okb);
     }
 }
    public void UpdatePlatform(DataTransfer.Platform dto) {
      roleVerifier.AuthenticateForAllRoles(OKBRoles.OKBAdministrator);

      using (OKBDataContext okb = new OKBDataContext()) {
        DataAccess.Platform entity = okb.Platforms.FirstOrDefault(x => x.Id == dto.Id);
        Convert.ToEntity(dto, entity);
        okb.SubmitChanges();
      }
    }
    public void DeletePlatform(long id) {
      roleVerifier.AuthenticateForAllRoles(OKBRoles.OKBAdministrator);

      using (OKBDataContext okb = new OKBDataContext()) {
        DataAccess.Platform entity = okb.Platforms.FirstOrDefault(x => x.Id == id);
        if (entity != null) okb.Platforms.DeleteOnSubmit(entity);
        okb.SubmitChanges();
      }
    }
    public long AddPlatform(DataTransfer.Platform dto) {
      roleVerifier.AuthenticateForAllRoles(OKBRoles.OKBAdministrator);

      using (OKBDataContext okb = new OKBDataContext()) {
        DataAccess.Platform entity = Convert.ToEntity(dto); entity.Id = 0;
        okb.Platforms.InsertOnSubmit(entity);
        okb.SubmitChanges();
        return entity.Id;
      }
    }
Beispiel #10
0
 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)
     });
 }
        public static DA.CharacteristicValue ToEntity(DT.Value source, DA.OKBDataContext okb, DA.Problem problem, DA.CharacteristicType type)
        {
            if (okb == null || problem == null || source == null || string.IsNullOrEmpty(source.Name))
            {
                throw new ArgumentNullException();
            }
            var entity = new DA.CharacteristicValue();

            entity.Problem        = problem;
            entity.DataType       = Convert.ToEntity(source.DataType, okb);
            entity.Characteristic = Convert.ToEntity(source.Name, type, okb);
            if (source is DT.BoolValue)
            {
                entity.BoolValue = ((DT.BoolValue)source).Value;
            }
            else if (source is DT.IntValue)
            {
                entity.IntValue = ((DT.IntValue)source).Value;
            }
            else if (source is DT.TimeSpanValue)
            {
                entity.LongValue = ((DT.TimeSpanValue)source).Value;
            }
            else if (source is DT.LongValue)
            {
                entity.LongValue = ((DT.LongValue)source).Value;
            }
            else if (source is DT.FloatValue)
            {
                entity.FloatValue = ((DT.FloatValue)source).Value;
            }
            else if (source is DT.DoubleValue)
            {
                entity.DoubleValue = ((DT.DoubleValue)source).Value;
            }
            else if (source is DT.PercentValue)
            {
                entity.DoubleValue = ((DT.PercentValue)source).Value;
            }
            else if (source is DT.StringValue)
            {
                entity.StringValue = ((DT.StringValue)source).Value;
            }
            else
            {
                throw new ArgumentException("Unknown characteristic type.", "source");
            }
            return(entity);
        }
    public byte[] GetAlgorithmData(long algorithmId) {
      roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser);

      using (OKBDataContext okb = new OKBDataContext()) {
        var result = okb.Algorithms.Where(x => x.Id == algorithmId).Select(x => x.BinaryData.Data.ToArray()).FirstOrDefault();

        if (roleVerifier.IsInRole(OKBRoles.OKBAdministrator)) {
          return result;
        } else {
          var algUsers = okb.AlgorithmUsers.Where(x => x.AlgorithmId == algorithmId);
          if (algUsers.Count() == 0 || userManager.VerifyUser(userManager.CurrentUserId, algUsers.Select(y => y.UserGroupId).ToList())) {
            return result;
          } else {
            return null;
          }
        }
      }
    }
        public static DA.DataType ToEntity(DT.DataType source, DA.OKBDataContext okb)
        {
            if (source == null)
            {
                return(null);
            }
            var entity = okb.DataTypes.FirstOrDefault(x => (x.Name == source.Name) && (x.TypeName == source.TypeName));

            if (entity == null)
            {
                entity = new DA.DataType()
                {
                    Id = 0, Name = source.Name, TypeName = source.TypeName
                }
            }
            ;
            return(entity);
        }
        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 DA.Characteristic ToEntity(string name, DA.CharacteristicType type, DA.OKBDataContext okb)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }
            var entity = okb.Characteristics.FirstOrDefault(x => (x.Name == name) && (x.Type == type));

            return(entity ?? new DA.Characteristic()
            {
                Id = 0, Name = name, Type = type
            });
        }
Beispiel #17
0
    private bool IsAuthorizedForProblem(long problemId, OKBDataContext okb) {
      var problemUsers = okb.ProblemUsers.Where(x => x.ProblemId == problemId).Select(x => x.UserGroupId).ToList();

      if (problemUsers.Count == 0 || userManager.VerifyUser(userManager.CurrentUserId, problemUsers)) {
        return true;
      }
      return false;
    }
Beispiel #18
0
    public IEnumerable<DataTransfer.Run> GetRunsWithValues(IEnumerable<long> ids, bool includeBinaryValues, IEnumerable<DataTransfer.ValueName> valueNames) {
      using (OKBDataContext okb = new OKBDataContext()) {
        DataLoadOptions dlo = new DataLoadOptions();
        // TODO: specify LoadWiths
        okb.LoadOptions = dlo;

        return FilterUnauthorizedRuns(okb.Runs.Where(x => ids.Contains(x.Id)).ToList(), okb).Select(x => Convert.ToDto(x, includeBinaryValues, valueNames)).ToArray();
      }
    }
Beispiel #19
0
        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 void UpdateProblemData(long problemId, byte[] data) {
      roleVerifier.AuthenticateForAllRoles(OKBRoles.OKBAdministrator);

      using (OKBDataContext okb = new OKBDataContext()) {
        var entity = okb.Problems.Where(x => x.Id == problemId).FirstOrDefault();
        if (entity != null)
          entity.BinaryData = Convert.ToEntity(data, okb);
        okb.SubmitChanges();
      }
    }
    public byte[] GetProblemData(long problemId) {
      roleVerifier.AuthenticateForAllRoles(OKBRoles.OKBAdministrator);

      using (OKBDataContext okb = new OKBDataContext()) {
        var data = okb.Problems.Where(x => x.Id == problemId).Select(x => x.BinaryData).FirstOrDefault();
        if (data != null) return data.Data.ToArray();
        else return null;
      }
    }
    public void UpdateProblemUsers(long problemId, IEnumerable<Guid> users) {
      roleVerifier.AuthenticateForAllRoles(OKBRoles.OKBAdministrator);

      using (OKBDataContext okb = new OKBDataContext()) {
        okb.ProblemUsers.DeleteAllOnSubmit(okb.ProblemUsers.Where(x => x.ProblemId == problemId));
        okb.ProblemUsers.InsertAllOnSubmit(users.Select(x => new DataAccess.ProblemUser { ProblemId = problemId, UserGroupId = x }));
        okb.SubmitChanges();
      }
    }
    public IEnumerable<Guid> GetProblemUsers(long problemId) {
      roleVerifier.AuthenticateForAllRoles(OKBRoles.OKBAdministrator);

      using (OKBDataContext okb = new OKBDataContext()) {
        return okb.ProblemUsers.Where(x => x.ProblemId == problemId).Select(x => x.UserGroupId).ToArray();
      }
    }
Beispiel #24
0
    public IEnumerable<Filter> GetFilters() {
      List<Filter> filters = new List<Filter>();
      using (OKBDataContext okb = new OKBDataContext()) {
        #region Run Filters
        filters.Add(new OrdinalComparisonDateTimeFilter(typeof(RunCreatedDateFilter).AssemblyQualifiedName, "Run Created Date"));
        filters.Add(new StringComparisonFilter(typeof(RunUserNameFilter).AssemblyQualifiedName, "Run User Name"));
        filters.Add(new StringComparisonFilter(typeof(RunClientNameFilter).AssemblyQualifiedName, "Run Client Name"));
        #endregion

        #region Parameter Filters
        filters.Add(new StringComparisonAvailableValuesFilter(
          typeof(ValueNameFilter).AssemblyQualifiedName,
          "Parameter Name",
          okb.ValueNames.Where(x => x.Category == ValueNameCategory.Parameter).Select(x => x.Name).Distinct().ToArray()
        ));
        foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Parameter) && (x.Type == ValueNameType.Binary)).Select(x => x.Name).Distinct())
          filters.Add(new NameStringComparisonAvailableValuesFilter(
            typeof(ValueDataTypeNameFilter).AssemblyQualifiedName,
            "Parameter " + name + " Value Data Type Name",
            name,
            okb.Values.Where(x => (x.ValueName.Name == name) && (x.ValueName.Category == ValueNameCategory.Parameter) && (x.ValueName.Type == ValueNameType.Binary)).Select(x => x.DataType.Name).Distinct().ToArray()
          ));
        foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Parameter) && (x.Type == ValueNameType.Bool)).Select(x => x.Name).Distinct())
          filters.Add(new NameEqualityComparisonBoolFilter(
            typeof(BoolValueFilter).AssemblyQualifiedName,
            "Parameter " + name + " Value",
            name
          ));
        foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Parameter) && (x.Type == ValueNameType.Int)).Select(x => x.Name).Distinct())
          filters.Add(new NameOrdinalComparisonIntFilter(
            typeof(IntValueFilter).AssemblyQualifiedName,
            "Parameter " + name + " Value",
            name
          ));
        foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Parameter) && (x.Type == ValueNameType.Long)).Select(x => x.Name).Distinct())
          filters.Add(new NameOrdinalComparisonLongFilter(
            typeof(LongValueFilter).AssemblyQualifiedName,
            "Parameter " + name + " Value",
            name
          ));
        foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Parameter) && (x.Type == ValueNameType.TimeSpan)).Select(x => x.Name).Distinct())
          filters.Add(new NameOrdinalComparisonTimeSpanFilter(
            typeof(TimeSpanValueFilter).AssemblyQualifiedName,
            "Parameter " + name + " Value",
            name
          ));
        foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Parameter) && (x.Type == ValueNameType.Float)).Select(x => x.Name).Distinct())
          filters.Add(new NameOrdinalComparisonFloatFilter(
            typeof(FloatValueFilter).AssemblyQualifiedName,
            "Parameter " + name + " Value",
            name
          ));
        foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Parameter) && (x.Type == ValueNameType.Double)).Select(x => x.Name).Distinct())
          filters.Add(new NameOrdinalComparisonDoubleFilter(
            typeof(DoubleValueFilter).AssemblyQualifiedName,
            "Parameter " + name + " Value",
            name
          ));
        foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Parameter) && (x.Type == ValueNameType.Percent)).Select(x => x.Name).Distinct())
          filters.Add(new NameOrdinalComparisonPercentFilter(
            typeof(PercentValueFilter).AssemblyQualifiedName,
            "Parameter " + name + " Value",
            name
          ));
        foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Parameter) && (x.Type == ValueNameType.String)).Select(x => x.Name).Distinct())
          filters.Add(new NameStringComparisonFilter(
            typeof(StringValueFilter).AssemblyQualifiedName,
            "Parameter " + name + " Value",
            name
          ));
        foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Parameter) && (x.Type == ValueNameType.Binary)).Select(x => x.Name).Distinct())
          filters.Add(new NameEqualityComparisonByteArrayFilter(
            typeof(BinaryValueFilter).AssemblyQualifiedName,
            "Parameter " + name + " Value",
            name
          ));
        #endregion

        #region Result Filters
        filters.Add(new StringComparisonAvailableValuesFilter(
          typeof(ValueNameFilter).AssemblyQualifiedName,
          "Result Name",
          okb.ValueNames.Where(x => x.Category == ValueNameCategory.Result).Select(x => x.Name).Distinct().ToArray()
        ));
        foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Result) && (x.Type == ValueNameType.Binary)).Select(x => x.Name).Distinct())
          filters.Add(new NameStringComparisonAvailableValuesFilter(
            typeof(ValueDataTypeNameFilter).AssemblyQualifiedName,
            "Result " + name + " Value Data Type Name",
            name,
            okb.Values.Where(x => (x.ValueName.Name == name) && (x.ValueName.Category == ValueNameCategory.Result) && (x.ValueName.Type == ValueNameType.Binary)).Select(x => x.DataType.Name).Distinct().ToArray()
          ));
        foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Result) && (x.Type == ValueNameType.Bool)).Select(x => x.Name).Distinct())
          filters.Add(new NameEqualityComparisonBoolFilter(
            typeof(BoolValueFilter).AssemblyQualifiedName,
            "Result " + name + " Value",
            name
          ));
        foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Result) && (x.Type == ValueNameType.Int)).Select(x => x.Name).Distinct())
          filters.Add(new NameOrdinalComparisonIntFilter(
            typeof(IntValueFilter).AssemblyQualifiedName,
            "Result " + name + " Value",
            name
          ));
        foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Result) && (x.Type == ValueNameType.Long)).Select(x => x.Name).Distinct())
          filters.Add(new NameOrdinalComparisonLongFilter(
            typeof(LongValueFilter).AssemblyQualifiedName,
            "Result " + name + " Value",
            name
          ));
        foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Result) && (x.Type == ValueNameType.TimeSpan)).Select(x => x.Name).Distinct())
          filters.Add(new NameOrdinalComparisonTimeSpanFilter(
            typeof(TimeSpanValueFilter).AssemblyQualifiedName,
            "Result " + name + " Value",
            name
          ));
        foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Result) && (x.Type == ValueNameType.Float)).Select(x => x.Name).Distinct())
          filters.Add(new NameOrdinalComparisonFloatFilter(
            typeof(FloatValueFilter).AssemblyQualifiedName,
            "Result " + name + " Value",
            name
          ));
        foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Result) && (x.Type == ValueNameType.Double)).Select(x => x.Name).Distinct())
          filters.Add(new NameOrdinalComparisonDoubleFilter(
            typeof(DoubleValueFilter).AssemblyQualifiedName,
            "Result " + name + " Value",
            name
          ));
        foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Result) && (x.Type == ValueNameType.Percent)).Select(x => x.Name).Distinct())
          filters.Add(new NameOrdinalComparisonPercentFilter(
            typeof(PercentValueFilter).AssemblyQualifiedName,
            "Result " + name + " Value",
            name
          ));
        foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Result) && (x.Type == ValueNameType.String)).Select(x => x.Name).Distinct())
          filters.Add(new NameStringComparisonFilter(
            typeof(StringValueFilter).AssemblyQualifiedName,
            "Result " + name + " Value",
            name
          ));
        foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Result) && (x.Type == ValueNameType.Binary)).Select(x => x.Name).Distinct())
          filters.Add(new NameEqualityComparisonByteArrayFilter(
            typeof(BinaryValueFilter).AssemblyQualifiedName,
            "Result " + name + " Value",
            name
          ));
        #endregion

        #region Algorithm Filters
        filters.Add(new StringComparisonAvailableValuesFilter(
          typeof(AlgorithmNameFilter).AssemblyQualifiedName,
          "Algorithm Name",
          okb.Algorithms.Select(x => x.Name).Distinct().ToArray()
        ));
        filters.Add(new StringComparisonAvailableValuesFilter(
          typeof(AlgorithmClassNameFilter).AssemblyQualifiedName,
          "Algorithm Class Name",
          okb.AlgorithmClasses.Select(x => x.Name).Distinct().ToArray()
        ));
        filters.Add(new StringComparisonAvailableValuesFilter(
          typeof(AlgorithmPlatformNameFilter).AssemblyQualifiedName,
          "Algorithm Platform Name",
          okb.Platforms.Select(x => x.Name).Distinct().ToArray()
        ));
        filters.Add(new StringComparisonAvailableValuesFilter(
          typeof(AlgorithmDataTypeNameFilter).AssemblyQualifiedName,
          "Algorithm Data Type Name",
          okb.Algorithms.Select(x => x.DataType.Name).Distinct().ToArray()
        ));
        #endregion

        #region Problem Filters
        filters.Add(new StringComparisonAvailableValuesFilter(
          typeof(ProblemNameFilter).AssemblyQualifiedName,
          "Problem Name",
          okb.Problems.Select(x => x.Name).Distinct().ToArray()
        ));
        filters.Add(new StringComparisonAvailableValuesFilter(
          typeof(ProblemClassNameFilter).AssemblyQualifiedName,
          "Problem Class Name",
          okb.ProblemClasses.Select(x => x.Name).Distinct().ToArray()
        ));
        filters.Add(new StringComparisonAvailableValuesFilter(
          typeof(ProblemPlatformNameFilter).AssemblyQualifiedName,
          "Problem Platform Name",
          okb.Platforms.Select(x => x.Name).Distinct().ToArray()
        ));
        filters.Add(new StringComparisonAvailableValuesFilter(
          typeof(ProblemDataTypeNameFilter).AssemblyQualifiedName,
          "Problem Data Type Name",
          okb.Problems.Select(x => x.DataType.Name).Distinct().ToArray()
        ));
        #endregion

        #region Combined Filters
        filters.Add(new CombinedFilter(typeof(AndFilter).AssemblyQualifiedName, "AND", BooleanOperation.And));
        filters.Add(new CombinedFilter(typeof(OrFilter).AssemblyQualifiedName, "OR", BooleanOperation.Or));
        #endregion
      }
      return filters.OrderBy(x => x.Label);
    }
Beispiel #25
0
 public IEnumerable<long> GetRunIds(Filter filter) {
   using (OKBDataContext okb = new OKBDataContext()) {
     return FilterRuns(okb.Runs, filter, okb).Select(x => x.Id).ToArray();
   }
 }
        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.FirstOrDefault(x => (x.Name == name) && (x.Category == category) && (x.Type == type));

            if (entity == null)
            {
                entity = new DA.ValueName()
                {
                    Id = 0, Name = name, Category = category, Type = type
                }
            }
            ;
            return(entity);
        }
Beispiel #27
0
    private List<DataAccess.Run> FilterUnauthorizedRuns(List<DataAccess.Run> runs, OKBDataContext okb) {
      List<DataAccess.Run> results = new List<DataAccess.Run>();

      if (roleVerifier.IsInRole(OKBRoles.OKBAdministrator)) {
        results.AddRange(runs);
      } else {
        foreach (DataAccess.Run r in runs) {
          if (IsAuthorizedForAlgorithm(r.AlgorithmId, okb) && IsAuthorizedForProblem(r.ProblemId, okb)) {
            results.Add(r);
          }
        }
      }
      return results;
    }
        public static DA.SingleObjectiveSolution ToEntity(DT.SingleObjectiveSolution source, byte[] data, DA.OKBDataContext okb)
        {
            var sol = okb.SingleObjectiveSolutions.SingleOrDefault(x => x.Id == source.Id) ?? new DA.SingleObjectiveSolution()
            {
                ProblemId = source.ProblemId,
                RunId     = source.RunId,
                Quality   = source.Quality
            };

            if (source.DataType != null)
            {
                sol.DataType = ToEntity(source.DataType, okb);
            }
            if (data != null && data.Length > 0)
            {
                byte[] hash;
                using (var sha1 = SHA1.Create()) {
                    hash = sha1.ComputeHash(data);
                }
                sol.BinaryData = new DA.BinaryData()
                {
                    Data = data,
                    Hash = hash
                };
            }
            return(sol);
        }
Beispiel #29
0
 public IEnumerable<DataTransfer.ValueName> GetValueNames() {
   using (OKBDataContext okb = new OKBDataContext()) {
     return okb.ValueNames.Select(x => Convert.ToDto(x)).ToArray();
   }
 }
Beispiel #30
0
    private List<DataAccess.Run> FilterRuns(IQueryable<DataAccess.Run> runs, Filter filter, OKBDataContext okb) {
      IFilter f = (IFilter)Activator.CreateInstance(Type.GetType(filter.FilterTypeName), filter);

      var query = runs.Where(f.Expression);
      List<DataAccess.Run> results = new List<DataAccess.Run>();

      if (roleVerifier.IsInRole(OKBRoles.OKBAdministrator)) {
        results.AddRange(query);
      } else {
        foreach (DataAccess.Run r in query) {
          if (IsAuthorizedForAlgorithm(r.AlgorithmId, okb) && IsAuthorizedForProblem(r.ProblemId, okb)) {
            results.Add(r);
          }
        }
      }
      return results;
    }
Beispiel #31
0
    private bool IsAuthorizedForAlgorithm(long algorithmId, OKBDataContext okb) {
      var algUsers = okb.AlgorithmUsers.Where(x => x.AlgorithmId == algorithmId).Select(x => x.UserGroupId).ToList();

      if (algUsers.Count == 0 || userManager.VerifyUser(userManager.CurrentUserId, algUsers)) {
        return true;
      }
      return false;
    }
    public void AddRun(DataTransfer.Run run) {
      roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser);

      using (OKBDataContext okb = new OKBDataContext()) {
        DataAccess.Run entity = Convert.ToEntity(run, okb);
        okb.Runs.InsertOnSubmit(entity);
        okb.SubmitChanges();
      }
    }
Beispiel #33
0
 public long GetNumberOfRuns(Filter filter) {
   using (OKBDataContext okb = new OKBDataContext()) {
     return FilterRuns(okb.Runs, filter, okb).LongCount();
   }
 }