protected int GetIdFor(IClassifiable entity, string name) { var ids = relationService.GetRelatedIds(entity, RelationDirection.Forward, relationNode); var metricsid = metricsRepo.FindIdByNameAndRelationIds(name, ids.Where(t => t.Name == MetricsEntity.OBJECT_NAME).Select(t => t.Id).ToArray()); return(metricsid); }
public bool AddValueIfChanged(IClassifiable entity, string name, decimal value, DateTime at, string descr = null) { var metricsid = GetIdFor(entity, name); if (metricsid == 0) { var metrics = CreateMetrics(name, entity, descr); metrics.AddEntry(value, at); metricsRepo.Update(metrics); return(true); } var dbVal = metricsEntryRepo.GetValueAt(metricsid, at); if (dbVal != value) { var metrics = GetOrCreateFor(entity, name, descr); var me = new MetricsEntryEntity() { Metrics = metrics, RecordDate = at, Value = value }; metricsEntryRepo.Save(me); return(true); } return(false); }
public bool AddValueIfChanged(IClassifiable entity, string name, decimal value, DateTime at, string descr = null) { var metricsid = GetIdFor(entity, name); if (metricsid == 0) { var metrics = CreateMetrics(name, entity, descr); metrics.AddEntry(value, at); metricsRepo.Update(metrics); return true; } var dbVal = metricsEntryRepo.GetValueAt(metricsid, at); if (dbVal != value) { var metrics = GetOrCreateFor(entity, name, descr); var me = new MetricsEntryEntity() { Metrics = metrics, RecordDate = at, Value = value }; metricsEntryRepo.Save(me); return true; } return false; }
protected void RelateInternal(IClassifiable relatable, IClassifiable related, RelationDirection direction, TaxonomyNode type) { var currentRelation = GetRelation(relatable, related, type); if (direction == RelationDirection.Undefined) { if (currentRelation != null) { relationRepo.Delete(currentRelation); } //do nothing if direction is undefined } else { if (currentRelation == null) { currentRelation = RelationEntity.Create(relatable, related, type == null?null:type.entity, direction); relationRepo.Save(currentRelation); } else { currentRelation.Direction = direction; relationRepo.Update(currentRelation); } } }
public void SaveFor(IClassifiable entity, SettingsEntity settings) { if (settings != null) { settingsRepo.SaveOrUpdateFor(entity, settings); } }
public void SetRelation(IClassifiable relatable, IClassifiable related, RelationDirection direction = RelationDirection.Undefined, TaxonomyNode type = null) { foreach (var relEntity in relationRepo.GetRelated(relatable, direction, type == null ? null : type.entity)) { relationRepo.Delete(relEntity); } RelateInternal(relatable, related, direction, type); }
public void EnsureRelation(IClassifiable entity, MetricsEntity metrics) { if (!relationService.IsRelated(entity, metrics, relationNode)) { relationService.RemoveRelations(metrics, relationNode); relationService.AddRelation(entity, metrics, RelationDirection.Forward, relationNode); } }
public void DeleteFor(IClassifiable entity) { lock (locker) { var dbMetrics = GetFor(entity); metricsRepo.DeleteAll(dbMetrics); } }
public void DeleteFor(IClassifiable entity) { var dbSetting = GetOneFor(entity); if (dbSetting != null) { Delete(dbSetting); } }
public decimal GetValueAt(IClassifiable entity, string name, DateTime at) { var metricsid = GetIdFor(entity, name); if (metricsid == 0) { return 0; } return metricsEntryRepo.GetValueAt(metricsid, at); }
public MetricsEntity CreateMetrics(string name, IClassifiable entity, string descr) { MetricsEntity metrics; metrics = new MetricsEntity(name, descr ?? String.Format("for {0}({1})", entity.ObjectName, entity.Id)); metricsRepo.Save(metrics); relationService.AddRelation(entity, metrics, RelationDirection.Forward, relationNode); return(metrics); }
public void DeclassifyAll(IClassifiable classifiable) { var related = relationSrv.GetRelated <TaxonEntity>(classifiable, RelationDirection.Both); foreach (var taxonEntity in related) { relationSrv.RemoveRelation(classifiable, taxonEntity); } }
public IList <RelationEntity> GetAllRelationsFor(IClassifiable classifiable) { using (var wu = SessionManager.WorkUnitFor(this, DbWorkUnitType.Read)) { var ret = this.AsQueryable(wu.Session) .Where(x => (x.ObjectName == classifiable.ObjectName && x.ObjectID == classifiable.Id) || (x.RelatedObjectName == classifiable.ObjectName && x.RelatedObjectID == classifiable.Id)); return(ret.ToList()); } }
public decimal GetValueAt(IClassifiable entity, string name, DateTime at) { var metricsid = GetIdFor(entity, name); if (metricsid == 0) { return(0); } return(metricsEntryRepo.GetValueAt(metricsid, at)); }
public void AddClassifiable(IClassifiable classifiable) { if (_allClassifiables.ExistsById(classifiable.Id)) { return; } _allClassifiables.Add(classifiable); HasChanged = true; }
private void moveNewSimulationUnderOldClassification(IProject project, IClassifiable oldClassifiable) { if (oldClassifiable == null) { return; } project.AddClassifiable(new ClassifiableSimulation { Subject = _newBuildingBlock, Parent = oldClassifiable.Parent }); }
public RelationEntity GetRelation(IClassifiable relatable, IClassifiable related, TaxonEntity type = null) { using (var wu = SessionManager.WorkUnitFor(this, DbWorkUnitType.Read)) { return(AsQueryable(wu.Session) .Where(x => x.RelatedObjectName == related.ObjectName && x.RelatedObjectID == related.Id) .Where(x => x.ObjectName == relatable.ObjectName && x.ObjectID == relatable.Id) .Where(x => x.Type == type) .FirstOrDefault()); } }
public int RemoveRelations(IClassifiable relatable, TaxonomyNode type = null) { var rels = relationRepo.GetAllRelationsFor(relatable).AsEnumerable(); if (type != null) { rels = rels.Where(r => r.Type != null && r.Type.Id == type.entity.Id); } relationRepo.DeleteAll(rels); return(rels.Count()); }
public static RelationEntity Create(IClassifiable relatable, IClassifiable related, TaxonEntity type = null, RelationDirection direction = RelationDirection.Undefined) { return new RelationEntity() { Type = type, Direction = direction, ObjectName = relatable.ObjectName, ObjectID = relatable.Id, RelatedObjectName = related.ObjectName, RelatedObjectID = related.Id, }; }
public static RelationEntity Create(IClassifiable relatable, IClassifiable related, TaxonEntity type = null, RelationDirection direction = RelationDirection.Undefined) { return(new RelationEntity() { Type = type, Direction = direction, ObjectName = relatable.ObjectName, ObjectID = relatable.Id, RelatedObjectName = related.ObjectName, RelatedObjectID = related.Id, }); }
public MetricsEntity GetOrCreateFor(IClassifiable entity, string name = null, string descr = null) { lock (locker) { name = name ?? "default"; var metrics = GetFor(entity, name); if (metrics == null) { metrics = CreateMetrics(name, entity, descr); } return(metrics); } }
public SettingsEntity GetOrCreate(IClassifiable entity) { var dbSetting = GetOneFor(entity); if (dbSetting != null) { return(dbSetting); } return(new SettingsEntity() { Name = "For " + entity }); }
public IList <RelationEntity> GetByRelated(IClassifiable classifiable, RelationDirection direction = RelationDirection.Undefined, TaxonEntity type = null) { if (classifiable == null) { log.Warn("GetByRelated null request"); return(null); } using (var wu = SessionManager.WorkUnitFor(this, DbWorkUnitType.Read)) { var criteria = CreateGetByRelatedCriteria(wu, classifiable, direction, type); return(criteria.List <RelationEntity>()); } }
public MetricsEntity GetOrCreateFor(IClassifiable entity, string name = null, string descr = null) { lock (locker) { name = name ?? "default"; var metrics = GetFor(entity, name); if (metrics == null) { metrics = CreateMetrics(name, entity, descr); } return metrics; } }
protected override void Context() { base.Context(); _addedNodes = new List <ITreeNode>(); _classifiable = _project.AllClassifiables.FindById(_simulation.Id); _classification = new Classification(); _classifiable.Parent = _classification; _project.AddClassification(_classification); _classificationNode = new ClassificationNode(_classification); A.CallTo(() => _view.TreeView.NodeById(_classification.Id)).Returns(_classificationNode); A.CallTo(() => _view.AddNode(A <ITreeNode> ._)).Invokes(x => _addedNodes.Add(x.GetArgument <ITreeNode>(0))); _project.AddObservedData(new DataRepository(_usedObservedData.Id)); }
private IEnumerable <object> GetListEntriesViewModel(IClassifiable classifiable) { var metrics = _metricsService.GetFor(classifiable); return(metrics.Select( d => new { Name = d.Name, Value = d.GetLastValueOrDefault(), Changes = d.Entries.Count, Values = SparkleValues(d), LastChange = d.GetLastChange() }).Where(d => d.Changes > 0)); }
private ICriteria CreateGetByRelatedCriteria(DbWorkUnit wu, IClassifiable classifiable, RelationDirection direction = RelationDirection.Undefined, TaxonEntity type = null) { var criteria = wu.Session.CreateCriteria <RelationEntity>() .Add(Restrictions.Eq("RelatedObjectName", classifiable.ObjectName)) .Add(Restrictions.Eq("RelatedObjectID", classifiable.Id)); if (type != null) { criteria.Add(Restrictions.Eq("Type", type)); } if (direction != RelationDirection.Undefined) { criteria.Add(Restrictions.Eq("Direction", (int)direction)); } return(criteria); }
public IList <RelatedIdsResult> GetByRelatedIds(IClassifiable classifiable, RelationDirection direction = RelationDirection.Undefined, TaxonEntity type = null) { if (classifiable == null) { log.Warn("GetByRelatedIds null request"); return(null); } using (var wu = SessionManager.WorkUnitFor(this, DbWorkUnitType.Read)) { var criteria = CreateGetByRelatedCriteria(wu, classifiable, direction, type) .SetProjection(Projections.ProjectionList() .Add(Projections.Property("ObjectID"), "Id") .Add(Projections.Property("ObjectName"), "Name")) .SetResultTransformer(new AliasToBeanResultTransformer(typeof(RelatedIdsResult))); return(criteria.List <RelatedIdsResult>()); } }
public IList <T> GetByRelated <T>(IClassifiable classifiable, RelationDirection direction = RelationDirection.Undefined, TaxonEntity type = null) where T : Entity, IClassifiable { List <T> ret = new List <T>(); using (var repo = new Repository <T>(context, log)) { var idList = GetByRelated(classifiable, direction, type).Select(y => y.ObjectID).ToList(); if (idList.Count() > 0) { using (var wu = SessionManager.WorkUnitFor(this, DbWorkUnitType.Read)) { ret = repo.AsQueryable(wu.Session).Where(x => idList.Contains(x.Id)).ToList(); } } ret.ForEach(x => repo.Evict(x)); } return(ret); }
//public override SettingsEntity Update(SettingsEntity entity) //{ // return base.Update(entity); //} //public override SettingsEntity Save(SettingsEntity entity) //{ // return base.Save(entity); //} //public override SettingsEntity SaveOrUpdate(SettingsEntity entity) //{ // return base.SaveOrUpdate(entity); //} public void SaveOrUpdateFor(IClassifiable entity, SettingsEntity setting) { var dbSetting = GetOneFor(entity); if (dbSetting != null) { if (dbSetting.Id != setting.Id) { throw new DataLayerException("Another setting is associated with object, shouldn't be there"); } Update(setting); } else { setting.Name = String.Format("for {0}({1})", entity.ObjectName, entity.Id); setting = Save(setting); relationService.SetRelation(entity, setting, RelationDirection.Forward, settingsRelation); } }
public ActivityLogEntity AddLog(string descriminator, ActivityLogLevel level = ActivityLogLevel.Info, string message = null, IClassifiable classifiable = null, object contract = null) { var entry = new ActivityLogEntity(); entry.Descriminator = descriminator; entry.Message = message; entry.Level = level; if(contract!=null)entry.SetValue(contract); if (classifiable != null) { entry.ClassifiableId = classifiable.Id; entry.ClassifiableName = classifiable.ObjectName; } entry = logRepo.Save(entry); InvokeOnNewLog(entry); return entry; }
public ActivityLogEntity AddLog(string descriminator, ActivityLogLevel level = ActivityLogLevel.Info, string message = null, IClassifiable classifiable = null, object contract = null) { var entry = new ActivityLogEntity(); entry.Descriminator = descriminator; entry.Message = message; entry.Level = level; if (contract != null) { entry.SetValue(contract); } if (classifiable != null) { entry.ClassifiableId = classifiable.Id; entry.ClassifiableName = classifiable.ObjectName; } entry = logRepo.Save(entry); InvokeOnNewLog(entry); return(entry); }
public void DeleteFor(IClassifiable entity) { settingsRepo.DeleteFor(entity); }
private IEnumerable<object> GetListEntriesViewModel(IClassifiable classifiable) { var metrics = _metricsService.GetFor(classifiable); return metrics.Select( d => new { Name = d.Name, Value = d.GetLastValueOrDefault(), Changes = d.Entries.Count, Values = SparkleValues(d), LastChange = d.GetLastChange() }).Where(d => d.Changes > 0); }
public void RemoveClassifiable(IClassifiable classifiable) { _allClassifiables.Remove(classifiable); }
public SettingsEntity GetFor(IClassifiable entity) { return(settingsRepo.GetOrCreate(entity)); }
protected int GetIdFor(IClassifiable entity, string name) { var ids = relationService.GetRelatedIds(entity, RelationDirection.Forward, relationNode); var metricsid = metricsRepo.FindIdByNameAndRelationIds(name, ids.Where(t => t.Name == MetricsEntity.OBJECT_NAME).Select(t => t.Id).ToArray()); return metricsid; }
public IList<MetricsEntity> GetFor(IClassifiable entity) { return relationService.GetRelated<MetricsEntity>(entity, RelationDirection.Forward, relationNode); }
public void EnsureRelation(IClassifiable entity, MetricsEntity metrics) { if(!relationService.IsRelated(entity, metrics, relationNode)) { relationService.RemoveRelations(metrics, relationNode); relationService.AddRelation(entity, metrics, RelationDirection.Forward, relationNode); } }
public MetricsEntity CreateMetrics(string name, IClassifiable entity, string descr) { MetricsEntity metrics; metrics = new MetricsEntity(name, descr ?? String.Format("for {0}({1})", entity.ObjectName, entity.Id)); metricsRepo.Save(metrics); relationService.AddRelation(entity, metrics, RelationDirection.Forward, relationNode); return metrics; }
public SettingsEntity GetFor(IClassifiable entity) { return settingsRepo.GetOrCreate(entity); }