Exemplo n.º 1
0
        private static ProjectModel LoadProjectModel(string loadPath)
        {
            Properties.Settings.Default.Reset();
            ProjectModel project = new ProjectModel();

            using (BinaryReader reader = new BinaryReader(File.Open(loadPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
            {
                // Skip Magic
                reader.BaseStream.Seek(4, 0);

                // Validate
                bool isValid = (reader.ReadUInt16() == reader.BaseStream.Length);
                if (!isValid) { ShowCorruptionMessage(); return new ProjectModel(); }

                bool correctVersion = (reader.ReadByte() == 2);
                if (!isValid) { ShowIncompatibleVersionMessage(); return new ProjectModel(); }

                // Read Task Name
                int taskTitleLength = reader.ReadByte();
                project.Task = new string(reader.ReadChars(taskTitleLength));

                // Get DateTime of Project Beginning
                int month = reader.ReadByte();
                int day = reader.ReadByte();
                int year = reader.ReadInt32();
                int hour = reader.ReadByte();
                int minute = reader.ReadByte();
                DateTime dateTime = new DateTime(year, month, day, hour, minute, 0, 0);
                project.StartDate = dateTime;

                // Get Target Hours
                project.TargetHours = reader.ReadUInt32();

                // Get Total Elapsed Time
                project.ElapsedTime = reader.ReadDouble();

                project.IsMonitoring = reader.ReadBoolean();

                int applicationCount = reader.ReadByte();

                if (applicationCount != 0)
                {
                    for (int i = 0; i < applicationCount; i++)
                    {
                        int charLength = reader.ReadByte();
                        string application = new string(reader.ReadChars(charLength));
                        if (!project.Applications.Contains(application))
                        {
                            project.Applications.Add(application);
                        }
                    }
                }
            }
            return project;
        }
Exemplo n.º 2
0
 public static bool Save(ProjectModel project, bool SetStartDate = false)
 {
     string fileName = "";
     if (SaveFile(out fileName))
     {
         SaveProjectModel(project, fileName, SetStartDate);
         Properties.Settings.Default.HasLoadPath = true;
         Properties.Settings.Default.LastLoadPath = fileName;
         return true;
     }
     return false;
 }
Exemplo n.º 3
0
        public static ProjectModel Load()
        {
            ProjectModel project = new ProjectModel();
            string fileName = "";

            if (OpenFile(out fileName))
            {
                project = LoadProjectModel(fileName);
                Properties.Settings.Default.HasLoadPath = true;
                Properties.Settings.Default.LastLoadPath = fileName;
                return project;
            }
            return null;
        }
Exemplo n.º 4
0
        public DetailsPanel(ProjectModel project)
        {
            InitializeComponent();
            ChallengeText.Content = "My " + project.TargetHours.ToString("G") + " hour mastery of " + project.Task;
            Started.Content = "Officially started on " + project.StartDate;
            Hours.Content = project.CurrentHour.ToString();
            Statement.Content = "Hours Spent " + project.Task;

            double total = project.TargetHours * 3600000.0;
            ProgressBar.Value = (project.ElapsedTime / total) * 100;
            ProgressPercentage.Text = ((ProgressBar.Value >= 100) ? 100 : ProgressBar.Value).ToString("F4") + "%";

            Console.WriteLine(ChallengeText);
        }
Exemplo n.º 5
0
 public static void SaveNoPrompt(ProjectModel project)
 {
     SaveProjectModel(project, Properties.Settings.Default.LastLoadPath);
 }
Exemplo n.º 6
0
        private static void SaveProjectModel(ProjectModel project, string fileName, bool SetStartDate = false)
        {
            string[] rawName = new FileInfo(fileName).Name.Split('.');
            string rawDirectory = new FileInfo(fileName).DirectoryName;
            string pathTmp = Path.Combine(rawDirectory, rawName[0] + ".tmp");

            // clean
            File.Delete(pathTmp);

            // write temp
            using (BinaryWriter writer = new BinaryWriter(File.Open(pathTmp, FileMode.Create)))
            {
                writer.Write(Encoding.UTF8.GetBytes("MPF0")); // magic
                writer.Write((UInt16)0); // save space for length
                writer.Write((byte)2); // Version Number
                writer.Write((byte)project.Task.Count());
                writer.Write(Encoding.UTF8.GetBytes(project.Task));
                if (SetStartDate)
                {
                    writer.Write((byte)DateTime.Now.Month);
                    writer.Write((byte)DateTime.Now.Day);
                    writer.Write(DateTime.Now.Year);
                    writer.Write((byte)DateTime.Now.Hour);
                    writer.Write((byte)DateTime.Now.Minute);
                }
                else
                {
                    writer.Write((byte)project.StartDate.Month);
                    writer.Write((byte)project.StartDate.Day);
                    writer.Write(project.StartDate.Year);
                    writer.Write((byte)project.StartDate.Hour);
                    writer.Write((byte)project.StartDate.Minute);
                }
                writer.Write((uint)project.TargetHours);
                writer.Write(project.ElapsedTime);

                writer.Write(project.IsMonitoring);
                writer.Write((byte)project.Applications.Count);

                for (int i = 0; i < project.Applications.Count; i++)
                {
                    writer.Write((byte)project.Applications[i].Count());
                    writer.Write(Encoding.UTF8.GetBytes(project.Applications[i]));
                }
                writer.Seek(4, 0);
                writer.Write((UInt16)writer.BaseStream.Length);
            }

            // overwrite save
            File.Copy(pathTmp, fileName, true);

            // it's safe, delete the temp now
            File.Delete(pathTmp);
        }