Пример #1
0
 public Project(int id, string name, List<ProjectLog> completedLogs = null, ProjectLog incompleteLog = null, List<ProjectFile> files = null)
 {
     Id = id;
     Name = name;
     CompletedLogs = completedLogs != null ? completedLogs : new List<ProjectLog>();
     IncompleteLog = incompleteLog;
     Files = files != null ? files : new List<ProjectFile>();
 }
        public ProjectLogRow(ProjectLog log, ProjectMenu parentProjectMenu)
        {
            InitializeComponent();
            Log = log;
            ParentProjectMenu = parentProjectMenu;

            SetDate(log.Start);
            tbl_Description.Text = log.Description;
        }
Пример #3
0
        /// <summary>
        /// Base constructor for all options.
        /// </summary>
        private SummaryRow(string title, TimeSpan time, Project project, ProjectLog log)
        {
            InitializeComponent();
            tbl_Name.Text = title;

            Time = time;
            SetTime();

            CurrProject = project;
            CurrLog = log;
        }
        // NOTE:
        // We return true on DialogResult if the client should update its list of logs.
        // This could happend due to a change in the log or a delete.
        public ViewLogDialog(ProjectLog log)
        {
            InitializeComponent();

            // Init some fields and the UI
            Log = log;
            dtp_StartTime.FormatString = dateTimeFormat;
            dtp_EndTime.FormatString = dateTimeFormat;
            SetUpGuiFromLog();

            // Change the calendar style once we're loaded
            dtp_StartTime.Loaded += DateTimePicker_Loaded;
            dtp_EndTime.Loaded += DateTimePicker_Loaded;
        }
        /// <summary>
        /// Returns a tuple containing the a list of the project's completed logs and the project's incomplete log. 
        /// </summary>
        /// <param name="project">The project whose logs to return.</param>
        /// <returns>A tuple containg the project logs.</returns>
        public static Tuple<List<ProjectLog>, ProjectLog> GetLogsForProjectFromFile(Project project)
        {
            List<ProjectLog> completeEntries = new List<ProjectLog>();
            ProjectLog incompleteEntry = null;

            // Get the non-empty and non-comment lines from the log file
            List<string> projectLogRows = GetNonEmptyAndNonCommentLinesFromFile(GetFileNameForProject(project, FileType.LOGS));
            Nullable<bool> parsingCompletedEntries = null;

            // Parse the remaining lines
            foreach (var line in projectLogRows)
            {
                // Check if we have a keywork (incomplete or complete)
                if (line == incomplete)
                {
                    parsingCompletedEntries = false;
                    continue;
                }
                else if (line == complete)
                {
                    parsingCompletedEntries = true;
                    continue;
                }

                // Make sure that we know what type of entry we are parsing
                if (parsingCompletedEntries == null)
                {
                    ErrorLogger.AddLog(string.Format("Could not determin with log '{0}' should be complete or incomplete. Skipping entry.", line), ErrorSeverity.HIGH);
                    continue;
                }

                // If we got here, then we should have a log entry
                // Ensure that the line has the correct format
                string[] lineItems = line.Split('|');
                int numberOfItems = 4;
                if (lineItems.Length != numberOfItems)
                {
                    ErrorLogger.AddLog(string.Format("Could not parse line '{0}'. Skipping entry.", line), ErrorSeverity.HIGH);
                    continue;
                }

                // Ensure that the first part is a valid id
                int logId;
                int minId = 0;
                bool parseIdSuccess = int.TryParse(lineItems[0], out logId);
                if (!parseIdSuccess || logId < minId)
                {
                    ErrorLogger.AddLog(string.Format("Could not parse log id '{0}'. Skipping entry.", lineItems[0]), ErrorSeverity.HIGH);
                    continue;
                }

                // Ensure that the second part is a valid datetime
                DateTime start = DateTime.MinValue;
                try
                {
                    start = DateTime.Parse(lineItems[1]);
                }
                catch (Exception e)
                {
                    if (e is ArgumentNullException || e is FormatException)
                    {
                        ErrorLogger.AddLog(string.Format("Could not parse log start time '{0}'. Skipping entry.", lineItems[1]), ErrorSeverity.HIGH);
                        continue;
                    }
                    else
                    {
                        throw;
                    }
                }

                // Ensure that the third part is either blank (for incomplete entries) or a valid datetime (for complete entries)
                DateTime end;
                // If we're blank but parsing an incomplete entry, just set end to the default value
                if (lineItems[2] == "" && parsingCompletedEntries == false)
                {
                    end = DateTime.MaxValue;
                }
                // Otherwise, if we're not blank and parsing a complete entry, try to parse the value
                else if (lineItems[2] != "" && parsingCompletedEntries == true)
                {
                    try
                    {
                        end = DateTime.Parse(lineItems[2]);
                    }
                    catch (FormatException)
                    {
                        ErrorLogger.AddLog(string.Format("Could not parse log end time '{0}'. Skipping entry.", lineItems[1]), ErrorSeverity.HIGH);
                        continue;
                    }
                }
                // Otherwise, we're invalid
                else
                {
                    ErrorLogger.AddLog(string.Format("Invalid end time '{0}' for log completion status ({1}). Skipping entry.", lineItems[1],
                        parsingCompletedEntries == true ? "complete" : "incomplete"), ErrorSeverity.HIGH);
                    continue;
                }

                // Ensure that the fourth part is a valid description
                string description = lineItems[3];
                if (description == "")
                {
                    ErrorLogger.AddLog(string.Format("Invalid log description '{0}'. Skipping entry.", lineItems[1]), ErrorSeverity.HIGH);
                    continue;
                }

                // If we got here, we have valid project log entry, so create an instance
                if (parsingCompletedEntries == true)
                {
                    // Create a complete entry here
                    ProjectLog logEntry = new ProjectLog(logId, start, end, description, project);
                    highestLogIdsInUse[project.Id] = Math.Max(highestLogIdsInUse[project.Id], logId);
                    completeEntries.Add(logEntry);
                }
                else
                {
                    // Try to create an incomplete entry here, but don't allow multiple incomplete entries
                    if (incompleteEntry == null)
                    {
                        // Create an incomplete entry here
                        ProjectLog logEntry = new ProjectLog(logId, start, description, project);
                        highestLogIdsInUse[project.Id] = Math.Max(highestLogIdsInUse[project.Id], logId);
                        incompleteEntry = logEntry;
                    }
                    else
                    {
                        ErrorLogger.AddLog(string.Format("Only one incomplete entry is allowed. Additional entry '{0}' will be skipped.", description), ErrorSeverity.HIGH);
                        continue;
                    }
                }
            }

            return new Tuple<List<ProjectLog>,ProjectLog>(completeEntries, incompleteEntry);
        }
Пример #6
0
        /// <summary>
        /// Adds the given log to the project (if it is not already there) and the UI. Will null the project's IncompleteEntry reference
        /// if it is currently referencing the given log.
        /// </summary>
        /// <param name="log">The log to add.</param>
        private void AddCompleteLogToProject(ProjectLog log)
        {
            if (log.End == DateTime.MaxValue)
            {
                ErrorLogger.AddLog(string.Format("Cannot add log '{0}', as it is not complete.", log.Description), ErrorSeverity.HIGH);
                return;
            }

            // If this log is the project's current incomplete log, finish it
            if (CurrentProject.IncompleteLog == log)
            {
                CurrentProject.FinishIncompleteLog();
            }

            // Otherwise, just add it
            else if (!CurrentProject.CompletedLogs.Contains(log))
            {
                CurrentProject.CompletedLogs.Add(log);
            }

            // Either way, sort the projects
            CurrentProject.SortCompletedEntries();

            // Update the backing file
            ProjectFileInterface.WriteProjectLogsToFile(CurrentProject);
        }
Пример #7
0
        /// <summary>
        /// Creates and adds a new log with the given description. The start date time is
        /// automatically added. This method should not be called if the project already has a
        /// log in progress.
        /// </summary>
        /// <param name="description">The description for the new log.</param>
        private void StartLog(string description)
        {
            // Make sure we don't already have an incomplete log outstanding
            if (CurrentProject.IncompleteLog != null)
            {
                ErrorLogger.AddLog(string.Format("Cannot start a log while there is still a incomplete log outstanding. Log '{0}' ignored.", description), ErrorSeverity.HIGH);
                return;
            }

            // Create the new log
            DateTime start = DateTime.Now;
            int id = ProjectFileInterface.RequestLogId(CurrentProject.Id);
            ProjectLog log = new ProjectLog(id, start, description, CurrentProject);

            // Add the log to the project
            AddIncompleteLogToProject(log);

            // Refresh the UI
            RefreshLogsOnUI();
        }
Пример #8
0
        /// <summary>
        /// Adds the given log to the project (if it is not already there). Will not add if the project already has an
        /// IncompleteEntry reference.
        /// </summary>
        /// <param name="log">The log to add.</param>
        private void AddIncompleteLogToProject(ProjectLog log)
        {
            if (CurrentProject.IncompleteLog != null && CurrentProject.IncompleteLog != log)
            {
                ErrorLogger.AddLog(string.Format("Cannot add incomplete log '{0}', as project '{1}' already has a different incomplete log '{2}'.",
                    log.Description, CurrentProject.Name, CurrentProject.IncompleteLog.Description), ErrorSeverity.HIGH);
                return;
            }

            // Add the reference in the project
            CurrentProject.IncompleteLog = log;

            // Update the backing file
            ProjectFileInterface.WriteProjectLogsToFile(CurrentProject);
        }
Пример #9
0
        /// <summary>
        /// Removes the given log from the project if possible.
        /// </summary>
        /// <param name="log">The log to remove.</param>
        public void RemoveLogEntry(ProjectLog log)
        {
            if (CompletedLogs.Contains(log))
            {
                CompletedLogs.Remove(log);
            }

            if (IncompleteLog == log)
            {
                IncompleteLog = null;
            }
        }
Пример #10
0
 /// <summary>
 /// Use this constructor if you have a project log instance.
 /// </summary>
 public SummaryRow(ProjectLog log)
     : this(log.Description, log.End - log.Start, null, log)
 {
 }