Example #1
0
 MYDBo AddTable(string parent, string adr, string name, string value, long offset)
 {
     lock (all as object)
     {
         /*parent = parent.Substring(1);
          * adr = adr.Substring(1);*/
         for (int i = 0; i < tables.Count; i++)
         {
             if (tables[i].Adress == adr)
             {
                 if (parent == "-1")
                 {
                     RemoveTable(adr);
                     return(null);
                 }
                 else
                 {
                     tables[i].Name  = name;
                     tables[i].Value = value;
                     return(tables[i]);
                 }
             }
         }
         MYDBo ns = new MYDBo(parent, adr, name, value, offset, this);
         RemoveFree(adr);
         tables.Add(ns);
         //RemoveFree(adr);
         return(ns);
     }
 }
Example #2
0
 public MYDBo SetPar(string addr, string parent)
 {
     for (int i = 0; i < tables.Count; i++)
     {
         if (tables[i].Adress == addr)
         {
             try
             {
                 //MYDBo parentlink = Get(parent);
                 if (tables[i].ParentAdress != parent)
                 {
                     MYDBo parentlink = Get(parent);
                     tables[i].ParentAdress = parent;
                     tables[i].Parent       = parentlink;
                 }
                 BinaryWriter w = new BinaryWriter(File.Open(path, FileMode.OpenOrCreate), Encoding.UTF8);
                 w.BaseStream.Seek(0, SeekOrigin.End);
                 w.Write("x" + tables[i].Parent);
                 w.Write("x" + addr);
                 w.Write(tables[i].Name + ":" + tables[i].Value);
                 w.Close();
                 all++;
             }
             catch (Exception ex)
             {
                 return(null);
             }
             return(tables[i]);
         }
     }
     return(null);
 }
Example #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="array"></param>
 /// <param name="parentAddr"></param>
 /// <returns></returns>
 public static MYDBo[] Add(this MYDBo obj, string name, string value = "")
 {
     MYDBo[] ot = new MYDBo[2];
     ot[0] = obj;
     ot[1] = obj.link.Add(name, value, obj.Adress);
     return(ot);
 }
Example #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="parentAddr"></param>
 /// <returns></returns>
 public static MYDBo[] toArray(this MYDBo obj)
 {
     if (obj == null)
     {
         return(null);
     }
     return(new MYDBo[1] {
         obj
     });
 }
Example #5
0
        public MYDBo Add(string name, string val, string parent)
        {
            string ot      = GetAdd();
            MYDBo  ret     = null;
            string parName = "0";

            if (ot != "null")
            {
                //BinaryWriter w = null;
                try
                {
                    if (w == null)
                    {
                        w = new BinaryWriter(File.Open(path, FileMode.OpenOrCreate), Encoding.UTF8);
                    }
                    w.BaseStream.Seek(0, SeekOrigin.End);
                    if (parent != "")
                    {
                        parName = parent;
                    }
                    w.Write("x" + parName);
                    w.Write("x" + ot);
                    w.Write(name + ":" + val);
                    ret = AddTable(parName, ot, name, val, w.BaseStream.Position);
                    all++;
                    w.Close();
                }
                catch (Exception ex)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    return(null);
                }
                finally
                {
                    if (w != null)
                    {
                        w.Close();
                    }
                }
            }
            return(ret);
        }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="parentAddr"></param>
        /// <returns></returns>
        public static MYDBo[] GetChilds(this MYDBo obj, MYDBo[] from = null)
        {
            if (obj == null)
            {
                return(null);
            }
            if (from == null)
            {
                from = obj.link.tables.ToArray();
            }
            List <MYDBo> ot = new List <MYDBo>();

            for (int n = 0; n < from.Length; n++)
            {
                if (obj.Adress == from[n].ParentAdress)
                {
                    ot.Add(from[n]);
                }
            }
            return(ot.ToArray());
        }
Example #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="array"></param>
 /// <param name="parentAddr"></param>
 /// <returns></returns>
 public static MYDBo[] Add(this MYDBo[] obj, string name, string value = "", Picker parentPic = Picker.Last)
 {
     MYDBo[] ot = new MYDBo[obj.Length + 1];
     for (int i = 0; i < obj.Length; i++)
     {
         ot[i] = obj[i];
     }
     if (parentPic == Picker.First)
     {
         ot[ot.Length - 1] = obj[0].link.Add(name, value, obj[0].Adress);
     }
     else if (parentPic == Picker.Last)
     {
         ot[ot.Length - 1] = obj[obj.Length - 1].link.Add(name, value, obj[obj.Length - 1].Adress);
     }
     else if (parentPic == Picker.Last)
     {
         ot[ot.Length - 1] = obj[ran.Next(0, obj.Length)].link.Add(name, value, obj[ran.Next(0, obj.Length)].Adress);
     }
     return(ot);
 }