Exemplo n.º 1
0
        /// <summary>
        /// Loads instance source from a dictionary object (provided by JSON)
        /// </summary>
        /// <param name="obj">Key/value dictionary with <c>instances</c> and other optional elements</param>
        /// <exception cref="eduJSON.InvalidParameterTypeException"><paramref name="obj"/> type is not <c>Dictionary&lt;string, object&gt;</c></exception>
        public virtual void Load(object obj)
        {
            if (obj is Dictionary <string, object> obj2)
            {
                InstanceList.Clear();

                // Parse all instances listed. Don't do it in parallel to preserve the sort order.
                foreach (var el in eduJSON.Parser.GetValue <List <object> >(obj2, "instances"))
                {
                    var instance = new Instance();
                    instance.Load(el);
                    InstanceList.Add(instance);
                }

                // Parse sequence.
                Sequence = (uint)eduJSON.Parser.GetValue <int>(obj2, "seq");

                // Parse signed date.
                SignedAt = eduJSON.Parser.GetValue(obj2, "signed_at", out string signed_at) && DateTime.TryParse(signed_at, out var signed_at_date) ? signed_at_date : (DateTime?)null;
            }
            else
            {
                throw new eduJSON.InvalidParameterTypeException(nameof(obj), typeof(Dictionary <string, object>), obj.GetType());
            }
        }
Exemplo n.º 2
0
 public void LoadInstances()
 {
     InstanceList.Clear();
     foreach (Instance inst in Instance.LoadInstances(AppSettings.Main.InstanceDir))
     {
         InstanceList.Add(inst);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Loads instance source from a dictionary object (provided by JSON)
        /// </summary>
        /// <param name="obj">Key/value dictionary with <c>instances</c> and other optional elements</param>
        /// <exception cref="eduJSON.InvalidParameterTypeException"><paramref name="obj"/> type is not <c>Dictionary&lt;string, object&gt;</c></exception>
        public virtual void Load(object obj)
        {
            if (!(obj is Dictionary <string, object> obj2))
            {
                throw new eduJSON.InvalidParameterTypeException(nameof(obj), typeof(Dictionary <string, object>), obj.GetType());
            }

            InstanceList.Clear();

            // Parse all instances listed. Don't do it in parallel to preserve the sort order.
            foreach (var el in eduJSON.Parser.GetValue <List <object> >(obj2, "instances"))
            {
                var instance = new Instance();
                instance.Load(el);
                InstanceList.Add(instance);
            }
        }
Exemplo n.º 4
0
        public virtual void SetOriginal(T original)
        {
            if (original.Equals(this.original))
            {
                return;
            }
            this.original = original;

            for (int i = 0; i < InstanceList.Count; i++)
            {
                Destroy(InstanceList[i].gameObject);
            }

            InstanceList.Clear();
            ActiveInstanceList.Clear();
            deactiveInstanceList.Clear();
        }