/// <summary> /// Simulate a delay and return stub data /// </summary> private void LongOperationToFetchTasks(object param) { Thread.Sleep (600); if (FetchTasksCompleteEvent == null) return; View vw = (View)param; TaskFetchCompletedEventArgs args; try { args = new TaskFetchCompletedEventArgs(); //return an in-memory copy, objective - update this in memory copy during update operations //if (StubDataProvider.StubbedTasks == null) //{ StubDataProvider.StubbedTasks = StubDataProvider.CreateStubbedTasks(view); //} //introducing variability in the number of tasks returned from the stub int count = DateTime.Now.Second % StubDataProvider.StubbedTasks.Count; args.Tasks=StubDataProvider.StubbedTasks;//.GetRange (0,count); } catch (Exception ex) { args = new TaskFetchCompletedEventArgs(ex, true, null); args.Tasks = new List<TaskItem>();//return an empty collection nevertheless } Deployment.Current.Dispatcher.BeginInvoke(delegate() { //emit custom data to mimic custom search foreach (TaskItem t in args.Tasks) { t.TaskName = "selectedview-"+vw.ToString (); //System.Diagnostics.Debug.WriteLine("Emitting a task: " + t.DueTime); } FetchTasksCompleteEvent(this, args); }); }
void provider_FetchTasksCompleteEvent(object sender, TaskFetchCompletedEventArgs args) { //TODO remmove event handler if already wired up if ((args.Error != null) || (args.Cancelled == true)) { if (args.Error != null) Status.Exception = args.Error; else Status.Message = "The web service operation was cancelled by the user"; this.Tasks.BeginUpdate(); this.Tasks.Clear(); this.Refreshing = false; this.Tasks.EndUpdate(); } else { this.TimeLastSync = DateTime.Now; this.Status.Exception = null; this.Status.Message = string.Format("Last synchronized at {0}, {1} records were fetched", this.TimeLastSync, args.Tasks.Count); this.Tasks.BeginUpdate();//supress change notifications till all Tasks are added to the collection this.Tasks.Clear(); foreach (TaskItem item in args.Tasks) { //Mar 2011, Do not show NA tasks in the non-NA views. View vwCurrent = this.SelectedView; if ( ((vwCurrent & View.vwNotApplicable) > 0) || ((vwCurrent & View.vwArchiveView) > 0) || ((vwCurrent & View.vwCustomSearch) > 0) ) { } else { if (item.Status == CamlHelper.NOTAPPLICABLE_STATUS) continue; } this.Tasks.Add(item); if (this.Tasks.MemorizedSelectedIDs.Contains(item.ID)) item.IsSelected = true;//Oct 27 } Tasks.EndUpdate(); Refreshing = false; } }
void omdBridge_QueryTasksCompleted(object sender, BCheck.Data.BCheckOMDQuery.QueryTasksCompletedEventArgs e) { TaskFetchCompletedEventArgs args = null; if (e.Cancelled == true) { args = new TaskFetchCompletedEventArgs(null, true, null); args.Tasks = new List<TaskItem>();//return an empty collection nevertheless } else if (e.Error != null) { args = new TaskFetchCompletedEventArgs(e.Error, false, null); args.Tasks = new List<TaskItem>();//return an empty collection nevertheless ViewModel.Current.Status.AddToLog(e.Error.ToString(), true); } else { args = new TaskFetchCompletedEventArgs(null, false, null); if (e.Result.rows == null) args.Tasks = new List<TaskItem>();//return an empty collection nevertheless else { args.Tasks = TaskItemFactory.ConvertTasksFromOMD(e.Result.rows); ArchiveHelper.ProcessMessage(e.Result.message); } } if (FetchTasksCompleteEvent != null) FetchTasksCompleteEvent(this, args); }
void listClient_GetListItemsCompleted(object sender, BCheck.Data.BCheckLists.GetListItemsCompletedEventArgs e) { if (FetchTasksCompleteEvent == null) return; TaskFetchCompletedEventArgs args; try { if (e.Error != null) { args = new TaskFetchCompletedEventArgs(e.Error, e.Cancelled, null); } else { args = new TaskFetchCompletedEventArgs(); args.Tasks = new List<TaskItem>(); XElement xresults = e.Result; XNamespace ns = "#RowsetSchema"; var query = from x in xresults.Descendants() where x.Name == ns + "row" select new TaskItem { TaskName = (string)x.Attribute("ows_Title"), ID = (int?)x.Attribute("ows_ID") ?? 0, Version = (int?)x.Attribute("ows_owshiddenversion") ?? 1, TaskDescription = (string)x.Attribute("ows_High_x0020_Level_x0020_Descripti"), AssignedTo = (string)x.Attribute("ows_Assign_x0020_to"), Status = (string)x.Attribute("ows_Status"), DueTime = (string)x.Attribute("ows_Due_x0020_Time"), ManagementSignOff = (string)x.Attribute("ows_Management_x0020_Signoff"), Kri = (string)x.Attribute("ows_KPI"), Comments = (string)x.Attribute("ows_Comments"), CreatedUtc = (DateTime)x.Attribute("ows_Created"), AttachmentUrl = (string)x.Attribute("ows_Attachments"), KriDefinition = (string)x.Attribute("ows_Matrix_x0020_Definition"), AlertTime = (string)x.Attribute("ows_Alert_x0020_Time"), EscalationTime = (string)x.Attribute("ows_Escalation_x0020_Level_x0020_1_x"), LinkToProcess = (string)x.Attribute("ows_Link_x0020_to_x0020_Process"), Manager = (string)x.Attribute("ows_Manager"), CreatedLocal = TaskItem.GetCreatedTimeAsPerCurrentRegion((DateTime)x.Attribute("ows_Created")), Functional = (string)x.Attribute("ows_Functional"), BypassApproval = (string)x.Attribute("ows_BypassManagerApproval"), ManagerSelfApproval = (string)x.Attribute("ows_ManagerSelfApproval"), TaskOwner = (string)x.Attribute("ows_TaskOwner"), TimeForCompletion = (string)x.Attribute("ows_Time_x0020_Taken"), LateIncompleteReason = (string)x.Attribute("ows_LateIncompleteReason"), SystemOutrage = (string)x.Attribute("ows_SystemOutrage"), CompletedBy = (string)x.Attribute("ows_Completed_x0020_By") }; //Status = x.Attribute("ows_Status").Value, //ManagementSignOff = x.Attribute("Management_x0020_Signoff").Value //select (string)c.Element("Name"); /* loop through all the XML entries and construct a TaskItem object here */ foreach (TaskItem t in query) { t.CompletedBy = RegexMatchOrNull(t.CompletedBy); t.SetInitializationComplete(); args.Tasks.Add(t); } } } catch (Exception ex) { args = new TaskFetchCompletedEventArgs(ex, true, null); args.Tasks = new List<TaskItem>();//return an empty collection nevertheless } Deployment.Current.Dispatcher.BeginInvoke(delegate() { if (e.UserState == null) { FetchTasksCompleteEvent(this, args); return; } if (e.UserState.Equals(IIsAction.QUERYSINGLE))//May10,when a single Task is udpated , fire back a different event. You do not want the complete UI to refresh { TaskItemUpdateCompleteEventArgs evargs = new TaskItemUpdateCompleteEventArgs(null, false, null); evargs.UpdatedTasks = args.Tasks; TaskUpdateCompleteEvent(this, evargs); return; } }); }
public virtual void FetchTasks(View vw, SearchParams paramSearch) { string queryXml = ""; string viewFieldsXml = ""; #region Old CamlCreator //switch (vw) //{ // case View.vwOpsChecklistLoad: // //queryXml = CamlHelper.QueryMyTasksOnLoad(); // //viewFieldsXml = CamlHelper.VIEWFIELDS_MYTASKSVERBOSE; // queryXml = CamlHelper.QueryMyTasksDueToday(); // viewFieldsXml = CamlHelper.VIEWFIELDS_MYTASKSVERBOSE; // break; // case View.vwDueToday | View.vwAssignedTasks: // queryXml = CamlHelper.QueryMyTasksDueToday(); // viewFieldsXml = CamlHelper.VIEWFIELDS_MYTASKSVERBOSE; // break; // case View.vwOverDue | View.vwAssignedTasks: // queryXml = CamlHelper.QueryMyTasksOverdue(); // viewFieldsXml = CamlHelper.VIEWFIELDS_MYTASKSVERBOSE; // break; // case View.vwCompletedApproved | View.vwAssignedTasks: // queryXml = CamlHelper.QueryMyTasksApprovedComplete(); // viewFieldsXml = CamlHelper.VIEWFIELDS_MYTASKSVERBOSE; // break; // case View.vwDueToday | View.vwManagedTasks: // queryXml = CamlHelper.QueryManagedTasksDueToday(); // viewFieldsXml = CamlHelper.VIEWFIELDS_MYTASKSVERBOSE; // break; // case View.vwOverDue | View.vwManagedTasks: // queryXml = CamlHelper.QueryManagedTasksIncomplete(); // viewFieldsXml = CamlHelper.VIEWFIELDS_MYTASKSVERBOSE; // break; // case View.vwCompletedApproved | View.vwManagedTasks: // queryXml = CamlHelper.QueryManagedTasksCompleted(); // viewFieldsXml = CamlHelper.VIEWFIELDS_MYTASKSVERBOSE; // break; // case View.vwCustomSearch: // queryXml = CamlHelper.QueryCustomSearch(paramSearch); // viewFieldsXml = CamlHelper.VIEWFIELDS_MYTASKSVERBOSE; // break; // case View.vwArchiveView: // // If its the custom search do nothing, we just use the different service to query // break; // case View.vwAssignedTasks | View.vwNotApplicable: // queryXml = CamlHelper.QueryAssignedTasksNotApplicable(); // viewFieldsXml = CamlHelper.VIEWFIELDS_MYTASKSVERBOSE; // break; // case View.vwManagedTasks | View.vwNotApplicable: // queryXml = CamlHelper.QueryManagedTasksNotApplicable(); // viewFieldsXml = CamlHelper.VIEWFIELDS_MYTASKSVERBOSE; // break; // default: // queryXml = ""; // throw new NotImplementedException("this view has not been implemented:" + vw.ToString()); // //break; //} //queryXml = queryXml.Replace("&", "&"); #endregion UserTasks taskids = MasterLookupService.Current.GetUserTaskIDs(); if (vw == View.vwArchiveView || vw == View.vwCustomSearch) { //int hoursOffset = -12; //EndpointAddress addr = new EndpointAddress(ViewModel.OMDQueryAsmxUrl); //BasicHttpBinding bnd = new BasicHttpBinding(); //bnd.ReceiveTimeout = TimeSpan.FromMinutes(6); //bnd.SendTimeout = TimeSpan.FromMinutes(6); //bnd.OpenTimeout = TimeSpan.FromMinutes(6); //bnd.CloseTimeout = TimeSpan.FromMinutes(6); //bnd.MaxBufferSize = InitParams.Current.MaxBufferSize; //bnd.MaxReceivedMessageSize = bnd.MaxBufferSize; //OMDQuerySoapClient omdQuery = new OMDQuerySoapClient(bnd, addr); //DateTime? startDate = paramSearch.StartDate; //DateTime? endDate = paramSearch.EndDate; //if (paramSearch.StartDate != null) // startDate = ((DateTime)paramSearch.StartDate).AddHours(hoursOffset); //if (paramSearch.EndDate != null) // endDate = ((DateTime)paramSearch.EndDate).AddDays(1).AddHours(hoursOffset).AddMinutes(-1); //omdQuery.QueryTasksCompleted += new EventHandler<BCheck.Data.BCheckOMDQuery.QueryTasksCompletedEventArgs>(omdBridge_QueryTasksCompleted); //omdQuery.QueryTasksAsync(ArchiveHelper.GetUserSearchText(paramSearch.AssignedTo), paramSearch.TaskName, ArchiveHelper.GetUserSearchText(paramSearch.Manager), // paramSearch.StartDate, endDate, null); TaskFetchCompletedEventArgs args = new TaskFetchCompletedEventArgs(); args.Tasks = new List<TaskItem>(); FetchedTasks = new List<bCheckV2.Helpers.Definitions.TaskItem>(); OpsChecklistDataAgentService opschecklistdataservice = new OpsChecklistDataAgentService(); opschecklistdataservice.GetArchivedTasks(results => { FetchedTasks.AddRange(results); foreach (bCheckV2.Helpers.Definitions.TaskItem task in results) { args.Tasks.Add(FormatTaskItem(task, View.vwAssignedTasks)); } Deployment.Current.Dispatcher.BeginInvoke(delegate() { FetchTasksCompleteEvent(this, args); return; }); }, ArchiveHelper.GetUserSearchText(paramSearch.AssignedTo), paramSearch.TaskName, ArchiveHelper.GetUserSearchText(paramSearch.Manager), paramSearch.StartDate.Value.ToString(), paramSearch.EndDate.Value.ToString(), paramSearch.Functional, paramSearch.BusinessArea, paramSearch.Status); } else if (vw == View.vwCustomSearch) { string url = this.ConstructUrlParams(IIsAction.QUERY, vw, 0); EndpointAddress addr = new EndpointAddress(url);//URL params injected, Mar 29 BasicHttpBinding bnd = new BasicHttpBinding(); bnd.ReceiveTimeout = TimeSpan.FromMinutes(6); bnd.SendTimeout = TimeSpan.FromMinutes(6); bnd.OpenTimeout = TimeSpan.FromMinutes(6); bnd.CloseTimeout = TimeSpan.FromMinutes(6); bnd.MaxBufferSize = InitParams.Current.MaxBufferSize; bnd.MaxReceivedMessageSize = bnd.MaxBufferSize; BCheckLists.ListsSoapClient listClient = new BCheck.Data.BCheckLists.ListsSoapClient(bnd, addr); listClient.GetListItemsCompleted += new EventHandler<BCheck.Data.BCheckLists.GetListItemsCompletedEventArgs>(listClient_GetListItemsCompleted); XElement query = XElement.Parse(queryXml); XElement viewFields = XElement.Parse(viewFieldsXml); string queryOptionsXml = "<QueryOptions><DateInUtc>TRUE</DateInUtc><IncludeAttachmentUrls>TRUE</IncludeAttachmentUrls><IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns></QueryOptions>"; XElement queryOptions = XElement.Parse(queryOptionsXml); string maxrows = BCheck.Data.InitParams.Current.MaxCamlRows.ToString(); listClient.GetListItemsAsync(InitParams.Current.ListName, "", query, viewFields, maxrows, queryOptions, null); } else { TaskFetchCompletedEventArgs args = new TaskFetchCompletedEventArgs(); args.Tasks = new List<TaskItem>(); FetchedTasks = new List<bCheckV2.Helpers.Definitions.TaskItem>(); OpsChecklistDataAgentService opschecklistdataservice = new OpsChecklistDataAgentService(); if (vw == (View.vwAssignedTasks | View.vwDueToday) || vw == View.vwOpsChecklistLoad) { opschecklistdataservice.GetAssignedTasksDueToday(results => { FetchedTasks.AddRange(results); foreach (bCheckV2.Helpers.Definitions.TaskItem task in results) { args.Tasks.Add(FormatTaskItem(task, View.vwAssignedTasks)); } Deployment.Current.Dispatcher.BeginInvoke(delegate() { FetchTasksCompleteEvent(this, args); return; }); }); } if (vw == (View.vwAssignedTasks | View.vwNotApplicable)) { opschecklistdataservice.GetAssignedTasksNotApplicable(results => { FetchedTasks.AddRange(results); foreach (bCheckV2.Helpers.Definitions.TaskItem task in results) { args.Tasks.Add(FormatTaskItem(task, View.vwAssignedTasks)); } Deployment.Current.Dispatcher.BeginInvoke(delegate() { FetchTasksCompleteEvent(this, args); return; }); }); } if (vw == (View.vwManagedTasks | View.vwNotApplicable)) { opschecklistdataservice.GetAssignedTasksNotApplicable(results => { FetchedTasks.AddRange(results); foreach (bCheckV2.Helpers.Definitions.TaskItem task in results) { args.Tasks.Add(FormatTaskItem(task, View.vwManagedTasks)); } Deployment.Current.Dispatcher.BeginInvoke(delegate() { FetchTasksCompleteEvent(this, args); return; }); }); } if (vw == (View.vwAssignedTasks | View.vwOverDue)) { opschecklistdataservice.GetAssignedTasksOverdue(results => { FetchedTasks.AddRange(results); foreach (bCheckV2.Helpers.Definitions.TaskItem task in results) { args.Tasks.Add(FormatTaskItem(task, View.vwAssignedTasks)); } Deployment.Current.Dispatcher.BeginInvoke(delegate() { FetchTasksCompleteEvent(this, args); return; }); }); } if (vw == (View.vwAssignedTasks | View.vwCompletedApproved)) { opschecklistdataservice.GetAssignedTasksCompleted(results => { FetchedTasks.AddRange(results); foreach (bCheckV2.Helpers.Definitions.TaskItem task in results) { args.Tasks.Add(FormatTaskItem(task, View.vwAssignedTasks)); } Deployment.Current.Dispatcher.BeginInvoke(delegate() { FetchTasksCompleteEvent(this, args); return; }); }); } if (vw == (View.vwManagedTasks | View.vwDueToday)) { opschecklistdataservice.GetManagedTasksDueToday(results => { FetchedTasks.AddRange(results); foreach (bCheckV2.Helpers.Definitions.TaskItem task in results) { args.Tasks.Add(FormatTaskItem(task, View.vwManagedTasks)); } Deployment.Current.Dispatcher.BeginInvoke(delegate() { FetchTasksCompleteEvent(this, args); return; }); }); } if (vw == (View.vwManagedTasks | View.vwOverDue)) { opschecklistdataservice.GetManagedTasksOverdue(results => { FetchedTasks.AddRange(results); foreach (bCheckV2.Helpers.Definitions.TaskItem task in results) { args.Tasks.Add(FormatTaskItem(task, View.vwManagedTasks)); } Deployment.Current.Dispatcher.BeginInvoke(delegate() { FetchTasksCompleteEvent(this, args); return; }); }); } if (vw == (View.vwManagedTasks | View.vwCompletedApproved)) { opschecklistdataservice.GetManagedTasksApproved(results => { FetchedTasks.AddRange(results); foreach (bCheckV2.Helpers.Definitions.TaskItem task in results) { args.Tasks.Add(FormatTaskItem(task, View.vwManagedTasks)); } Deployment.Current.Dispatcher.BeginInvoke(delegate() { FetchTasksCompleteEvent(this, args); return; }); }); } /* string TasksCAMLQuery = CreateCAMLQuery(vw, paramSearch, taskids); if (TasksCAMLQuery != "Overload") { if (vw == View.vwOpsChecklistLoad || vw == (View.vwDueToday | View.vwAssignedTasks) || vw == (View.vwDueToday | View.vwManagedTasks)) { TaskFetchCompletedEventArgs args; TaskAlertsFetchCompletedEventArgs alertargs; alertargs = new TaskAlertsFetchCompletedEventArgs(); args = new TaskFetchCompletedEventArgs(); args.Tasks = new List<TaskItem>(); alertargs.AssignedTasks = new List<TaskItem>(); alertargs.ManagedTasks = new List<TaskItem>(); MasterLookupService.Current.GetTasksWithDetails(TasksCAMLQuery, tasks => { alertargs.HasAssignedTasks = false; List<String> assignedtaskidstocheck = new List<String>(); taskids.AssignedTasksDueToday.ForEach(tid => assignedtaskidstocheck.Add(tid)); taskids.AssignedTasksOverdue.ForEach(tid => assignedtaskidstocheck.Add(tid)); taskids.AssignedTasksCompletedApproved.ForEach(tid => assignedtaskidstocheck.Add(tid)); taskids.AssignedTasksNotApplicable.ForEach(tid => assignedtaskidstocheck.Add(tid)); foreach (var taskid in assignedtaskidstocheck) { var tasksassigned = tasks.Where(t => t.ID == int.Parse(taskid)); if (tasksassigned.Count() > 0) { TaskItem t = tasksassigned.First(); t.SetInitializationComplete(); if ((vw & View.vwAssignedTasks) == View.vwAssignedTasks || vw == View.vwOpsChecklistLoad) { args.Tasks.Add(t); } alertargs.AssignedTasks.Add(t); alertargs.HasAssignedTasks = true; } } alertargs.HasManagedTasks = false; List<String> managedtaskstocheck = new List<string>(); taskids.ManagedTasksDueToday.ForEach(tid => managedtaskstocheck.Add(tid)); taskids.ManagedTasksIncomplete.ForEach(tid => managedtaskstocheck.Add(tid)); taskids.ManagedTasksCompleted.ForEach(tid => managedtaskstocheck.Add(tid)); taskids.ManagedTasksNotApplicable.ForEach(tid => managedtaskstocheck.Add(tid)); foreach (var taskid in managedtaskstocheck) { var tasksmanaged = tasks.Where(t => t.ID == int.Parse(taskid)); if (tasksmanaged.Count() > 0) { TaskItem t = tasksmanaged.First(); t.SetInitializationComplete(); if ((vw & View.vwManagedTasks) == View.vwManagedTasks) { args.Tasks.Add(t); } alertargs.ManagedTasks.Add(t); alertargs.HasManagedTasks = true; } } Deployment.Current.Dispatcher.BeginInvoke(delegate() { FetchTasksCompleteEvent(this, args); FetchTaskAlertsCompleteEvent(this, alertargs); return; }); }); } else { TaskFetchCompletedEventArgs args; args = new TaskFetchCompletedEventArgs(); //string TasksCAMLQuery = CreateCAMLQuery(vw, paramSearch, taskids); args.Tasks = new List<TaskItem>(); //Adding tasks which have been returned in the query, the task filtering happens in the CAML helper MasterLookupService.Current.GetTasksWithDetails(TasksCAMLQuery, tasks => { // if ((vw == (View.vwOverDue | View.vwAssignedTasks)) || (vw == (View.vwOverDue | View.vwManagedTasks))) if ((vw & View.vwOverDue) == View.vwOverDue ) { foreach (var task in tasks) { if (task.CreatedUtc < RegionalSetting.GetRegionalMidnightToUtc()) { task.SetInitializationComplete(); args.Tasks.Add(task); } } } else { foreach (var task in tasks) { task.SetInitializationComplete(); args.Tasks.Add(task); } } Deployment.Current.Dispatcher.BeginInvoke(delegate() { FetchTasksCompleteEvent(this, args); return; }); }); } } else { string url = this.ConstructUrlParams(IIsAction.QUERY, vw, 0); EndpointAddress addr = new EndpointAddress(url);//URL params injected, Mar 29 BasicHttpBinding bnd = new BasicHttpBinding(); bnd.ReceiveTimeout = TimeSpan.FromMinutes(6); bnd.SendTimeout = TimeSpan.FromMinutes(6); bnd.OpenTimeout = TimeSpan.FromMinutes(6); bnd.CloseTimeout = TimeSpan.FromMinutes(6); bnd.MaxBufferSize = InitParams.Current.MaxBufferSize; bnd.MaxReceivedMessageSize = bnd.MaxBufferSize; BCheckLists.ListsSoapClient listClient = new BCheck.Data.BCheckLists.ListsSoapClient(bnd, addr); listClient.GetListItemsCompleted += new EventHandler<BCheck.Data.BCheckLists.GetListItemsCompletedEventArgs>(listClient_GetListItemsCompleted); XElement query = XElement.Parse(queryXml); XElement viewFields = XElement.Parse(viewFieldsXml); string queryOptionsXml = "<QueryOptions><DateInUtc>TRUE</DateInUtc><IncludeAttachmentUrls>TRUE</IncludeAttachmentUrls><IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns></QueryOptions>"; XElement queryOptions = XElement.Parse(queryOptionsXml); string maxrows = BCheck.Data.InitParams.Current.MaxCamlRows.ToString(); listClient.GetListItemsAsync(InitParams.Current.ListName, "", query, viewFields, maxrows, queryOptions, null); FetchAlertsForOverLoadCondition(); }*/ } }