public EditBlock(BlockViewMode mode, ScheduleView view, PlanBlock block) { InitializeComponent(); Mode = mode; View = view; Core = view.Core; Plans = view.Plans; Block = block; StartTime.Value = new DateTime(Core.TimeNow.Year, Core.TimeNow.Month, Core.TimeNow.Day); EndTime.Value = StartTime.Value.AddDays(1); if (block == null) return; TitleBox.Text = block.Title; StartTime.Value = block.StartTime.ToLocalTime(); EndTime.Value = block.EndTime.ToLocalTime(); DescriptionInput.InputBox.Text = block.Description; SetScopeLink(block.Scope); if (mode != BlockViewMode.Show) return; TitleBox.ReadOnly = true; StartTime.Enabled = false; EndTime.Enabled = false; DescriptionInput.ReadOnly = true; ScopeLink.Enabled = false; }
public ScheduleView(CoreUI ui, PlanService plans, ulong id, uint project) { InitializeComponent(); UI = ui; Core = ui.Core; Plans = plans; Trust = Core.Trust; UserID = id; ProjectID = project; StartTime = Core.TimeNow; EndTime = Core.TimeNow.AddMonths(3); GuiUtils.SetupToolstrip(TopStrip, new OpusColorTable()); MainSplit.Panel2Collapsed = true; Core.KeepDataGui += new KeepDataHandler(Core_KeepData); PlanStructure.NodeExpanding += new EventHandler(PlanStructure_NodeExpanding); PlanStructure.NodeCollapsed += new EventHandler(PlanStructure_NodeCollapsed); // set last block so that setdetails shows correctly LastBlock = new PlanBlock(); SetDetails(null); }
public void AddBlock(PlanBlock block) { if (Blocks == null) { Blocks = new Dictionary <uint, List <PlanBlock> >(); } if (!Blocks.ContainsKey(block.ProjectID)) { Blocks[block.ProjectID] = new List <PlanBlock>(); } int i = 0; foreach (PlanBlock compare in Blocks[block.ProjectID]) { if (compare.StartTime > block.StartTime) { break; } i++; } Blocks[block.ProjectID].Insert(i, block); }
short CurrentScope = -1; // everyone default public EditBlock(BlockViewMode mode, ScheduleView view, PlanBlock block) { InitializeComponent(); Mode = mode; View = view; Core = view.Core; Plans = view.Plans; Block = block; StartTime.Value = new DateTime(Core.TimeNow.Year, Core.TimeNow.Month, Core.TimeNow.Day); EndTime.Value = StartTime.Value.AddDays(1); if (block == null) { return; } TitleBox.Text = block.Title; StartTime.Value = block.StartTime.ToLocalTime(); EndTime.Value = block.EndTime.ToLocalTime(); DescriptionInput.InputBox.Text = block.Description; SetScopeLink(block.Scope); if (mode != BlockViewMode.Show) { return; } TitleBox.ReadOnly = true; StartTime.Enabled = false; EndTime.Enabled = false; DescriptionInput.ReadOnly = true; ScopeLink.Enabled = false; }
public BlockArea(Rectangle rect, PlanBlock block, int level, bool local) { Rect = rect; Block = block; Level = level; Local = local; }
public DrawBlock(List <DrawBlock> layer, DrawBlock top) { Layer = layer; Block = top.Block; Rect = top.Rect; Above = top; top.Below = this; }
public void SetDetails(PlanBlock block) { List <string[]> tuples = new List <string[]>(); string notes = null; // get inof that needs to be set if (block != null) { tuples.Add(new string[] { "title", block.Title }); tuples.Add(new string[] { "start", block.StartTime.ToLocalTime().ToString("D") }); tuples.Add(new string[] { "finish", block.EndTime.ToLocalTime().ToString("D") }); tuples.Add(new string[] { "notes", block.Description.Replace("\r\n", "<br>") }); notes = block.Description; } // set details button DetailsButton.ForeColor = Color.Black; if (MainSplit.Panel2Collapsed && notes != null && notes != "") { DetailsButton.ForeColor = Color.Red; } if (LastBlock != block) { Details.Length = 0; if (block != null) { Details.Append(BlockPage); } 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] }); } } LastBlock = block; }
public static PlanBlock Decode(byte[] data) { G2Header root = new G2Header(data); if (!G2Protocol.ReadPacket(root)) { return(null); } if (root.Name != PlanPacket.Block) { return(null); } return(PlanBlock.Decode(root)); }
public static PlanBlock Decode(G2Header root) { PlanBlock block = new PlanBlock(); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_ProjectID: block.ProjectID = BitConverter.ToUInt32(child.Data, child.PayloadPos); break; case Packet_Title: block.Title = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_StartTime: block.StartTime = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos)); break; case Packet_EndTime: block.EndTime = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos)); break; case Packet_Description: block.Description = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Scope: block.Scope = BitConverter.ToInt16(child.Data, child.PayloadPos); break; case Packet_Unique: block.Unique = BitConverter.ToInt32(child.Data, child.PayloadPos); break; } } return(block); }
public static PlanBlock Decode(G2Header root) { PlanBlock block = new PlanBlock(); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) continue; switch (child.Name) { case Packet_ProjectID: block.ProjectID = BitConverter.ToUInt32(child.Data, child.PayloadPos); break; case Packet_Title: block.Title = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_StartTime: block.StartTime = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos)); break; case Packet_EndTime: block.EndTime = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos)); break; case Packet_Description: block.Description = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Scope: block.Scope = BitConverter.ToInt16(child.Data, child.PayloadPos); break; case Packet_Unique: block.Unique = BitConverter.ToInt32(child.Data, child.PayloadPos); break; } } return block; }
private bool BlockinRange(PlanBlock block, ref Rectangle rect) { bool add = false; // start is in span if (View.StartTime < block.StartTime && block.StartTime < EndTime) { rect.X = (int)((block.StartTime.Ticks - StartTime.Ticks) / TicksperPixel); rect.Width = Width - rect.X; add = true; } // end is in span if (StartTime < block.EndTime && block.EndTime < EndTime) { long startTicks = StartTime.Ticks; if (!add) { rect.X = 0; // if rect set above, dont reset left } else { startTicks = block.StartTime.Ticks; } rect.Width = (int)((block.EndTime.Ticks - startTicks) / TicksperPixel); add = true; } // if block spans entire row if (block.StartTime < StartTime && EndTime < block.EndTime) { rect.X = 0; rect.Width = Width; add = true; } return(add); }
public void AddBlock(PlanBlock block) { if (Blocks == null) Blocks = new Dictionary<uint, List<PlanBlock>>(); if (!Blocks.ContainsKey(block.ProjectID)) Blocks[block.ProjectID] = new List<PlanBlock>(); int i = 0; foreach (PlanBlock compare in Blocks[block.ProjectID]) { if (compare.StartTime > block.StartTime) break; i++; } Blocks[block.ProjectID].Insert(i, block); }
private void OkButton_Click(object sender, EventArgs e) { if (Mode == BlockViewMode.Show) { Close(); return; } if (EndTime.Value < StartTime.Value) { MessageBox.Show("Start time must be earlier than End time"); return; } if (Block != null && Plans.LocalPlan.Blocks.ContainsKey(Block.ProjectID)) { Plans.LocalPlan.Blocks[Block.ProjectID].Remove(Block); } PlanBlock block = (Block != null) ? Block : new PlanBlock(); block.ProjectID = View.ProjectID; block.Title = TitleBox.Text; block.StartTime = StartTime.Value.ToUniversalTime(); block.EndTime = EndTime.Value.ToUniversalTime(); block.Description = DescriptionInput.InputBox.Text; block.Scope = CurrentScope; if (Mode == BlockViewMode.New) { block.Unique = Core.RndGen.Next(); } // add to local plan Plans.LocalPlan.AddBlock(block); DialogResult = DialogResult.OK; Close(); }
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(); }
public DrawBlock(PlanBlock block, Rectangle rect) { Block = block; Rect = rect; }
public BlockMenuItem(string text, PlanBlock block, Image icon, EventHandler onClick) : base(text, icon, onClick) { Block = block; }
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); } }
public void SetDetails(PlanBlock block) { List<string[]> tuples = new List<string[]>(); string notes = null; // get inof that needs to be set if (block != null) { tuples.Add(new string[] { "title", block.Title }); tuples.Add(new string[] { "start", block.StartTime.ToLocalTime().ToString("D") }); tuples.Add(new string[] { "finish", block.EndTime.ToLocalTime().ToString("D") }); tuples.Add(new string[] { "notes", block.Description.Replace("\r\n", "<br>") }); notes = block.Description; } // set details button DetailsButton.ForeColor = Color.Black; if (MainSplit.Panel2Collapsed && notes != null && notes != "") DetailsButton.ForeColor = Color.Red; if (LastBlock != block) { Details.Length = 0; if (block != null) Details.Append(BlockPage); 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] }); } LastBlock = block; }
private bool BlockinRange(PlanBlock block, ref Rectangle rect) { bool add = false; // start is in span if (View.StartTime < block.StartTime && block.StartTime < EndTime) { rect.X = (int)((block.StartTime.Ticks - StartTime.Ticks) / TicksperPixel); rect.Width = Width - rect.X; add = true; } // end is in span if (StartTime < block.EndTime && block.EndTime < EndTime) { long startTicks = StartTime.Ticks; if (!add) rect.X = 0; // if rect set above, dont reset left else startTicks = block.StartTime.Ticks; rect.Width = (int)((block.EndTime.Ticks - startTicks) / TicksperPixel); add = true; } // if block spans entire row if (block.StartTime < StartTime && EndTime < block.EndTime) { rect.X = 0; rect.Width = Width; add = true; } return add; }
public DrawBlock(List<DrawBlock> layer, DrawBlock top) { Layer = layer; Block = top.Block; Rect = top.Rect; Above = top; top.Below = this; }
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(); }