Esempio n. 1
0
        private Projeto RecuperaProjeto(string diretorioProjeto, string opcaoDeploy, string arquivoConfiguracoes)
        {
            string      csproj    = string.Empty;
            XmlDocument xmlCsproj = null;
            Projeto     retorno   = null;
            XmlNodeList auxNodes;
            XmlNode     auxNode;

            csproj = File.ReadAllText(diretorioProjeto);
            csproj = Infra.RemoveTagXmlTexto(csproj, " xmlns=\"");

            xmlCsproj = new XmlDocument();
            xmlCsproj.LoadXml(csproj);

            retorno = new Projeto();

            auxNode = xmlCsproj.SelectSingleNode("/Project/PropertyGroup/AssemblyName");

            retorno.ArtefatoGerado = auxNode.InnerText;

            auxNode = xmlCsproj.SelectSingleNode("/Project/PropertyGroup/ProjectGuid");

            retorno.GUIDProjeto = auxNode.InnerText;

            auxNode = xmlCsproj.SelectSingleNode("/Project/PropertyGroup/OutputType");

            switch (auxNode.InnerText)
            {
            case "Exe":
                retorno.TipoProjeto = Constantes.TipoProjeto.exe;
                break;

            case "Library":
                retorno.TipoProjeto = Constantes.TipoProjeto.dll;
                break;
            }

            auxNodes = xmlCsproj.SelectNodes("/Project/ItemGroup/Compile");

            if (auxNodes.Count > 0)
            {
                foreach (XmlNode node in auxNodes)
                {
                    retorno.ArtefatosCompiladosProjeto.Add(Infra.EncontraDiretorio(diretorioProjeto, node.Attributes["Include"].Value));
                }
            }

            auxNodes = xmlCsproj.SelectNodes("/Project/ItemGroup/Reference/HintPath");

            if (auxNodes.Count > 0)
            {
                foreach (XmlNode node in auxNodes)
                {
                    retorno.ArtefatosNaoCompiladosImportadosProjeto.Add(Infra.EncontraDiretorio(diretorioProjeto, node.InnerText));
                }
            }

            auxNodes = xmlCsproj.SelectNodes("/Project/ItemGroup/Content");

            if (auxNodes.Count > 0)
            {
                foreach (XmlNode node in auxNodes)
                {
                    retorno.ArtefatosNaoCompiladosProjeto.Add(Infra.EncontraDiretorio(diretorioProjeto, node.Attributes["Include"].Value));
                }
            }

            auxNodes = xmlCsproj.SelectNodes("/Project/ItemGroup/None");

            if (auxNodes.Count > 0)
            {
                foreach (XmlNode node in auxNodes)
                {
                    if (node.HasChildNodes &&
                        node.ChildNodes.Cast <XmlNode>().Where(x => x.Name == "SubType" && x.InnerText == "Designer").Any())
                    {
                        retorno.ArtefatosNaoCompiladosProjeto.Add(Infra.EncontraDiretorio(diretorioProjeto, node.Attributes["Include"].Value));
                    }
                }
            }

            auxNodes = xmlCsproj.SelectNodes("/Project/ItemGroup/ProjectReference/Project");

            if (auxNodes.Count > 0)
            {
                foreach (XmlNode node in auxNodes)
                {
                    retorno.ReferenciasProjeto.Add(node.InnerText.ToUpper());
                }
            }

            auxNodes = xmlCsproj.SelectNodes("/Project/PropertyGroup");

            var noTipoDeploy =
                auxNodes.Cast <XmlNode>()
                .Where(x =>
                       x.ChildNodes.Cast <XmlNode>()
                       .Any(a => a.Name == "OutputPath"))
                .Where(x =>
                       x.Attributes["Condition"].Value.Contains(opcaoDeploy))
                .ToList()
                .FirstOrDefault();

            if (noTipoDeploy != null)
            {
                XmlNode caminhoTipoDeploy = noTipoDeploy.ChildNodes.Cast <XmlNode>().Where(x => x.Name == "OutputPath").FirstOrDefault();

                retorno.ArtefatoGerado = Infra.EncontraDiretorio(diretorioProjeto, caminhoTipoDeploy.InnerText) + retorno.ArtefatoGerado + "." + retorno.TipoProjeto;
            }

            retorno.DiretorioProjeto = Path.GetDirectoryName(diretorioProjeto);

            retorno.ConfiguracaoDeploy = RecuperaConfiguracoesDeploy(retorno.DiretorioProjeto, retorno.DiretorioProjeto + Path.DirectorySeparatorChar + arquivoConfiguracoes);

            return(retorno);
        }
Esempio n. 2
0
        public void GerarPacote(string solution, string diretorioDeltaArtefatos, List <string> artefatosDelta, string diretorioPacote, string opcaoDeploy, string arquivoConfiguracao, string caminhoInicioDeltaSolution)
        {
            List <string> projetosSolution = this.RecuperaProjetosSolution(solution);

            string diretorioSolution = Path.GetDirectoryName(solution);

            List <Projeto> lstProjeto = new List <Projeto>();

            foreach (var caminhoProjeto in projetosSolution)
            {
                string caminhoRealProjeto = string.Empty;

                if (!Path.IsPathRooted(caminhoProjeto))
                {
                    caminhoRealProjeto = Infra.EncontraDiretorio(diretorioSolution + Path.DirectorySeparatorChar, caminhoProjeto);
                }

                lstProjeto.Add(this.RecuperaProjeto(caminhoRealProjeto, opcaoDeploy, arquivoConfiguracao));
            }

            var artefatosDeltaCaminhoCorrigido = artefatosDelta.Select(b => b.Replace(diretorioDeltaArtefatos, string.Empty)).ToList();

            //identifica projetos que precisar ter suas DLLs enviadas novamente
            var projetosAfetados =
                lstProjeto
                .Where(x =>
                       x.ArtefatosCompiladosProjeto
                       .Select(y => y.Replace(caminhoInicioDeltaSolution, string.Empty))
                       .Where(a =>
                              artefatosDeltaCaminhoCorrigido.Contains(a))
                       .Any()
                       ||
                       x.ArtefatosNaoCompiladosImportadosProjeto
                       .Select(y => y.Replace(caminhoInicioDeltaSolution, string.Empty))
                       .Where(a =>
                              artefatosDeltaCaminhoCorrigido.Contains(a))
                       .Any()
                       ||
                       x.ArtefatosNaoCompiladosProjeto
                       .Select(y => y.Replace(caminhoInicioDeltaSolution, string.Empty))
                       .Where(a =>
                              artefatosDeltaCaminhoCorrigido.Contains(a))
                       .Any()
                       ).ToList();

            Dictionary <Projeto, List <ObjetoDeploy> > dicArtefatosNecessarios = new Dictionary <Projeto, List <ObjetoDeploy> >();

            RecuperaArtefatos(projetosAfetados, lstProjeto, artefatosDeltaCaminhoCorrigido, caminhoInicioDeltaSolution, ref dicArtefatosNecessarios);

            if (Directory.Exists(diretorioPacote))
            {
                Directory.Delete(diretorioPacote, true);
            }

            foreach (var artefatosNecessarios in dicArtefatosNecessarios)
            {
                for (int i = 0; i < artefatosNecessarios.Key.ConfiguracaoDeploy.Servidor.Count; i++)
                {
                    var diretorioPacoteProjeto = diretorioPacote + artefatosNecessarios.Key.ConfiguracaoDeploy.Servidor[i];

                    foreach (var artefato in artefatosNecessarios.Value)
                    {
                        if (artefato.Binario)
                        {
                            var diretorioDestino = diretorioPacoteProjeto + artefatosNecessarios.Key.ConfiguracaoDeploy.DiretorioBinario[i] + Path.GetFileName(artefato.Arquivo);

                            if (!Directory.Exists(Path.GetDirectoryName(diretorioDestino)))
                            {
                                Directory.CreateDirectory(Path.GetDirectoryName(diretorioDestino));
                            }

                            File.Copy(artefato.Arquivo, diretorioDestino, true);
                        }
                        else
                        {
                            var arquivo = string.Empty;

                            arquivo = artefato.Arquivo.Remove(artefato.Arquivo.IndexOf(artefatosNecessarios.Key.DiretorioProjeto, 0), artefatosNecessarios.Key.DiretorioProjeto.Length);

                            if (arquivo.StartsWith(@"\"))
                            {
                                arquivo = arquivo.Remove(0, 1);
                            }

                            var diretorioDestino = diretorioPacoteProjeto + artefatosNecessarios.Key.ConfiguracaoDeploy.Diretorio[i] + arquivo;

                            if (!Directory.Exists(Path.GetDirectoryName(diretorioDestino)))
                            {
                                Directory.CreateDirectory(Path.GetDirectoryName(diretorioDestino));
                            }

                            File.Copy(artefato.Arquivo, diretorioDestino, true);
                        }
                    }
                }
            }
        }