public PlanService(OpCore core) { Core = core; Network = core.Network; Protocol = Network.Protocol; Store = Network.Store; Trust = Core.Trust; if (Core.Sim != null) { SaveInterval = 30; } Core.SecondTimerEvent += Core_SecondTimer; Cache = new VersionedCache(Network, ServiceID, DataTypeFile, false); Cache.FileAquired += new FileAquiredHandler(Cache_FileAquired); Cache.FileRemoved += new FileRemovedHandler(Cache_FileRemoved); Cache.Load(); if (!PlanMap.SafeContainsKey(Core.UserID)) { LocalPlan = new OpPlan(new OpVersionedFile(Core.User.Settings.KeyPublic)); LocalPlan.Init(); LocalPlan.Loaded = true; PlanMap.SafeAdd(Core.UserID, LocalPlan); } }
void Plans_Update(OpPlan plan) { RefreshAssigned(); MainPanel.PlanUpdate(plan); SetDetails(LastGoal, LastItem); }
void Cache_FileRemoved(OpVersionedFile file) { OpPlan plan = GetPlan(file.UserID, false); if (plan == null) { return; } PlanMap.SafeRemove(file.UserID); }
private List <PlanBlock> GetBlocks(ulong key) { OpPlan plan = View.Plans.GetPlan(key, true); if (plan != null && plan.Loaded && plan.Blocks != null && plan.Blocks.ContainsKey(View.ProjectID)) { return(plan.Blocks[View.ProjectID]); } return(new List <PlanBlock>()); }
public void UpdateRow(bool immediate) { OpPlan plan = View.Plans.GetPlan(UserID, true); if (plan != null && !plan.Loaded) { View.Plans.LoadPlan(UserID); } Redraw = true; Invalidate(); if (immediate) { Update(); } }
public OpPlan GetPlan(ulong id, bool tryLoad) { OpPlan plan = null; PlanMap.SafeTryGetValue(id, out plan); if (plan == null) { return(null); } if (tryLoad && !plan.Loaded) { LoadPlan(id); } return((!tryLoad || (tryLoad && plan.Loaded)) ? plan : null); }
private void ReloadGoals() { TreeMap.Clear(); GoalTree.Nodes.Clear(); List <ulong> uplinks = Trust.GetUplinkIDs(View.UserID, View.ProjectID); uplinks.Add(View.UserID); // show all branches if (!MineOnly.Checked) { GoalNode root = CreateNode(Head); LoadNode(root); GoalTree.Nodes.Add(root); ExpandPath(root, uplinks); } // show only our branch else if (Head != null) { foreach (ulong id in uplinks) { OpPlan plan = Plans.GetPlan(id, true); if (plan != null && plan.GoalMap.ContainsKey(Head.Ident)) { foreach (PlanGoal goal in plan.GoalMap[Head.Ident]) { if (goal.Person == View.UserID) { GoalNode root = CreateNode(goal); LoadNode(root); InsertSubNode(GoalTree.virtualParent, root); root.Expand(); } } } } } Reselect(); }
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); } } } }
void Plans_Update(OpPlan plan) { // if node not tracked if (!NodeMap.ContainsKey(plan.UserID)) { return; } // update this node, and all subs (visible below) TreeListNode node = (TreeListNode)NodeMap[plan.UserID]; bool done = false; while (node != null && !done) { ((PlanNode)node).UpdateBlock(); done = PlanStructure.GetNextNode(ref node); } RefreshGoalCombo(); }
private void LoadNode(GoalNode node) { // check if already loaded if (node.AddSubs) { return; } node.AddSubs = true; // load that person specified by the node OpPlan plan = Plans.GetPlan(node.Goal.Person, true); if (plan == null) { Plans.Research(node.Goal.Person); return; } if (!plan.GoalMap.ContainsKey(Head.Ident)) { return; } // read the person's goals foreach (PlanGoal goal in plan.GoalMap[Head.Ident]) { // if the upbranch matches the node's down branch, add if (goal.BranchDown == 0 || goal.BranchUp != node.Goal.BranchDown) { continue; } if (CheckGoal(plan.UserID, goal)) { InsertSubNode(node, CreateNode(goal)); } } }
private void BlockRow_Paint(object sender, PaintEventArgs e) { if (DisplayBuffer == null) { DisplayBuffer = new Bitmap(Width, Height); } if (!Redraw) { e.Graphics.DrawImage(DisplayBuffer, 0, 0); return; } Redraw = false; // background Graphics buffer = Graphics.FromImage(DisplayBuffer); buffer.Clear(Color.White); //buffer.SmoothingMode = SmoothingMode.AntiAlias; // draw tick lines foreach (int mark in View.ScheduleSlider.SmallMarks) { buffer.DrawLine(SmallPen, mark, 0, mark, Height); } foreach (int mark in View.ScheduleSlider.BigMarks) { buffer.DrawLine(BigPen, mark, 0, mark, Height); } //buffer.DrawLine(RefPen, View.ScheduleSlider.RefMark, 0, View.ScheduleSlider.RefMark, Height); // setup vars Rectangle tempRect = new Rectangle(); tempRect.Y = 0; tempRect.Height = Height; StartTime = View.GetStartTime().ToUniversalTime(); EndTime = View.GetEndTime().ToUniversalTime(); TicksperPixel = View.ScheduleSlider.TicksperPixel; // draw higher plans BlockAreas.Clear(); GoalAreas.Clear(); Uplinks = View.Core.Trust.GetUnconfirmedUplinkIDs(UserID, View.ProjectID); // upnodes just used for scope calc now List <PlanNode> upnodes = new List <PlanNode>(); PlanNode nextNode = Node; while (nextNode.Parent.GetType() == typeof(PlanNode)) { nextNode = (PlanNode)nextNode.Parent; upnodes.Add(nextNode); } upnodes.Reverse(); // draw plans for each node above in the current block layered on top of one another // if we want to change to loop doesnt inherit other loop member's plans, replace foreach uplinks with upnodes // not obvious behaviour int level = 0; //foreach (ulong uplink in Uplinks) foreach (PlanNode node in upnodes) { ulong uplink = node.Link.UserID; foreach (PlanBlock block in GetBlocks(uplink)) { // scope -1 everyone or current level 0 highest + scope is >= than current node if ((block.Scope == -1 || (level + block.Scope >= upnodes.Count)) && BlockinRange(block, ref tempRect)) { buffer.FillRectangle(GetMask(uplink, true), tempRect); BlockAreas.Add(new BlockArea(tempRect, block, level, false)); } } level++; } // draw local plans List <List <DrawBlock> > layers = new List <List <DrawBlock> >(); // arrange visible blocks foreach (PlanBlock block in GetBlocks(UserID)) { if (BlockinRange(block, ref tempRect)) { AddDrawBlock(new DrawBlock(block, tempRect), layers); } } List <KeyValuePair <string, PointF> > StringList = new List <KeyValuePair <string, PointF> >(); // draw blocks if (layers.Count > 0) { int y = 2; int yStep = (Height - 2) / layers.Count; foreach (List <DrawBlock> list in layers) { foreach (DrawBlock item in list) { if (item.Above == null) { item.Rect.Y = y; item.Rect.Height = yStep - 1; DrawBlock down = item.Below; while (down != null) { item.Rect.Height += yStep; down = down.Below; } BlockAreas.Add(new BlockArea(item.Rect, item.Block, level, true)); Rectangle fill = item.Rect; fill.Height = Height - y; buffer.FillRectangle(GetMask(UserID, true), fill); if (item.Block == View.SelectedBlock) { buffer.DrawRectangle(SelectPen, item.Rect); } SizeF size = buffer.MeasureString(item.Block.Title, Tahoma); if (size.Width < item.Rect.Width - 2 && size.Height < item.Rect.Height - 2) { StringList.Add(new KeyValuePair <string, PointF>(item.Block.Title, new PointF(item.Rect.X + (item.Rect.Width - size.Width) / 2, item.Rect.Y + (item.Rect.Height - size.Height) / 2))); } } } y += yStep; } } // scan higher's goal lists for assigned goals to this id if (View.SelectedGoalID != 0) { // cache what to draw, look at how goals control get progress status // color goal bars solid red / blue / gray // cache strings, draw after goals //Uplinks.Add(Node.Link.DhtID); // add self to scan upnodes.Add(Node); foreach (PlanNode node in upnodes) { ulong userID = node.Link.UserID; OpPlan upPlan = View.Plans.GetPlan(userID, true); if (upPlan != null) { if (upPlan.GoalMap.ContainsKey(View.SelectedGoalID)) { foreach (PlanGoal goal in upPlan.GoalMap[View.SelectedGoalID]) { if (goal.Project == View.ProjectID && goal.Person == UserID) { if (StartTime < goal.End && goal.End < EndTime) { int x = (int)((goal.End.Ticks - StartTime.Ticks) / TicksperPixel); int completed = 0, total = 0; View.Plans.GetEstimate(goal, ref completed, ref total); // draw divider line with little right triangles in top / bottom buffer.FillRectangle(WhiteBrush, new Rectangle(x - 4, 2, 2, Height - 4)); if (total > 0) { int progress = completed * (Height - 4) / total; buffer.FillRectangle(GreenBrush, new Rectangle(x - 4, 2 + (Height - 4) - progress, 2, progress)); } buffer.FillPolygon(GetMask(UserID, false), new Point[] { new Point(x - 6, 2), new Point(x, 2), new Point(x, Height - 2), new Point(x - 6, Height - 2), new Point(x - 2, Height - 2 - 5), new Point(x - 2, 2 + 5) }); GoalAreas.Add(new BlockArea(new Rectangle(x - 6, 2, 6, Height - 4), goal)); } } } } } } } // draw strings foreach (KeyValuePair <string, PointF> pair in StringList) { buffer.DrawString(pair.Key, Tahoma, blackBrush, pair.Value); } // draw selection if (Node.Selected) { if (View.PlanStructure.Focused) { buffer.FillRectangle(Highlight, 0, 0, Width, 2); buffer.FillRectangle(Highlight, 0, Height - 2, Width, 2); } else { buffer.DrawLine(BlackPen, 1, 0, Width - 1, 0); buffer.DrawLine(BlackPen, 0, Height - 1, Width, Height - 1); } } // Copy buffer to display e.Graphics.DrawImage(DisplayBuffer, 0, 0); }
private void Cache_FileAquired(OpVersionedFile file) { OpPlan prevPlan = GetPlan(file.UserID, false); OpPlan newPlan = new OpPlan(file); PlanMap.SafeAdd(newPlan.UserID, newPlan); if (file.UserID == Core.UserID) { LocalPlan = newPlan; } if ((newPlan == LocalPlan) || (prevPlan != null && prevPlan.Loaded)) // if loaded, reload { LoadPlan(newPlan.UserID); } // update subs if (Network.Established) { List <LocationData> locations = new List <LocationData>(); Trust.ProjectRoots.LockReading(delegate() { foreach (uint project in Trust.ProjectRoots.Keys) { if (newPlan.UserID == Core.UserID || Trust.IsHigher(newPlan.UserID, project)) { Trust.GetLocsBelow(Core.UserID, project, locations); } } }); Store.PublishDirect(locations, newPlan.UserID, ServiceID, DataTypeFile, newPlan.File.SignedHeader); } // see if we need to update our own goal estimates if (newPlan.UserID != Core.UserID && LocalPlan != null) { Trust.ProjectRoots.LockReading(delegate() { foreach (uint project in Trust.ProjectRoots.Keys) { if (Trust.IsLower(Core.UserID, newPlan.UserID, project)) // updated plan must be lower than us to have an effect { foreach (int ident in LocalPlan.GoalMap.Keys) { if (!newPlan.Loaded) { LoadPlan(newPlan.UserID); } // if updated plan part of the same goal ident, re-estimate our own goals, incorporating update's changes if (newPlan.GoalMap.ContainsKey(ident) || newPlan.ItemMap.ContainsKey(ident)) { foreach (PlanGoal goal in LocalPlan.GoalMap[ident]) { int completed = 0, total = 0; GetEstimate(goal, ref completed, ref total); if (completed != goal.EstCompleted || total != goal.EstTotal) { goal.EstCompleted = completed; goal.EstTotal = total; if (RunSaveLocal == 0) // if countdown not started, start { RunSaveLocal = SaveInterval; } } } } } } } }); } Core.RunInGuiThread(PlanUpdate, newPlan); if (Core.NewsWorthy(newPlan.UserID, 0, false)) { Core.MakeNews(ServiceIDs.Plan, "Plan updated by " + Core.GetName(newPlan.UserID), newPlan.UserID, 0, false); } }
public void SaveLocal() { try { string tempPath = Core.GetTempPath(); byte[] key = Utilities.GenerateKey(Core.StrongRndGen, 256); using (IVCryptoStream stream = IVCryptoStream.Save(tempPath, key)) { // write dummy block if nothing to write OpPlan plan = GetPlan(Core.UserID, true); if (plan == null || plan.Blocks == null || plan.Blocks.Count == 0) { Protocol.WriteToFile(new PlanBlock(), stream); } if (plan != null) { foreach (List <PlanBlock> list in plan.Blocks.Values) { foreach (PlanBlock block in list) { Protocol.WriteToFile(block, stream); } } foreach (List <PlanGoal> list in plan.GoalMap.Values) { foreach (PlanGoal goal in list) { GetEstimate(goal, ref goal.EstCompleted, ref goal.EstTotal); Protocol.WriteToFile(goal, stream); } } foreach (List <PlanItem> list in plan.ItemMap.Values) { foreach (PlanItem item in list) { Protocol.WriteToFile(item, stream); } } } stream.WriteByte(0); // signal last packet stream.FlushFinalBlock(); } OpVersionedFile file = Cache.UpdateLocal(tempPath, key, null); Store.PublishDirect(Core.Trust.GetLocsAbove(), Core.UserID, ServiceID, DataTypeFile, file.SignedHeader); } catch (Exception ex) { Core.Network.UpdateLog("Plan", "Error updating local " + ex.Message); } }
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); } }
private void Cache_FileAquired(OpVersionedFile file) { OpPlan prevPlan = GetPlan(file.UserID, false); OpPlan newPlan = new OpPlan(file); PlanMap.SafeAdd(newPlan.UserID, newPlan); if (file.UserID == Core.UserID) LocalPlan = newPlan; if ((newPlan == LocalPlan) || (prevPlan != null && prevPlan.Loaded)) // if loaded, reload LoadPlan(newPlan.UserID); // update subs if (Network.Established) { List<LocationData> locations = new List<LocationData>(); Trust.ProjectRoots.LockReading(delegate() { foreach (uint project in Trust.ProjectRoots.Keys) if (newPlan.UserID == Core.UserID || Trust.IsHigher(newPlan.UserID, project)) Trust.GetLocsBelow(Core.UserID, project, locations); }); Store.PublishDirect(locations, newPlan.UserID, ServiceID, DataTypeFile, newPlan.File.SignedHeader); } // see if we need to update our own goal estimates if (newPlan.UserID != Core.UserID && LocalPlan != null) Trust.ProjectRoots.LockReading(delegate() { foreach (uint project in Trust.ProjectRoots.Keys) if (Trust.IsLower(Core.UserID, newPlan.UserID, project)) // updated plan must be lower than us to have an effect foreach (int ident in LocalPlan.GoalMap.Keys) { if (!newPlan.Loaded) LoadPlan(newPlan.UserID); // if updated plan part of the same goal ident, re-estimate our own goals, incorporating update's changes if (newPlan.GoalMap.ContainsKey(ident) || newPlan.ItemMap.ContainsKey(ident)) foreach (PlanGoal goal in LocalPlan.GoalMap[ident]) { int completed = 0, total = 0; GetEstimate(goal, ref completed, ref total); if (completed != goal.EstCompleted || total != goal.EstTotal) { goal.EstCompleted = completed; goal.EstTotal = total; if (RunSaveLocal == 0) // if countdown not started, start RunSaveLocal = SaveInterval; } } } }); Core.RunInGuiThread(PlanUpdate, newPlan); if (Core.NewsWorthy(newPlan.UserID, 0, false)) Core.MakeNews(ServiceIDs.Plan, "Plan updated by " + Core.GetName(newPlan.UserID), newPlan.UserID, 0, false); }
public void TrustUpdate(ulong key) { if (Head == null) { return; } List <ulong> visible = new List <ulong>(); // remove key from all parent sub items // if link changed children confirmations, this takes care of that during the re-add if (MineOnly.Checked) { return; } if (key == Head.Person || MineOnly.Checked) { ReloadGoals(); return; } else if (TreeMap.ContainsKey(key)) { List <GoalNode> list = new List <GoalNode>(TreeMap[key]); foreach (GoalNode node in list) { RemoveNode(node, visible); } } List <ulong> myUplinks = Trust.GetUplinkIDs(View.UserID, View.ProjectID); List <ulong> linkUplinks = Trust.GetUplinkIDs(key, View.ProjectID); // each uplink from this key can assign goals, we need to see if a re-add is necessary foreach (ulong uplink in linkUplinks) { OpPlan plan = Plans.GetPlan(uplink, true); if (plan != null && TreeMap.ContainsKey(uplink)) { foreach (GoalNode treeNode in TreeMap[uplink]) { // look through goals for assignments for this link if (treeNode.AddSubs && plan.GoalMap.ContainsKey(Head.Ident)) { foreach (PlanGoal goal in plan.GoalMap[Head.Ident]) { if (goal.Person == key && treeNode.Goal.BranchDown == goal.BranchUp && CheckGoal(plan.UserID, goal)) { GoalNode node = CreateNode(goal); InsertSubNode(treeNode, node); RefreshParents(node); if (treeNode.IsExpanded) { LoadNode(node); } } } } } } } // make removed nodes that were visible, visible again foreach (ulong id in visible) { List <ulong> uplinks = Trust.GetUplinkIDs(id, View.ProjectID); foreach (GoalNode root in GoalTree.Nodes) // should only be one root { VisiblePath(root, uplinks); } } Reselect(); }
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(); }
public void GetAssignedGoals(ulong target, uint project, List <PlanGoal> roots, List <PlanGoal> archived) { List <PlanGoal> tempRoots = new List <PlanGoal>(); List <PlanGoal> tempArchived = new List <PlanGoal>(); List <int> assigned = new List <int>(); // foreach self & higher List <ulong> ids = Trust.GetUplinkIDs(target, project); ids.Add(target); foreach (ulong id in ids) { OpPlan plan = GetPlan(id, true); if (plan == null) { continue; } // apart of goals we have been assigned to foreach (List <PlanGoal> list in plan.GoalMap.Values) { foreach (PlanGoal goal in list) { if (goal.Project != project) { break; } if (goal.Person == target && !assigned.Contains(goal.Ident)) { assigned.Add(goal.Ident); } if (goal.BranchDown == 0) { if (goal.Archived) { tempArchived.Add(goal); } else { tempRoots.Add(goal); } } } } } foreach (PlanGoal goal in tempArchived) { if (assigned.Contains(goal.Ident)) { archived.Add(goal); } } foreach (PlanGoal goal in tempRoots) { if (assigned.Contains(goal.Ident)) { roots.Add(goal); } } }
public void PlanUpdate(OpPlan plan) { if (Head == null) return; if (!plan.Loaded) Plans.LoadPlan(plan.UserID); // update progress of high levels for updated plan not in tree map because it is hidden if (plan.GoalMap.ContainsKey(Head.Ident) || plan.ItemMap.ContainsKey(Head.Ident)) { List<ulong> uplinks = Trust.GetUplinkIDs(plan.UserID, View.ProjectID); uplinks.Add(plan.UserID); if (uplinks.Contains(Head.Person)) foreach (ulong id in uplinks) if (TreeMap.ContainsKey(id)) foreach (GoalNode node in TreeMap[id]) node.RefreshProgress(); } if (!TreeMap.ContainsKey(plan.UserID)) return; if (MineOnly.Checked) { List<ulong> myUplinks = Trust.GetUplinkIDs(View.UserID, View.ProjectID); myUplinks.Add(View.UserID); if (myUplinks.Contains(plan.UserID)) { ReloadGoals(); return; } } List<PlanGoal> updated = new List<PlanGoal>(); if(plan.GoalMap.ContainsKey(Head.Ident)) updated = plan.GoalMap[Head.Ident]; List<ulong> visible = new List<ulong>(); foreach (GoalNode oldNode in TreeMap[plan.UserID]) { // if root if (oldNode.Goal.BranchDown == 0) { foreach (PlanGoal updatedGoal in updated) if (updatedGoal.BranchDown == 0) { oldNode.Update(updatedGoal); RefreshParents(oldNode); break; } } // go through displayed goals, if doesn't exist in update, remove List<GoalNode> removeList = new List<GoalNode>(); foreach (GoalNode original in oldNode.Nodes) { bool remove = true; foreach (PlanGoal updatedGoal in updated) if (oldNode.Goal.BranchDown == updatedGoal.BranchUp && original.Goal.BranchDown == updatedGoal.BranchDown) { remove = false; original.Update(updatedGoal); RefreshParents(original); } if (remove) removeList.Add(original); } foreach (GoalNode node in removeList) RemoveNode(node, visible); // go through updated goals, if isn't shown in display, add foreach (PlanGoal updatedGoal in updated) { bool add = true; // if not in subs, add if (updatedGoal.BranchDown == 0) continue; if (oldNode.Goal.BranchDown != updatedGoal.BranchUp) continue; foreach (GoalNode original in oldNode.Nodes) if (oldNode.Goal.BranchDown == updatedGoal.BranchUp && original.Goal.BranchDown == updatedGoal.BranchDown) add = false; //crit check this is hit if (add && oldNode.AddSubs && CheckGoal(plan.UserID, updatedGoal)) { GoalNode node = CreateNode(updatedGoal); InsertSubNode(oldNode, node); RefreshParents(node); if(oldNode.IsExpanded) LoadNode(node); } } } Reselect(); }
public void PlanUpdate(OpPlan plan) { if (Head == null) { return; } if (!plan.Loaded) { Plans.LoadPlan(plan.UserID); } // update progress of high levels for updated plan not in tree map because it is hidden if (plan.GoalMap.ContainsKey(Head.Ident) || plan.ItemMap.ContainsKey(Head.Ident)) { List <ulong> uplinks = Trust.GetUplinkIDs(plan.UserID, View.ProjectID); uplinks.Add(plan.UserID); if (uplinks.Contains(Head.Person)) { foreach (ulong id in uplinks) { if (TreeMap.ContainsKey(id)) { foreach (GoalNode node in TreeMap[id]) { node.RefreshProgress(); } } } } } if (!TreeMap.ContainsKey(plan.UserID)) { return; } if (MineOnly.Checked) { List <ulong> myUplinks = Trust.GetUplinkIDs(View.UserID, View.ProjectID); myUplinks.Add(View.UserID); if (myUplinks.Contains(plan.UserID)) { ReloadGoals(); return; } } List <PlanGoal> updated = new List <PlanGoal>(); if (plan.GoalMap.ContainsKey(Head.Ident)) { updated = plan.GoalMap[Head.Ident]; } List <ulong> visible = new List <ulong>(); foreach (GoalNode oldNode in TreeMap[plan.UserID]) { // if root if (oldNode.Goal.BranchDown == 0) { foreach (PlanGoal updatedGoal in updated) { if (updatedGoal.BranchDown == 0) { oldNode.Update(updatedGoal); RefreshParents(oldNode); break; } } } // go through displayed goals, if doesn't exist in update, remove List <GoalNode> removeList = new List <GoalNode>(); foreach (GoalNode original in oldNode.Nodes) { bool remove = true; foreach (PlanGoal updatedGoal in updated) { if (oldNode.Goal.BranchDown == updatedGoal.BranchUp && original.Goal.BranchDown == updatedGoal.BranchDown) { remove = false; original.Update(updatedGoal); RefreshParents(original); } } if (remove) { removeList.Add(original); } } foreach (GoalNode node in removeList) { RemoveNode(node, visible); } // go through updated goals, if isn't shown in display, add foreach (PlanGoal updatedGoal in updated) { bool add = true; // if not in subs, add if (updatedGoal.BranchDown == 0) { continue; } if (oldNode.Goal.BranchDown != updatedGoal.BranchUp) { continue; } foreach (GoalNode original in oldNode.Nodes) { if (oldNode.Goal.BranchDown == updatedGoal.BranchUp && original.Goal.BranchDown == updatedGoal.BranchDown) { add = false; } } //crit check this is hit if (add && oldNode.AddSubs && CheckGoal(plan.UserID, updatedGoal)) { GoalNode node = CreateNode(updatedGoal); InsertSubNode(oldNode, node); RefreshParents(node); if (oldNode.IsExpanded) { LoadNode(node); } } } } Reselect(); }
void Plans_Update(OpPlan plan) { // if node not tracked if(!NodeMap.ContainsKey(plan.UserID)) return; // update this node, and all subs (visible below) TreeListNode node = (TreeListNode) NodeMap[plan.UserID]; bool done = false; while (node != null && !done) { ((PlanNode)node).UpdateBlock(); done = PlanStructure.GetNextNode(ref node); } RefreshGoalCombo(); }
private void RefreshGoalCombo() { GoalComboItem prevItem = GoalCombo.SelectedItem as GoalComboItem; int prevSelectedID = 0; if (prevItem != null) { prevSelectedID = prevItem.ID; } GoalCombo.Items.Clear(); GoalCombo.Items.Add(new GoalComboItem("None", 0)); // go up the chain looking for goals which have been assigned to this person // at root goal is the title of the goal List <PlanGoal> rootList = new List <PlanGoal>(); List <int> assigned = new List <int>(); // foreach self & higher List <ulong> ids = Trust.GetUplinkIDs(UserID, ProjectID); ids.Add(UserID); foreach (ulong id in ids) { OpPlan plan = Plans.GetPlan(id, true); if (plan == null) { continue; } // goals we have been assigned to foreach (List <PlanGoal> list in plan.GoalMap.Values) { foreach (PlanGoal goal in list) { if (goal.Project != ProjectID) { break; } if (goal.Person == UserID && !assigned.Contains(goal.Ident)) { assigned.Add(goal.Ident); } if (goal.BranchDown == 0) { if (!goal.Archived) { rootList.Add(goal); } } } } } // update combo GoalComboItem prevSelected = null; foreach (PlanGoal goal in rootList) { if (assigned.Contains(goal.Ident)) { GoalComboItem item = new GoalComboItem(goal.Title, goal.Ident); if (goal.Ident == prevSelectedID) { prevSelected = item; } GoalCombo.Items.Add(item); } } if (prevSelected != null) { GoalCombo.SelectedItem = prevSelected; } else { GoalCombo.SelectedIndex = 0; } }
int SaveInterval = 60*10; // 10 min stagger, prevent cascade up #endregion Fields #region Constructors public PlanService(OpCore core) { Core = core; Network = core.Network; Protocol = Network.Protocol; Store = Network.Store; Trust = Core.Trust; if (Core.Sim != null) SaveInterval = 30; Core.SecondTimerEvent += Core_SecondTimer; Cache = new VersionedCache(Network, ServiceID, DataTypeFile, false); Cache.FileAquired += new FileAquiredHandler(Cache_FileAquired); Cache.FileRemoved += new FileRemovedHandler(Cache_FileRemoved); Cache.Load(); if (!PlanMap.SafeContainsKey(Core.UserID)) { LocalPlan = new OpPlan(new OpVersionedFile(Core.User.Settings.KeyPublic)); LocalPlan.Init(); LocalPlan.Loaded = true; PlanMap.SafeAdd(Core.UserID, LocalPlan); } }