本文整理汇总了C#中ItemDictionary.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ItemDictionary.Add方法的具体用法?C# ItemDictionary.Add怎么用?C# ItemDictionary.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ItemDictionary
的用法示例。
在下文中一共展示了ItemDictionary.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SecondaryItemNotShadowedByPrimaryItem
public void SecondaryItemNotShadowedByPrimaryItem()
{
ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>();
table1.Add(new ProjectItemInstance(project, "i1", "a1", project.FullPath));
table1.Add(new ProjectItemInstance(project, "i2", "a%3b1", project.FullPath));
Lookup lookup = LookupHelpers.CreateLookup(table1);
Lookup.Scope enteredScope = lookup.EnterScope("x");
// Should return item from the secondary table.
Assert.Equal("a1", lookup.GetItems("i1").First().EvaluatedInclude);
Assert.Equal("a;1", lookup.GetItems("i2").First().EvaluatedInclude);
}
示例2: AddsWithDuplicateRemovalItemSpecsOnly
public void AddsWithDuplicateRemovalItemSpecsOnly()
{
ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
// One item in the project
ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>();
table1.Add(new ProjectItemInstance(project, "i1", "a1", project.FullPath));
// Add an existing duplicate
table1.Add(new ProjectItemInstance(project, "i1", "a1", project.FullPath));
Lookup lookup = LookupHelpers.CreateLookup(table1);
var scope = lookup.EnterScope("test");
// This one should not get added
ProjectItemInstance[] newItems = new ProjectItemInstance[]
{
new ProjectItemInstance(project, "i1", "a1", project.FullPath), // Should not get added
new ProjectItemInstance(project, "i1", "a2", project.FullPath), // Should get added
};
// Perform the addition
lookup.AddNewItemsOfItemType("i1", newItems, doNotAddDuplicates: true);
var group = lookup.GetItems("i1");
// We should have the original two duplicates plus one new addition.
Assert.Equal(3, group.Count);
// Only two of the items should have the 'a1' include.
Assert.Equal(2, group.Where(item => item.EvaluatedInclude == "a1").Count());
// And ensure the other item got added.
Assert.Equal(1, group.Where(item => item.EvaluatedInclude == "a2").Count());
scope.LeaveScope();
group = lookup.GetItems("i1");
// We should have the original two duplicates plus one new addition.
Assert.Equal(3, group.Count);
// Only two of the items should have the 'a1' include.
Assert.Equal(2, group.Where(item => item.EvaluatedInclude == "a1").Count());
// And ensure the other item got added.
Assert.Equal(1, group.Where(item => item.EvaluatedInclude == "a2").Count());
}
示例3: RemoveItemFromProjectPreviouslyModifiedAndGottenThroughGetItem
public void RemoveItemFromProjectPreviouslyModifiedAndGottenThroughGetItem()
{
ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
// Create some project state with an item with m=m1 and n=n1
ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>();
ProjectItemInstance item1 = new ProjectItemInstance(project, "i1", "a2", project.FullPath);
item1.SetMetadata("m", "m1");
table1.Add(item1);
Lookup lookup = LookupHelpers.CreateLookup(table1);
Lookup.Scope enteredScope = lookup.EnterScope("x");
// Make a modification to the item to be m=m2
Lookup.MetadataModifications newMetadata = new Lookup.MetadataModifications(keepOnlySpecified: false);
newMetadata.Add("m", "m2");
List<ProjectItemInstance> group = new List<ProjectItemInstance>();
group.Add(item1);
lookup.ModifyItems(item1.ItemType, group, newMetadata);
// Get the item (under the covers, it cloned it in order to apply the modification)
ICollection<ProjectItemInstance> group2 = lookup.GetItems(item1.ItemType);
Assert.Equal(1, group2.Count);
ProjectItemInstance item1b = group2.First();
// Remove the item
lookup.RemoveItem(item1b);
// There's now no items at all
ICollection<ProjectItemInstance> group3 = lookup.GetItems(item1.ItemType);
Assert.Equal(0, group3.Count);
// Leave scope
enteredScope.LeaveScope();
// And now none left in the project either
Assert.Equal(0, table1["i1"].Count);
}
示例4: ModifyItemInProjectPreviouslyModifiedAndGottenThroughGetItem
public void ModifyItemInProjectPreviouslyModifiedAndGottenThroughGetItem()
{
ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
// Create some project state with an item with m=m1 and n=n1
ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>();
ProjectItemInstance item1 = new ProjectItemInstance(project, "i1", "a2", project.FullPath);
item1.SetMetadata("m", "m1");
table1.Add(item1);
Lookup lookup = LookupHelpers.CreateLookup(table1);
Lookup.Scope enteredScope = lookup.EnterScope("x");
// Make a modification to the item to be m=m2
Lookup.MetadataModifications newMetadata = new Lookup.MetadataModifications(keepOnlySpecified: false);
newMetadata.Add("m", "m2");
List<ProjectItemInstance> group = new List<ProjectItemInstance>();
group.Add(item1);
lookup.ModifyItems(item1.ItemType, group, newMetadata);
// Get the item (under the covers, it cloned it in order to apply the modification)
ICollection<ProjectItemInstance> group2 = lookup.GetItems(item1.ItemType);
Assert.Equal(1, group2.Count);
ProjectItemInstance item1b = group2.First();
// Modify to m=m3
Lookup.MetadataModifications newMetadata2 = new Lookup.MetadataModifications(keepOnlySpecified: false);
newMetadata2.Add("m", "m3");
List<ProjectItemInstance> group3 = new List<ProjectItemInstance>();
group3.Add(item1b);
lookup.ModifyItems(item1b.ItemType, group3, newMetadata2);
// Modifications are visible
ICollection<ProjectItemInstance> group4 = lookup.GetItems(item1b.ItemType);
Assert.Equal(1, group4.Count);
Assert.Equal("m3", group4.First().GetMetadataValue("m"));
// Leave scope
enteredScope.LeaveScope();
// Still visible
ICollection<ProjectItemInstance> group5 = lookup.GetItems(item1b.ItemType);
Assert.Equal(1, group5.Count);
Assert.Equal("m3", group5.First().GetMetadataValue("m"));
// And the one in the project is changed
Assert.Equal("m3", item1.GetMetadataValue("m"));
}
示例5: ConditionedPropertyUpdateTests
public void ConditionedPropertyUpdateTests()
{
Parser p = new Parser();
ProjectInstance parentProject = new ProjectInstance(ProjectRootElement.Create());
ItemDictionary<ProjectItemInstance> itemBag = new ItemDictionary<ProjectItemInstance>();
itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "foo.cs", parentProject.FullPath));
itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "bar.cs", parentProject.FullPath));
itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "baz.cs", parentProject.FullPath));
Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(new PropertyDictionary<ProjectPropertyInstance>(), itemBag);
Dictionary<string, List<string>> conditionedProperties = new Dictionary<string, List<string>>();
ConditionEvaluator.IConditionEvaluationState state =
new ConditionEvaluator.ConditionEvaluationState<ProjectPropertyInstance, ProjectItemInstance>
(
String.Empty,
expander,
ExpanderOptions.ExpandAll,
conditionedProperties,
Environment.CurrentDirectory,
ElementLocation.EmptyLocation
);
List<string> properties = null;
AssertParseEvaluate(p, "'0' == '1'", expander, false, state);
Assert.IsTrue(conditionedProperties.Count == 0);
AssertParseEvaluate(p, "$(foo) == foo", expander, false, state);
Assert.IsTrue(conditionedProperties.Count == 1);
properties = conditionedProperties["foo"];
Assert.IsTrue(properties.Count == 1);
AssertParseEvaluate(p, "'$(foo)' != 'bar'", expander, true, state);
Assert.IsTrue(conditionedProperties.Count == 1);
properties = conditionedProperties["foo"];
Assert.IsTrue(properties.Count == 2);
AssertParseEvaluate(p, "'$(branch)|$(build)|$(platform)' == 'lab22dev|debug|x86'", expander, false, state);
Assert.IsTrue(conditionedProperties.Count == 4);
properties = conditionedProperties["foo"];
Assert.IsTrue(properties.Count == 2);
properties = conditionedProperties["branch"];
Assert.IsTrue(properties.Count == 1);
properties = conditionedProperties["build"];
Assert.IsTrue(properties.Count == 1);
properties = conditionedProperties["platform"];
Assert.IsTrue(properties.Count == 1);
AssertParseEvaluate(p, "'$(branch)|$(build)|$(platform)' == 'lab21|debug|x86'", expander, false, state);
Assert.IsTrue(conditionedProperties.Count == 4);
properties = conditionedProperties["foo"];
Assert.IsTrue(properties.Count == 2);
properties = conditionedProperties["branch"];
Assert.IsTrue(properties.Count == 2);
properties = conditionedProperties["build"];
Assert.IsTrue(properties.Count == 1);
properties = conditionedProperties["platform"];
Assert.IsTrue(properties.Count == 1);
AssertParseEvaluate(p, "'$(branch)|$(build)|$(platform)' == 'lab23|retail|ia64'", expander, false, state);
Assert.IsTrue(conditionedProperties.Count == 4);
properties = conditionedProperties["foo"];
Assert.IsTrue(properties.Count == 2);
properties = conditionedProperties["branch"];
Assert.IsTrue(properties.Count == 3);
properties = conditionedProperties["build"];
Assert.IsTrue(properties.Count == 2);
properties = conditionedProperties["platform"];
Assert.IsTrue(properties.Count == 2);
DumpDictionary(conditionedProperties);
}
示例6: GetSiblingsFile
public KeyValuePair<string, ItemDictionary<String, String>> GetSiblingsFile(String fileId, String sfilter, OrderBy orderBy, String ssubject, String searchText)
{
var filter = (FilterType)Convert.ToInt32(sfilter);
var subjectId = string.IsNullOrEmpty(ssubject) ? Guid.Empty : new Guid(ssubject);
using (var fileDao = GetFileDao())
using (var folderDao = GetFolderDao())
{
var file = fileDao.GetFile(fileId);
ErrorIf(file == null, FilesCommonResource.ErrorMassage_FileNotFound);
ErrorIf(!FileSecurity.CanRead(file), FilesCommonResource.ErrorMassage_SecurityException_ReadFile);
var folder = folderDao.GetFolder(file.FolderID);
ErrorIf(folder == null, FilesCommonResource.ErrorMassage_FolderNotFound);
ErrorIf(folder.RootFolderType == FolderType.TRASH, FilesCommonResource.ErrorMassage_ViewTrashItem);
var folderId = file.FolderID;
var entries = Enumerable.Empty<FileEntry>();
if (!FileSecurity.CanRead(folder) &&
folder.RootFolderType == FolderType.USER && !Equals(folder.RootFolderId, Global.FolderMy))
{
folderId = Global.FolderShare;
orderBy = new OrderBy(SortedByType.DateAndTime, false);
var shared = (IEnumerable<FileEntry>)FileSecurity.GetSharesForMe();
shared = EntryManager.FilterEntries(shared, filter, subjectId, searchText)
.Where(f => f is File &&
f.CreateBy != SecurityContext.CurrentAccount.ID && // don't show my files
f.RootFolderType == FolderType.USER); // don't show common files (common files can read)
entries = entries.Concat(shared);
}
else if (folder.FolderType == FolderType.BUNCH)
{
var path = folderDao.GetBunchObjectID(folder.RootFolderId);
var projectID = path.Split('/').Last();
if (String.IsNullOrEmpty(projectID))
{
folderId = Global.FolderMy;
entries = entries.Concat(new List<FileEntry> {file});
}
else
{
entries = entries.Concat(folderDao.GetFiles(folder.ID, orderBy, filter, subjectId, searchText));
}
}
else
{
entries = entries.Concat(folderDao.GetFiles(folder.ID, orderBy, filter, subjectId, searchText));
}
entries = EntryManager.SortEntries(entries, orderBy);
var siblingType = FileUtility.GetFileTypeByFileName(file.Title);
var result = new ItemDictionary<String, String>();
FileSecurity.FilterRead(entries)
.OfType<File>()
.Where(f => siblingType.Equals(FileUtility.GetFileTypeByFileName(f.Title)))
.ToList()
.ForEach(f => result.Add(f.ID.ToString(), f.Version + "&" + f.Title));
return new KeyValuePair<string, ItemDictionary<string, string>>(folderId.ToString(), result);
}
}
示例7: CreateItemFunctionExpander
/// <summary>
/// Creates an expander populated with some ProjectPropertyInstances and ProjectPropertyItems.
/// </summary>
/// <returns></returns>
private Expander<ProjectPropertyInstance, ProjectItemInstance> CreateItemFunctionExpander()
{
ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
PropertyDictionary<ProjectPropertyInstance> pg = new PropertyDictionary<ProjectPropertyInstance>();
pg.Set(ProjectPropertyInstance.Create("p", "v0"));
pg.Set(ProjectPropertyInstance.Create("p", "v1"));
pg.Set(ProjectPropertyInstance.Create("Val", "2"));
pg.Set(ProjectPropertyInstance.Create("a", "filename"));
ItemDictionary<ProjectItemInstance> ig = new ItemDictionary<ProjectItemInstance>();
for (int n = 0; n < 10; n++)
{
ProjectItemInstance pi = new ProjectItemInstance(project, "i", "i" + n.ToString(), project.FullPath);
for (int m = 0; m < 5; m++)
{
pi.SetMetadata("Meta" + m.ToString(), @"c:\firstdirectory\seconddirectory\file" + m.ToString() + ".ext");
}
pi.SetMetadata("Meta9", @"seconddirectory\file.ext");
pi.SetMetadata("Meta10", @";someo%3bherplace\foo.txt;secondd%3brectory\file.ext;");
pi.SetMetadata("MetaBlank", @"");
if (n % 2 > 0)
{
pi.SetMetadata("Even", "true");
pi.SetMetadata("Odd", "false");
}
else
{
pi.SetMetadata("Even", "false");
pi.SetMetadata("Odd", "true");
}
ig.Add(pi);
}
Dictionary<string, string> itemMetadataTable = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
itemMetadataTable["Culture"] = "abc%253bdef;$(Gee_Aych_Ayee)";
itemMetadataTable["Language"] = "english";
IMetadataTable itemMetadata = new StringMetadataTable(itemMetadataTable);
Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(pg, ig, itemMetadata);
return expander;
}
示例8: EvaluateAVarietyOfExpressions
public void EvaluateAVarietyOfExpressions()
{
string[] files = { "a", "a;b", "a'b", ";", "'" };
try
{
foreach (string file in files)
{
using (StreamWriter sw = File.CreateText(file)) {; }
}
Parser p = new Parser();
GenericExpressionNode tree;
ItemDictionary<ProjectItemInstance> itemBag = new ItemDictionary<ProjectItemInstance>();
// Dummy project instance to own the items.
ProjectRootElement xml = ProjectRootElement.Create();
xml.FullPath = @"c:\abc\foo.proj";
ProjectInstance parentProject = new ProjectInstance(xml);
itemBag.Add(new ProjectItemInstance(parentProject, "u", "a'b;c", parentProject.FullPath));
itemBag.Add(new ProjectItemInstance(parentProject, "v", "a", parentProject.FullPath));
itemBag.Add(new ProjectItemInstance(parentProject, "w", "1", parentProject.FullPath));
itemBag.Add(new ProjectItemInstance(parentProject, "x", "true", parentProject.FullPath));
itemBag.Add(new ProjectItemInstance(parentProject, "y", "xxx", parentProject.FullPath));
itemBag.Add(new ProjectItemInstance(parentProject, "z", "xxx", parentProject.FullPath));
itemBag.Add(new ProjectItemInstance(parentProject, "z", "yyy", parentProject.FullPath));
PropertyDictionary<ProjectPropertyInstance> propertyBag = new PropertyDictionary<ProjectPropertyInstance>();
propertyBag.Set(ProjectPropertyInstance.Create("a", "no"));
propertyBag.Set(ProjectPropertyInstance.Create("b", "true"));
propertyBag.Set(ProjectPropertyInstance.Create("c", "1"));
propertyBag.Set(ProjectPropertyInstance.Create("d", "xxx"));
propertyBag.Set(ProjectPropertyInstance.Create("e", "xxx"));
propertyBag.Set(ProjectPropertyInstance.Create("f", "1.9.5"));
propertyBag.Set(ProjectPropertyInstance.Create("and", "and"));
propertyBag.Set(ProjectPropertyInstance.Create("a_semi_b", "a;b"));
propertyBag.Set(ProjectPropertyInstance.Create("a_apos_b", "a'b"));
propertyBag.Set(ProjectPropertyInstance.Create("foo_apos_foo", "foo'foo"));
propertyBag.Set(ProjectPropertyInstance.Create("a_escapedsemi_b", "a%3bb"));
propertyBag.Set(ProjectPropertyInstance.Create("a_escapedapos_b", "a%27b"));
propertyBag.Set(ProjectPropertyInstance.Create("has_trailing_slash", @"foo\"));
Dictionary<string, string> metadataDictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
metadataDictionary["Culture"] = "french";
StringMetadataTable itemMetadata = new StringMetadataTable(metadataDictionary);
Expander<ProjectPropertyInstance, ProjectItemInstance> expander =
new Expander<ProjectPropertyInstance, ProjectItemInstance>(propertyBag, itemBag, itemMetadata);
string[] trueTests = {
"true or (SHOULDNOTEVALTHIS)", // short circuit
"(true and false) or true",
"false or true or false",
"(true) and (true)",
"false or !false",
"($(a) or true)",
"('$(c)'==1 and (!false))",
"@(z -> '%(filename).z', '$')=='xxx.z$yyy.z'",
"@(w -> '%(definingprojectname).barproj') == 'foo.barproj'",
"false or (false or (false or (false or (false or (true)))))",
"!(true and false)",
"$(and)=='and'",
"0x1==1.0",
"0xa==10",
"0<0.1",
"+4>-4",
"'-$(c)'==-1",
"$(a)==faLse",
"$(a)==oFF",
"$(a)==no",
"$(a)!=true",
"$(b)== True",
"$(b)==on",
"$(b)==yes",
"$(b)!=1",
"$(c)==1",
"$(d)=='xxx'",
"$(d)==$(e)",
"$(d)=='$(e)'",
"@(y)==$(d)",
"'@(z)'=='xxx;yyy'",
"$(a)==$(a)",
"'1'=='1'",
"'1'==1",
"1\n==1",
"1\t==\t\r\n1",
"123=='0123.0'",
"123==123",
"123==0123",
"123==0123.0",
"123!=0123.01",
"1.2.3<=1.2.3.0",
"12.23.34==12.23.34",
"0.8.0.0<8.0.0",
"1.1.2>1.0.1.2",
"8.1>8.0.16.23",
//.........这里部分代码省略.........
示例9: ItemListTests
public void ItemListTests()
{
Parser p = new Parser();
ProjectInstance parentProject = new ProjectInstance(ProjectRootElement.Create());
ItemDictionary<ProjectItemInstance> itemBag = new ItemDictionary<ProjectItemInstance>();
itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "foo.cs", parentProject.FullPath));
itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "bar.cs", parentProject.FullPath));
itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "baz.cs", parentProject.FullPath));
itemBag.Add(new ProjectItemInstance(parentProject, "Boolean", "true", parentProject.FullPath));
Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(new PropertyDictionary<ProjectPropertyInstance>(), itemBag);
AssertParseEvaluate(p, "@(Compile) == 'foo.cs;bar.cs;baz.cs'", expander, true);
AssertParseEvaluate(p, "@(Compile,' ') == 'foo.cs bar.cs baz.cs'", expander, true);
AssertParseEvaluate(p, "@(Compile,'') == 'foo.csbar.csbaz.cs'", expander, true);
AssertParseEvaluate(p, "@(Compile->'%(Filename)') == 'foo;bar;baz'", expander, true);
AssertParseEvaluate(p, "@(Compile -> 'temp\\%(Filename).xml', ' ') == 'temp\\foo.xml temp\\bar.xml temp\\baz.xml'", expander, true);
AssertParseEvaluate(p, "@(Compile->'', '') == ''", expander, true);
AssertParseEvaluate(p, "@(Compile->'') == ';;'", expander, true);
AssertParseEvaluate(p, "@(Compile->'%(Nonexistent)', '') == ''", expander, true);
AssertParseEvaluate(p, "@(Compile->'%(Nonexistent)') == ';;'", expander, true);
AssertParseEvaluate(p, "@(Boolean)", expander, true);
AssertParseEvaluate(p, "@(Boolean) == true", expander, true);
AssertParseEvaluate(p, "'@(Empty, ';')' == ''", expander, true);
}
示例10: GetSiblingsFile
public ItemDictionary<String, String> GetSiblingsFile(String fileId, String sfilter, OrderBy orderBy, String ssubject, String searchText)
{
var filter = (FilterType) Convert.ToInt32(sfilter);
var subjectId = string.IsNullOrEmpty(ssubject) ? Guid.Empty : new Guid(ssubject);
using (var fileDao = GetFileDao())
using (var folderDao = GetFolderDao())
{
var file = fileDao.GetFile(fileId);
ErrorIf(file == null, FilesCommonResource.ErrorMassage_FileNotFound, true);
ErrorIf(!FileSecurity.CanRead(file), FilesCommonResource.ErrorMassage_SecurityException_ReadFile, true);
var folder = folderDao.GetFolder(file.FolderID);
ErrorIf(folder == null, FilesCommonResource.ErrorMassage_FolderNotFound, true);
ErrorIf(folder.RootFolderType == FolderType.TRASH, FilesCommonResource.ErrorMassage_ViewTrashItem, true);
var entries = Enumerable.Empty<FileEntry>();
if (!FileSecurity.CanRead(folder) &&
folder.RootFolderType == FolderType.USER && !Equals(folder.RootFolderId, Global.FolderMy))
{
orderBy = new OrderBy(SortedByType.DateAndTime, false);
var shared = (IEnumerable<FileEntry>) FileSecurity.GetSharesForMe();
shared = FilterEntries(shared, filter, subjectId, searchText)
.Where(f => f is File &&
f.CreateBy != SecurityContext.CurrentAccount.ID && // don't show my files
f.RootFolderType == FolderType.USER); // don't show common files (common files can read)
entries = entries.Concat(shared);
}
else
{
entries = entries.Concat(folderDao.GetFiles(folder.ID, orderBy, filter, subjectId, searchText).Cast<FileEntry>());
}
entries = SortEntries(entries, orderBy);
var result = new ItemDictionary<string, String>();
FileSecurity.FilterRead(entries)
.OfType<File>()
.Where(f => FileUtility.ExtsImagePreviewed.Contains(FileUtility.GetFileExtension(f.Title)))
.ToList()
.ForEach(f => result.Add(f.ID.ToString(), f.Version + "#" + f.Title));
return result;
}
}
示例11: MoveOrCopyFilesCheck
public ItemDictionary<String, String> MoveOrCopyFilesCheck(ItemList<String> items, String destFolderId)
{
var result = new ItemDictionary<string, String>();
if (items.Count == 0) return result;
List<object> folders;
List<object> files;
ParseArrayItems(items, out folders, out files);
using (var folderDao = GetFolderDao())
using (var fileDao = GetFileDao())
{
var toFolder = folderDao.GetFolder(destFolderId);
if (toFolder == null) return result;
ErrorIf(!FileSecurity.CanCreate(toFolder), FilesCommonResource.ErrorMassage_SecurityException_Create, true);
foreach (var id in files)
{
var file = fileDao.GetFile(id);
if (file != null && fileDao.IsExist(file.Title, toFolder.ID))
{
result.Add(id.ToString(), file.Title);
}
}
foreach (var pair in folderDao.CanMoveOrCopy(folders.ToArray(), toFolder.ID))
{
result.Add(pair.Key.ToString(), pair.Value);
}
}
return result;
}
示例12: InitializeHost
/// <summary>
/// Initialize the host object
/// </summary>
/// <param name="throwOnExecute">Should the task throw when executed</param>
private void InitializeHost(bool throwOnExecute)
{
_loggingService = LoggingService.CreateLoggingService(LoggerMode.Synchronous, 1) as ILoggingService;
_logger = new MockLogger();
_loggingService.RegisterLogger(_logger);
_host = new TaskExecutionHost();
TargetLoggingContext tlc = new TargetLoggingContext(_loggingService, new BuildEventContext(1, 1, BuildEventContext.InvalidProjectContextId, 1));
// Set up a temporary project and add some items to it.
ProjectInstance project = CreateTestProject();
TypeLoader typeLoader = new TypeLoader(new TypeFilter(IsTaskFactoryClass));
AssemblyLoadInfo loadInfo = AssemblyLoadInfo.Create(Assembly.GetAssembly(typeof(TaskBuilderTestTask.TaskBuilderTestTaskFactory)).FullName, null);
LoadedType loadedType = new LoadedType(typeof(TaskBuilderTestTask.TaskBuilderTestTaskFactory), loadInfo);
TaskBuilderTestTask.TaskBuilderTestTaskFactory taskFactory = new TaskBuilderTestTask.TaskBuilderTestTaskFactory();
taskFactory.ThrowOnExecute = throwOnExecute;
string taskName = "TaskBuilderTestTask";
(_host as TaskExecutionHost)._UNITTESTONLY_TaskFactoryWrapper = new TaskFactoryWrapper(taskFactory, loadedType, taskName, null);
_host.InitializeForTask
(
this,
tlc,
project,
taskName,
ElementLocation.Create("none", 1, 1),
this,
false,
null,
false,
CancellationToken.None
);
ProjectTaskInstance taskInstance = project.Targets["foo"].Tasks.First();
TaskLoggingContext talc = tlc.LogTaskBatchStarted(".", taskInstance);
ItemDictionary<ProjectItemInstance> itemsByName = new ItemDictionary<ProjectItemInstance>();
ProjectItemInstance item = new ProjectItemInstance(project, "ItemListContainingOneItem", "a.cs", ".");
item.SetMetadata("Culture", "fr-fr");
itemsByName.Add(item);
_oneItem = new ITaskItem[] { new TaskItem(item) };
item = new ProjectItemInstance(project, "ItemListContainingTwoItems", "b.cs", ".");
ProjectItemInstance item2 = new ProjectItemInstance(project, "ItemListContainingTwoItems", "c.cs", ".");
item.SetMetadata("HintPath", "c:\\foo");
item2.SetMetadata("HintPath", "c:\\bar");
itemsByName.Add(item);
itemsByName.Add(item2);
_twoItems = new ITaskItem[] { new TaskItem(item), new TaskItem(item2) };
_bucket = new ItemBucket(new string[0], new Dictionary<string, string>(), new Lookup(itemsByName, new PropertyDictionary<ProjectPropertyInstance>(), null), 0);
_host.FindTask(null);
_host.InitializeForBatch(talc, _bucket, null);
_parametersSetOnTask = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
_outputsReadFromTask = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
}
示例13: SetAccessToWebItems
public IEnumerable<SecurityWrapper> SetAccessToWebItems(IEnumerable<ItemKeyValuePair<String, Boolean>> items)
{
SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
var itemList = new ItemDictionary<String, Boolean>();
foreach (ItemKeyValuePair<String, Boolean> item in items)
{
if (!itemList.ContainsKey(item.Key))
itemList.Add(item.Key, item.Value);
}
foreach (var item in itemList)
{
Guid[] subjects = null;
if (item.Value)
{
var webItem = WebItemManager.Instance[new Guid(item.Key)] as IProduct;
if (webItem != null)
{
var productInfo = WebItemSecurity.GetSecurityInfo(item.Key);
var selectedGroups = productInfo.Groups.Select(group => group.ID).ToList();
var selectedUsers = productInfo.Users.Select(user => user.ID).ToList();
selectedUsers.AddRange(selectedGroups);
if (selectedUsers.Count > 0)
{
subjects = selectedUsers.ToArray();
}
}
}
WebItemSecurity.SetSecurity(item.Key, item.Value, subjects);
}
return GetWebItemSecurityInfo(itemList.Keys.ToList());
}
示例14: GetNearestTask
public ItemDictionary<int, TaskWrapper> GetNearestTask(IEnumerable<int> contactid)
{
var sqlResult = DaoFactory.GetTaskDao().GetNearestTask(contactid.ToArray());
var result = new ItemDictionary<int, TaskWrapper>();
foreach (var item in sqlResult)
result.Add(item.Key, ToTaskWrapper(item.Value));
return result;
}
示例15: AddsWithDuplicateRemovalWithMetadata
public void AddsWithDuplicateRemovalWithMetadata()
{
ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>();
// Two items, differ only by metadata
table1.Add(new ProjectItemInstance(project, "i1", "a1", new KeyValuePair<string, string>[] { new KeyValuePair<string, string>("m1", "m1") }, project.FullPath));
table1.Add(new ProjectItemInstance(project, "i1", "a1", new KeyValuePair<string, string>[] { new KeyValuePair<string, string>("m1", "m2") }, project.FullPath));
Lookup lookup = LookupHelpers.CreateLookup(table1);
var scope = lookup.EnterScope("test");
// This one should not get added
ProjectItemInstance[] newItems = new ProjectItemInstance[]
{
new ProjectItemInstance(project, "i1", "a1", project.FullPath), // Should get added
new ProjectItemInstance(project, "i1", "a2", new KeyValuePair<string, string>[] { new KeyValuePair<string, string>( "m1", "m1" ) }, project.FullPath), // Should get added
new ProjectItemInstance(project, "i1", "a1", new KeyValuePair<string, string>[] { new KeyValuePair<string, string>( "m1", "m1" ) }, project.FullPath), // Should not get added
new ProjectItemInstance(project, "i1", "a1", new KeyValuePair<string, string>[] { new KeyValuePair<string, string>( "m1", "m3" ) }, project.FullPath), // Should get added
};
// Perform the addition
lookup.AddNewItemsOfItemType("i1", newItems, doNotAddDuplicates: true);
var group = lookup.GetItems("i1");
// We should have the original two duplicates plus one new addition.
Assert.Equal(5, group.Count);
// Four of the items will have the a1 include
Assert.Equal(4, group.Where(item => item.EvaluatedInclude == "a1").Count());
// One item will have the a2 include
Assert.Equal(1, group.Where(item => item.EvaluatedInclude == "a2").Count());
scope.LeaveScope();
group = lookup.GetItems("i1");
// We should have the original two duplicates plus one new addition.
Assert.Equal(5, group.Count);
// Four of the items will have the a1 include
Assert.Equal(4, group.Where(item => item.EvaluatedInclude == "a1").Count());
// One item will have the a2 include
Assert.Equal(1, group.Where(item => item.EvaluatedInclude == "a2").Count());
}