Example #1
0
        public void AddGoal(PlanGoal goal)
        {
            if (!GoalMap.ContainsKey(goal.Ident))
                GoalMap[goal.Ident] = new List<PlanGoal>();

            GoalMap[goal.Ident].Add(goal);
        }
Example #2
0
        public EditPlanItem(EditItemMode mode, PlanGoal goal, PlanItem editing)
        {
            InitializeComponent();

            Mode = mode;
            Goal = goal;
            Editing = editing;

            TitleBox.Text = editing.Title;
            //StartTime.Value = editing.Start.ToLocalTime();
            //EndTime.Value = editing.End.ToLocalTime();
            CompletedHours.Text = editing.HoursCompleted.ToString();
            TotalHours.Text = editing.HoursTotal.ToString();
            DescriptionInput.InputBox.Text = editing.Description;

            if (Mode == EditItemMode.New)
                Text = "New Plan Item";

            if (Mode == EditItemMode.Edit)
                Text = "Edit Plan Item";

            if (Mode == EditItemMode.View)
            {
                Text = editing.Title;

                TitleBox.ReadOnly = true;
                //StartTime.Enabled = false;
                //EndTime.Enabled = false;
                CompletedHours.ReadOnly = true;
                TotalHours.ReadOnly = true;
                DescriptionInput.ReadOnly = true;
            }
        }
Example #3
0
        public void Update(PlanGoal goal)
        {
            Goal = goal;

            Text = Goal.Title;

            string name = Panel.Core.GetName(goal.Person);

            SubItems[0].Text = name;
            SubItems[2].Text = Panel.GetTimeText(goal.End.ToLocalTime() - Panel.Core.TimeNow, goal.End.ToLocalTime(), false);

            if (goal.Person == Panel.View.UserID)
            {
                ImageIndex = 1;
            }
            // higher
            else if (Panel.Trust.IsHigher(Panel.View.UserID, goal.Person, Panel.View.ProjectID))
            {
                ImageIndex = 2;
            }
            // lower
            else if (Panel.Trust.IsHigher(goal.Person, Panel.View.UserID, Panel.View.ProjectID))
            {
                ImageIndex = 3;
            }
            else
            {
                ImageIndex = 0;
            }

            RefreshProgress();
        }
Example #4
0
        public void AddGoal(PlanGoal goal)
        {
            if (!GoalMap.ContainsKey(goal.Ident))
            {
                GoalMap[goal.Ident] = new List <PlanGoal>();
            }

            GoalMap[goal.Ident].Add(goal);
        }
Example #5
0
        public GoalNode(GoalPanel panel, PlanGoal goal)
        {
            Panel = panel;

            SubItems.Add("");       // person
            SubItems.Add(Progress); // progress
            SubItems.Add("");       // deadline

            Update(goal);
        }
Example #6
0
 public void RemoveGoal(PlanGoal goal)
 {
     if (GoalMap.ContainsKey(goal.Ident))
     {
         if (GoalMap[goal.Ident].Contains(goal))
         {
             GoalMap[goal.Ident].Remove(goal);
         }
     }
 }
Example #7
0
        public GoalNode(GoalPanel panel, PlanGoal goal)
        {
            Panel = panel;

            SubItems.Add(""); // person
            SubItems.Add(Progress); // progress
            SubItems.Add(""); // deadline

            Update(goal);
        }
Example #8
0
        private GoalNode CreateNode(PlanGoal goal)
        {
            GoalNode node = new GoalNode(this, goal);

            if (!TreeMap.ContainsKey(goal.Person))
            {
                TreeMap[goal.Person] = new List <GoalNode>();
            }

            TreeMap[goal.Person].Add(node);

            return(node);
        }
Example #9
0
        public void LoadGoal(PlanGoal head)
        {
            Head = head;

            ReloadGoals();

            // make self visible / select
            if (TreeMap.ContainsKey(View.UserID))
            {
                List <GoalNode> list = TreeMap[View.UserID];

                list[0].Selected = true;
                UpdatePlanItems(list[0]);
            }
        }
Example #10
0
        public static PlanGoal Decode(byte[] data)
        {
            G2Header root = new G2Header(data);

            if (!G2Protocol.ReadPacket(root))
            {
                return(null);
            }

            if (root.Name != PlanPacket.Goal)
            {
                return(null);
            }

            return(PlanGoal.Decode(root));
        }
Example #11
0
        private void DelegateLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            PlanGoal goal = new PlanGoal();

            goal.Ident   = Head.Ident;
            goal.Project = Head.Project;
            goal.End     = Head.End;

            goal.BranchUp   = Selected.BranchDown;
            goal.BranchDown = Core.RndGen.Next();

            EditGoal form = new EditGoal(EditGoalMode.Delgate, View, goal);

            if (form.ShowDialog(this) == DialogResult.OK)
            {
                View.ChangesMade();
            }
        }
Example #12
0
        private void SelectGoalMenu_Create(object sender, EventArgs e)
        {
            PlanGoal goal = new PlanGoal();

            goal.Ident   = Core.RndGen.Next();
            goal.Project = ProjectID;
            goal.Person  = Core.UserID;
            goal.End     = Core.TimeNow.AddDays(30).ToUniversalTime();

            EditGoal form = new EditGoal(EditGoalMode.New, this, goal);

            if (form.ShowDialog(this) == DialogResult.OK)
            {
                ChangesMade();

                MainPanel.LoadGoal(goal);
            }
        }
Example #13
0
        bool CheckGoal(ulong higher, PlanGoal goal)
        {
            // if only branch
            if (MineOnly.Checked && View.UserID != goal.Person)
            {
                if (!Trust.IsHigher(View.UserID, goal.Person, View.ProjectID) && // show only if person is higher than self
                    !Trust.IsLower(View.UserID, goal.Person, View.ProjectID))    // or is lower than self
                {
                    return(false);
                }
            }

            // only subordinates can have goals assigned
            if (!Trust.IsLower(higher, goal.Person, View.ProjectID))
            {
                return(false);
            }

            return(true);
        }
Example #14
0
        public EditGoal(EditGoalMode mode, GoalsView view, PlanGoal editing)
        {
            InitializeComponent();

            Mode    = mode;
            View    = view;
            Core    = View.Core;
            Editing = editing;

            if (Mode == EditGoalMode.New)
            {
                Text = "New Goal";
                PersonLabel.Visible = false;
                PickLink.Visible    = false;
            }

            if (Mode == EditGoalMode.Delgate)
            {
                Text = "Delegate Responsibility";
            }

            if (Mode == EditGoalMode.View)
            {
                Text = editing.Title;

                TitleBox.ReadOnly   = true;
                Deadline.Enabled    = false;
                PickLink.Enabled    = false;
                NotesInput.ReadOnly = true;
            }

            if (Mode == EditGoalMode.Edit)
            {
                Text = "Edit Goal";
            }

            TitleBox.Text  = Editing.Title;
            Deadline.Value = Editing.End.ToLocalTime();
            SetPerson(Editing.Person);
            NotesInput.InputBox.Text = Editing.Description;
        }
Example #15
0
        public void GetEstimate(PlanGoal goal, ref int completed, ref int total)
        {
            OpPlan plan = GetPlan(goal.Person, true);

            // if person not found use last estimate
            if (plan == null)
            {
                completed = goal.EstCompleted;
                total     = goal.EstTotal;
                return;
            }

            // add person's items to estimate
            if (plan.ItemMap.ContainsKey(goal.Ident))
            {
                foreach (PlanItem item in plan.ItemMap[goal.Ident])
                {
                    if (item.BranchUp == goal.BranchDown)
                    {
                        completed += item.HoursCompleted;
                        total     += item.HoursTotal;
                    }
                }
            }

            // add person's delegated goals to estimate
            if (plan.GoalMap.ContainsKey(goal.Ident))
            {
                foreach (PlanGoal sub in plan.GoalMap[goal.Ident])
                {
                    if (goal.BranchDown == sub.BranchUp && sub.BranchDown != 0)
                    {
                        if (Trust.TrustMap.SafeContainsKey(sub.Person) && !Trust.IsLower(goal.Person, sub.Person, goal.Project))
                        {
                            continue; // only pass if link file for sub is loaded, else assume linked so whole net can be reported
                        }
                        GetEstimate(sub, ref completed, ref total);
                    }
                }
            }
        }
Example #16
0
        private void RemoveFromMap(PlanGoal goal)
        {
            if (!TreeMap.ContainsKey(goal.Person))
            {
                return;
            }

            List <GoalNode> list = TreeMap[goal.Person];

            foreach (GoalNode item in list)
            {
                if (item.Goal.BranchDown == goal.BranchDown)
                {
                    list.Remove(item);
                    break;
                }
            }

            if (list.Count == 0)
            {
                TreeMap.Remove(goal.Person);
            }
        }
Example #17
0
        public EditPlanItem(EditItemMode mode, PlanGoal goal, PlanItem editing)
        {
            InitializeComponent();

            Mode    = mode;
            Goal    = goal;
            Editing = editing;

            TitleBox.Text = editing.Title;
            //StartTime.Value = editing.Start.ToLocalTime();
            //EndTime.Value = editing.End.ToLocalTime();
            CompletedHours.Text            = editing.HoursCompleted.ToString();
            TotalHours.Text                = editing.HoursTotal.ToString();
            DescriptionInput.InputBox.Text = editing.Description;

            if (Mode == EditItemMode.New)
            {
                Text = "New Plan Item";
            }

            if (Mode == EditItemMode.Edit)
            {
                Text = "Edit Plan Item";
            }

            if (Mode == EditItemMode.View)
            {
                Text = editing.Title;

                TitleBox.ReadOnly = true;
                //StartTime.Enabled = false;
                //EndTime.Enabled = false;
                CompletedHours.ReadOnly   = true;
                TotalHours.ReadOnly       = true;
                DescriptionInput.ReadOnly = true;
            }
        }
Example #18
0
 public BlockMenuItem(string text, PlanGoal goal, Image icon, EventHandler onClick)
     : base(text, icon, onClick)
 {
     Goal = goal;
 }
Example #19
0
 public BlockArea(Rectangle rect, PlanGoal goal)
 {
     Rect = rect;
     Goal = goal;
 }
Example #20
0
 public BlockMenuItem(string text, PlanGoal goal, Image icon, EventHandler onClick)
     :
     base(text, icon, onClick)
 {
     Goal = goal;
 }
Example #21
0
        bool CheckGoal(ulong higher, PlanGoal goal)
        {
            // if only branch
            if (MineOnly.Checked && View.UserID != goal.Person)
                if (!Trust.IsHigher(View.UserID, goal.Person, View.ProjectID) && // show only if person is higher than self
                    !Trust.IsLower(View.UserID, goal.Person, View.ProjectID))   // or is lower than self
                    return false;

            // only subordinates can have goals assigned
            if (!Trust.IsLower(higher, goal.Person, View.ProjectID))
                return false;

            return true;
        }
Example #22
0
        public void SimTest()
        {
            if (Core.InvokeRequired)
            {
                Core.RunInCoreAsync(delegate() { SimTest(); });
                return;
            }

            uint project = 0;

            // schedule
            PlanBlock block = new PlanBlock();

            block.ProjectID = project;
            block.Title = Core.TextGen.GenerateWords(1)[0];
            block.StartTime = Core.TimeNow.AddDays(Core.RndGen.Next(365)); // anytime in next year
            block.EndTime = block.StartTime.AddDays(Core.RndGen.Next(3, 90)); // half a week to 3 months
            block.Description = Core.TextGen.GenerateSentences(1)[0];
            block.Scope = -1;
            block.Unique = Core.RndGen.Next();

            // add to local plan
            LocalPlan.AddBlock(block);

            // goals

            // get  uplinks including self and scan all goals for  anything assigned to local
            List<ulong> uplinks = Core.Trust.GetUplinkIDs(Core.UserID, project);
            uplinks.Add(Core.UserID);

            List<PlanGoal> assignedGoals = new List<PlanGoal>();

            PlanMap.LockReading(delegate()
            {
                foreach (ulong uplink in uplinks)
                    if (PlanMap.ContainsKey(uplink) && PlanMap[uplink].GoalMap != null)
                        foreach (List<PlanGoal> list in PlanMap[uplink].GoalMap.Values)
                            foreach (PlanGoal goal in list)
                                if (goal.Person == Core.UserID)
                                    assignedGoals.Add(goal);
            });

            PlanGoal randGoal = null;
            if (assignedGoals.Count > 0)
                randGoal = assignedGoals[Core.RndGen.Next(assignedGoals.Count)];

            List<ulong> downlinks = Core.Trust.GetDownlinkIDs(Core.UserID, project, 3);

            if (downlinks.Count > 0)
            {
                // create new goal
                PlanGoal newGoal = new PlanGoal();

                newGoal.Project = project;
                newGoal.Title = GetRandomTitle();
                newGoal.End = Core.TimeNow.AddDays(Core.RndGen.Next(30, 300));
                newGoal.Description = Core.TextGen.GenerateSentences(1)[0];

                int choice = Core.RndGen.Next(100);

                // create new goal
                if (randGoal == null || choice < 10)
                {
                    newGoal.Ident = Core.RndGen.Next();
                    newGoal.Person = Core.UserID;
                }

                // delegate goal to sub
                else if (randGoal != null && choice < 50)
                {
                    PlanGoal head = randGoal;

                    // delegate down
                    newGoal.Ident = head.Ident;
                    newGoal.BranchUp = head.BranchDown;
                    newGoal.BranchDown = Core.RndGen.Next();
                    newGoal.Person = downlinks[Core.RndGen.Next(downlinks.Count)];
                }
                else
                    newGoal = null;

                if(newGoal != null)
                    LocalPlan.AddGoal(newGoal);
            }

            // add item to random goal
            if (randGoal != null)
            {
                PlanItem item = new PlanItem();

                item.Ident = randGoal.Ident;
                item.Project = randGoal.Project;
                item.BranchUp = randGoal.BranchDown;

                item.Title = GetRandomTitle();
                item.HoursTotal = Core.RndGen.Next(3, 30);
                item.HoursCompleted = Core.RndGen.Next(0, item.HoursTotal);
                item.Description = Core.TextGen.GenerateSentences(1)[0];

                LocalPlan.AddItem(item);
            }

            SaveLocal();
        }
Example #23
0
        private void UpdatePlanItems(GoalNode node)
        {
            PlanListItem ReselectPlanItem = null;

            if (PlanList.SelectedItems.Count > 0)
            {
                ReselectPlanItem = PlanList.SelectedItems[0] as PlanListItem;
            }

            PlanList.Items.Clear();


            if (node == null)
            {
                Selected = null;
                DelegateLink.Hide();
                PlanList.Columns[0].Text = "Plan";
                //splitContainer2.Panel1Collapsed = true;
                return;
            }

            Selected = node.Goal;


            // set delegate task vis
            if (Selected.Person == Core.UserID && Trust.HasSubs(Selected.Person, View.ProjectID))
            {
                DelegateLink.Show();
            }
            else
            {
                DelegateLink.Hide();
            }

            if (Selected.Person == Core.UserID)
            {
                AddItemLink.Show();
            }
            else
            {
                AddItemLink.Hide();
            }

            // name's Plan for <goal>

            PlanList.Columns[0].Text = Core.GetName(node.Goal.Person) + "'s Plan for " + node.Goal.Title;

            // set plan items
            OpPlan plan = Plans.GetPlan(Selected.Person, true);

            if (plan == null) // re-searched at during selection
            {
                return;
            }


            if (plan.ItemMap.ContainsKey(Head.Ident))
            {
                foreach (PlanItem item in plan.ItemMap[Head.Ident])
                {
                    if (item.BranchUp == Selected.BranchDown)
                    {
                        PlanListItem row = new PlanListItem(item);

                        if (ReselectPlanItem != null && item == ReselectPlanItem.Item)
                        {
                            row.Selected = true;
                        }

                        PlanList.Items.Add(row);
                        FormatTime(row);
                    }
                }
            }

            PlanList.Invalidate();
        }
Example #24
0
        private void UpdatePlanItems(GoalNode node)
        {
            PlanListItem ReselectPlanItem = null;
            if (PlanList.SelectedItems.Count > 0)
                ReselectPlanItem = PlanList.SelectedItems[0] as PlanListItem;

            PlanList.Items.Clear();

            if (node == null)
            {
                Selected = null;
                DelegateLink.Hide();
                PlanList.Columns[0].Text = "Plan";
                //splitContainer2.Panel1Collapsed = true;
                return;
            }

            Selected = node.Goal;

            // set delegate task vis
            if (Selected.Person == Core.UserID && Trust.HasSubs(Selected.Person, View.ProjectID ))
                DelegateLink.Show();
            else
                DelegateLink.Hide();

            if (Selected.Person == Core.UserID)
                AddItemLink.Show();
            else
                AddItemLink.Hide();

            // name's Plan for <goal>

            PlanList.Columns[0].Text = Core.GetName(node.Goal.Person) + "'s Plan for " + node.Goal.Title;

            // set plan items
            OpPlan plan = Plans.GetPlan(Selected.Person, true);

            if (plan == null) // re-searched at during selection
                return;

            if (plan.ItemMap.ContainsKey(Head.Ident))
                foreach (PlanItem item in plan.ItemMap[Head.Ident])
                    if (item.BranchUp == Selected.BranchDown)
                    {
                        PlanListItem row = new PlanListItem(item);

                        if (ReselectPlanItem != null && item == ReselectPlanItem.Item)
                            row.Selected = true;

                        PlanList.Items.Add(row);
                        FormatTime(row);
                    }

            PlanList.Invalidate();
        }
Example #25
0
        public void LoadGoal(PlanGoal head)
        {
            Head = head;

            ReloadGoals();

            // make self visible / select
            if (TreeMap.ContainsKey(View.UserID))
            {
                List<GoalNode> list = TreeMap[View.UserID];

                list[0].Selected = true;
                UpdatePlanItems(list[0]);
            }
        }
Example #26
0
        public void Update(PlanGoal goal)
        {
            Goal = goal;

            Text = Goal.Title;

            string name = Panel.Core.GetName(goal.Person);

            SubItems[0].Text = name;
            SubItems[2].Text = Panel.GetTimeText(goal.End.ToLocalTime() - Panel.Core.TimeNow, goal.End.ToLocalTime(), false);

            if (goal.Person == Panel.View.UserID)
                ImageIndex = 1;
            // higher
            else if (Panel.Trust.IsHigher(Panel.View.UserID, goal.Person, Panel.View.ProjectID))
                ImageIndex = 2;
            // lower
            else if (Panel.Trust.IsHigher(goal.Person, Panel.View.UserID, Panel.View.ProjectID))
                ImageIndex = 3;
            else
                ImageIndex = 0;

            RefreshProgress();
        }
Example #27
0
        private void RemoveFromMap(PlanGoal goal)
        {
            if (!TreeMap.ContainsKey(goal.Person))
                return;

            List<GoalNode> list = TreeMap[goal.Person];

            foreach (GoalNode item in list)
                if (item.Goal.BranchDown == goal.BranchDown)
                {
                    list.Remove(item);
                    break;
                }

            if (list.Count == 0)
                TreeMap.Remove(goal.Person);
        }
Example #28
0
        public void GetEstimate(PlanGoal goal, ref int completed, ref int total)
        {
            OpPlan plan = GetPlan(goal.Person, true);

            // if person not found use last estimate
            if (plan == null)
            {
                completed = goal.EstCompleted;
                total = goal.EstTotal;
                return;
            }

            // add person's items to estimate
            if (plan.ItemMap.ContainsKey(goal.Ident))
                foreach (PlanItem item in plan.ItemMap[goal.Ident])
                    if (item.BranchUp == goal.BranchDown)
                    {
                        completed += item.HoursCompleted;
                        total += item.HoursTotal;
                    }

            // add person's delegated goals to estimate
            if (plan.GoalMap.ContainsKey(goal.Ident))
                foreach (PlanGoal sub in plan.GoalMap[goal.Ident])
                    if (goal.BranchDown == sub.BranchUp && sub.BranchDown != 0)
                    {
                        if (Trust.TrustMap.SafeContainsKey(sub.Person) && !Trust.IsLower(goal.Person, sub.Person, goal.Project))
                            continue; // only pass if link file for sub is loaded, else assume linked so whole net can be reported

                        GetEstimate(sub, ref completed, ref total);
                    }
        }
Example #29
0
        private void DelegateLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            PlanGoal goal = new PlanGoal();
            goal.Ident = Head.Ident;
            goal.Project = Head.Project;
            goal.End = Head.End;

            goal.BranchUp = Selected.BranchDown;
            goal.BranchDown = Core.RndGen.Next();

            EditGoal form = new EditGoal(EditGoalMode.Delgate, View, goal);

            if (form.ShowDialog(this) == DialogResult.OK)
                View.ChangesMade();
        }
Example #30
0
        private GoalNode CreateNode(PlanGoal goal)
        {
            GoalNode node = new GoalNode(this, goal);

            if (!TreeMap.ContainsKey(goal.Person))
                TreeMap[goal.Person] = new List<GoalNode>();

            TreeMap[goal.Person].Add(node);

            return node;
        }
Example #31
0
 public BlockArea(Rectangle rect, PlanGoal goal)
 {
     Rect = rect;
     Goal = goal;
 }
Example #32
0
        public void SetDetails(PlanGoal goal, PlanItem item)
        {
            LastGoal = goal;
            LastItem = item;

            List <string[]> tuples = new List <string[]>();

            string          notes = null;
            DetailsModeType mode  = DetailsModeType.None;

            // get inof that needs to be set
            if (goal != null)
            {
                tuples.Add(new string[] { "title", goal.Title });
                tuples.Add(new string[] { "due", goal.End.ToLocalTime().ToString("D") });
                tuples.Add(new string[] { "person", Core.GetName(goal.Person) });
                tuples.Add(new string[] { "notes", goal.Description.Replace("\r\n", "<br>") });

                notes = goal.Description;
                mode  = DetailsModeType.Goal;
            }

            else if (item != null)
            {
                tuples.Add(new string[] { "title", item.Title });
                tuples.Add(new string[] { "progress", item.HoursCompleted.ToString() + " of " + item.HoursTotal.ToString() + " Hours Completed" });
                tuples.Add(new string[] { "notes", item.Description.Replace("\r\n", "<br>") });

                notes = item.Description;
                mode  = DetailsModeType.Item;
            }

            // set details button
            DetailsButton.ForeColor = Color.Black;

            if (splitContainer1.Panel2Collapsed && notes != null && notes != "")
            {
                DetailsButton.ForeColor = Color.Red;
            }



            if (mode != DetailsMode)
            {
                DetailsMode = mode;

                Details.Length = 0;

                if (mode == DetailsModeType.Goal)
                {
                    Details.Append(GoalPage);
                }
                else if (mode == DetailsModeType.Item)
                {
                    Details.Append(ItemPage);
                }
                else
                {
                    Details.Append(DefaultPage);
                }

                foreach (string[] tuple in tuples)
                {
                    Details.Replace("<?=" + tuple[0] + "?>", tuple[1]);
                }

                SetDisplay(Details.ToString());
            }
            else
            {
                foreach (string[] tuple in tuples)
                {
                    DetailsBrowser.SafeInvokeScript("SetElement", new String[] { tuple[0], tuple[1] });
                }
            }
        }
Example #33
0
 public GoalMenuItem(string caption, PlanGoal goal, Image icon, EventHandler onClick)
     : base(caption, icon, onClick)
 {
     Goal = goal;
 }
Example #34
0
 public SelectMenuItem(PlanGoal goal, EventHandler onClick)
     : base(goal.Title, null, onClick)
 {
     Goal = goal;
 }
Example #35
0
        public void LoadPlan(ulong id)
        {
            if (Core.InvokeRequired)
            {
                Core.RunInCoreBlocked(delegate() { LoadPlan(id); });
                return;
            }

            OpPlan plan = GetPlan(id, false);

            if (plan == null)
            {
                return;
            }

            // if local plan file not created yet
            if (plan.File.Header == null)
            {
                if (plan.UserID == Core.UserID)
                {
                    plan.Init();
                }

                return;
            }

            try
            {
                string path = Cache.GetFilePath(plan.File.Header);

                if (!File.Exists(path))
                {
                    return;
                }

                plan.Init();

                List <int> myjobs = new List <int>();

                using (TaggedStream file = new TaggedStream(path, Network.Protocol))
                    using (IVCryptoStream crypto = IVCryptoStream.Load(file, plan.File.Header.FileKey))
                    {
                        PacketStream stream = new PacketStream(crypto, Network.Protocol, FileAccess.Read);

                        G2Header root = null;

                        while (stream.ReadPacket(ref root))
                        {
                            if (root.Name == PlanPacket.Block)
                            {
                                PlanBlock block = PlanBlock.Decode(root);

                                if (block != null)
                                {
                                    plan.AddBlock(block);
                                }
                            }

                            if (root.Name == PlanPacket.Goal)
                            {
                                PlanGoal goal = PlanGoal.Decode(root);

                                if (goal != null)
                                {
                                    plan.AddGoal(goal);
                                }
                            }

                            if (root.Name == PlanPacket.Item)
                            {
                                PlanItem item = PlanItem.Decode(root);

                                if (item != null)
                                {
                                    plan.AddItem(item);
                                }
                            }
                        }
                    }

                plan.Loaded = true;


                // check if we have tasks for this person, that those jobs still exist
                //crit do check with plan items, make sure goal exists for them

                /*List<PlanTask> removeList = new List<PlanTask>();
                 * bool update = false;
                 *
                 * foreach(List<PlanTask> tasklist in LocalPlan.TaskMap.Values)
                 * {
                 *  removeList.Clear();
                 *
                 *  foreach (PlanTask task in tasklist)
                 *      if(task.Assigner == id)
                 *          if(!myjobs.Contains(task.Unique))
                 *              removeList.Add(task);
                 *
                 *  foreach(PlanTask task in removeList)
                 *      tasklist.Remove(task);
                 *
                 *  if (removeList.Count > 0)
                 *      update = true;
                 * }
                 *
                 * if (update)
                 *  SaveLocal();*/
            }
            catch (Exception ex)
            {
                Core.Network.UpdateLog("Plan", "Error loading plan " + ex.Message);
            }
        }
Example #36
0
        public static PlanGoal Decode(G2Header root)
        {
            PlanGoal goal = new PlanGoal();
            G2Header child = new G2Header(root.Data);

            while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD)
            {
                if (!G2Protocol.ReadPayload(child))
                    continue;

                switch (child.Name)
                {
                    case Packet_Ident:
                        goal.Ident = BitConverter.ToInt32(child.Data, child.PayloadPos);
                        break;

                    case Packet_BranchUp:
                        goal.BranchUp = BitConverter.ToInt32(child.Data, child.PayloadPos);
                        break;

                    case Packet_BranchDown:
                        goal.BranchDown = BitConverter.ToInt32(child.Data, child.PayloadPos);
                        break;

                    case Packet_Project:
                        goal.Project = BitConverter.ToUInt32(child.Data, child.PayloadPos);
                        break;

                    case Packet_Title:
                        goal.Title = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_End:
                        goal.End = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos));
                        break;

                    case Packet_Desc:
                        goal.Description = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_Person:
                        goal.Person = BitConverter.ToUInt64(child.Data, child.PayloadPos);
                        break;

                    case Packet_Archived:
                        goal.Archived = BitConverter.ToBoolean(child.Data, child.PayloadPos);
                        break;

                    case Packet_EstCompleted:
                        goal.EstCompleted = BitConverter.ToInt32(child.Data, child.PayloadPos);
                        break;

                    case Packet_EstTotal:
                        goal.EstTotal = BitConverter.ToInt32(child.Data, child.PayloadPos);
                        break;
                }
            }

            return goal;
        }
Example #37
0
        public void SimTest()
        {
            if (Core.InvokeRequired)
            {
                Core.RunInCoreAsync(delegate() { SimTest(); });
                return;
            }

            uint project = 0;

            // schedule
            PlanBlock block = new PlanBlock();

            block.ProjectID   = project;
            block.Title       = Core.TextGen.GenerateWords(1)[0];
            block.StartTime   = Core.TimeNow.AddDays(Core.RndGen.Next(365));      // anytime in next year
            block.EndTime     = block.StartTime.AddDays(Core.RndGen.Next(3, 90)); // half a week to 3 months
            block.Description = Core.TextGen.GenerateSentences(1)[0];
            block.Scope       = -1;
            block.Unique      = Core.RndGen.Next();

            // add to local plan
            LocalPlan.AddBlock(block);


            // goals

            // get  uplinks including self and scan all goals for  anything assigned to local
            List <ulong> uplinks = Core.Trust.GetUplinkIDs(Core.UserID, project);

            uplinks.Add(Core.UserID);

            List <PlanGoal> assignedGoals = new List <PlanGoal>();

            PlanMap.LockReading(delegate()
            {
                foreach (ulong uplink in uplinks)
                {
                    if (PlanMap.ContainsKey(uplink) && PlanMap[uplink].GoalMap != null)
                    {
                        foreach (List <PlanGoal> list in PlanMap[uplink].GoalMap.Values)
                        {
                            foreach (PlanGoal goal in list)
                            {
                                if (goal.Person == Core.UserID)
                                {
                                    assignedGoals.Add(goal);
                                }
                            }
                        }
                    }
                }
            });


            PlanGoal randGoal = null;

            if (assignedGoals.Count > 0)
            {
                randGoal = assignedGoals[Core.RndGen.Next(assignedGoals.Count)];
            }


            List <ulong> downlinks = Core.Trust.GetDownlinkIDs(Core.UserID, project, 3);

            if (downlinks.Count > 0)
            {
                // create new goal
                PlanGoal newGoal = new PlanGoal();

                newGoal.Project     = project;
                newGoal.Title       = GetRandomTitle();
                newGoal.End         = Core.TimeNow.AddDays(Core.RndGen.Next(30, 300));
                newGoal.Description = Core.TextGen.GenerateSentences(1)[0];

                int choice = Core.RndGen.Next(100);

                // create new goal
                if (randGoal == null || choice < 10)
                {
                    newGoal.Ident  = Core.RndGen.Next();
                    newGoal.Person = Core.UserID;
                }

                // delegate goal to sub
                else if (randGoal != null && choice < 50)
                {
                    PlanGoal head = randGoal;

                    // delegate down
                    newGoal.Ident      = head.Ident;
                    newGoal.BranchUp   = head.BranchDown;
                    newGoal.BranchDown = Core.RndGen.Next();
                    newGoal.Person     = downlinks[Core.RndGen.Next(downlinks.Count)];
                }
                else
                {
                    newGoal = null;
                }


                if (newGoal != null)
                {
                    LocalPlan.AddGoal(newGoal);
                }
            }


            // add item to random goal
            if (randGoal != null)
            {
                PlanItem item = new PlanItem();

                item.Ident    = randGoal.Ident;
                item.Project  = randGoal.Project;
                item.BranchUp = randGoal.BranchDown;

                item.Title          = GetRandomTitle();
                item.HoursTotal     = Core.RndGen.Next(3, 30);
                item.HoursCompleted = Core.RndGen.Next(0, item.HoursTotal);
                item.Description    = Core.TextGen.GenerateSentences(1)[0];

                LocalPlan.AddItem(item);
            }

            SaveLocal();
        }
Example #38
0
        public static PlanGoal Decode(G2Header root)
        {
            PlanGoal goal  = new PlanGoal();
            G2Header child = new G2Header(root.Data);

            while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD)
            {
                if (!G2Protocol.ReadPayload(child))
                {
                    continue;
                }

                switch (child.Name)
                {
                case Packet_Ident:
                    goal.Ident = BitConverter.ToInt32(child.Data, child.PayloadPos);
                    break;

                case Packet_BranchUp:
                    goal.BranchUp = BitConverter.ToInt32(child.Data, child.PayloadPos);
                    break;

                case Packet_BranchDown:
                    goal.BranchDown = BitConverter.ToInt32(child.Data, child.PayloadPos);
                    break;

                case Packet_Project:
                    goal.Project = BitConverter.ToUInt32(child.Data, child.PayloadPos);
                    break;

                case Packet_Title:
                    goal.Title = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_End:
                    goal.End = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos));
                    break;

                case Packet_Desc:
                    goal.Description = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_Person:
                    goal.Person = BitConverter.ToUInt64(child.Data, child.PayloadPos);
                    break;

                case Packet_Archived:
                    goal.Archived = BitConverter.ToBoolean(child.Data, child.PayloadPos);
                    break;

                case Packet_EstCompleted:
                    goal.EstCompleted = BitConverter.ToInt32(child.Data, child.PayloadPos);
                    break;

                case Packet_EstTotal:
                    goal.EstTotal = BitConverter.ToInt32(child.Data, child.PayloadPos);
                    break;
                }
            }

            return(goal);
        }
Example #39
0
 public void RemoveGoal(PlanGoal goal)
 {
     if (GoalMap.ContainsKey(goal.Ident))
         if (GoalMap[goal.Ident].Contains(goal))
             GoalMap[goal.Ident].Remove(goal);
 }
Example #40
0
 public GoalMenuItem(string caption, PlanGoal goal, Image icon, EventHandler onClick)
     : base(caption, icon, onClick)
 {
     Goal = goal;
 }