protected void ButtonSenadores_Click(object sender, EventArgs e)
        {
            String atualDir = Server.MapPath("Upload");

            if (FileUpload.FileName != "")
            {
                FileUpload.SaveAs(atualDir + "//" + FileUpload.FileName);

                ICSharpCode.SharpZipLib.Zip.ZipFile file = null;

                try
                {
                    file = new ICSharpCode.SharpZipLib.Zip.ZipFile(atualDir + "//" + FileUpload.FileName);

                    if (file.TestArchive(true) == false)
                    {
                        Response.Write("<script>alert('Erro no Zip. Faça o upload novamente.')</script>");
                        return;
                    }
                }
                finally
                {
                    if (file != null)
                    {
                        file.Close();
                    }
                }

                ICSharpCode.SharpZipLib.Zip.FastZip zip = new ICSharpCode.SharpZipLib.Zip.FastZip();
                zip.ExtractZip(atualDir + "//" + FileUpload.FileName, Server.MapPath("Upload"), null);

                File.Delete(atualDir + "//" + FileUpload.FileName);

                CarregarSenadores(atualDir);
            }
            else
            {
                DirectoryInfo dir = new DirectoryInfo(atualDir);

                foreach (FileInfo file in dir.GetFiles("*.zip"))
                {
                    ICSharpCode.SharpZipLib.Zip.FastZip zip = new ICSharpCode.SharpZipLib.Zip.FastZip();
                    zip.ExtractZip(file.FullName, file.DirectoryName, null);

                    File.Delete(file.FullName);

                    CarregarSenadores(file.DirectoryName);
                }
            }

            Cache.Remove("menorAnoSenadores");
            Cache.Remove("ultimaAtualizacaoSenadores");
            Cache.Remove("tableSenadores");
            Cache.Remove("tableDespesaSenadores");
            Cache.Remove("tablePartidoSenadores");
        }
        public override DTSExecResult Execute(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, object transaction)
        {
            bool b = false;

            componentEvents.FireInformation(1, "UnZip SSIS", "Start 1", null, 0, ref b);

            componentEvents.FireInformation(1, "UnZip SSIS", "Start process file: '" + _folderDest + _fileZip + "'.", null, 0, ref b);

            if (_typeOperation == Type_Operation.Please_Select)
            {
                componentEvents.FireError(1, "UnZip SSIS", "Please select type operation (De/Compress).", null, 0);
                throw new Exception("Please select type operation (De/Compress).");
            }

            ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip();

            if (!_folderSource.EndsWith("\\"))
            {
                _folderSource = _folderSource + "\\";
            }
            if (!_folderDest.EndsWith("\\"))
            {
                _folderDest = _folderDest + "\\";
            }

            if (!string.IsNullOrEmpty(_password))
            {
                fz.Password = _password;
            }

            try
            {
                if (!System.IO.Directory.Exists(_folderDest))
                {
                    componentEvents.FireInformation(1, "UnZip SSIS", "Create Folder: '" + _folderDest + "'.", null, 0, ref b);
                    System.IO.Directory.CreateDirectory(_folderDest);
                }

                if (_typeOperation == Type_Operation.Compress)
                {
                    fz.CreateZip(_folderDest + _fileZip, _folderSource, _Recurse, _FileFilter);

                    if ((_testarchive) || (!string.IsNullOrEmpty(_comment)))
                    {
                        ICSharpCode.SharpZipLib.Zip.ZipFile zipFile = new ICSharpCode.SharpZipLib.Zip.ZipFile(_folderDest + _fileZip);

                        if (_testarchive)
                        {
                            componentEvents.FireInformation(1, "UnZip SSIS", "Start verify file ZIP (" + _fileZip + ")", null, 0, ref b);
                            if (!zipFile.TestArchive(true))
                            {
                                throw new Exception("Verify file zip: " + _fileZip + " failed.");
                            }
                        }

                        if (!string.IsNullOrEmpty(_comment))
                        {
                            componentEvents.FireInformation(1, "UnZip SSIS", "Set Comment.", null, 0, ref b);
                            zipFile.BeginUpdate();
                            zipFile.SetComment(_comment);
                            zipFile.CommitUpdate();
                        }
                    }
                }
                else
                {
                    if (_testarchive)
                    {
                        ICSharpCode.SharpZipLib.Zip.ZipFile zipFile = new ICSharpCode.SharpZipLib.Zip.ZipFile(_folderSource + _fileZip);

                        componentEvents.FireInformation(1, "UnZip SSIS", "Start verify file ZIP (" + _fileZip + ")", null, 0, ref b);

                        if (!zipFile.TestArchive(true))
                        {
                            throw new Exception("Verify file zip: " + _fileZip + " failed.");
                        }
                    }

                    fz.ExtractZip(_folderSource + _fileZip, _folderDest, _FileFilter);
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            componentEvents.FireInformation(1, "UnZip SSIS", "End process file: '" + _folderDest + _fileZip + "'.", null, 0, ref b);

            return(DTSExecResult.Success);
        }
示例#3
0
		//protected void Page_Load(object sender, EventArgs e)
		//{
		//    //CifrarStringConexao();
		//    GridViewAcerto.PreRender += GridViewAcerto_PreRender;
		//    GridViewPrevia.PreRender += GridViewPrevia_PreRender;
		//}

		//private void GridViewPrevia_PreRender(object sender, EventArgs e)
		//{
		//    try
		//    {
		//        GridViewPrevia.HeaderRow.TableSection = TableRowSection.TableHeader;
		//    }
		//    catch (Exception)
		//    { }
		//}

		//private void GridViewAcerto_PreRender(object sender, EventArgs e)
		//{
		//    try
		//    {
		//        GridViewAcerto.HeaderRow.TableSection = TableRowSection.TableHeader;
		//    }
		//    catch (Exception)
		//    { }
		//}

		protected void ButtonEnviar_Click(object sender, EventArgs e)
		{
			Cache.Remove("menorAno");
			Cache.Remove("ultima_atualizacao");
			Cache.Remove("tableParlamentar");
			Cache.Remove("tableDespesa");
			Cache.Remove("tablePartido");

			String atualDir = Server.MapPath("Upload");

			if (FileUpload.FileName != "")
			{
				//string ftpUrl = ConfigurationManager.AppSettings["ftpAddress"];
				//string ftpUsername = ConfigurationManager.AppSettings["ftpUsername"];
				//string ftpPassword = ConfigurationManager.AppSettings["ftpPassword"];
				//FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpUrl + "Transactions.zip");
				//request.Proxy = new WebProxy(); //-----The requested FTP command is not supported when using HTTP proxy.
				//request.Method = WebRequestMethods.Ftp.UploadFile;
				//request.Credentials = new NetworkCredential(ftpUsername, ftpPassword);
				//StreamReader sourceStream = new StreamReader(fileToBeUploaded);
				//byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
				//sourceStream.Close();
				//request.ContentLength = fileContents.Length;
				//Stream requestStream = request.GetRequestStream();
				//requestStream.Write(fileContents, 0, fileContents.Length);
				//requestStream.Close();
				//FtpWebResponse response = (FtpWebResponse)request.GetResponse();
				//Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);
				//response.Close();

				//using (var requestStream = request.GetRequestStream())
				//{
				//    using (var input = File.OpenRead(fileToBeUploaded))
				//    {
				//        input.CopyTo(requestStream);
				//    }
				//}

				if (!Directory.Exists(atualDir))
					Directory.CreateDirectory(atualDir);

				FileUpload.SaveAs(atualDir + "\\" + FileUpload.FileName);

				ICSharpCode.SharpZipLib.Zip.ZipFile file = null;

				try
				{
					file = new ICSharpCode.SharpZipLib.Zip.ZipFile(atualDir + "\\" + FileUpload.FileName);

					if (file.TestArchive(true) == false)
					{
						Response.Write("<script>alert('Erro no Zip. Faça o upload novamente.')</script>");
						return;
					}
				}
				finally
				{
					if (file != null)
						file.Close();
				}

				ICSharpCode.SharpZipLib.Zip.FastZip zip = new ICSharpCode.SharpZipLib.Zip.FastZip();
				zip.ExtractZip(atualDir + "//" + FileUpload.FileName, Server.MapPath("Upload"), null);

				File.Delete(atualDir + "//" + FileUpload.FileName);

				Carregar(atualDir);
			}
			else
			{
				DirectoryInfo dir = new DirectoryInfo(atualDir);

				foreach (FileInfo file in dir.GetFiles("*.zip"))
				{
					ICSharpCode.SharpZipLib.Zip.FastZip zip = new ICSharpCode.SharpZipLib.Zip.FastZip();
					zip.ExtractZip(file.FullName, file.DirectoryName, null);

					File.Delete(file.FullName);

					Carregar(file.DirectoryName);
				}
			}
		}
示例#4
0
		protected void ButtonSenadores_Click(object sender, EventArgs e)
		{
			String atualDir = Server.MapPath("Upload");

			if (FileUpload.FileName != "")
			{
				FileUpload.SaveAs(atualDir + "//" + FileUpload.FileName);

				ICSharpCode.SharpZipLib.Zip.ZipFile file = null;

				try
				{
					file = new ICSharpCode.SharpZipLib.Zip.ZipFile(atualDir + "//" + FileUpload.FileName);

					if (file.TestArchive(true) == false)
					{
						Response.Write("<script>alert('Erro no Zip. Faça o upload novamente.')</script>");
						return;
					}
				}
				finally
				{
					if (file != null)
						file.Close();
				}

				ICSharpCode.SharpZipLib.Zip.FastZip zip = new ICSharpCode.SharpZipLib.Zip.FastZip();
				zip.ExtractZip(atualDir + "//" + FileUpload.FileName, Server.MapPath("Upload"), null);

				File.Delete(atualDir + "//" + FileUpload.FileName);

				CarregarSenadores(atualDir);
			}
			else
			{
				DirectoryInfo dir = new DirectoryInfo(atualDir);

				foreach (FileInfo file in dir.GetFiles("*.zip"))
				{
					ICSharpCode.SharpZipLib.Zip.FastZip zip = new ICSharpCode.SharpZipLib.Zip.FastZip();
					zip.ExtractZip(file.FullName, file.DirectoryName, null);

					File.Delete(file.FullName);

					CarregarSenadores(file.DirectoryName);
				}
			}

			Cache.Remove("menorAnoSenadores");
			Cache.Remove("ultimaAtualizacaoSenadores");
			Cache.Remove("tableSenadores");
			Cache.Remove("tableDespesaSenadores");
			Cache.Remove("tablePartidoSenadores");
		}
        //protected void Page_Load(object sender, EventArgs e)
        //{
        //    //CifrarStringConexao();
        //    GridViewAcerto.PreRender += GridViewAcerto_PreRender;
        //    GridViewPrevia.PreRender += GridViewPrevia_PreRender;
        //}

        //private void GridViewPrevia_PreRender(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        GridViewPrevia.HeaderRow.TableSection = TableRowSection.TableHeader;
        //    }
        //    catch (Exception)
        //    { }
        //}

        //private void GridViewAcerto_PreRender(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        GridViewAcerto.HeaderRow.TableSection = TableRowSection.TableHeader;
        //    }
        //    catch (Exception)
        //    { }
        //}

        protected void ButtonEnviar_Click(object sender, EventArgs e)
        {
            Cache.Remove("menorAno");
            Cache.Remove("ultima_atualizacao");
            Cache.Remove("tableParlamentar");
            Cache.Remove("tableDespesa");
            Cache.Remove("tablePartido");

            String atualDir = Server.MapPath("Upload");

            if (FileUpload.FileName != "")
            {
                //string ftpUrl = ConfigurationManager.AppSettings["ftpAddress"];
                //string ftpUsername = ConfigurationManager.AppSettings["ftpUsername"];
                //string ftpPassword = ConfigurationManager.AppSettings["ftpPassword"];
                //FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpUrl + "Transactions.zip");
                //request.Proxy = new WebProxy(); //-----The requested FTP command is not supported when using HTTP proxy.
                //request.Method = WebRequestMethods.Ftp.UploadFile;
                //request.Credentials = new NetworkCredential(ftpUsername, ftpPassword);
                //StreamReader sourceStream = new StreamReader(fileToBeUploaded);
                //byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
                //sourceStream.Close();
                //request.ContentLength = fileContents.Length;
                //Stream requestStream = request.GetRequestStream();
                //requestStream.Write(fileContents, 0, fileContents.Length);
                //requestStream.Close();
                //FtpWebResponse response = (FtpWebResponse)request.GetResponse();
                //Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);
                //response.Close();

                //using (var requestStream = request.GetRequestStream())
                //{
                //    using (var input = File.OpenRead(fileToBeUploaded))
                //    {
                //        input.CopyTo(requestStream);
                //    }
                //}

                if (!Directory.Exists(atualDir))
                {
                    Directory.CreateDirectory(atualDir);
                }

                FileUpload.SaveAs(atualDir + "\\" + FileUpload.FileName);

                ICSharpCode.SharpZipLib.Zip.ZipFile file = null;

                try
                {
                    file = new ICSharpCode.SharpZipLib.Zip.ZipFile(atualDir + "\\" + FileUpload.FileName);

                    if (file.TestArchive(true) == false)
                    {
                        Response.Write("<script>alert('Erro no Zip. Faça o upload novamente.')</script>");
                        return;
                    }
                }
                finally
                {
                    if (file != null)
                    {
                        file.Close();
                    }
                }

                ICSharpCode.SharpZipLib.Zip.FastZip zip = new ICSharpCode.SharpZipLib.Zip.FastZip();
                zip.ExtractZip(atualDir + "//" + FileUpload.FileName, Server.MapPath("Upload"), null);

                File.Delete(atualDir + "//" + FileUpload.FileName);

                Carregar(atualDir);
            }
            else
            {
                DirectoryInfo dir = new DirectoryInfo(atualDir);

                foreach (FileInfo file in dir.GetFiles("*.zip"))
                {
                    ICSharpCode.SharpZipLib.Zip.FastZip zip = new ICSharpCode.SharpZipLib.Zip.FastZip();
                    zip.ExtractZip(file.FullName, file.DirectoryName, null);

                    File.Delete(file.FullName);

                    Carregar(file.DirectoryName);
                }
            }
        }