Example #1
0
        static void Main(string[] args)
        {
            //Load a project
            ProjectReader rdr = new ProjectReader();
            FileStream    St  = new FileStream("Project.mpp", FileMode.Open);
            Project       prj = rdr.Read(St);

            St.Close();

            //Link the tasks
            TaskLink tsklnk = new TaskLink(prj.RootTask.Children[0] as Aspose.Tasks.Task, prj.RootTask.Children[1] as Aspose.Tasks.Task, TaskLinkType.FinishToStart);

            prj.AddTaskLink(tsklnk);
            tsklnk = new TaskLink(prj.RootTask.Children[1] as Aspose.Tasks.Task, prj.RootTask.Children[2] as Aspose.Tasks.Task, TaskLinkType.FinishToStart);
            prj.AddTaskLink(tsklnk);
            tsklnk = new TaskLink(prj.RootTask.Children[2] as Aspose.Tasks.Task, prj.RootTask.Children[3] as Aspose.Tasks.Task, TaskLinkType.FinishToStart);
            prj.AddTaskLink(tsklnk);
            tsklnk = new TaskLink(prj.RootTask.Children[3] as Aspose.Tasks.Task, prj.RootTask.Children[4] as Aspose.Tasks.Task, TaskLinkType.FinishToStart);
            prj.AddTaskLink(tsklnk);
            tsklnk = new TaskLink(prj.RootTask.Children[1] as Aspose.Tasks.Task, prj.RootTask.Children[4] as Aspose.Tasks.Task, TaskLinkType.FinishToStart);
            prj.AddTaskLink(tsklnk);

            //Display links among the tasks
            ArrayList allinks = new ArrayList(prj.TaskLinks);

            foreach (TaskLink tasklnk in allinks)
            {
                Console.WriteLine("From ID = " + tasklnk.PredTask.Id + "=>To ID = " + tasklnk.SuccTask.Id);
                Console.WriteLine("________________________________________");
            }
            //Save the project
            prj.Save("Project1.mpp", Aspose.Tasks.Saving.SaveFileFormat.MPP);
        }
        static void Main(string[] args)
        {
            //Load a project
            ProjectReader rdr = new ProjectReader();
            FileStream St = new FileStream("Project.mpp", FileMode.Open);
            Project prj = rdr.Read(St);
            St.Close();

            //Link the tasks
            TaskLink tsklnk = new TaskLink(prj.RootTask.Children[0] as Aspose.Tasks.Task, prj.RootTask.Children[1] as Aspose.Tasks.Task, TaskLinkType.FinishToStart);
            prj.AddTaskLink(tsklnk);
            tsklnk = new TaskLink(prj.RootTask.Children[1] as Aspose.Tasks.Task, prj.RootTask.Children[2] as Aspose.Tasks.Task, TaskLinkType.FinishToStart);
            prj.AddTaskLink(tsklnk);
            tsklnk = new TaskLink(prj.RootTask.Children[2] as Aspose.Tasks.Task, prj.RootTask.Children[3] as Aspose.Tasks.Task, TaskLinkType.FinishToStart);
            prj.AddTaskLink(tsklnk);
            tsklnk = new TaskLink(prj.RootTask.Children[3] as Aspose.Tasks.Task, prj.RootTask.Children[4] as Aspose.Tasks.Task, TaskLinkType.FinishToStart);
            prj.AddTaskLink(tsklnk);
            tsklnk = new TaskLink(prj.RootTask.Children[1] as Aspose.Tasks.Task, prj.RootTask.Children[4] as Aspose.Tasks.Task, TaskLinkType.FinishToStart);
            prj.AddTaskLink(tsklnk);

            //Display links among the tasks
            ArrayList allinks = new ArrayList(prj.TaskLinks);
            foreach (TaskLink tasklnk in allinks)
            {
                Console.WriteLine("From ID = " + tasklnk.PredTask.Id + "=>To ID = " + tasklnk.SuccTask.Id);
                Console.WriteLine("________________________________________");
            }
            //Save the project
            prj.Save("Project1.mpp", Aspose.Tasks.Saving.SaveFileFormat.MPP);
        }
Example #3
0
        /// <summary>
        /// Removes all parameters from the task.
        /// Does not remove any "special" parameters: ContinueOnError, Condition, etc.
        /// </summary>
        public void RemoveAllParameters()
        {
            if (Link != null)
            {
                TaskLink.RemoveAllParameters();
                return;
            }

            lock (_locker)
            {
                _parameters = null;
                List <XmlAttribute> toRemove = null;

                // note this was a long standing bug in here (which would make this only work if there is no attributes to remove).
                // calling XmlElement.RemoveAttributeNode will cause foreach to throw ArgumentException (collection modified)
                foreach (XmlAttribute attribute in XmlElement.Attributes)
                {
                    if (!XMakeAttributes.IsSpecialTaskAttribute(attribute.Name))
                    {
                        toRemove = toRemove ?? new List <XmlAttribute>();
                        toRemove.Add(attribute);
                    }
                }

                if (toRemove != null)
                {
                    foreach (var attribute in toRemove)
                    {
                        XmlElement.RemoveAttributeNode(attribute);
                    }

                    MarkDirty("Remove all task parameters on {0}", Name);
                }
            }
        }
        public static void Run()
        {
            // ExStart:ApplyCalculationModeManual
            // Create empty project and set calculation mode to Manual
            Project project = new Project();

            project.CalculationMode = CalculationMode.Manual;

            // Set project start date and add new tasks
            project.Set(Prj.StartDate, new DateTime(2015, 4, 15));
            Task task1 = project.RootTask.Children.Add("Task 1");
            Task task2 = project.RootTask.Children.Add("Task 2");

            // The necessary properties are set in manual mode
            Console.WriteLine("Task1.Id Equals 1 : {0} ", task1.Get(Tsk.Id).Equals(1));
            Console.WriteLine("Task1 OutlineLevel Equals 1 : {0} ", task1.Get(Tsk.OutlineLevel).Equals(1));
            Console.WriteLine("Task1 Start Equals 15/04/2015 08:00 AM : {0} ", task1.Get(Tsk.Start).Equals(new DateTime(2015, 4, 15, 8, 0, 0)));
            Console.WriteLine("Task1 Finish Equals 15/04/2015 05:00 PM : {0} ", task1.Get(Tsk.Finish).Equals(new DateTime(2015, 4, 15, 17, 0, 0)));
            Console.WriteLine("Task1 Duration Equals 1 day : {0} ", task1.Get(Tsk.Duration).ToString().Equals("1 day"));
            Console.WriteLine("Task2 Start Equals 15/04/2015 08:00 AM : {0} ", task2.Get(Tsk.Start).Equals(new DateTime(2015, 4, 15, 8, 0, 0)));
            Console.WriteLine("Task2 Finish Equals 15/04/2015 05:00 PM : {0} ", task2.Get(Tsk.Finish).Equals(new DateTime(2015, 4, 15, 17, 0, 0)));
            Console.WriteLine("Task2 Duration Equals 1 day : {0} ", task2.Get(Tsk.Duration).ToString().Equals("1 day"));

            // When we link two tasks together their dates are not recalculated in manual mode
            TaskLink link = project.TaskLinks.Add(task1, task2, TaskLinkType.FinishToStart);

            // Task 2 Start has not been changed
            Console.WriteLine("Task1 Start Equals Task2 Start : {0} ", task1.Get(Tsk.Start).Equals(task2.Get(Tsk.Start)));
            Console.WriteLine("Task1 Finish Equals Task2 Finish : {0} ", task1.Get(Tsk.Finish).Equals(task2.Get(Tsk.Finish)));
            // ExEnd:ApplyCalculationModeManual
        }
Example #5
0
    public ITask CreatTask(string path, Action <string, Object> finish_cb)
    {
        var dependencies = manifest.GetAllDependencies(path);
        var length       = dependencies.Length;
        var tasks        = new ITask[length];

        for (int i = 0; i < length; i++)
        {
            var ab_path = dependencies[i];
            if (task_dic.ContainsKey(ab_path))
            {
                tasks[i] = new TaskLink(task_dic[ab_path]);
            }
            else
            {
                var tsk = CreatTask(ab_path, finish_cb);
                tasks[i] = tsk;
            }
        }
        var task = new Task(tasks, path);

        task.Finish_CB = finish_cb;
        task_dic.Add(path, task);
        return(new Task(tasks, path));
    }
        public NewRedisClient0(IPEndPoint point)
        {
            _protocalStart = (byte)43;
            _store         = new TaskLink <bool>();
            _taskLink      = _store;
            _head          = _taskLink;
            SocketConnectionFactory client = new SocketConnectionFactory(new SocketTransportOptions());

            _connection = client.ConnectAsync(point).Result;
            _sender     = _connection.Transport.Output;
            _reciver    = _connection.Transport.Input;
            RunReciver();
            //Task.Run(async () => {
            //    await Task.Delay(30000);
            //    Console.WriteLine(total);
            //    Console.WriteLine(_receiverQueue.Count);
            //    await Task.Delay(20000);
            //    Console.WriteLine(total);
            //    Console.WriteLine(_receiverQueue.Count);
            //    await Task.Delay(10000);
            //    Console.WriteLine(total);
            //    Console.WriteLine(_receiverQueue.Count);
            //});
            //RunSender();
        }
Example #7
0
        public void RemoveLink(TaskLink link)
        {
            var query = Delete(TasksLinksTable)
                        .Where((Exp.Eq("task_id", link.DependenceTaskId) & Exp.Eq("parent_id", link.ParentTaskId)) |
                               (Exp.Eq("task_id", link.ParentTaskId) & Exp.Eq("parent_id", link.DependenceTaskId)));

            Db.ExecuteNonQuery(query);
        }
Example #8
0
        /// <summary>
        /// 捕获异常线程
        /// </summary>
        /// <param name="onException">异常处理委托</param>
        /// <param name="callerFilePath">调用文件路径</param>
        /// <param name="callerLineNumber">所在文件行数</param>
        /// <param name="callerMemberName">调用成员名称</param>
        protected CatchTask(Action <AggregateException> onException, string callerFilePath, int callerLineNumber, string callerMemberName)
        {
            CallerLineNumber = callerLineNumber;
            CallerFilePath   = callerFilePath;
            CallerMemberName = callerMemberName;

            this.onException = onException;
            TaskLink.PushNotNull(this);
        }
Example #9
0
        public bool IsExistLink(TaskLink link)
        {
            var query = Query(TasksLinksTable)
                        .SelectCount()
                        .Where((Exp.Eq("task_id", link.DependenceTaskId) & Exp.Eq("parent_id", link.ParentTaskId)) |
                               (Exp.Eq("task_id", link.ParentTaskId) & Exp.Eq("parent_id", link.DependenceTaskId)));

            return(Db.ExecuteScalar <long>(query) > 0);
        }
Example #10
0
        public void AddLink(TaskLink link)
        {
            var query = Insert(TasksLinksTable)
                        .InColumnValue("task_id", link.DependenceTaskId)
                        .InColumnValue("parent_id", link.ParentTaskId)
                        .InColumnValue("link_type", link.LinkType);

            Db.ExecuteNonQuery(query);
        }
        public static void Run()
        {
            // ExStart:UpdateProjectAndRescheduleUncompletedWork
            // The path to the documents directory.
            string  dataDir = RunExamples.GetDataDir_WorkingWithProjects();
            Project project = new Project();

            project.Set(Prj.StartDate, new DateTime(2014, 1, 27, 8, 0, 0));
            Task task1 = project.RootTask.Children.Add("Task 1");
            Task task2 = project.RootTask.Children.Add("Task 2");

            task2.Set(Tsk.Duration, task2.ParentProject.GetDuration(16, TimeUnitType.Hour));
            Task task3 = project.RootTask.Children.Add("Task 3");

            task3.Set(Tsk.Duration, task2.ParentProject.GetDuration(24, TimeUnitType.Hour));
            Task task4 = project.RootTask.Children.Add("Task 4");

            task4.Set(Tsk.Duration, task2.ParentProject.GetDuration(16, TimeUnitType.Hour));
            Task task5 = project.RootTask.Children.Add("Task 5");

            task5.Set(Tsk.Duration, task2.ParentProject.GetDuration(16, TimeUnitType.Hour));
            TaskLink link12 = project.TaskLinks.Add(task1, task2, TaskLinkType.FinishToStart);
            TaskLink link23 = project.TaskLinks.Add(task2, task3, TaskLinkType.FinishToStart);

            link23.LinkLag = 4800; // one day lag
            TaskLink link34 = project.TaskLinks.Add(task3, task4, TaskLinkType.FinishToStart);
            TaskLink link45 = project.TaskLinks.Add(task4, task5, TaskLinkType.FinishToStart);
            Task     task6  = project.RootTask.Children.Add("Task 6");
            Task     task7  = project.RootTask.Children.Add("Task 7");

            task7.Set(Tsk.Duration, task7.ParentProject.GetDuration(24, TimeUnitType.Hour));
            Task task8 = project.RootTask.Children.Add("Task 8");

            task8.Set(Tsk.Duration, task2.ParentProject.GetDuration(16, TimeUnitType.Hour));
            Task task9 = project.RootTask.Children.Add("Task 9");

            task9.Set(Tsk.Duration, task2.ParentProject.GetDuration(16, TimeUnitType.Hour));
            Task     task10  = project.RootTask.Children.Add("Task 10");
            TaskLink link67  = project.TaskLinks.Add(task6, task7, TaskLinkType.FinishToStart);
            TaskLink link78  = project.TaskLinks.Add(task7, task8, TaskLinkType.FinishToStart);
            TaskLink link89  = project.TaskLinks.Add(task8, task9, TaskLinkType.FinishToStart);
            TaskLink link910 = project.TaskLinks.Add(task9, task10, TaskLinkType.FinishToStart);

            task6.Set(Tsk.IsManual, true);
            task7.Set(Tsk.IsManual, true);
            task8.Set(Tsk.IsManual, true);
            task9.Set(Tsk.IsManual, true);
            task10.Set(Tsk.IsManual, true);
            project.Save(dataDir + "not updated.xml", SaveFileFormat.XML);
            project.UpdateProjectWorkAsComplete(new DateTime(2014, 1, 28, 17, 0, 0), false);
            project.Save(dataDir + "updated_out.xml", SaveFileFormat.XML);
            project.RescheduleUncompletedWorkToStartAfter(new DateTime(2014, 2, 7, 8, 0, 0));
            project.Save(dataDir + "rescheduled_out.xml", SaveFileFormat.XML);
            // ExEnd:UpdateProjectAndRescheduleUncompletedWork
        }
Example #12
0
        public void RemoveLink(TaskLink link)
        {
            using (var db = new DbManager(DatabaseId))
            {
                var query = Delete(TasksLinksTable)
                            .Where((Exp.Eq("task_id", link.DependenceTaskId) & Exp.Eq("parent_id", link.ParentTaskId)) |
                                   (Exp.Eq("task_id", link.ParentTaskId) & Exp.Eq("parent_id", link.DependenceTaskId)));

                db.ExecuteNonQuery(query);
            }
        }
Example #13
0
        public static void Run()
        {
            // ExStart:CreateTaskLinks
            // Create new project and add tasks
            Project project1 = new Project();
            Task    pred     = project1.RootTask.Children.Add("Task 1");
            Task    succ     = project1.RootTask.Children.Add("Task 2");

            // Links tasks
            TaskLink link = project1.TaskLinks.Add(pred, succ);
            // ExEnd:CreateTaskLinks
        }
Example #14
0
        public void AddLink(TaskLink link)
        {
            using (var db = new DbManager(DatabaseId))
            {
                var query = Insert(TasksLinksTable)
                            .InColumnValue("task_id", link.DependenceTaskId)
                            .InColumnValue("parent_id", link.ParentTaskId)
                            .InColumnValue("link_type", link.LinkType);

                db.ExecuteNonQuery(query);
            }
        }
        public static void Run()
        {
            // ExStart:SetTaskLinkType
            // Create new project and add tasks
            Project project = new Project();
            Task    pred    = project.RootTask.Children.Add("Task 1");
            Task    succ    = project.RootTask.Children.Add("Task 2");

            // Link tasks with link type set to Start to Start
            TaskLink link = project.TaskLinks.Add(pred, succ);

            link.LinkType = TaskLinkType.StartToStart;
            // ExEnd:SetTaskLinkType
        }
Example #16
0
        /// <summary>
        /// Removes any parameter on this task with the specified name.
        /// If there is no such parameter, does nothing.
        /// </summary>
        public void RemoveParameter(string name)
        {
            if (Link != null)
            {
                TaskLink.RemoveParameter(name);
                return;
            }

            lock (_locker)
            {
                _parameters = null;
                XmlElement.RemoveAttribute(name);
                MarkDirty("Remove task parameter {0}", name);
            }
        }
        public override Task <bool> SetAsync(string key, string value)
        {
            var bytes      = Encoding.UTF8.GetBytes($"SET {key} {value}\r\n");
            var taskSource = new TaskLink <bool>();

            WaitSend();
            if (_taskLink == null)
            {
                _taskLink = _store;
                _head     = _store;
            }
            _taskLink.Next = taskSource;
            _taskLink      = _taskLink.Next;
            _sender.WriteAsync(bytes);
            return(taskSource._task);
        }
Example #18
0
        /// <summary>
        /// 任务完成检测
        /// </summary>
        internal void OnCompleted()
        {
            TaskAwaiter TaskAwaiter = task.GetAwaiter();

            if (TaskAwaiter.IsCompleted)
            {
                if (TaskLink.PopNotNull(this))
                {
                    checkException(task.Exception, onException);
                }
            }
            else
            {
                TaskAwaiter.OnCompleted(OnCompleted);
            }
        }
Example #19
0
        /// <summary>
        /// Adds (or modifies the value of) a parameter on this task
        /// </summary>
        public void SetParameter(string name, string unevaluatedValue)
        {
            if (Link != null)
            {
                TaskLink.SetParameter(name, unevaluatedValue);
                return;
            }

            lock (_locker)
            {
                ErrorUtilities.VerifyThrowArgumentLength(name, nameof(name));
                ErrorUtilities.VerifyThrowArgumentNull(unevaluatedValue, nameof(unevaluatedValue));
                ErrorUtilities.VerifyThrowArgument(!XMakeAttributes.IsSpecialTaskAttribute(name), "CannotAccessKnownAttributes", name);

                _parameters = null;
                XmlElement.SetAttribute(name, unevaluatedValue);
                MarkDirty("Set task parameter {0}", name);
            }
        }
Example #20
0
        public void AddLink(Task parentTask, Task dependentTask, TaskLinkType linkType)
        {
            CheckLink(parentTask, dependentTask, linkType);

            var link = new TaskLink
            {
                ParentTaskId     = parentTask.ID,
                DependenceTaskId = dependentTask.ID,
                LinkType         = linkType
            };

            if (taskDao.IsExistLink(link))
            {
                throw new Exception("link already exist");
            }

            ProjectSecurity.DemandEdit(dependentTask);
            ProjectSecurity.DemandEdit(parentTask);

            taskDao.AddLink(link);
        }
Example #21
0
        /// <summary>
        /// Gets the value of the parameter with the specified name,
        /// or empty string if it is not present.
        /// </summary>
        public string GetParameter(string name)
        {
            if (Link != null)
            {
                return(TaskLink.GetParameter(name));
            }

            lock (_locker)
            {
                ErrorUtilities.VerifyThrowArgumentLength(name, nameof(name));

                EnsureParametersInitialized();

                if (_parameters.TryGetValue(name, out Tuple <string, ElementLocation> parameter))
                {
                    return(parameter.Item1);
                }

                return(String.Empty);
            }
        }
        public static void Run()
        {
            try
            {
                string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

                // ExStart:LinkTasks
                Project project = new Project(dataDir + "SampleProject.mpp");

                Task task1 = project.RootTask.Children.GetById(1);
                Task task2 = project.RootTask.Children.GetById(2);
                Task task3 = project.RootTask.Children.GetById(3);
                Task task4 = project.RootTask.Children.GetById(4);
                Task task5 = project.RootTask.Children.GetById(5);

                // Link the tasks
                TaskLink tsklnk = project.TaskLinks.Add(task1, task2, TaskLinkType.FinishToStart);
                tsklnk = project.TaskLinks.Add(task2, task3, TaskLinkType.FinishToStart);
                tsklnk = project.TaskLinks.Add(task3, task4, TaskLinkType.FinishToStart);
                tsklnk = project.TaskLinks.Add(task4, task5, TaskLinkType.FinishToStart);
                tsklnk = project.TaskLinks.Add(task2, task5, TaskLinkType.FinishToStart);

                // Display links among the tasks
                TaskLinkCollection allinks = project.TaskLinks;
                foreach (TaskLink tasklnk in allinks)
                {
                    Console.WriteLine("From ID = " + tasklnk.PredTask.Get(Tsk.Id) + "=>To ID = " + tasklnk.SuccTask.Get(Tsk.Id));
                    Console.WriteLine("________________________________________");
                }

                // Save the project
                project.Save(dataDir + "LinkTasks_out.mpp", SaveFileFormat.MPP);
                // ExEnd:LinkTasks
            }
            catch (NotSupportedException ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
            }
        }
        public void TestPostTaskLink()
        {
            TasksApi   target     = new TasksApi(APIKEY, APPSID, BASEPATH);
            StorageApi storageApi = new StorageApi(APIKEY, APPSID, BASEPATH);


            string   name     = "sample-project-2.mpp";
            string   storage  = null;
            string   folder   = null;
            string   fileName = null;
            TaskLink body     = new TaskLink();

            body.Index          = 2;
            body.PredecessorUid = 1;
            body.SuccessorUid   = 2;

            storageApi.PutCreate(name, null, null, System.IO.File.ReadAllBytes("\\temp\\tasks\\resources\\" + name));
            SaaSposeResponse actual;

            actual = target.PostTaskLink(name, storage, folder, fileName, body);
            Assert.AreEqual("200", actual.Code);
            Assert.IsInstanceOfType(new SaaSposeResponse(), actual.GetType());
        }
Example #24
0
        public static void Run()
        {
            //ExStart:ApplyCalculationModeAuto
            // Create empty project and set calculation mode to Automatic
            Project project = new Project();

            project.CalculationMode = CalculationMode.Automatic;

            // Set project start date and add new tasks
            project.Set(Prj.StartDate, new DateTime(2015, 4, 15));
            Task task1 = project.RootTask.Children.Add("Task 1");
            Task task2 = project.RootTask.Children.Add("Task 2");

            // Link tasks
            TaskLink link = project.TaskLinks.Add(task1, task2, TaskLinkType.FinishToStart);

            // Verify dates have been recalculated
            Console.WriteLine("Task1 Start + 1 Equals Task2 Start : {0} ", task1.Get(Tsk.Start).AddDays(1).Equals(task2.Get(Tsk.Start)));
            Console.WriteLine("Task1 Finish + 1 Equals Task2 Finish : {0} ", task1.Get(Tsk.Finish).AddDays(1).Equals(task2.Get(Tsk.Finish)));
            Console.WriteLine("RootTask Finish Equals Task2 Finish : {0} ", task2.Get(Tsk.Finish).Equals(project.RootTask.Get(Tsk.Finish)));
            Console.WriteLine("Project Finish Date Equals Task2 Finish : {0} ", task2.Get(Tsk.Finish).Equals(project.Get(Prj.FinishDate)));
            //ExEnd:ApplyCalculationModeAuto
        }
 public TaskLinkWrapper(TaskLink link)
 {
     DependenceTaskId = link.DependenceTaskId;
     ParentTaskId     = link.ParentTaskId;
     LinkType         = link.LinkType;
 }
Example #26
0
        static void Main(string[] args)
        {
            // Read a table from sql server via a query, then make an exact copy
            // of that table.
            // Step 1. Read source table schema
            // Step 2. Create exact same schema on destination
            // Step 3. Copy Data

            // Prepare reflow engine
            ReflowEngine engine = new ReflowEngine();
            // Test DB Path

            string test = "text"; // "access";
            string sourceConnectionString = string.Empty;

            ILinkProvider sourceProvider = null;

            if (test == "access")
            {
                string accessDBPath = AppDomain.CurrentDomain.BaseDirectory + "db1.accdb";
                sourceConnectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=False;",
                                                       accessDBPath);
                sourceProvider = new Provider.Access.AccessLinkProvider();
            }
            else if (test == "text")
            {
                // TODO: Test and implement text driver
                string txtDBPath = AppDomain.CurrentDomain.BaseDirectory + "text\\HumanResources_Employee.txt";
                sourceConnectionString = "@File=" + txtDBPath + ";@Type=Delimited;RowSeperator=\r\n;ColumnSeperator=,;FirstRowHasNames=True";
                // TODO: Fixed length - Need to implement
                //sourceConnectionString = "@File="+txtDBPath + ";@Type=Fixed;";
                sourceProvider = new Provider.Text.TextProvider();
            }

            IDataLink linkSource = sourceProvider.CreateLink(sourceConnectionString);

            ILinkProvider sqlProvider          = new Provider.SqlServer.SqlLinkProvider();
            string        destConnectionString = "Server=localhost;Database=REflow;Trusted_Connection=True;";
            IDataLink     linkDestination      = sqlProvider.CreateLink(destConnectionString);

            // Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=c:\txtFilesFolder\;Extensions=asc,csv,tab,txt;

            string selectQuery = "Select * from HumanResources_Employee";

            // First lets discover the schema of the query [source table]
            DiscoverSchemaTask task1 = new DiscoverSchemaTask();

            task1.Name  = "DiscoverSchema";
            task1.Query = selectQuery;
            task1.Link  = linkSource;

            // Then we need to create a table in the destinaton database.
            TableCreateTask task2 = new TableCreateTask();

            task2.Name               = "CreateTableAbc";
            task2.TableName          = "abc";
            task2.Link               = linkDestination;
            task2.ShouldDropExisting = true;
            // Now we need to map task1 output to be the input of task2 since
            // task1 will discover column names and we need to map discovered
            // columns to the Columns property of task 2. We can do this one of
            // two way.

            // First, we can use a delegate to call onbeforeexecute for task2 and
            // assign task result of task 1 to the column property of task 2. But that
            // would be problematic for the scenario where we want to serialize the task
            // and deserialize.

            // Second, We can we task link object map output of task1 to go into certain
            // properties of task 2. This can be serialized. We would use this technique

            TaskLink link = new TaskLink();

            link.LastTask = task1;
            link.NextTask = task2;
            // Map the output called DiscoveredColumns ( found in TaskResult.Output["DiscoveredColumns"]) to
            // task2.Columns once task1 has been executed
            link.TaskPipe["Columns"] = "Columns";
            link.Bind();

            // Now we will execute the data copy task. Will need to do the column mapping
            // Interestingly, since our output columns are same as input columns at source,
            // we can use the automap property to map the columns automatically.


            DataFlowTask task3 = new DataFlowTask()
            {
                Name = "DataCopyTask"
            };
            ILinkReader reader = sourceProvider.CreateReader(linkSource, selectQuery);       // Since we are using same query
            ILinkWriter writer = sqlProvider.CreateWriter(linkDestination, task2.TableName); //  Dest table

            task3.Input  = reader;
            task3.Output = writer;

            /* We would notmally create column mapping here and and map source and
             * destination and put custom expressions if needed. But since we are doing a
             * direct table copy, we can just use Automap property. */
            // ColumnMappings maps = new ColumnMappings();
            task3.IsAutoMap = true;
            task3.TableName = task2.TableName;

            // TODO: Add column mapping support
            // Add scripting transformation
            ColumnMap map = new ColumnMap();

            map.Destination = "Title";
            Expression exp = new Expression()
            {
                Code = "NationalIDNumber & \" \" &  UCASE(Title) & CSTR(LEN(Title))"
            };

            map.TransformExpression = exp;
            task3.Mapping.Add(map);

            engine.Tasks.Add(task1);
            engine.Tasks.Add(task2);
            engine.Tasks.Add(task3);


            ExecutionEventListener eventListener = new ExecutionEventListener();

            eventListener.OnTaskExecutionEvent += delegate(string taskname, string eventName, string description)
            {
                Console.WriteLine(string.Format("{0,15} |{1,10} | {2}", taskname, eventName, description));
            };
            eventListener.LoggingLevel = ExecutionEventListener.LogLevel.Verbose;
            engine.Execute(eventListener);
        }
        public static void Run()
        {
            // ExStart:UpdateProjectAndRescheduleUncompletedWork
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

            // Create a new project and set start date
            Project project = new Project();

            project.Set(Prj.StartDate, new DateTime(2014, 1, 27, 8, 0, 0));

            // Add new tasks
            Task task1 = project.RootTask.Children.Add("Task 1");
            Task task2 = project.RootTask.Children.Add("Task 2");

            task2.Set(Tsk.Duration, task2.ParentProject.GetDuration(16, TimeUnitType.Hour));
            Task task3 = project.RootTask.Children.Add("Task 3");

            task3.Set(Tsk.Duration, task2.ParentProject.GetDuration(24, TimeUnitType.Hour));
            Task task4 = project.RootTask.Children.Add("Task 4");

            task4.Set(Tsk.Duration, task2.ParentProject.GetDuration(16, TimeUnitType.Hour));
            Task task5 = project.RootTask.Children.Add("Task 5");

            task5.Set(Tsk.Duration, task2.ParentProject.GetDuration(16, TimeUnitType.Hour));

            // Add links between tasks
            TaskLink link12 = project.TaskLinks.Add(task1, task2, TaskLinkType.FinishToStart);
            TaskLink link23 = project.TaskLinks.Add(task2, task3, TaskLinkType.FinishToStart);

            // One day lag
            link23.LinkLag = 4800;
            TaskLink link34 = project.TaskLinks.Add(task3, task4, TaskLinkType.FinishToStart);
            TaskLink link45 = project.TaskLinks.Add(task4, task5, TaskLinkType.FinishToStart);

            // Add new tasks
            Task task6 = project.RootTask.Children.Add("Task 6");
            Task task7 = project.RootTask.Children.Add("Task 7");

            task7.Set(Tsk.Duration, task7.ParentProject.GetDuration(24, TimeUnitType.Hour));
            Task task8 = project.RootTask.Children.Add("Task 8");

            task8.Set(Tsk.Duration, task2.ParentProject.GetDuration(16, TimeUnitType.Hour));
            Task task9 = project.RootTask.Children.Add("Task 9");

            task9.Set(Tsk.Duration, task2.ParentProject.GetDuration(16, TimeUnitType.Hour));
            Task task10 = project.RootTask.Children.Add("Task 10");

            // Add links between tasks
            TaskLink link67  = project.TaskLinks.Add(task6, task7, TaskLinkType.FinishToStart);
            TaskLink link78  = project.TaskLinks.Add(task7, task8, TaskLinkType.FinishToStart);
            TaskLink link89  = project.TaskLinks.Add(task8, task9, TaskLinkType.FinishToStart);
            TaskLink link910 = project.TaskLinks.Add(task9, task10, TaskLinkType.FinishToStart);

            task6.Set(Tsk.IsManual, true);
            task7.Set(Tsk.IsManual, true);
            task8.Set(Tsk.IsManual, true);
            task9.Set(Tsk.IsManual, true);
            task10.Set(Tsk.IsManual, true);

            // Save project before and after updating work as completed
            project.Save(dataDir + "RescheduleUncompletedWork_not updated_out.xml", SaveFileFormat.XML);
            project.UpdateProjectWorkAsComplete(new DateTime(2014, 1, 28, 17, 0, 0), false);
            project.Save(dataDir + "RescheduleUncompletedWork_updated_out.xml", SaveFileFormat.XML);

            // Save project after rescheduling uncompleted work
            project.RescheduleUncompletedWorkToStartAfter(new DateTime(2014, 2, 7, 8, 0, 0));
            project.Save(dataDir + "RescheduleUncompletedWork_rescheduled_out.xml", SaveFileFormat.XML);
            // ExEnd:UpdateProjectAndRescheduleUncompletedWork
        }