コード例 #1
0
 /// <summary>
 /// Abstract out the creation of the new AssemblyTaskFactory with default task, and
 /// with some basic validation.
 /// </summary>
 private void SetupTaskFactory(IDictionary <string, string> factoryParameters, bool explicitlyLaunchTaskHost)
 {
     _taskFactory = new AssemblyTaskFactory();
     _loadInfo    = AssemblyLoadInfo.Create(null, Assembly.GetAssembly(typeof(TaskToTestFactories)).Location);
     _loadedType  = _taskFactory.InitializeFactory(_loadInfo, "TaskToTestFactories", new Dictionary <string, TaskPropertyInfo>(), string.Empty, factoryParameters, explicitlyLaunchTaskHost, null, ElementLocation.Create("NONE"), String.Empty);
     Assert.True(_loadedType.Assembly.Equals(_loadInfo)); // "Expected the AssemblyLoadInfo to be equal"
 }
コード例 #2
0
 public void GoodTaskNameButNotInInfo()
 {
     Assert.Throws <InvalidProjectFileException>(() =>
     {
         AssemblyTaskFactory taskFactory = new AssemblyTaskFactory();
         taskFactory.InitializeFactory(_loadInfo, "RandomTask", new Dictionary <string, TaskPropertyInfo>(), string.Empty, null, false, null, ElementLocation.Create("NONE"), String.Empty);
     }
                                                 );
 }
コード例 #3
0
 public void NullLoadInfo()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         AssemblyTaskFactory taskFactory = new AssemblyTaskFactory();
         taskFactory.InitializeFactory(null, "TaskToTestFactories", new Dictionary <string, TaskPropertyInfo>(), string.Empty, null, false, null, ElementLocation.Create("NONE"), String.Empty);
     }
                                           );
 }
コード例 #4
0
 public void CallPublicInitializeFactory2()
 {
     Assert.Throws <InternalErrorException>(() =>
     {
         AssemblyTaskFactory taskFactory = new AssemblyTaskFactory();
         taskFactory.Initialize(String.Empty, null, new Dictionary <string, TaskPropertyInfo>(), String.Empty, null);
     }
                                            );
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: benwitman/msbuild
        private static int RunTarget()
        {
            StaticTarget target;
            var          ser = new DataContractJsonSerializer(typeof(StaticTarget));

            using (var memoryStream = new MemoryStream())
            {
                using (var writer = new StreamWriter(memoryStream, Encoding.Default, 1024 * 4, true))
                {
                    string s;
                    while ((s = Console.ReadLine()) != null)
                    {
                        writer.WriteLine(s);
                    }
                }

                memoryStream.Position = 0;
                target = (StaticTarget)ser.ReadObject(memoryStream);
            }

            foreach (StaticTarget.Task staticTask in target.Tasks)
            {
                Type type;
                if (staticTask.AssemblyFile != null)
                {
                    AssemblyName an = AssemblyName.GetAssemblyName(staticTask.AssemblyFile);
                    if (an == null)
                    {
                        Console.WriteLine("Caouldn't get assembly name for assembly file: " + staticTask.AssemblyFile);
                        return(1);
                    }
                    Assembly a = Assembly.Load(an);
                    if (a == null)
                    {
                        Console.WriteLine("Couldn't loaded assembly for assembly: " + an.FullName + " from file: " + staticTask.AssemblyFile);
                        return(1);
                    }
                    type = a.GetType(staticTask.Name.Split(',')[0]);
                    if (type == null)
                    {
                        Console.WriteLine("Couldn't create type for string: " + staticTask.Name.Split(',')[0] + " assembly file: " + (staticTask.AssemblyFile ?? "null") + " and assembly name: " + (staticTask.AssemblyName ?? "null"));
                        Console.WriteLine("Types in the assembly:\n" + string.Join(",\n", a.GetTypes().Select(availableType => availableType.FullName)));
                        return(1);
                    }
                }
                else
                {
                    type = Type.GetType(staticTask.Name);
                    if (type == null)
                    {
                        Console.WriteLine("Couldn't create type for string: " + staticTask.Name + " assembly file: " + (staticTask.AssemblyFile ?? "null") + " and assembly name: " + (staticTask.AssemblyName ?? "null"));
                        return(1);
                    }
                }

                var assemblyLoadInfo = AssemblyLoadInfo.Create(assemblyFile: staticTask.AssemblyFile, assemblyName: staticTask.AssemblyName);
                if (assemblyLoadInfo == null)
                {
                    Console.WriteLine("Couldn't create type for assembly file: " + (staticTask.AssemblyFile ?? "null") + " and name: " + (staticTask.AssemblyName ?? "null"));
                    return(1);
                }

                LoadedType         loadedType     = new LoadedType(type, assemblyLoadInfo, null);
                TaskPropertyInfo[] taskProperties = AssemblyTaskFactory.GetTaskParameters(loadedType);

                ITask task = TaskLoader.CreateTask(loadedType, staticTask.Name, staticTask.AssemblyName, 0, 0, null

#if FEATURE_APPDOMAIN
                                                   , null
#endif
                                                   , false
#if FEATURE_APPDOMAIN
                                                   , out var appDomain
#endif
                                                   );
                foreach (var parameter in staticTask.Parameters)
                {
                    var taskPropertyInfo = taskProperties.FirstOrDefault(property => property.Name == parameter.Key);
                    if (taskPropertyInfo == null)
                    {
                        Console.Error.WriteLine("Could not find property: \"" + parameter.Key + "\" for task + \"" + staticTask.Name + "\"");
                        return(1);
                    }

                    StaticTarget.Task.ParameterType parameterType = parameter.Value.ParameterType;
                    switch (parameterType)
                    {
                    case StaticTarget.Task.ParameterType.Primitive:
                        object value = GetTypedValue(parameter.Value.Primitive.Type, parameter.Value.Primitive.Value);
                        TaskFactoryWrapper.SetPropertyValue(task, taskPropertyInfo, value);
                        break;

                    case StaticTarget.Task.ParameterType.Primitives:
                        var values = GetTypedArrayValue(parameter.Value.Primitives.Type, parameter.Value.Primitives.Values);
                        TaskFactoryWrapper.SetPropertyValue(task, taskPropertyInfo, values);
                        break;

                    case StaticTarget.Task.ParameterType.TaskItem:
                        TaskFactoryWrapper.SetPropertyValue(task, taskPropertyInfo, new TaskItem(parameter.Value.TaskItem.ItemSpec, parameter.Value.TaskItem.Metadata));
                        break;

                    case StaticTarget.Task.ParameterType.TaskItems:
                        ITaskItem[] taskItems = parameter.Value.TaskItems.Select(taskItem => new TaskItem(taskItem.ItemSpec, taskItem.Metadata)).ToArray();
                        TaskFactoryWrapper.SetPropertyValue(task, taskPropertyInfo, taskItems);
                        break;
                    }
                }


                task.BuildEngine = new SimpleBuildEngine();
                try
                {
                    // MSBuild ignores this return value :(
                    task.Execute();
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine("TASK ERROR: " + e);
                    return(1);
                }
            }

            return(0);
        }
コード例 #6
0
        public void EmptyTaskName()
        {
            AssemblyTaskFactory taskFactory = new AssemblyTaskFactory();

            taskFactory.InitializeFactory(_loadInfo, String.Empty, new Dictionary <string, TaskPropertyInfo>(), string.Empty, null, false, null, ElementLocation.Create("NONE"), String.Empty);
        }
コード例 #7
0
 public void TearDownAttribute()
 {
     _taskFactory = null;
     _loadInfo    = null;
     _loadedType  = null;
 }
コード例 #8
0
        public void CallPublicInitializeFactory2()
        {
            AssemblyTaskFactory taskFactory = new AssemblyTaskFactory();

            taskFactory.Initialize(String.Empty, null, new Dictionary <string, TaskPropertyInfo>(), String.Empty, null);
        }