WriteVerbose() public static method

public static WriteVerbose ( SourceInfo logSourceInfo, TextBox textbox, BackgroundExecutorWithStatus bgws, string msg ) : void
logSourceInfo SourceInfo
textbox System.Windows.Forms.TextBox
bgws BackgroundExecutorWithStatus
msg string
return void
 public BackgroundExecutorWithStatus(TextBox control, string textToAnimate)
 {
     _statusControl              = control;
     AnimateText                 = string.Empty;
     _maxDots                    = 4;
     AnimateText                 = textToAnimate;
     _statusControl.TextChanged += (sender, e) =>
     {
         _statusControl.InvokeIfRequired(tb =>
         {
             tb.Focus();
             tb.SelectionStart = tb.Text.Length;
             tb.ScrollToCaret();
         });
     };
     Log.WriteVerbose(new SourceInfo(), "Initializing Background Worker.");
     _actionWorker                     = new BackgroundExecutorBase();
     _actionWorker.DoWork             += actionWorker_DoWork;
     _actionWorker.ProgressChanged    += actionWorker_ProgressChanged;
     _actionWorker.RunWorkerCompleted += actionWorker_RunWorkerCompleted;
 }
Exemplo n.º 2
0
        private bool HandleLogin()
        {
            bool loginSucess = false;

            LBL_MainText.Hide();
            foreach (Control ctrl in TLP_Main.Controls)
            {
                if (!(ctrl is FlowLayoutPanel) || ctrl.Tag == null || ctrl.Tag.ToString() != "DisplayForm")
                {
                    continue;
                }
                FlowLayoutPanel flp = ctrl as FlowLayoutPanel;
                Log.WriteVerbose(new SourceInfo(), "Clearing Panel:{0} and its controls", flp.Name);
                flp.Controls.Clear();
                _panelCache.Remove(ctrl as FlowLayoutPanel);
                TLP_Main.Controls.Remove(ctrl);
            }

            CsomBase.ClearCsomObjects();
            ResetDisplayPanel();
            using (LoginPage lgf = new LoginPage())
            {
                lgf.StartPosition = FormStartPosition.CenterParent;
                DialogResult dr = lgf.ShowDialog(this);
                if (dr != DialogResult.Cancel)
                {
                    Log.WriteVerbose(new SourceInfo(), "Login successful. Displaying user properties on the main form header.");
                    TB_DisplayName.Text = CsomBase.CurrentUser.Title;
                    TB_UserName.Text    = CsomBase.CurrentUser.LoginName;
                    TB_Email.Text       = CsomBase.CurrentUser.Email;
                    TB_Url.Text         = CsomBase.CurrentUser.Context.Url;
                    loginSucess         = true;
                }
                else
                {
                    Log.WriteVerbose(new SourceInfo(), "Login failed.");
                }
            }
            return(loginSucess);
        }
        private static void SetPropertyValueInDataColumn(DataRow dr, PropertyInfo property, ClientObject clientObject)
        {
            object propValue = property.GetValue(clientObject);

            Log.WriteVerbose(new SourceInfo(), "Retrieved  {0}: {1}", property.Name, propValue);
            if (IsPrimitiveEquatable(property.PropertyType))
            {
                dr[property.Name] = propValue;
            }
            else
            {
                ClientObject co = (ClientObject)propValue;
                if (co.IsNull())
                {
                    dr[property.Name] = null;
                }
                else
                {
                    dr[property.Name] = co;
                }
            }
        }
Exemplo n.º 4
0
        private void LoginProjectServer()
        {
            Log.WriteVerbose(new SourceInfo(), "Logging into project server on url:{0}", TB_Url.Text);
            ProjContext = new ProjectContext(TB_Url.Text);
            Log.WriteVerbose(new SourceInfo(), "Authenticating against {0} pwa instance", CB_Online.Checked ? "Online" : "OnPerm");

            if (CB_Online.Checked && RB_Forms.Checked)
            {
                //case online with user credential
                SecureString secpassword = new SecureString();
                foreach (char c in TB_Password.Text)
                {
                    secpassword.AppendChar(c);
                }
                ProjContext.Credentials = new SharePointOnlineCredentials(TB_UserName.Text, secpassword);
            }
            else if (!CB_Online.Checked && RB_Forms.Checked)
            {
                //case onprem with user credential
                ProjContext.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;
                FormsAuthenticationLoginInfo formsAuthInfo = new FormsAuthenticationLoginInfo(TB_UserName.Text, TB_Password.Text);
                ProjContext.FormsAuthenticationLoginInfo = formsAuthInfo;
            }
            else
            {
                //Default case - Windows Auth
                ProjContext.Credentials = CredentialCache.DefaultCredentials;
            }
            CsomHelper.ProjContext   = ProjContext;
            CsomBase.CurrentResource = CsomHelper.LoadMe();
            CsomBase.CurrentUser     = CsomBase.CurrentResource.User;
            if (_bge.TaskCancelled || _bge.ActionTask.IsFaulted)
            {
                return;
            }
            Log.WriteVerbose(new SourceInfo(), "Login on url:{0} for user:{1}", TB_Url.Text, CsomBase.CurrentUser.Title);
            DialogResult = DialogResult.OK;
        }
 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.");
     }
 }
Exemplo n.º 6
0
        private void CheckInResources()
        {
            List <EnterpriseResource> resourceList = new List <EnterpriseResource>();

            LV_ServerObjects.InvokeIfRequired(s =>
            {
                ListView.SelectedListViewItemCollection selectedItems = s.SelectedItems;
                resourceList.AddRange(selectedItems.Cast <ListViewItem>().Select(selectedItem => (EnterpriseResource)selectedItem.Tag));
            });
            if (!resourceList.Any())
            {
                return;
            }
            foreach (var res in resourceList.Where(r => r.IsCheckedOut))
            {
                Log.WriteVerbose(new SourceInfo(), TB_Status, "Checking in Resource {0}", res.Name);
                res.ForceCheckIn();
            }

            ProjContext.ExecuteQuery();
            Log.WriteVerbose(new SourceInfo(), TB_Status, _backgroundExecutorWithStatus, "Loading Resources");
            LoadResources();
        }
Exemplo n.º 7
0
        private void LoadEnterpriseResources()
        {
            Log.WriteVerbose(new SourceInfo(), "Loading Enterprise Resources");

            LV_EnterpiseResources.InvokeIfRequired(s => s.Items.Clear());
            IEnumerable <EnterpriseResource> resourcesList = ProjContext.LoadQuery(ProjContext.EnterpriseResources.Include(r => r.Name, r => r.User));

            ProjContext.ExecuteQuery();
            List <ListViewItem> listViewItems = resourcesList.Where(r => !r.User.IsNull()).Select(res =>
            {
                Log.WriteVerbose(new SourceInfo(), TB_Status, "Found Enterprise Resource {0}", res.Name);
                return(new ListViewItem(res.Name)
                {
                    Tag = res
                });
            }).ToList();

            LV_EnterpiseResources.InvokeIfRequired(s =>
            {
                s.Items.AddRange(listViewItems.ToArray());
                s.Columns[0].Text = $"Enterprise Resources({listViewItems.Count})";
            });
        }
Exemplo n.º 8
0
        private void LoadProjects()
        {
            Log.WriteVerbose(new SourceInfo(), "Loading projects");

            IEnumerable <PublishedProject> projectList = ProjContext.LoadQuery(ProjContext.Projects.Include(p => p.Name, p => p.Owner, p => p.Id, p => p.Owner.Title, p => p.IsCheckedOut, p => p.CheckedOutBy.Title, p => p.Draft.LastSavedDate, p => p.Draft));

            ProjContext.ExecuteQuery();
            List <ListViewItem> listViewItems = new List <ListViewItem>();

            foreach (PublishedProject project in projectList)
            {
                ListViewItem lvi = new ListViewItem(project.Name);
                lvi.SubItems.Add(project.Owner.Title);
                if (project.CheckedOutBy.IsNull())
                {
                    lvi.SubItems.Add(String.Empty);
                }
                else
                {
                    lvi.SubItems.Add(project.CheckedOutBy.Title);
                }
                lvi.SubItems.Add(project.Draft.LastSavedDate.ToString(CultureInfo.InvariantCulture));

                lvi.Tag = project;
                Log.WriteVerbose(new SourceInfo(), "Found Project:{0}", project.Name);
                listViewItems.Add(lvi);
            }
            LV_Projects.InvokeIfRequired(s =>
            {
                s.Items.Clear();
                s.Items.AddRange(listViewItems.ToArray());
                s.Columns[0].Text = $"Projects({listViewItems.Count})";
                LV_Projects.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                LV_Projects.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            });
        }
Exemplo n.º 9
0
        private void CreateLookupTables()
        {
            for (int lookupTableCount = 1; lookupTableCount <= Convert.ToInt32(NUD_LTNumber.Value); lookupTableCount++)
            {
                List <LookupMask> masks = new List <LookupMask>();
                for (int levelCount = 0; levelCount <= Convert.ToInt32(NUD_Levels.Value); levelCount++)
                {
                    LookupMask lkm = new LookupMask
                    {
                        Length    = 0,
                        MaskType  = LookupTableMaskSequence.CHARACTERS,
                        Separator = "."
                    };
                    masks.Add(lkm);
                }

                List <LookupEntryCreationInformation> lookupEntry = new List <LookupEntryCreationInformation>();
                for (int levelCount = 1; levelCount <= Convert.ToInt32(NUD_Levels.Value); levelCount++)
                {
                    //creating the parent level
                    LookupEntryCreationInformation parentCi = new LookupEntryCreationInformation
                    {
                        Id        = Guid.NewGuid(),
                        SortIndex = 0,
                        Value     =
                            new LookupEntryValue {
                            TextValue = RandomEx.RandomString(Convert.ToInt32(NUD_Length.Value))
                        }
                    };
                    lookupEntry.Add(parentCi);

                    //creating the child levels
                    for (int subLevel = 1; subLevel <= Convert.ToInt32(NUD_ValuePerLevel.Value); subLevel++)
                    {
                        LookupEntryCreationInformation childCi = new LookupEntryCreationInformation
                        {
                            Id        = Guid.NewGuid(),
                            ParentId  = parentCi.Id,
                            SortIndex = 0,
                            Value     =
                                new LookupEntryValue
                            {
                                TextValue = RandomEx.RandomString(Convert.ToInt32(NUD_Length.Value))
                            }
                        };
                        lookupEntry.Add(childCi);
                    }
                }

                LookupTableSortOrder lookupTableSortOrder = LookupTableSortOrder.Ascending;
                CB_Sort.InvokeIfRequired(cb => lookupTableSortOrder = (LookupTableSortOrder)cb.SelectedValue);

                LookupTableCreationInformation ltCi = new LookupTableCreationInformation
                {
                    Name      = TB_Name.Text + lookupTableCount,
                    Masks     = masks,
                    SortOrder = lookupTableSortOrder,
                    Entries   = lookupEntry
                };
                Log.WriteVerbose(new SourceInfo(), TB_Status, "Creating lookup field with name {0}", ltCi.Name);
                ProjContext.LookupTables.Add(ltCi);
            }
            ProjContext.LookupTables.Update();
            ProjContext.ExecuteQuery();
        }
Exemplo n.º 10
0
 private void ServerMain_FormClosing(object sender, FormClosingEventArgs e)
 {
     Log.WriteVerbose(new SourceInfo(), "***** Application Exited. *****");
 }
Exemplo n.º 11
0
 public ServerMain()
 {
     Icon = Resources.Project;
     InitializeComponent();
     Log.WriteVerbose(new SourceInfo(), "***** Application Started. *****");
 }
Exemplo n.º 12
0
 public static bool CheckCurrentResourceIsAssignable()
 {
     Log.WriteVerbose(new SourceInfo(), "Current user resource type:[{0}].",
                      CsomBase.CurrentResource.ResourceType);
     return(CsomBase.CurrentResource.ResourceType == EnterpriseResourceType.Work);
 }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
        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);
                }
            }
        }
Exemplo n.º 15
0
        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);
        }