/// <summary> /// Finds the concern element with the specified path. /// </summary> /// <param name="cc">The configcontainer with all the concerns.</param> /// <param name="concernFile">The full path of the concern to find.</param> /// <param name="newConcern">if set to <see langword="true"/> then the concern is new since the last build.</param> /// <returns>returns <see langword="null"/> when the concern is not in the list or a <see cref="T:ConcernElement">ConcernElement</see> for the concern file.</returns> private ConcernElement FindConcernElement(ConfigurationContainer cc, string concernFile, out bool newConcern) { string basePath = Path.GetDirectoryName(concernFile); string filename = Path.GetFileName(concernFile); string fullPath = Path.Combine(basePath, filename); ConcernElement ce = cc.Concerns.Find(delegate(ConcernElement e) { return(e.FullPath.Equals(fullPath)); }); if (ce == null) { // create a new ConcernElement ce = new ConcernElement(); ce.PathName = basePath; ce.FileName = filename; ce.Timestamp = File.GetLastWriteTime(concernFile).Ticks; _concernsDirty = true; newConcern = true; } else { newConcern = false; } return(ce); }
public void FullPathTest() { ConcernElement target = new ConcernElement(); string val = null; // TODO: Assign to an appropriate value for the property Assert.AreEqual(val, target.FullPath, "Composestar.StarLight.Entities.Concerns.ConcernElement.FullPath was not set corre" + "ctly."); Assert.Inconclusive("Verify the correctness of this test method."); }
public void TimestampTest() { ConcernElement target = new ConcernElement(); long val = 0; // TODO: Assign to an appropriate value for the property target.Timestamp = val; Assert.AreEqual(val, target.Timestamp, "Composestar.StarLight.Entities.Concerns.ConcernElement.Timestamp was not set corr" + "ectly."); Assert.Inconclusive("Verify the correctness of this test method."); }
/// <summary> /// When overridden in a derived class, executes the task. /// </summary> /// <returns> /// true if the task successfully executed; otherwise, false. /// </returns> public override bool Execute() { base.Execute(); List <string> refTypes = new List <string>(); Stopwatch sw = Stopwatch.StartNew(); try { // Open DB Log.LogMessageFromResources(MessageImportance.Low, "OpenDatabase", _repositoryFileName); IEntitiesAccessor entitiesAccessor = EntitiesAccessor.Instance; ConfigurationContainer configContainer = entitiesAccessor.LoadConfiguration(_repositoryFileName); // Create a list with the new concerns List <ConcernElement> concernsToAdd = new List <ConcernElement>(); // Parse all concern files and add to the database foreach (ITaskItem item in _concernFiles) { string concernFile = item.ToString(); bool newConcern; ConcernElement ce = FindConcernElement(configContainer, concernFile, out newConcern); // Do a time check, if new or change, run the parser and store the data if (newConcern || File.GetLastWriteTime(concernFile).Ticks > ce.Timestamp) { Log.LogMessageFromResources("ParsingConcernFile", concernFile); // File is changed, we might not have the correct data ICpsParser parser = new CpsFileParserEx(concernFile); // Parse the concern file parser.Parse(); // Indicate if there are any outputfilters ce.HasOutputFilters = parser.HasOutputFilters; // Store the embedded code (if any) ce.EmbeddedFileName = StoreEmbeddedCode(concernFile, parser.EmbeddedCode); // Add the referenced types ce.ReferencedTypes.AddRange(parser.ReferencedTypes); // Update timestamp ce.Timestamp = File.GetLastWriteTime(concernFile).Ticks; // Indicate that the concerns are most likely dirty _concernsDirty = true; } else { Log.LogMessageFromResources("AddingConcernFile", concernFile); } if (!string.IsNullOrEmpty(ce.EmbeddedFileName)) { _extraSources.Add(new TaskItem(ce.EmbeddedFileName)); } _hasOutputFilters |= ce.HasOutputFilters; refTypes.AddRange(ce.ReferencedTypes); concernsToAdd.Add(ce); } sw.Stop(); Log.LogMessageFromResources("FoundReferenceType", refTypes.Count, _concernFiles.Length, sw.Elapsed.TotalSeconds); // Pass all the referenced types back to msbuild if (refTypes != null && refTypes.Count > 0) { int index = 0; _referencedTypes = new ITaskItem[refTypes.Count]; foreach (String type in refTypes) { _referencedTypes[index] = new TaskItem(type); index++; } } // Save the configContainer configContainer.Concerns = concernsToAdd; entitiesAccessor.SaveConfiguration(_repositoryFileName, configContainer); } catch (CpsParserException ex) { Log.LogErrorFromException(ex, false); } catch (FileNotFoundException ex) { Log.LogErrorFromException(ex, false); } return(!Log.HasLoggedErrors); }