Beispiel #1
0
        public static PlanItem Decode(byte[] data)
        {
            G2Header root = new G2Header(data);

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

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

            return(PlanItem.Decode(root));
        }
Beispiel #2
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);
            }
        }