Ejemplo n.º 1
0
        public int Store(string data, Json json = null)
        {
            string sql  = Converter.Convert(data);
            int    rows = -1;

            if (!string.IsNullOrWhiteSpace(sql))
            {
                //Console.WriteLine(sql);
                try
                {
                    if (!ExcludedTables.Contains(json?.Table))
                    {
                        rows = Database.Execute(sql);
                    }
                    if (json != null)
                    {
                        FireEvents(json);
                    }
                }
                catch (SqlException ex)
                {
                    Console.Error.WriteLine(ex.ToString());
                    if (IsAlive)
                    {
                        Close();
                    }
                }
            }
            return(rows);
        }
Ejemplo n.º 2
0
        // DFS-based topological sort similar to the listing in: https://en.wikipedia.org/w/index.php?title=Topological_sorting&oldid=753542990.
        // Restructured to avoid recursive calls in the two special scenarios, for readability and a better error message. Table's dependent
        // upon table (table's which reference it through a required foreign key) are added to the stack, then table is.
        protected virtual void ComputeOrdering(Stack <Table> tables, HashSet <Table> beingVisited, HashSet <Table> beenVisited, Table table)
        {
            beingVisited.Add(table);

            foreach (var dependentTable in table.ReferencingForeignKeys
                     .Where(k => k.IsEffectivelyRequired)
                     .Select(k => k.ParentTable)
                     .Where(t => !ExcludedTables.Contains(t))
                     .Distinct())
            {
                // If a table is being visited, we're in the process of visiting all tables dependent upon it. Therefore, if dependentTable
                // is already being visited, table must depend upon it... but it evidently also depends upon table, so there's a cycle.
                if (beingVisited.Contains(dependentTable))
                {
                    throw new ArgumentException($"A dependency cycle exists through {dependentTable} and {table}.");
                }

                if (!beenVisited.Contains(dependentTable))
                {
                    ComputeOrdering(tables, beingVisited, beenVisited, dependentTable);
                }
            }

            beenVisited.Add(table);
            beingVisited.Remove(table);
            tables.Push(table);
        }
Ejemplo n.º 3
0
 public BitmexSocket(string url, string key, string secret) : base(url, key, secret)
 {
     ExcludedTables.Add("trade");
 }