public bool Remove(int id) { if (id < 1) { throw new ArgumentException("Неверное значение.", nameof(id)); } KeyFeature keyFeature = GetById(id); if (keyFeature == null) { return(false); } var keyFeatureClient = db.KeyFeatureClients .Where(kfc => kfc.IdKeyFeature == id) .ToList(); db.KeyFeatures.Remove(keyFeature); db.KeyFeatureClients.RemoveRange(keyFeatureClient); db.SaveChanges(); return(true); }
private KeyFeature CreateNew(int id) { KeyFeature kf = CreateNew(); kf.Id = id; return(kf); }
public bool Add(IEnumerable <ModelViewKeyFeature> keyFeat, out string error) { if (keyFeat == null) { throw new ArgumentNullException(nameof(keyFeat)); } error = string.Empty; foreach (var item in keyFeat) { var keyFeature = new KeyFeature() { IdFeature = item.IdFeature, IdHaspKey = item.IdKey, StartDate = item.StartDate ?? DateTime.MinValue, EndDate = item.EndDate ?? DateTime.MinValue, }; if (!this.keyFeatureLogic.Save(keyFeature)) { error += errorAdd + item.Feature + '\n'; } } return(string.IsNullOrEmpty(error)); }
public static VectorPointBase ToVectorPoint(this KeyFeature data, IEmbeddingModel model, int id) { if (model is Ip2VecModel || model is NeVeModel) { return(new DoubleVectorPoint { TimeTick = DateTime.Parse(data.Timestamp).SecondsTick(), Vector = data.VectorByModel(model), Id = id }); } else if (model is StringEmbeddingModel) { return(new StringVectorPoint { TimeTick = DateTime.Parse(data.Timestamp).SecondsTick(), Vector = ((StringEmbeddingModel)model).GetStringVector(data), Id = id }); } else { throw new InvalidCastException(string.Format("Unknown type of {0}", model.GetType())); } }
public static double[] VectorByModel(this KeyFeature x, IEmbeddingModel model) { return(model.LookupVectorByWord(x.SourceIp) .Zip(model.LookupVectorByWord(x.TargetIp), Sum) .Zip(model.LookupVectorByWord(x.TargetPort), Sum) .Zip(model.LookupVectorByWord(x.Protocol), Sum) .ToArray()); }
private KeyFeature CreateNew(int id, int idHaspKey, int idFeature) { KeyFeature kf = CreateNew(id); kf.IdHaspKey = idHaspKey; kf.IdFeature = idFeature; return(kf); }
public string[] GetStringVector(KeyFeature keyFeature) { return(new string[] { keyFeature.ThreatName, keyFeature.SourceIp, keyFeature.TargetIp, keyFeature.TargetPort, keyFeature.Protocol }); }
private bool Validation(KeyFeature random, KeyFeature clustered) { return(random.ThreatName == clustered.ThreatName && random.SourceIp == random.SourceIp && random.TargetIp == random.TargetIp && random.SourcePort == random.SourcePort && random.TargetPort == random.TargetPort && random.Protocol == random.Protocol && random.Timestamp == random.Timestamp); }
/// <summary> /// Проверка на дубли связи ключ-фича. /// </summary> /// <param name="entity">Связь ключ-фича.</param> /// <returns>Результат проверки.</returns> public bool ContainsDB(KeyFeature entity) { var keyFeature = db.KeyFeatures .SingleOrDefault(x => x.IdHaspKey == entity.IdHaspKey && x.IdFeature == entity.IdFeature && x.StartDate == entity.StartDate && x.EndDate == entity.EndDate); return(keyFeature != null); }
public bool Update(KeyFeature entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } CheckArgument(entity); return(!keyFeatureDAO.ContainsDB(entity) ? keyFeatureDAO.Update(entity) : false); }
public Sentence(KeyFeature keyFeature) { ThreatName = keyFeature.ThreatName; SourceIp = keyFeature.SourceIp; SourcePort = keyFeature.SourcePort; TargetIp = keyFeature.TargetIp; TargetPort = keyFeature.TargetPort; Protocol = keyFeature.Protocol; Timestamp = keyFeature.Timestamp; Sid = keyFeature.Sid; }
public int Add(KeyFeature entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } var keyFeature = db.KeyFeatures.Add(entity); db.SaveChanges(); return(keyFeature.Id); }
public void GetByIdKeyFeature() { KeyFeature getById; KeyFeature kfExpected = CreateNew(1); using (var db = new EntitesContext()) { ClearTable.KeyFeatures(db); keyFeatureL = Get(db); keyFeatureL.Save(CreateNew()); getById = keyFeatureL.GetById(1); } Assert.AreEqual(getById, kfExpected); }
private void CheckArgument(KeyFeature entity) { if (entity.IdHaspKey < 1) { throw new ArgumentException(nameof(entity.IdHaspKey)); } if (entity.IdFeature < 1) { throw new ArgumentException(nameof(entity.IdFeature)); } if (entity.EndDate < entity.StartDate) { throw new ArgumentException(nameof(entity.EndDate) + ", " + nameof(entity.StartDate)); } }
public static string GetCsv(this KeyFeature item) { var array = new string[CsvOrdering.Count]; array[CsvOrdering[nameof(KeyFeature.Timestamp)]] = item.Timestamp.ToString(); array[CsvOrdering[nameof(KeyFeature.SourceIp)]] = item.SourceIp.ToString(); array[CsvOrdering[nameof(KeyFeature.SourcePort)]] = item.SourcePort.ToString(); array[CsvOrdering[nameof(KeyFeature.TargetIp)]] = item.TargetIp.ToString(); array[CsvOrdering[nameof(KeyFeature.TargetPort)]] = item.TargetPort.ToString(); array[CsvOrdering[nameof(KeyFeature.Protocol)]] = item.Protocol.ToString(); array[CsvOrdering[nameof(KeyFeature.ThreatName)]] = item.ThreatName.ToString(); array[CsvOrdering[nameof(KeyFeature.Sid)]] = item.Sid.ToString(); return(string.Join(Symbols.CSVSeparator.ToString(), array)); }
public void GetByIdKeyFeature() { KeyFeature getById; KeyFeature kfExpected = CreateNew(1); using (var db = new EntitesContext()) { ClearTable.KeyFeatures(db); kfDAO = new DbKeyFeatureDAO(db); kfDAO.Add(CreateNew()); getById = kfDAO.GetById(1); } Assert.AreEqual(getById, kfExpected); }
public void UpdateNoDBKeyFeature() { var kfNoDB = new KeyFeature { Id = 32, IdFeature = 3, IdHaspKey = 24, EndDate = date.AddDays(100), StartDate = date, }; using (var db = new EntitesContext()) { ClearTable.KeyFeatures(db); kfDAO = new DbKeyFeatureDAO(db); kfDAO.Add(CreateNew()); Assert.IsFalse(kfDAO.Update(kfNoDB)); } }
public bool Save(KeyFeature entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } CheckArgument(entity); int id; if (!keyFeatureDAO.ContainsDB(entity)) { id = keyFeatureDAO.Add(entity); } else { return(false); } return(id > 0); }
public bool Update(IEnumerable <ModelViewKeyFeature> keyFeat, out string error) { if (keyFeat == null) { throw new ArgumentNullException(nameof(keyFeat)); } error = string.Empty; var allFeatureAtKey = GetAllFeatureAtKey(keyFeat.First().IdKey); foreach (var item in keyFeat) { if (allFeatureAtKey .Any(x => x.IdKeyFeature == item.IdKeyFeature && x.Selected == item.Selected && x.EndDate == item.EndDate && x.StartDate == item.StartDate)) { continue; } var keyFeature = new KeyFeature() { Id = item.IdKeyFeature, IdFeature = item.IdFeature, IdHaspKey = item.IdKey, StartDate = (DateTime)item.StartDate, EndDate = (DateTime)item.EndDate, }; if (!this.keyFeatureLogic.Update(keyFeature)) { error += errorUpdate + item.Feature.Name + '\n'; } } return(string.IsNullOrEmpty(error)); }
public bool Update(KeyFeature entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } var keyFeature = GetById(entity.Id); if (keyFeature == null) { return(false); } keyFeature.IdFeature = entity.IdFeature; keyFeature.IdHaspKey = entity.IdHaspKey; keyFeature.StartDate = entity.StartDate; keyFeature.EndDate = entity.EndDate; db.SaveChanges(); return(true); }
public void ErroneousArgumentSaveKeyFeature() { KeyFeature keyFeature = CreateNew(); using (var db = new EntitesContext()) { ClearTable.KeyFeatures(db); keyFeatureL = Get(db); keyFeature.IdFeature = 0; Assert.ThrowsException <ArgumentException>(() => keyFeatureL.Save(keyFeature)); keyFeature.IdFeature = -12; Assert.ThrowsException <ArgumentException>(() => keyFeatureL.Save(keyFeature)); keyFeature.IdFeature = 45; keyFeature.IdHaspKey = 0; Assert.ThrowsException <ArgumentException>(() => keyFeatureL.Save(keyFeature)); keyFeature.IdHaspKey = -12; Assert.ThrowsException <ArgumentException>(() => keyFeatureL.Save(keyFeature)); keyFeature.StartDate = keyFeature.EndDate.AddDays(-45); Assert.ThrowsException <ArgumentException>(() => keyFeatureL.Save(keyFeature)); } }