Ejemplo n.º 1
0
        private static List<UserTask> GetIncompleteTaskAll(string siteUrl)
        {
            List<UserTask> incompleteTasks = new List<UserTask>();
            using (ClientContext ctx = new ClientContext(siteUrl))
            {
                //Get all sites under Dashboard site (recursvie)
                Web oWeb = ctx.Web;
                WebCollection Webs = oWeb.Webs;
                ctx.Load(Webs);
                ctx.ExecuteQuery();
                var websFromLooping = new ArrayList();
                GetListOfWebs(ctx, Webs, websFromLooping);

                foreach (string webUrl in websFromLooping)
                {
                    ClientContext subContext = new ClientContext(webUrl);
                    // check task list existed
                    Web osubWeb = subContext.Web;
                    if (ListExists(osubWeb, ConfigurationManager.AppSettings["tasklist"].ToString()))
                    {
                        try
                        {
                            List list = subContext.Web.Lists.GetByTitle(ConfigurationManager.AppSettings["tasklist"].ToString());
                            CamlQuery camlQuery = new CamlQuery();

                            string viewQueryTask = @"
                                        <View>
                                        <Query><Where>
                                            <Or>
                                                <Or>
                                                <And>
                                                    <Or>
                                                        <And>
                                                            <IsNotNull>
                                                                <FieldRef Name='AssignedTo' />
                                                            </IsNotNull>
                                                            <Neq>
                                                                <FieldRef Name='PercentComplete' /><Value Type='Number'>1.00</Value>
                                                            </Neq>
                                                        </And>
                                                        <Neq>
                                                            <FieldRef Name='Status' /><Value Type='Choice'>Completed</Value>
                                                        </Neq>
                                                    </Or>
                                                    <Eq>
                                                          <FieldRef Name='DueDate' IncludeTimeValue='FALSE' /><Value Type='DateTime' IncludeTimeValue='FALSE'><Today  OffsetDays='-3' /></Value>
                                                    </Eq>
                                                </And>
                                                    <Eq>
                                                            <FieldRef Name='DueDate' IncludeTimeValue='FALSE' /><Value Type='DateTime' IncludeTimeValue='FALSE'><Today  OffsetDays='3' /></Value>
                                                    </Eq>
                                                </Or>
                                                    <Eq>
                                                        <FieldRef Name='DueDate' IncludeTimeValue='FALSE' /><Value Type='DateTime' IncludeTimeValue='FALSE'><Today  OffsetDays='0' /></Value>
                                                    </Eq>
                                            </Or>
                                            </Where> </Query>
                                         <OrderBy>
                                                <FieldRef Name='Modified' Ascending='False' />
                                        </OrderBy>
                                        <ViewFields><FieldRef Name='ID'/><FieldRef Name='Title'/><FieldRef Name='Body' /><FieldRef Name='Status'/><FieldRef Name='Created'/><FieldRef Name='DueDate'/><FieldRef Name='AssignedTo' />
                                        </ViewFields></View>";

                            camlQuery.ViewXml = viewQueryTask;
                            ListItemCollection items = list.GetItems(camlQuery);
                            subContext.Load(items);
                            subContext.ExecuteQuery();
                            if (items.Count > 0)
                            {
                                foreach (ListItem item in items)
                                {
                                    FieldUserValue[] assignedTo = (FieldUserValue[])item["AssignedTo"];
                                    UserTask userTask = new UserTask
                                    {

                                        UID = item["AssignedTo"] !=null ? assignedTo[0].LookupId : -1,
                                        TaskID = item["ID"] != null ? item["ID"].ToString() : string.Empty,
                                        TaskName = item["Title"] !=null ? item["Title"].ToString(): string.Empty,
                                        TaskDescription = item["Body"] != null ? item["Body"].ToString() : string.Empty,
                                        TaskUrl = String.Format("{0}/Lists/Tasks/DispForm.aspx?ID={1}", webUrl, item["ID"]),
                                        TaskStatus = item["Status"] != null ? item["Status"].ToString() : string.Empty,
                                        DueDate = item["DueDate"] != null ? Convert.ToDateTime(item["DueDate"].ToString()) : DateTime.MinValue
                                    };
                                    incompleteTasks.Add(userTask);
                                }

                            }

                        }
                        catch (Exception e)
                        {
                            Console.Write(e);
                        }

                    }

                }
            }
            return incompleteTasks;
        }
Ejemplo n.º 2
0
        private static List<UserTask> GetIncompleteTasksbyProject(ref ClientContext ctx, string webURL)
        {
            List<UserTask> incompleteTasks = new List<UserTask>();
            try
            {
                List list = ctx.Web.Lists.GetByTitle(ConfigurationManager.AppSettings["tasklist"].ToString());
                CamlQuery camlQuery = new CamlQuery();

                string viewQueryTask = @"
                                         <Where>
                                             <Or>
                                                 <Or>
                                                    <And>
                                                       <Neq>
                                                          <FieldRef Name='PercentComplete' /><Value Type='Number'>1.00</Value>
                                                       </Neq>
                                                       <Eq>
                                                          <FieldRef Name='DueDate' IncludeTimeValue='FALSE' /><Value Type='DateTime' IncludeTimeValue='FALSE'><Today  OffsetDays='-3' /></Value>
                                                       </Eq>
                                                    </And>
                                                    <Eq>
                                                       <FieldRef Name='DueDate' IncludeTimeValue='FALSE' /><Value Type='DateTime' IncludeTimeValue='FALSE'><Today  OffsetDays='3' /></Value>
                                                    </Eq>
                                                 </Or>
                                                 <Eq>
                                                    <FieldRef Name='DueDate' IncludeTimeValue='FALSE' /><Value Type='DateTime' IncludeTimeValue='FALSE'><Today  OffsetDays='0' /></Value>
                                                 </Eq>
                                              </Or>
                                         </Where>
                                          <OrderBy>
                                                <FieldRef Name='Modified' Ascending='False' />
                                        </OrderBy>
                                        <ViewFields><FieldRef Name='ID'/><FieldRef Name='Title'/><FieldRef Name='Status'/><FieldRef Name='Created'/><FieldRef Name='DueDate'/>
                                        </ViewFields></View>";

                camlQuery.ViewXml = viewQueryTask;
                ListItemCollection items = list.GetItems(camlQuery);
                ctx.Load(items);
                ctx.ExecuteQuery();
                if (items.Count > 0)
                {

                    foreach (ListItem item in items)
                    {
                        //var link = "<a href='" + webURL + "/Lists/Tasks/DispForm.aspx?ID=" + item["ID"] + "' target='_blank'>" + item["Title"] + "</a>";
                        UserTask userTask = new UserTask
                        {
                            //AssignedTo = item.FieldValues["AssignedTo"].ToString(),
                            TaskName = item.FieldValues["Title"].ToString()
                        };

                        incompleteTasks.Add(userTask);
                    }

                }

            }
            catch (Exception e)
            {
                Console.Write(e);
            }
            return incompleteTasks;
        }