public static WriteWarning ( |
||
logSourceInfo | ||
textbox | ||
bgws | ||
msg | string | |
리턴 | void |
private static void LogStatus(QueueJob job, TextBox textbox) { if (job.JobState != JobState.Success) { Log.WriteWarning(new SourceInfo(), textbox, "Queue job failed. Job State:{0}, Job Type:{1}", job.JobState, job.MessageType); } else { Log.WriteVerbose(new SourceInfo(), textbox, "Queue job successfully completed. Job State:{0}, Job Type:{1}", job.JobState, job.MessageType); } }
private void UpdateProjectOwner() { List <PublishedProject> projectList = new List <PublishedProject>(); EnterpriseResource resource = null; LV_Projects.InvokeIfRequired(s => { ListView.SelectedListViewItemCollection selectedItems = s.SelectedItems; projectList.AddRange(selectedItems.Cast <ListViewItem>().Select(selectedItem => (PublishedProject)selectedItem.Tag)); }); LV_EnterpiseResources.InvokeIfRequired(s => resource = (EnterpriseResource)s.SelectedItems[0].Tag); if (resource == null) { Log.WriteWarning(new SourceInfo(), TB_Status, "No enterprise resource selected."); return; } List <QueueJob> jobs = new List <QueueJob>(); foreach (PublishedProject publishedproject in projectList) { if (!publishedproject.IsCheckedOut) { publishedproject.CheckOut(); } else if (!publishedproject.CheckedOutBy.IsNull() && publishedproject.CheckedOutBy.Title != CsomBase.CurrentResource.User.Title) { Log.WriteWarning(new SourceInfo(), TB_Status, "Project:{0} checked out to a different user:{1}, not changing the owner to {2}.", publishedproject.Name, publishedproject.Owner.Title, resource.User.Title); continue; } Log.WriteVerbose(new SourceInfo(), TB_Status, "Updating project:{0}, Setting owner to:{1}", publishedproject.Name, resource.Name); publishedproject.Owner = resource.User; jobs.Add(publishedproject.Draft.Update()); } Log.WriteVerbose(new SourceInfo(), TB_Status, _bgeProject, "Waiting for the Project Update job to complete."); CsomHelper.ExecuteAndWait(jobs, TB_Status); Log.WriteVerbose(new SourceInfo(), TB_Status, _bgeProject, "Loading Projects."); LoadProjects(); }
private void actionWorker_DoWork(object sender, DoWorkEventArgs e) { Action functionToRun = (Action)e.Argument; ActionTask = Task.Factory.StartNew(() => { int executionCount = 0; while (executionCount < 3) { executionCount++; try { Log.WriteVerbose(new SourceInfo(), "Started Background Worker action."); ActionTaskThread = Thread.CurrentThread; functionToRun(); break; } catch (ThreadAbortException) { TaskCancelled = true; break; } catch (ClientRequestException cre) { if (cre.Message.Contains("The data is not available. The query may not have been executed.")) { Log.WriteWarning(new SourceInfo(), "Exception Caught. Retrying... \r\nEx:{0}", cre.Message); continue; } else { Log.WriteError(new SourceInfo(), "Exception Caught. \r\nEx:{0}", cre.Message); break; } } } Log.WriteVerbose(new SourceInfo(), "Completed Background Worker action."); }); while (!ActionTask.IsCompleted) { Thread.Sleep(500); BackgroundWorker statusWorker = (BackgroundWorker)sender; statusWorker.ReportProgress(0, AnimateText); } }
private void actionWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (TaskCancelled) { Log.WriteWarning(new SourceInfo(), _statusControl, "Query cancelled successfully."); return; } if (ActionTask.IsFaulted) { if (ActionTask.Exception != null) { foreach ( Exception ex in ActionTask.Exception.InnerExceptions.Where( ex => !(ex is ThreadAbortException) && !TaskCancelled)) { if (ex is ServerException) { ServerException se = (ServerException)ex; Log.WriteError(new SourceInfo(), _statusControl, "Error Code:{0}, ErrorDetail:{1}, CorrelationId:{2}, ErrorType:{3}, ErrorValue:{4}.", se.ServerErrorCode, se.ServerErrorDetails, se.ServerErrorTraceCorrelationId, se.ServerErrorTypeName, se.ServerErrorValue); } else { Log.WriteError(new SourceInfo(), _statusControl, "Exception:{0}, Message:{1}", ex.GetType().Name, ex.Message); } } } Log.WriteWarning(new SourceInfo(), _statusControl, "Query executed with errors."); } else { Log.WriteVerbose(new SourceInfo(), _statusControl, "Query executed successfully."); } }
private List <PropertyInfo> DisplayFields <T>(T clientObject) where T : ClientObject { IOrderedEnumerable <PropertyInfo> props = clientObject.GetType().GetProperties().Where(p => p.ReflectedType.Namespace.Contains("Project") && !_fieldsToExclude.Contains(p.Name)).OrderBy(p => p.Name); List <PropertyInfo> retrievedFields = new List <PropertyInfo>(); foreach ( PropertyInfo prop in props.Where(prop => !prop.PropertyType.IsSubclassOf(typeof(ClientObjectCollection)))) { if (IsPrimitiveEquatable(prop.PropertyType)) { if (clientObject.IsPropertyAvailable(prop.Name)) { Log.WriteVerbose(new SourceInfo(), "Displaying property:{0} of Type:{1}.", prop.Name, prop.PropertyType.Name); retrievedFields.Add(prop); } else { Log.WriteWarning(new SourceInfo(), "Failed Displaying property:{0} of Type:{1}.", prop.Name, prop.PropertyType.Name); } } else if (prop.PropertyType.IsEnum) { if (clientObject.IsPropertyAvailable(prop.Name)) { Log.WriteVerbose(new SourceInfo(), "Displaying Enum:{0} of Type:{1}.", prop.Name, prop.PropertyType.Name); retrievedFields.Add(prop); } else { Log.WriteWarning(new SourceInfo(), "Failed Displaying Enum:{0} of Type:{1}.", prop.Name, prop.PropertyType.Name); } } else if (prop.PropertyType.IsSubclassOf(typeof(ClientObject))) { if (clientObject.IsObjectPropertyInstantiated(prop.Name)) { Log.WriteVerbose(new SourceInfo(), "Displaying Object:{0} of Type:{1}.", prop.Name, prop.PropertyType.Name); retrievedFields.Add(prop); } else { Log.WriteWarning(new SourceInfo(), "Failed Displaying Object:{0} of Type:{1}.", prop.Name, prop.PropertyType.Name); } } else { Log.WriteWarning(new SourceInfo(), "Unknown property type {0} for property {1}", prop.PropertyType.Name, prop.Name); } } return(retrievedFields); }
private void LoadQueryFields <T>(T clientObject) where T : ClientObject { IOrderedEnumerable <PropertyInfo> props = clientObject.GetType().GetProperties().Where(p => p.ReflectedType.Namespace.Contains("Project") && !_fieldsToExclude.Contains(p.Name)).OrderBy(p => p.Name); MethodInfo lambdaMethod = typeof(Expression) .GetMethods() .First(x => x.Name.Contains("Lambda") && x.IsGenericMethod && x.GetParameters().Length == 2 && x.GetParameters()[1].ParameterType == typeof(ParameterExpression).MakeArrayType()) .MakeGenericMethod(typeof(Func <T, object>)); foreach (PropertyInfo prop in props) { if (IsPrimitiveEquatable(prop.PropertyType)) { Log.WriteVerbose(new SourceInfo(), "Loading property:{0} of Type:{1}.", prop.Name, prop.PropertyType.Name); Expression <Func <T, object> > expr = GetExpression(clientObject, lambdaMethod, prop); if (expr != null) { ProjContext.Load(clientObject, expr); } else { Log.WriteWarning(new SourceInfo(), "Failed loading property:{0} of Type:{1}.", prop.Name, prop.PropertyType.Name); } } else if (prop.PropertyType.IsEnum) { Log.WriteVerbose(new SourceInfo(), "Loading Enum:{0} of Type:{1}.", prop.Name, prop.PropertyType.Name); Expression <Func <T, object> > expr = GetExpression(clientObject, lambdaMethod, prop); if (expr != null) { ProjContext.Load(clientObject, expr); } else { Log.WriteWarning(new SourceInfo(), "Failed loading Enum:{0} of Type:{1}.", prop.Name, prop.PropertyType.Name); } } else if (prop.PropertyType.IsSubclassOf(typeof(ClientObject)) || prop.PropertyType.IsSubclassOf(typeof(ClientObjectCollection))) { Log.WriteVerbose(new SourceInfo(), "Loading Object:{0} of Type:{1}.", prop.Name, prop.PropertyType.Name); Expression <Func <T, object> > expr = GetExpression(clientObject, lambdaMethod, prop); if (expr != null) { ProjContext.Load(clientObject, expr); } else { Log.WriteWarning(new SourceInfo(), "Failed loading Object:{0} of Type:{1}.", prop.Name, prop.PropertyType.Name); } } else { Log.WriteWarning(new SourceInfo(), "Unknown property type {0} for property {1}", prop.PropertyType.Name, prop.Name); } } }
private void CreateProjects() { IList <EnterpriseResource> enterpriseResources = null; List <QueueJob> projectCreationJobs = new List <QueueJob>(); if (RB_AssignExistingEnterpriseResources.Checked) { IEnumerable <EnterpriseResource> resList = ProjContext.LoadQuery(ProjContext.EnterpriseResources.Where(r => r.ResourceType == EnterpriseResourceType.Work)); ProjContext.ExecuteQuery(); enterpriseResources = resList.ToList(); } for (int projCount = 1; projCount <= numProjects.Value; projCount++) { string projName = txtProjName.Text + projCount; List <EnterpriseResource> projectTeam = new List <EnterpriseResource>(); PublishedProject newProject = ProjContext.Projects.Add(new ProjectCreationInformation { Name = projName }); //Build the team first. if (RB_AssignExistingEnterpriseResources.Checked) { if (enterpriseResources.Count > 0) { projectTeam = enterpriseResources.PickRandom((int)numTasks.Value); projectTeam.ForEach(p => newProject.Draft.ProjectResources.AddEnterpriseResource(p)); } else { Log.WriteWarning(new SourceInfo(), TB_Status, "No enterprise resources available in the server."); } } else if (RB_AssignToMe.Checked) { if (CsomBase.CurrentResourceIsAssignable) { newProject.Draft.ProjectResources.AddEnterpriseResource(CsomBase.CurrentResource); } else { Log.WriteWarning(new SourceInfo(), TB_Status, "Current user is not resource. Not creating assignments."); } } List <TaskCreationInformation> dtc = CreateTasks(); if (CB_Tasks.Checked) { foreach (var task in dtc) { newProject.Draft.Tasks.Add(task); if (RB_AssignExistingEnterpriseResources.Checked) { if (projectTeam.Count > 0) { EnterpriseResource res = projectTeam.PickRandom(); newProject.Draft.Assignments.Add(new AssignmentCreationInformation { TaskId = task.Id, ResourceId = res.Id }); } else { Log.WriteWarning(new SourceInfo(), TB_Status, "No enterprise resources available in the server. Not creating assignments."); } } else if (RB_AssignToMe.Checked) { if (CsomBase.CurrentResourceIsAssignable) { AssignmentCreationInformation assnCi = CreateAssignment(task.Id, CsomBase.CurrentResource.Id); newProject.Draft.Assignments.Add(assnCi); } else { Log.WriteWarning(new SourceInfo(), TB_Status, "Current user is not resource. Not creating assignments."); } } } } if (RB_UseLocalResources.Checked) { for (int localResourceCount = 1; localResourceCount <= numTasks.Value; localResourceCount++) { ProjectResourceCreationInformation localResourceCi = CreateLocalResource(localResourceCount); newProject.Draft.ProjectResources.Add(localResourceCi); if (chkResAssign.Checked) { AssignmentCreationInformation assnCi = CreateAssignment(dtc.PickRandom().Id, localResourceCi.Id); newProject.Draft.Assignments.Add(assnCi); } } } Log.WriteVerbose(new SourceInfo(), TB_Status, "Creating project {0} of {1} with name {2}.", projCount, numProjects.Value, projName); projectCreationJobs.Add(newProject.Draft.Update()); } Log.WriteVerbose(new SourceInfo(), TB_Status, _backgroundExecutorWithStatus, "Waiting for the Project creation queue job to complete."); CsomHelper.ExecuteAndWait(projectCreationJobs, TB_Status); }