/// <summary> /// Add the data to the IfcTask object /// </summary> /// <param name="row">COBieJobRow holding the data</param> private void AddJob(COBieJobRow row) { IEnumerable<IfcTypeObject> ifcTypeObjects = Enumerable.Empty<IfcTypeObject>(); IfcTask ifcTask = null; //get the objects in the typeName cell if (ValidateString(row.TypeName)) { List<string> typeNames = SplitString(row.TypeName, ':'); ifcTypeObjects = IfcTypeObjects.Where(to => typeNames.Contains(to.Name.ToString().Trim())); } //if merging check for existing task if (XBimContext.IsMerge) { string taskNo = string.Empty; //get the task ID if (ValidateString(row.TaskNumber)) taskNo = row.TaskNumber; //see if task matches name and task number ifcTask = CheckIfObjExistOnMerge<IfcTask>(row.Name).Where(task => task.TaskId == taskNo).FirstOrDefault(); if (ifcTask != null) { IfcRelAssignsToProcess processRel = Model.Instances.Where<IfcRelAssignsToProcess>(rd => rd.RelatingProcess == ifcTask).FirstOrDefault(); int matchCount = ifcTypeObjects.Count(to => processRel.RelatedObjects.Contains(to)); if (matchCount == ifcTypeObjects.Count()) //task IfcRelAssignsToProcess object hold the correct number of ifcTypeObjects objects so consider a match return; //consider a match so return } } //no match on task ifcTask = Model.Instances.New<IfcTask>(); //Add Created By, Created On and ExtSystem to Owner History. SetUserHistory(ifcTask, row.ExtSystem, row.CreatedBy, row.CreatedOn); //using statement will set the Model.OwnerHistoryAddObject to ifcConstructionEquipmentResource.OwnerHistory as OwnerHistoryAddObject is used upon any property changes, //then swaps the original OwnerHistoryAddObject back in the dispose, so set any properties within the using statement using (COBieXBimEditScope context = new COBieXBimEditScope(Model, ifcTask.OwnerHistory)) { //Add Name if (ValidateString(row.Name)) ifcTask.Name = row.Name; //Add Category if (ValidateString(row.Category)) ifcTask.ObjectType = row.Category; //AddStatus if (ValidateString(row.Status)) ifcTask.Status = row.Status; //Add Type Relationship if (ifcTypeObjects.Any()) { SetRelAssignsToProcess(ifcTask, ifcTypeObjects); } //Add GlobalId AddGlobalId(row.ExtIdentifier, ifcTask); //add Description if (ValidateString(row.Description)) ifcTask.Description = row.Description; //Add Duration and duration Unit if (ValidateString(row.Duration)) { IfcPropertySingleValue ifcPropertySingleValue = AddPropertySingleValue(ifcTask, "Pset_Job_COBie", "Job Properties From COBie", "TaskDuration", "Task Duration", new IfcReal(row.Duration)); //DurationUnit if (ValidateString(row.DurationUnit)) ifcPropertySingleValue.Unit = GetDurationUnit(row.DurationUnit); } //Add start time and start unit if (ValidateString(row.Start)) { IfcPropertySingleValue ifcPropertySingleValue = AddPropertySingleValue(ifcTask, "Pset_Job_COBie", null, "TaskStartDate", "Task Start Date", new IfcText(row.Start)); //TaskStartUnit if (ValidateString(row.TaskStartUnit)) ifcPropertySingleValue.Unit = GetDurationUnit(row.TaskStartUnit); } //Add frequency and frequency unit if (ValidateString(row.Frequency)) { IfcPropertySingleValue ifcPropertySingleValue = AddPropertySingleValue(ifcTask, "Pset_Job_COBie", null, "TaskInterval", "Task Interval", new IfcReal(row.Frequency)); //TaskStartUnit if (ValidateString(row.FrequencyUnit)) ifcPropertySingleValue.Unit = GetDurationUnit(row.FrequencyUnit); } //Add Task ID if (ValidateString(row.TaskNumber)) ifcTask.TaskId = row.TaskNumber; //Add Priors, done in another loop see above //Add Resource names if (ValidateString(row.ResourceNames)) { List<string> Resources = row.ResourceNames.Split(',').ToList<string>(); //did dangerous using , as ',' as user can easily place out of sequence. for (int i = 0; i < Resources.Count; i++) { Resources[i] = Resources[i].ToLower().Trim().Replace(".", string.Empty); //remove full stop } IEnumerable<IfcConstructionEquipmentResource> ifcConstructionEquipmentResource = IfcConstructionEquipmentResources.Where(cer => Resources.Contains(cer.Name.ToString().ToLower().Trim().Replace(".", string.Empty))); if (ifcConstructionEquipmentResource != null) SetRelAssignsToProcess(ifcTask, ifcConstructionEquipmentResource); } } }
/// <summary> /// set up IfcRelSequence for the task /// </summary> /// <param name="row">COBieJobRow holding the data</param> private void SetPriors(COBieJobRow row) { IEnumerable<IfcTask> ifcTaskFound = IfcTasks.Where(task => task.Name == row.Name && task.TaskId == row.TaskNumber); if (ifcTaskFound.Count() == 1) //should equal one { IfcTask ifcTask = ifcTaskFound.First(); if (ValidateString(row.Priors)) { string priors = row.Priors.ToString(); char splitKey = GetSplitChar(priors); string[] priorsArray = row.Priors.ToString().Split(splitKey); foreach (string prior in priorsArray) { string name = row.Name.ToLower().Trim(); string testName = prior.ToLower().Trim(); IEnumerable<IfcTask> ifcTaskRelating = IfcTasks.Where(task => (ifcTask.EntityLabel != task.EntityLabel) && (task.TaskId.ToString().ToLower().Trim() == testName) && (task.Name.ToString().ToLower().Trim() == name)); List<IfcTask> ifcTaskRelatingTasks = ifcTaskRelating.ToList(); //avoids crash of foreach loop, Steve to fix then this can be removed foreach (IfcTask ifcTaskitem in ifcTaskRelatingTasks) { IfcRelSequence relSequence = Model.Instances.New<IfcRelSequence>(); relSequence.RelatedProcess = ifcTask; relSequence.RelatingProcess = ifcTaskitem; } } } } //throw new Exception("COBieXBimJob.SetPriors(): did not find a single task matching name and task number"); }