Example #1
0
        public static void DropObjects(IDatastoreObjectValidator valid, IDataStore dStore, string name)
        {
            IEnumerable <DBObject> data = valid.GetObjects().ToList();

            while (data.Count() != 0)
            {
                foreach (DBObject t in data)
                {
                    IDbCommand cmd = dStore.Connection.GetCommand();
                    cmd.CommandText = string.Format("DROP {0} {1}", name, GetTableName(t, dStore), dStore);
                    try { dStore.ExecuteCommand(cmd); }
                    catch { }
                }
                data = valid.GetObjects(true);
            }
        }
Example #2
0
        protected virtual void HandleViews(Assembly asmb)
        {
            List <ViewData> items   = ResolveViews(asmb);
            var             dbViews = _views.GetObjects().OrderBy(r => r.Name).ToList();

            //may have to run the following multiple times, [some options can prevent updating/removal]
            bool needsRepeat = true;

            while (needsRepeat)
            {
                needsRepeat = RemoveOptions(asmb, items, dbViews);
            }

            items = SortList(items);

            foreach (ViewData item in items)
            {
                Console.WriteLine("Working on view {0}: ", item.Name);

                if (ViewExists(dbViews, item.Name))
                {
                    RunCommand($"ALTER VIEW {item.Name} {item.Options} as {item.Script}");
                }
                else
                {
                    RunCommand($"CREATE VIEW {item.Name} {item.Options} as {item.Script}");
                }
            }
        }
Example #3
0
        protected virtual void HandleViews(Assembly asmb)
        {
            string          viewResource = asmb.GetManifestResourceNames().First(r => r.EndsWith("views.txt", StringComparison.InvariantCultureIgnoreCase));
            List <string>   views        = asmb.LoadResource(viewResource).Split(Environment.NewLine.ToCharArray()).ToList();
            List <ViewData> items        = new List <ViewData>();

            Console.WriteLine("Parsing View File....");
            foreach (string s in views)
            {
                if (!string.IsNullOrEmpty(s))
                {
                    string[] parts = s.Split('|');
                    ViewData data  = new ViewData(parts[0], parts[1]);

                    if (parts.Length == 3)
                    {
                        data.Options = parts[2];
                    }

                    items.Add(data);
                }
            }

            var dbViews = _views.GetObjects().OrderBy(r => r.Name).ToList();

            //may have to run the following multiple times, [some options can prevent updating/removal]
            bool needsRepeat = true;

            while (needsRepeat)
            {
                needsRepeat = RemoveOptions(asmb, items, dbViews);
            }

            foreach (var item in items)
            {
                Console.WriteLine("Working on view {0}: ", item.Name);
                string resource = asmb.GetManifestResourceNames().Single(r => r.EndsWith(item.Script));
                if (string.IsNullOrEmpty(resource))
                {
                    throw new Exception(string.Format("Resource for {0} was not found", item.Script));
                }

                string script = asmb.LoadResource(resource);

                if (ViewExists(dbViews, item.Name))
                {
                    RunCommand($"ALTER VIEW {item.Name} {item.Options} as {script}");
                }
                else
                {
                    RunCommand($"CREATE VIEW {item.Name} {item.Options} as {script}");
                }
            }
        }