Ejemplo n.º 1
0
        /*----< demonstrate requirements have been met >---------------*/

        static void Main(string[] args)
        {
            TestUtilities.title("Starting Repository", '=');

            ClientEnvironment.verbose = true; // if true, display test results

            PluggableRepo repo = new PluggableRepo();

            if (!repo.loadAndActivateComponents())
            {
                Console.Write("\n  Couldn't find Repository components.\n\n");
                return;
            }

            // if activation succeeded, then do self test on each

            IVersion   version   = repo.getVersion();
            IStorage   storage   = repo.getStorage();
            ICheckin   checkin   = repo.getCheckin();
            ICheckout  checkout  = repo.getCheckout();
            IBrowse    browse    = repo.getBrowse();
            IOwnership ownership = repo.getOwnership();

            storage.analyzeDependencies();

            if (
                Util.checkNull(version) || Util.checkNull(storage) || Util.checkNull(checkin) ||
                Util.checkNull(checkout) || Util.checkNull(browse) || Util.checkNull(ownership)
                )
            {
                Console.Write("\n  failed to load one or more required components");
            }
            else
            {
                Util.checkResult(version.testComponent(), version.componentType);
                TestUtilities.putLine();
                Util.checkResult(storage.testComponent(), storage.componentType);
                TestUtilities.putLine();
                Util.checkResult(checkin.testComponent(), checkin.componentType);
                TestUtilities.putLine();
                Util.checkResult(checkout.testComponent(), checkout.componentType);
                TestUtilities.putLine();
                Util.checkResult(browse.testComponent(), browse.componentType);
                TestUtilities.putLine();
                Util.checkResult(ownership.testComponent(), ownership.componentType);

                TestUtilities.putLine();
                Console.Write("\n  finished testing all loaded components");
            }

            Console.Write("\n\n");
        }
        public bool ProcessarCheckin(Unidade unidade, Usuario usuario, ICheckin checkin, IDataBase db)
        {
            if (!checkin.ÉVálido(unidade, usuario))
            {
                var usuarioAtualizado = db.ObterUsuario(usuario.Id);

                if (usuario != null &&
                    usuario.Id == usuarioAtualizado.Id)
                {
                    db.Salvar(checkin, unidade, usuario);
                    return(true);
                }
                return(false);
            }
            return(false);
        }
Ejemplo n.º 3
0
        public void Salvar(ICheckin checkin, Unidade unidade, Usuario usuario)
        {
            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();

            builder.DataSource     = "servidor.database.servidordaminhapp.net";
            builder.UserID         = "lazaro";
            builder.Password       = "******";
            builder.InitialCatalog = "db_producao";

            using (SqlConnection con = new SqlConnection(builder.ToString()))
            {
                con.Open();
                string     sql = "INSERT INTO checkin VALUES(@unidade,@usuario)";
                SqlCommand cmd = new SqlCommand(sql, con);
                cmd.Parameters.Add("@unidade", SqlDbType.Int).Value = unidade.Id;
                cmd.Parameters.Add("@usuario", SqlDbType.Int).Value = usuario.Id;
                cmd.CommandType = CommandType.Text;
                cmd.ExecuteNonQuery();
            }
        }
Ejemplo n.º 4
0
        /*----< activate pluggable component libraries >---------------*/

        /*
         *  Loads each of the libraries from the ComponentLibraries path.
         *  Each component is activated and bound to a RepoEnvironment
         *  reference.
         */
        public bool loadAndActivateComponents()
        {
            AppDomain currentDomain = AppDomain.CurrentDomain;

            currentDomain.AssemblyResolve += new ResolveEventHandler(LoadFromComponentLibFolder);

            // get names of component dlls

            if (!Directory.Exists(RepoEnvironment.componentsPath))
            {
                Console.Write("\n  can't find path to components");
                return(false);
            }
            string[] libraries = Directory.GetFiles(RepoEnvironment.componentsPath, "*.dll");

            // load libraries and, for each component, activate

            if (libraries.Length > 0)
            {
                foreach (string libName in libraries)
                {
                    // load library

                    string fileName = Path.GetFileName(libName);
                    Console.Write("\n  loading library: {0}", fileName);
                    string fullLibName = Path.GetFullPath(libName);
                    //Assembly asm = Assembly.LoadFile(fullLibName);
                    Assembly asm = Assembly.LoadFrom(fullLibName);

                    if (fileName.Contains("IPluggaleComponent.dll"))
                    {
                        continue;
                    }

                    // if library contains one of the Pluggable Components then activate

                    Type[] types = asm.GetExportedTypes();
                    foreach (Type t in types)
                    {
                        if (t.IsClass && typeof(IStorage).IsAssignableFrom(t))
                        {
                            storage = (IStorage)Activator.CreateInstance(t);
                            RepoEnvironment.storage = storage;
                            Console.Write("\n  creating {0} component", storage.componentType);
                            continue;
                        }
                        if (t.IsClass && typeof(IVersion).IsAssignableFrom(t))
                        {
                            version = (IVersion)Activator.CreateInstance(t);
                            RepoEnvironment.version = version;
                            Console.Write("\n  creating {0} component", version.componentType);
                            continue;
                        }
                        if (t.IsClass && typeof(ICheckin).IsAssignableFrom(t))
                        {
                            checkin = (ICheckin)Activator.CreateInstance(t);
                            RepoEnvironment.checkin = checkin;
                            Console.Write("\n  creating {0} component", checkin.componentType);
                            continue;
                        }
                        if (t.IsClass && typeof(ICheckout).IsAssignableFrom(t))
                        {
                            checkout = (ICheckout)Activator.CreateInstance(t);
                            RepoEnvironment.checkout = checkout;
                            Console.Write("\n  creating {0} component", checkout.componentType);
                            continue;
                        }
                        if (t.IsClass && typeof(IBrowse).IsAssignableFrom(t))
                        {
                            browse = (IBrowse)Activator.CreateInstance(t);
                            RepoEnvironment.browse = browse;
                            Console.Write("\n  creating {0} component", browse.componentType);
                            continue;
                        }
                        if (t.IsClass && typeof(IOwnership).IsAssignableFrom(t))
                        {
                            ownership = (IOwnership)Activator.CreateInstance(t);
                            RepoEnvironment.ownership = ownership;
                            Console.Write("\n  creating {0} component", ownership.componentType);
                            continue;
                        }
                    }
                }
            }
            Console.Write("\n");
            return(libraries.Length > 0);
        }
Ejemplo n.º 5
0
 public void Salvar(ICheckin checkin, Unidade unidade, Usuario usuario)
 {
     //nada
     this.Acessou = true;
 }