Exemplo n.º 1
0
        public void ACTest()
        {
            Guid.NewGuid().ToString().Replace("-", string.Empty);

            ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip();
            fz.CreateZip(@"C:\123.zip", @"C:\Users\0115289\Desktop\becky", true, string.Empty, string.Empty);
        }
Exemplo n.º 2
0
        private void btnConvertSelection_Click(object sender, EventArgs e)
        {
            var resp = MetroMessageBox.Show(this, "This action can´t will generate an backup of selected files on the root selected folder! \n Do you want to continue with this action?", "Converting files character set", MessageBoxButtons.YesNo);

            if (resp != DialogResult.Yes)
            {
                return;
            }

            var dstCharset     = Charsets.GetEncoding(cboDestinationEncode.SelectedItem.ToString());
            var parentBasePath = new DirectoryInfo(txtBaseDirectory.Text).Parent;
            var zipFileName    = Path.Combine(parentBasePath.FullName, DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".zip");

            MetroMessageBox.Show(this, string.Format("Right!, Your backup file wil be saved on \"{0}\"", zipFileName), "Converting files character set", MessageBoxButtons.OK);

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

            fz.CreateZip(zipFileName, txtBaseDirectory.Text, true, null);

            foreach (ListViewItem item in lstResults.SelectedItems)
            {
                var srcCharset = Charsets.GetEncoding(item.SubItems[0].Text);

                var srcFileName      = item.SubItems[1].Text;
                var srcDirectoryName = item.SubItems[2].Text;
                var srcFullName      = Path.Combine(srcDirectoryName, srcFileName);
                var dstFullName      = srcFullName;
                var srcContent       = File.ReadAllText(Path.Combine(srcDirectoryName, srcFileName), srcCharset);

                File.WriteAllText(dstFullName, srcContent, dstCharset);
            }

            MetroMessageBox.Show(this, "The selected files has ben converted!\n You have refresh view to see changes", "Right!");
        }
Exemplo n.º 3
0
 public static void CreatZipPassword(string desFile, string SourcePath, string password = "******")
 {
     ICSharpCode.SharpZipLib.Zip.FastZip fastzip = new ICSharpCode.SharpZipLib.Zip.FastZip();
     fastzip.Password = password;
     fastzip.UseZip64 = ICSharpCode.SharpZipLib.Zip.UseZip64.Off;
     fastzip.CreateZip(desFile, SourcePath, true, "");
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            StringWriter output = new StringWriter();

            Server.Execute("MotdTemplate.aspx?lobbyID=" + LobbyID, output);

            string tempDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            Directory.CreateDirectory(tempDirectory);

            string tempFile = Path.Combine(tempDirectory, "publicmessageoftheday.mdl");
            File.WriteAllText(tempFile, output.ToString());

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

            string zipFilename = Path.GetTempFileName();

            fastZip.CreateZip(zipFilename, tempDirectory, false, String.Empty);

            byte[] outputBytes = File.ReadAllBytes(zipFilename);

            Directory.Delete(tempDirectory, true);

            File.Delete(zipFilename);

            Response.ContentType = "application/zip";
            Response.AddHeader("Content-Disposition", "attachment; filename=publicmessageoftheday.zip");
            Response.AddHeader("ContentLength", outputBytes.Length.ToString());

            Response.BinaryWrite(outputBytes);
        }
Exemplo n.º 5
0
        public static void DownloadSimpleZip()
        {
            string path = @"D:\Stefan.Steiger\Documents\Visual Studio 2013\Projects\NancyHub\NancyHub\EmbeddedResources";

            System.Web.HttpResponse Response = System.Web.HttpContext.Current.Response;

            Response.ContentType = "application/zip";
            Response.AddHeader("content-disposition", "filename=" + "Download.zip");


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

            fastZip.CreateEmptyDirectories = true;
            // fastZip.Password = "******";


            // Include all files by recursing through the directory structure
            bool recurse = true;

            // Dont filter any files at all
            string filter = null;


            fastZip.CreateZip(Response.OutputStream, path, true, null, null);

            // fastZip.CreateZip("fileName.zip", @"C:\SourceDirectory", recurse, filter);
        } // End Sub DownloadSimpleZip
        protected void Page_Load(object sender, EventArgs e)
        {
            StringWriter output = new StringWriter();

            Server.Execute("MotdTemplate.aspx?lobbyID=" + LobbyID, output);

            string tempDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            Directory.CreateDirectory(tempDirectory);

            string tempFile = Path.Combine(tempDirectory, "publicmessageoftheday.mdl");

            File.WriteAllText(tempFile, output.ToString());

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

            string zipFilename = Path.GetTempFileName();

            fastZip.CreateZip(zipFilename, tempDirectory, false, String.Empty);

            byte[] outputBytes = File.ReadAllBytes(zipFilename);

            Directory.Delete(tempDirectory, true);

            File.Delete(zipFilename);

            Response.ContentType = "application/zip";
            Response.AddHeader("Content-Disposition", "attachment; filename=publicmessageoftheday.zip");
            Response.AddHeader("ContentLength", outputBytes.Length.ToString());

            Response.BinaryWrite(outputBytes);
        }
Exemplo n.º 7
0
        private Boolean lockZip(String r_password, String w_password)
        {
            ////////////////////////////////////////////////////
            // ZIP施錠
            ////////////////////////////////////////////////////
            if (avaZip)
            {
                if (r_password.Length == 0 || w_password.Length > 0)
                {
                    label2.Text = WindowsFormsApplication1.Properties.Resources.message3;
                    return(false);
                }
                // 一時ファイルの保存フォルダ名
                String tmpFilePath = Path.GetTempPath() + Path.GetRandomFileName();

                // パスワードなしで解凍を行う
                myZip.Password = null;
                try {
                    myZip.ExtractZip(dataGridView1.Rows[0].Cells[3].Value.ToString(), tmpFilePath, null);
                } catch {
                    label2.Text = WindowsFormsApplication1.Properties.Resources.zip1;
                    //"This workbook has been read password-protected.";
                    return(false);
                }

                try {
                    // 元のファイルを名前を変更
                    if (File.Exists(dataGridView1.Rows[0].Cells[3].Value.ToString() + "~"))
                    {
                        File.Delete(dataGridView1.Rows[0].Cells[3].Value.ToString() + "~");
                    }
                    File.Move(dataGridView1.Rows[0].Cells[3].Value.ToString(), dataGridView1.Rows[0].Cells[3].Value.ToString() + "~");
                    // パスワードを付けてファイルを作成
                    myZip.Password = r_password;
                    myZip.CreateZip(dataGridView1.Rows[0].Cells[3].Value.ToString(), tmpFilePath, true, null, null);
                    // 元ファイルを削除
                    File.Delete(dataGridView1.Rows[0].Cells[3].Value.ToString() + "~");
                    // 一時ファイルディレクトリを削除
                    Directory.Delete(tmpFilePath, true);
                } catch {
                    label2.Text = WindowsFormsApplication1.Properties.Resources.error1;
                    Directory.Delete(tmpFilePath, true);
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 8
0
 public static void ZipRepository(string path, System.IO.Stream strm)
 {
     // http://community.sharpdevelop.net/forums/t/2842.aspx
     // Added CreateExe to FastZip
     ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip();
     // fz.CreateZip("zipfilename", "sourceDir", true, null);
     fz.CreateZip(strm, path, true, null, null);
 }         // End Sub xxx
Exemplo n.º 9
0
        /// <summary>
        /// データをZip圧縮する
        /// </summary>
        /// <param name="saveFolder">Zip書庫を格納するフォルダのパス</param>
        /// <param name="zipFileName">圧縮したデータのパス</param>
        /// <param name="sourceDirectory">圧縮するデータのパス</param>
        public void DataZip(string saveFolder, string zipFileName, string sourceDirectory)
        {
            Directory.CreateDirectory(saveFolder);
            var fastZip = new ICSharpCode.SharpZipLib.Zip.FastZip();

            //空のフォルダも書庫に入れるか
            fastZip.CreateEmptyDirectories = true;

            fastZip.CreateZip(zipFileName, sourceDirectory, true, null);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 压缩
        /// </summary>
        /// <param name="_localPath">待压缩的目录或文件</param>
        /// <param name="_zipFileName">压缩后的目录文件</param>
        public static void compress(string _localPath, string _zipFileName)
        {
            string localPath   = _localPath;   //待压缩的目录或文件
            string zipFileName = _zipFileName; //压缩后的目录文件
            // Export the directory tree from SVN server.
            //localPath = System.IO.Path.Combine(localPath, Guid.NewGuid().ToString());
            // Zip it into a memory stream.

            var zip = new ICSharpCode.SharpZipLib.Zip.FastZip();

            zip.CreateZip(zipFileName, localPath, true, string.Empty, string.Empty);
        }
Exemplo n.º 11
0
        private string Pack()
        {
            string zippedSourceFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            Directory.CreateDirectory(zippedSourceFolder);
            foreach (var f in files) {
                File.Copy(f, Path.Combine(zippedSourceFolder, Path.GetFileName(f)), true);
            }

            string zippedArchive = Path.GetTempFileName();
            ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip();
            fz.CreateZip(zippedArchive, zippedSourceFolder, true, "", "");
            return zippedArchive;
        }
Exemplo n.º 12
0
        /// <summary>
        /// 壓縮檔案
        /// </summary>
        /// <param name="strSourceFilePath">來源檔案路徑</param>
        /// <param name="strDesFileName">目的檔名</param>
        /// <param name="SourceFileReg">需要壓縮的檔案</param>
        public void Compress(string strSourceFilePath, 
                             string strDesFileName,
                             string SourceFileReg
                             )
        {
            ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip();

            fz.CreateZip(strDesFileName,
                         strSourceFilePath, 
                         true, 
                         SourceFileReg
                         );
        }
Exemplo n.º 13
0
 public ActionResult BackupDB(string db)
 {
     if (db.IsNullOrEmpty()) db = System.Configuration.ConfigurationManager.AppSettings["DBName"];
     if (db.IsNullOrEmpty()) db = "EAP";
     string fileDir = Server.MapPath("~/db.bak/");
     string fileName = db + "-" + DateTime.Now.ToString("yyyyMMddHHmmss");
     string filePath = System.IO.Path.Combine(fileDir, fileName + ".bak");
     string sqlStr = "backup database " + db + " to disk='" + filePath + "' with format";
     Zippy.Data.StaticDB.DB.ExecuteNonQuery(sqlStr);
     ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip();
     fz.CreateZip(System.IO.Path.Combine(fileDir, fileName + ".zip"), fileDir, false, fileName + ".bak");
     System.IO.File.Delete(filePath);
     return Redirect("/System/Database/");
 }
Exemplo n.º 14
0
 /// <summary>
 /// Compress list of files [sourceFiles] to [zipFileName]
 /// </summary>
 /// <param name="zipFileName"></param>
 /// <param name="sourceFiles"></param>
 public static void Zip(string zipFileName, FileInfo[] sourceFiles)
 {
     try
     {
         // get the root folder. NOTE: it assums that the first file is at the root.
         string rootFolder = Path.GetDirectoryName(sourceFiles[0].FullName);
         // compress
         ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip();
         fz.CreateZip(zipFileName, rootFolder, true, "");
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 15
0
        } // End Sub DownloadSimpleZip

        public static void CreateSimpleZip()
        {
            ICSharpCode.SharpZipLib.Zip.FastZip fastZip = new ICSharpCode.SharpZipLib.Zip.FastZip();

            fastZip.CreateEmptyDirectories = true;
            // fastZip.Password = "******";


            // Include all files by recursing through the directory structure
            bool recurse = true;

            // Dont filter any files at all
            string filter = null;

            fastZip.CreateZip(@"D:\fileName.zip", @"D:\Stefan.Steiger\Documents\Visual Studio 2013\Projects\NancyHub\NancyHub\EmbeddedResources", recurse, filter);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            List <FileCollision>            fileCollisions     = new List <FileCollision>();
            Dictionary <string, UpdateItem> filesInPublication = new Dictionary <string, UpdateItem>();

            AutoUpdateManager.TryGetPublicationFiles(PublicationID, out filesInPublication, out fileCollisions);

            string publicationName = AutoUpdateManager.GetPublicationName(PublicationID);

            string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            Directory.CreateDirectory(tempPath);

            foreach (string filename in filesInPublication.Keys)
            {
                string targetFile = Path.Combine(tempPath, filename);

                if (Directory.Exists(Path.GetDirectoryName(targetFile)) == false)
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(targetFile));
                }


                File.Copy(filesInPublication[filename].FileInfo.FullName, targetFile, true);
            }

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

            string zipFilename = Path.GetTempFileName();

            fastZip.CreateZip(zipFilename, tempPath, true, String.Empty);

            byte[] outputBytes = File.ReadAllBytes(zipFilename);

            Directory.Delete(tempPath, true);

            File.Delete(zipFilename);


            Response.ContentType = "application/zip";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + publicationName + ".zip");
            Response.AddHeader("ContentLength", outputBytes.Length.ToString());


            Response.BinaryWrite(outputBytes);
        }
Exemplo n.º 17
0
        public string Sling(string path)
        {
            string token = Guid.NewGuid().ToString("N");

            string zipPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip();
            fz.CreateZip(zipPath, path, true, "", "");

            using (AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client("accesskey", "secret")) {
                try {
                    // simple object put
                    PutObjectRequest request = new PutObjectRequest();
                    request.WithBucketName("slingshot")
                    .WithKey(token + ".zip")
                    .WithCannedACL(S3CannedACL.PublicRead)
                    .WithFilePath(zipPath);

                    using (S3Response response = client.PutObject(request)) {
                        // work with it
                        Console.WriteLine(response.AmazonId2);
                    }
                }
                catch (AmazonS3Exception amazonS3Exception) {
                    if (amazonS3Exception.ErrorCode != null &&
                        (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") ||
                         amazonS3Exception.ErrorCode.Equals("InvalidSecurity")))
                    {
                        Console.WriteLine("Please check the provided AWS Credentials.");
                        Console.WriteLine("If you haven't signed up for Amazon S3, please visit http://aws.amazon.com/s3");
                    }
                    else
                    {
                        Console.WriteLine("An error occurred with the message '{0}' when writing an object", amazonS3Exception.Message);
                    }
                }
            }

            if (File.Exists(zipPath))
            {
                File.Delete(zipPath);
            }

            return(token);
        }
Exemplo n.º 18
0
        //============================================================================
        //! 選択されているファイルを圧縮する
        private void _ZipSelectFiles(string iZipFileName)
        {
            //出力先のフォルダがなければ作成
            if (!System.IO.Directory.Exists(@"Output"))
            {
                System.IO.Directory.CreateDirectory("Output");
            }

            //Tempフォルダがなければ作成
            if (!System.IO.Directory.Exists(@"Temp"))
            {
                System.IO.Directory.CreateDirectory("Temp");
            }

            //選択
            int index = 1;

            foreach (BindItem iItem in DirectoryListView.SelectedItems)
            {
                //Tempフォルダの中身を全削除
                foreach (var iFile in System.IO.Directory.GetFiles("Temp"))
                {
                    System.IO.File.Delete(iFile);
                }

                //Tempフォルダの中に指定フォルダのjpgファイルのみをコピー
                int file_Index = 0;
                foreach (var iFile in _GetImageFileList(iItem.FilePath))
                {
                    var extension = System.IO.Path.GetExtension(iFile);
                    var file_Name = String.Format(@"{0:D3}{1}", file_Index, extension);
                    System.IO.File.Copy(iFile, @"Temp\" + file_Name);
                    ++file_Index;
                }


                string zip_File_Path = @"Output\" + iZipFileName + ".zip";
                zip_File_Path = zip_File_Path.Replace("{NumKey}", index.ToString());

                var fast_Zip = new ICSharpCode.SharpZipLib.Zip.FastZip();
                fast_Zip.CreateZip(zip_File_Path, @"Temp\", false, null, null);

                ++index;
            }
        }
Exemplo n.º 19
0
        public string Sling(string path)
        {
            string token = Guid.NewGuid().ToString("N");

            string zipPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip();
            fz.CreateZip(zipPath, path, true, "", "");

            WebResponse r          = null;
            Uri         initialUri = new Uri("http://localhost:1771/upload/");

            Uri resumeUri = InitiateUpload(initialUri, "application/zip", new FileInfo(zipPath).Length);

            using (Stream s = new FileStream(zipPath, FileMode.Open)) {
                r = UploadStream(HttpMethods.Post, resumeUri, s, "application/zip", null);
            }

            return(token);
        }
Exemplo n.º 20
0
        public string Sling(string path)
        {
            string token = Guid.NewGuid().ToString("N");

            zipPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip();
            fz.CreateZip(zipPath, path, true, "", "");

            int CHUNK_SIZE = 10485760;

            ClientLoginAuthenticator cla = new ClientLoginAuthenticator("commanigy-slingshot-v1", ServiceNames.Documents, "username", "password");

            // Set up resumable uploader and notifications
            ResumableUploader ru = new ResumableUploader(CHUNK_SIZE);

            ru.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(this.OnDone);
            ru.AsyncOperationProgress  += new AsyncOperationProgressEventHandler(this.OnProgress);

            // Set metadata for our upload.
            Document entry = new Document();

            entry.Title = string.Format("testupload", token);
            //entry.MediaSource = new MediaFileSource(new FileStream(zipPath, FileMode.Open), "test.zip", "application/zip");
            //entry.MediaSource = new MediaFileSource(zipPath, "application/zip");
            entry.MediaSource = new MediaFileSource(zipPath, "application/zip");

            // Add the upload uri to document entry.
            Uri      createUploadUrl = new Uri("https://docs.google.com/feeds/upload/create-session/default/private/full");
            AtomLink link            = new AtomLink(createUploadUrl.AbsoluteUri);

            link.Rel = ResumableUploader.CreateMediaRelation;
            entry.DocumentEntry.Links.Add(link);

            string userObject = "Just a sample text";

            ru.InsertAsync(cla, entry.DocumentEntry, userObject);
            //ru.InsertAsync(cla, createUploadUrl, new FileStream(zipPath, FileMode.Open), "application/zip", "mytest.zip", userObject);

            return(token);
        }
Exemplo n.º 21
0
        public ActionResult BackupDB(string db)
        {
            if (db.IsNullOrEmpty())
            {
                db = System.Configuration.ConfigurationManager.AppSettings["DBName"];
            }
            if (db.IsNullOrEmpty())
            {
                db = "EAP";
            }
            string fileDir  = Server.MapPath("~/db.bak/");
            string fileName = db + "-" + DateTime.Now.ToString("yyyyMMddHHmmss");
            string filePath = System.IO.Path.Combine(fileDir, fileName + ".bak");
            string sqlStr   = "backup database " + db + " to disk='" + filePath + "' with format";

            Zippy.Data.StaticDB.DB.ExecuteNonQuery(sqlStr);
            ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip();
            fz.CreateZip(System.IO.Path.Combine(fileDir, fileName + ".zip"), fileDir, false, fileName + ".bak");
            System.IO.File.Delete(filePath);
            return(Redirect("/System/Database/"));
        }
Exemplo n.º 22
0
        private string ZippaDB(string p)
        {
            var zp = "";

            try
            {
                zp = System.IO.Path.ChangeExtension(p, ".zip");

                var cart = System.IO.Path.GetDirectoryName(p);
                var ext  = System.IO.Path.GetExtension(p);

                var z = new ICSharpCode.SharpZipLib.Zip.FastZip();
                z.CreateZip(zp, cart, false, ext);
            }
            catch
            {
                zp = "";
            }

            return(zp);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            List<FileCollision> fileCollisions = new List<FileCollision>();
            Dictionary<string, UpdateItem> filesInPublication = new Dictionary<string, UpdateItem>();

            AutoUpdateManager.TryGetPublicationFiles(PublicationID, out filesInPublication, out fileCollisions);

            string publicationName = AutoUpdateManager.GetPublicationName(PublicationID);

            string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            Directory.CreateDirectory(tempPath);

            foreach (string filename in filesInPublication.Keys)
            {
                string targetFile = Path.Combine(tempPath, filename);

                if(Directory.Exists(Path.GetDirectoryName(targetFile)) == false)
                    Directory.CreateDirectory(Path.GetDirectoryName(targetFile));

                File.Copy(filesInPublication[filename].FileInfo.FullName, targetFile, true);
            }

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

            string zipFilename = Path.GetTempFileName();

            fastZip.CreateZip(zipFilename, tempPath, true, String.Empty);

            byte[] outputBytes = File.ReadAllBytes(zipFilename);

            Directory.Delete(tempPath, true);

            File.Delete(zipFilename);

            Response.ContentType = "application/zip";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + publicationName + ".zip");
            Response.AddHeader("ContentLength", outputBytes.Length.ToString());

            Response.BinaryWrite(outputBytes);
        }
Exemplo n.º 24
0
        public static bool ZipDirectory(string zipFileName, string directory, string password = null, string filefilter = null)
        {
            try
            {
                Directory.CreateDirectory(Path.GetDirectoryName(zipFileName));
                SharpZipLib.Zip.FastZipEvents events = new SharpZipLib.Zip.FastZipEvents();
                events.CompletedFile += (object sender, SharpZipLib.Core.ScanEventArgs e) =>
                {
                    LogUtil.Log("Zip Directory{0} Successed.", e.Name);
                };

                SharpZipLib.Zip.FastZip fz = new SharpZipLib.Zip.FastZip(events);
                fz.CreateEmptyDirectories = true;
                fz.Password = password;
                fz.CreateZip(zipFileName, directory, true, filefilter);
                fz = null;
                return(true);
            }
            catch (Exception e)
            {
                LogUtil.LogError(e.Message);
                return(false);
            }
        }
Exemplo n.º 25
0
 /// <summary>
 /// Zips the folder name to create a zip file
 /// </summary>
 /// <param name="folderName"></param>
 /// <param name="zipFileName"></param>
 public static void Zip(string folderName, string zipFileName)
 {
     try
     {
         ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip();
         fz.CreateZip(zipFileName, folderName, true, "");
     }
     catch (ICSharpCode.SharpZipLib.SharpZipBaseException)
     {
         //Fail silently on cancel
         if (Directory.Exists(folderName))
         {
             Directory.Delete(folderName, true);
         }
         if (System.IO.File.Exists(zipFileName))
         {
             System.IO.File.Delete(zipFileName);
         }
     }
     catch
     {
         //Close silently
     }
 }
Exemplo n.º 26
0
        public bool Exportar()
        {
            try
            {
                //limpa os arquivos existentes
                foreach (string s in Directory.GetFiles(PastaTrabalho))
                {
                    if (s.EndsWith(".txt") || s.EndsWith(".csv") || s.EndsWith(".zip"))
                    {
                        File.Delete(s);
                    }
                }
            }
            catch (Exception ex)
            {
                Erro = "Erro ao apagar os arquivos temporários. " + ex.Message;

                return(false);
            }


            try
            {
                CultureInfo ci = new CultureInfo("pt-BR");


                //para cada arquivo selecionado gera o arquivo e salva na pasta temporária
                TextWriter tw = new StreamWriter(PastaTrabalho + "/dados.csv", false, Encoding.GetEncoding("iso-8859-1"));
                tw.Write(Arquivos.TR_FUNCIONARIOS.Carrega());
                tw.Close();
            }
            catch (Exception ex)
            {
                Erro = "Erro interno ao gerar o arquivo de funcionários, o erro foi: " + ex.Message;
                exx  = ex;

                return(false);
            }

            System.Threading.Thread.Sleep(500);


            try
            {
                //cria o ZIP
                ICSharpCode.SharpZipLib.Zip.FastZip objZip = new ICSharpCode.SharpZipLib.Zip.FastZip();
                objZip.CreateZip(PastaTrabalho + "\\ExportacaoTR.zip", PastaTrabalho + "\\", true, @"^.+\.((csv)|(doc)|(docx)|(rtf)|(kkk))$");


                CaminhoTxt = PastaTrabalho + "\\dados.csv";
                CaminhoZip = PastaTrabalho + "\\ExportacaoTR.zip";
            }
            catch (Exception ex)
            {
                Erro = "Erro ao criar arquivo ZIP o erro foi: " + ex.Message;
                return(false);
            }



            return(true);
        }
Exemplo n.º 27
0
        /*  void FncSetInnerCanvas()
        {
            //cnvPaint.Height = 280;
            //cnvPaint.Width = 700;

            Label lblHeader = new Label();
            lblHeader.Content = "CRM Designer";
            lblHeader.PreviewMouseDown += new MouseButtonEventHandler(lblDrag_PreviewMouseDown);
            lblHeader.FontSize = 19;

            ctlPOD objPOD1 = new ctlPOD();
            objPOD1.AllowDrop = true;
            objPOD1.Height = 45;
            objPOD1.Width = 700;
            objPOD1.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
            objPOD1.SetValue(Canvas.LeftProperty, 25.0);
            objPOD1.SetValue(Canvas.TopProperty, 0.0);
            MyPropGrid.ControlToBind = objPOD1;
            objPOD1.cnvPOD.Children.Add(lblHeader);
            currentControl = objPOD1;
            cnvPaint.Children.Add(objPOD1);

            Label lblQuestion = new Label();
            lblQuestion.Content = "CRM Designer2";
            lblQuestion.PreviewMouseDown += new MouseButtonEventHandler(lblDrag_PreviewMouseDown);
            lblQuestion.FontSize = 17;

            ctlPOD objPOD2 = new ctlPOD();
            objPOD2.AllowDrop = true;
            objPOD2.Height = 45;
            objPOD2.Width = 700;
            objPOD2.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
            objPOD2.SetValue(Canvas.LeftProperty, 0.0);
            objPOD2.SetValue(Canvas.TopProperty, 60.0);
            MyPropGrid.ControlToBind = objPOD2;
            objPOD2.cnvPOD.Children.Add(lblQuestion);
            currentControl = objPOD2;
            cnvPaint.Children.Add(objPOD2);

            ClsOptionCollection objOptCollection = ClsOptionCollection.GetAll(objQueCollection[CurrentQueCount].ID);

            varType = objQueCollection[CurrentQueCount].Category;

            if (varType == "CheckBox")
            {
                for (int i = 0; i < objOptCollection.Count; i++)
                {
                    CheckBox chk = new CheckBox();
                    chk.Content = objOptCollection[i].Options;
                    chk.Tag = objOptCollection[i].ActionQueueID.ToString() + "," + objOptCollection[i].ID.ToString();
                    chk.PreviewMouseDown += new MouseButtonEventHandler(chkDrag999_PreviewMouseDown);
                    chk.Height = 18;
                    chk.FontSize = 14;
                    varTop = 120 + (30 * i);

                    ctlPOD objPOD = new ctlPOD();
                    objPOD.AllowDrop = true;
                    objPOD.Height = 25;
                    objPOD.Width = 700;
                    objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
                    objPOD.SetValue(Canvas.LeftProperty, 25.0);
                    objPOD.SetValue(Canvas.TopProperty, varTop);
                    MyPropGrid.ControlToBind = objPOD;
                    objPOD.cnvPOD.Children.Add(chk);
                    currentControl = objPOD;
                    cnvPaint.Children.Add(objPOD);
                }
            }
            else if (varType == "RadioButton")
            {
                for (int i = 0; i < objOptCollection.Count; i++)
                {
                    RadioButton chk = new RadioButton();
                    chk.Content = objOptCollection[i].Options;
                    chk.Tag = objOptCollection[i].ActionQueueID.ToString() + "," + objOptCollection[i].ID.ToString();
                    chk.PreviewMouseDown += new MouseButtonEventHandler(radDrag999_PreviewMouseDown);
                    chk.Height = 18;
                    chk.FontSize = 14;
                    varTop = 120 + (30 * i);

                    ctlPOD objPOD = new ctlPOD();
                    objPOD.AllowDrop = true;
                    objPOD.Height = 25;
                    objPOD.Width = 700;
                    objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
                    objPOD.SetValue(Canvas.LeftProperty, 25.0);
                    objPOD.SetValue(Canvas.TopProperty, varTop);
                    MyPropGrid.ControlToBind = objPOD;
                    objPOD.cnvPOD.Children.Add(chk);
                    currentControl = objPOD;
                    cnvPaint.Children.Add(objPOD);
                }
            }
            else if (varType == "ListBox")
            {
                ListBox lst = new ListBox();
                lst.Height = 250;
                lst.Width = 700;
                lst.Tag = "code";
                lst.SetValue(Canvas.LeftProperty, 0.0);
                lst.SetValue(Canvas.TopProperty, 0.0);
                lst.PreviewMouseDown += new MouseButtonEventHandler(lstDrag999_PreviewMouseDown);
                //cnvMain.Children.Add(lst);

                for (int i = 0; i < objOptCollection.Count; i++)
                {
                    ListBoxItem lbi = new ListBoxItem();
                    //lbi.IsEnabled = false;
                    lbi.Content = objOptCollection[i].Options;
                    lbi.Tag = objOptCollection[i].ActionQueueID.ToString() + "," + objOptCollection[i].ID.ToString();
                    lst.Items.Add(lbi);
                }

                ctlPOD objPOD = new ctlPOD();
                objPOD.AllowDrop = true;
                objPOD.Height = 250;
                objPOD.Width = 700;
                objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
                objPOD.SetValue(Canvas.LeftProperty, 25.0);
                objPOD.SetValue(Canvas.TopProperty, 120.0);
                MyPropGrid.ControlToBind = objPOD;
                objPOD.cnvPOD.Children.Add(lst);
                currentControl = objPOD;
                cnvPaint.Children.Add(objPOD);
            }
            else if (varType == "ComboBox")
            {
                ComboBox cmb = new ComboBox();
                cmb.Height = 25;
                cmb.Width = 700;
                cmb.Tag = "code";
                cmb.PreviewMouseDown += new MouseButtonEventHandler(cmbDrag999_PreviewMouseDown);
                //lst.PreviewMouseDown += new MouseButtonEventHandler(lstDrag999_PreviewMouseDown);
                //cnvMain.Children.Add(lst);

                for (int i = 0; i < objOptCollection.Count; i++)
                {
                    ComboBoxItem cbi = new ComboBoxItem();
                    //cbi.IsEnabled = false;
                    cbi.Content = objOptCollection[i].Options;
                    cbi.Tag = objOptCollection[i].ActionQueueID.ToString() + "," + objOptCollection[i].ID.ToString();
                    cmb.Items.Add(cbi);
                }

                ctlPOD objPOD = new ctlPOD();
                objPOD.AllowDrop = true;
                objPOD.Height = 25;
                objPOD.Width = 700;
                objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
                objPOD.SetValue(Canvas.LeftProperty, 25.0);
                objPOD.SetValue(Canvas.TopProperty, 120.0);
                MyPropGrid.ControlToBind = objPOD;
                objPOD.cnvPOD.Children.Add(cmb);
                currentControl = objPOD;
                cnvPaint.Children.Add(objPOD);
            }

            Button btnNext = new Button();
            btnNext.Content = "Next >> ";
            // To Identify That is has some coding and it's Next Button //
            btnNext.Tag = varType.ToString().ToLower();
            btnNext.PreviewMouseDown += new MouseButtonEventHandler(btnDrag_PreviewMouseDown);
            btnNext.FontSize = 16;

            ctlPOD objPOD3 = new ctlPOD();
            objPOD3.AllowDrop = true;
            objPOD3.Height = 35;
            objPOD3.Width = 100;
            objPOD3.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
            objPOD3.SetValue(Canvas.LeftProperty, 25.0);

            if (varType.ToLower() != "listbox" && varType.ToLower() != "combobox")
            {
                objPOD3.SetValue(Canvas.TopProperty, varTop + 35.0);
            }
            else if (varType.ToLower() == "listbox")
            {
                objPOD3.SetValue(Canvas.TopProperty, 400.0);
            }
            else if (varType.ToLower() == "combobox")
            {
                objPOD3.SetValue(Canvas.TopProperty, 200.0);
            }

            MyPropGrid.ControlToBind = objPOD3;
            objPOD3.cnvPOD.Children.Add(btnNext);
            currentControl = objPOD3;
            cnvPaint.Children.Add(objPOD3);
            varTop = 0;
        }*/

        /*   void btnYes_Click(object sender, RoutedEventArgs e)
           {
               btnPrev.IsEnabled = true;

               Canvas c = new Canvas();
               int count = cnvPaint.Children.Count - 1;

               for (int i = count; i >= 0; i--)
               {
                   if (cnvPaint.Children[i].GetType() != typeof(Expander) && cnvPaint.Children[i].GetType() != typeof(Rectangle))
                   {
                       object o = cnvPaint.Children[i];
                       cnvPaint.Children.Remove(cnvPaint.Children[i]);
                       c.Children.Add((UIElement)o);
                   }
               }

               c.Background = cnvPaint.Background;
               c.Height = cnvPaint.Height;
               c.Width = cnvPaint.Width;

               if (GeneratedQuestions > CurrentQueCount)
               {
                   lstCanvas[CurrentQueCount] = c;
                   CurrentQueCount++;
               }
               else
               {
                   GeneratedQuestions++;
                   CurrentQueCount++;
                   lstCanvas.Add(c);
               }

               if (btnNext.Content.ToString() == "Finished")
               {
                   MessageBox.Show("Script Generated");
                   FncSaveFiles();
                   goto rax;
               }

               if (CurrentQueCount == lstCanvas.Count)
               {
                   FncSetInnerCanvas();
               }
               else
               {
                   FncListToCanvas();
               }

               if (CurrentQueCount + 1 == objQueCollection.Count)
               {
                   btnNext.Content = "Finished";
               }

               //cnvPaint.Children.Clear();
           rax: ;
           }*/
        #endregion

        void FncSaveFiles()
        {

            if (startQuestion == "")
            {
                startQuestion = "CRMDesigner";
                startQuestionID = 1;
            }

            #region Saving Files

            CurrentQueCount = -1;
            
            for (int j = 0; j < 1; j++)
            {
                CurrentQueCount++;
                int Counter = 0;
                string strCode = "";
                

                #region Creating .XAML File
            
                string strXML = "";
                strXML = "<UserControl x:Class=\"CRM.Presentation.UserControl" +  Convert.ToString(1) + "\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" Height=\"300\" Width=\"300\"  VerticalAlignment=\"Top\">";
                strXML = strXML + char.ConvertFromUtf32(13) + "<Canvas Name=\"cnvPaint" + "\" Height=\"" + (tbcMain.Height + 5).ToString() + "\" Width=\"" + (tbcMain.Width + 5).ToString() + "\" Background=\"Transparent\">";
                strXML = strXML + char.ConvertFromUtf32(13) + "<TabControl Name=\"tbcMain" + "\" Height=\"" + tbcMain.Height + "\" Width=\"" + tbcMain.Width + "\" Canvas.Left=\"0\" Canvas.Top=\"0\">";
                foreach (TabItem t in tbcMain.Items)
                {
                    pageCount++;
                    strXML = strXML + char.ConvertFromUtf32(13) + "<TabItem Header=\"" + t.Header.ToString() +"\">";
                    strXML = strXML + char.ConvertFromUtf32(13) + "<Canvas Name=\"cnvPaint" + pageCount.ToString() + "\" Height=\"" + tbcMain.Height + "\" Width=\"" + tbcMain.Width + "\" Background=\"Transparent\">";
                    
                foreach (object o in ((Canvas)t.Content).Children)
                {
                    if (o.GetType() == typeof(ctlPOD))
                    {
                        foreach (object chl in ((ctlPOD)o).cnvPOD.Children)
                        {
                            Counter++;
                            if (chl.GetType() == typeof(TextBox))
                            {
                               strXML = strXML + char.ConvertFromUtf32(13) + "<TextBox Name=\"control" + Counter.ToString() + "\" Height=\"" + ((ctlPOD)o).Height + "\" Width=\"" + ((ctlPOD)o).Width + "\" Canvas.Left=\"" + ((ctlPOD)o).GetValue(Canvas.LeftProperty) + "\" Canvas.Top=\"" + ((ctlPOD)o).GetValue(Canvas.TopProperty) + "\" Background=\"" + ((TextBox)chl).Background + "\" Foreground=\"" + ((TextBox)chl).Foreground + "\" Tag=\"" + ((TextBox)chl).Tag + "\" Text=\"" + ((TextBox)chl).Text + "\" FontFamily=\"" + ((TextBox)chl).FontFamily + "\" FontSize=\"" + ((TextBox)chl).FontSize + "\" IsEnabled=\"" + ((ctlPOD)o).IsEnabled + "\" FontWeight=\"" + ((TextBox)chl).FontWeight + "\" FontStyle=\"" + ((TextBox)chl).FontStyle + "\"/>";
                            }


                            else if (chl.GetType() == typeof(Label))
                            {
                                strXML = strXML + char.ConvertFromUtf32(13) + "<Label Name=\"control" + Counter.ToString() + "\" Height=\"" + ((ctlPOD)o).Height + "\" Width=\"" + ((ctlPOD)o).Width + "\" Canvas.Left=\"" + ((ctlPOD)o).GetValue(Canvas.LeftProperty) + "\" Canvas.Top=\"" + ((ctlPOD)o).GetValue(Canvas.TopProperty) + "\" Background=\"" + ((Label)chl).Background + "\" Foreground=\"" + ((Label)chl).Foreground + "\" Tag=\"" + ((Label)chl).Tag + "\" Content=\"" + ((Label)chl).Content + "\" FontFamily=\"" + ((Label)chl).FontFamily + "\" FontSize=\"" + ((Label)chl).FontSize + "\" FontWeight=\"" + ((Label)chl).FontWeight + "\" FontStyle=\"" + ((Label)chl).FontStyle + "\"/>";
                            }

                        }
                    }
                }
                strXML = strXML + char.ConvertFromUtf32(13) + "</Canvas></TabItem>";
                }
                strXML = strXML + "</TabControl>";
                strXML = strXML + " <Button Name=\"btnSave\" Height=\"25\" Width=\"70\" Canvas.Top=\"" + int.Parse((int.Parse(tbcMain.Height.ToString()) + 5).ToString()).ToString() + "\" Canvas.Left=\"100\" Content=\"Save\" Click=\"btnSave_Click\" /> <Button Name=\"btnCancel\" Height=\"25\" Width=\"70\" Canvas.Top=\"" + int.Parse((int.Parse(tbcMain.Height.ToString()) + 5).ToString()).ToString() + "\" Canvas.Left=\"200\" Content=\"Cancel\" Click=\"btnCancel_Click\" /> </Canvas></UserControl>";

                TextWriter tw = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRM_src\\CRM.Presentation\\" + startQuestion.ToString() + ".Xaml"));
                tw.WriteLine(strXML);
                tw.Close();

                TextReader tr101 = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll","\\CRMPages\\Binded Data.txt"));
                string str101 = tr101.ReadToEnd();
                tr101.Close();


                strXML = "using System;" + char.ConvertFromUtf32(13) +
                         "using System.Collections.Generic;" + char.ConvertFromUtf32(13) +
                         "using System.Linq;" + char.ConvertFromUtf32(13) +
                         "using System.Text;" + char.ConvertFromUtf32(13) +
                         "using System.Windows;" + char.ConvertFromUtf32(13) +
                         "using System.Windows.Controls;" + char.ConvertFromUtf32(13) +
                         "using System.Windows.Data;" + char.ConvertFromUtf32(13) +
                         "using System.Windows.Documents;" + char.ConvertFromUtf32(13) +
                         "using System.Windows.Input;" + char.ConvertFromUtf32(13) +
                         "using System.Windows.Media;" + char.ConvertFromUtf32(13) +
                         "using System.Windows.Media.Imaging;" + char.ConvertFromUtf32(13) +
                         "using System.Windows.Navigation;" + char.ConvertFromUtf32(13) +
                         "using System.Windows.Shapes;" + char.ConvertFromUtf32(13) +
                         "using CRM.Business;" + char.ConvertFromUtf32(13) +
                         char.ConvertFromUtf32(13) +

                         "namespace CRM.Presentation" + char.ConvertFromUtf32(13) +
                         "{" + char.ConvertFromUtf32(13) + 
                          "" + char.ConvertFromUtf32(13) +
                            "public partial class UserControl" + Convert.ToString(1) + ": UserControl" + char.ConvertFromUtf32(13) +
                                "{" + char.ConvertFromUtf32(13) + "" + char.ConvertFromUtf32(13) +
                                    "public UserControl" + Convert.ToString(1) + "()" + char.ConvertFromUtf32(13) +
                                     "{" + char.ConvertFromUtf32(13) +
                                     "InitializeComponent();" + char.ConvertFromUtf32(13)  + char.ConvertFromUtf32(13) +
                                     "VMuktiAPI.VMuktiHelper.RegisterEvent(\"SetLeadIDCRM\").VMuktiEvent += new VMuktiAPI.VMuktiEvents.VMuktiEventHandler(SetLeadIDCRM_VMuktiEvent);" + char.ConvertFromUtf32(13) +
                                     "}" + str101 + char.ConvertFromUtf32(13) + char.ConvertFromUtf32(13) + strCode + char.ConvertFromUtf32(13) +
                                     "}" + char.ConvertFromUtf32(13) +
                                     "}"; 

                TextWriter tw1 = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRM_src\\CRM.Presentation\\" + startQuestion.ToString() + ".Xaml.Cs"));
                tw1.WriteLine(strXML);
                tw1.Close();

                AddRef1_2 = AddRef1_2 + char.ConvertFromUtf32(13) + "<Page Include=\"" + startQuestion.ToString() + ".xaml\">"
                + char.ConvertFromUtf32(13) + "<Generator>MSBuild:Compile</Generator>"
                + char.ConvertFromUtf32(13) + "<SubType>Designer</SubType>"
                + char.ConvertFromUtf32(13) + "</Page>";

                AddRef2_3 = AddRef2_3 + char.ConvertFromUtf32(13) + "<Compile Include=\"" + startQuestion.ToString() + ".Xaml.Cs\">"
                + char.ConvertFromUtf32(13) + "<DependentUpon>" + startQuestion.ToString() + ".Xaml</DependentUpon>"
                + char.ConvertFromUtf32(13) + "<SubType>Code</SubType>"
                + char.ConvertFromUtf32(13) + "</Compile>";


                #endregion
            }

            #region Create Project File


            TextWriter tw11 = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRM_src\\CRM.Presentation\\CRM.Presentation.csproj"));

            TextReader tr1 = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRMPages\\1.txt"));
            string str1 = tr1.ReadToEnd();
            tr1.Close();

            TextReader tr2 = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRMPages\\2.txt"));
            string str2 = tr2.ReadToEnd();
            tr2.Close();

            TextReader tr3 = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRMPages\\3.txt"));
            string str3 = tr3.ReadToEnd();
            tr3.Close();

            tw11.WriteLine(str1 + AddRef2_3 + str2 + AddRef1_2 + str3);
            str1 = "";
            str2 = "";
            str3 = "";
            AddRef1_2 = "";
            AddRef2_3 = "";
            tw11.Close();

            TextWriter twStart = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRM_src\\CRM.Presentation\\clsStartClass.cs"));
            TextReader trClassRead = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRMPages\\ClassRead.txt"));
            string strClassRead = trClassRead.ReadToEnd();
            trClassRead.Close();

            string strBetween = char.ConvertFromUtf32(13) + "public static string strStartQuesion = \"UserControl" + startQuestionID.ToString() + "\";" + char.ConvertFromUtf32(13) + "public static int LeadID = 1;" + char.ConvertFromUtf32(13) + "public static int CallID;" + char.ConvertFromUtf32(13) + "public static string StateName = null;" + char.ConvertFromUtf32(13) + "public static string ZipCode = null;" + char.ConvertFromUtf32(13) + "}" + char.ConvertFromUtf32(13) + "}";

            twStart.WriteLine(strClassRead + strBetween);
            twStart.Close();

            #endregion


            #region After Integration
            //if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "CRM_src\\Script.DataAccess\\ReferencedAssemblies"))
            //{
            //    Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "CRM_src\\Script.DataAccess\\ReferencedAssemblies");
            //}

            //File.Copy(Assembly.GetAssembly(typeof(VMuktiAPI.ClsPeer)).Location, Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"\Script_src\Script.DataAccess\ReferencedAssemblies\VMuktiAPI.dll"));
            
            #endregion

            
            //#region Building the solution File

            //TextWriter tw1111 = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\Script\\Build.bat");
            //tw1111.WriteLine("cd\\");
            //tw1111.WriteLine("C:");
            //tw1111.WriteLine("cd \"C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.5\"");
            //tw1111.WriteLine("msbuild \"" + AppDomain.CurrentDomain.BaseDirectory + "\\Script\\Script.sln\" /t:Rebuild /p:Configuration=Debug");
            //tw1111.Close();

            //System.Diagnostics.Process.Start(AppDomain.CurrentDomain.BaseDirectory + "\\Script\\Build.bat");

            //#endregion

            //MessageBox.Show("Working Till Now");

            #region DLL File Naming

            if (cmbCRM.SelectedIndex < 0)
            {
                MessageBox.Show("Please select a CRM Name");
            }
            else
            {
                string crmName = ((ComboBoxItem)cmbCRM.SelectedItem).Content.ToString();

                TextReader txtReader = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRM_src\\CRM.Presentation\\CRM.Presentation.csproj"));
                string txtString = txtReader.ReadToEnd();
                txtReader.Close();

                txtString = txtString.Replace("<AssemblyName>CRM.Presentation</AssemblyName>", "<AssemblyName>" + crmName + "_CRM.Presentation</AssemblyName>");

                TextWriter txtWriter = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRM_src\\CRM.Presentation\\CRM.Presentation.csproj"));
                txtWriter.WriteLine(txtString);
                txtWriter.Close();



                TextReader txtReader1 = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRM_src\\CRM.Business\\CRM.Business.csproj"));
                string txtString1 = txtReader1.ReadToEnd();
                txtReader1.Close();

                txtString1 = txtString1.Replace("<AssemblyName>CRM.Business</AssemblyName>", "<AssemblyName>" + crmName + "_CRM.Business</AssemblyName>");

                TextWriter txtWriter1 = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRM_src\\CRM.Business\\CRM.Business.csproj"));
                txtWriter1.WriteLine(txtString1);
                txtWriter1.Close();



                TextReader txtReader2 = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRM_src\\CRM.Common\\CRM.Common.csproj"));
                string txtString2 = txtReader2.ReadToEnd();
                txtReader2.Close();

                txtString2 = txtString2.Replace("<AssemblyName>CRM.Common</AssemblyName>", "<AssemblyName>" + crmName + "_CRM.Common</AssemblyName>");

                TextWriter txtWriter2 = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRM_src\\CRM.Common\\CRM.Common.csproj"));
                txtWriter2.WriteLine(txtString2);
                txtWriter2.Close();

                TextReader txtReader3 = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRM_src\\CRM.DataAccess\\CRM.DataAccess.csproj"));
                string txtString3 = txtReader3.ReadToEnd();
                txtReader3.Close();

                txtString3 = txtString3.Replace("<AssemblyName>CRM.DataAccess</AssemblyName>", "<AssemblyName>" + crmName + "_CRM.DataAccess</AssemblyName>");

                TextWriter txtWriter3 = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "\\CRM_src\\CRM.DataAccess\\CRM.DataAccess.csproj"));
                txtWriter3.WriteLine(txtString3);
                txtWriter3.Close();

            #endregion

                #region Building the solution File

                string winDir = Environment.GetFolderPath(Environment.SpecialFolder.System);
                winDir = winDir.Substring(0, winDir.LastIndexOf(@"\"));

                Process buildProcess = new Process();

                File.Copy(Assembly.GetAssembly(typeof(VMuktiAPI.ClsPeer)).Location, Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", @"\CRM_src\CRM.DataAccess\ReferencedAssemblies\VMuktiAPI.dll"));
                //MessageBox.Show(Assembly.GetAssembly(typeof(VMuktiAPI.ClsPeer)).Location);
                //MessageBox.Show(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"Script_src\Script.Presentation\ReferencedAssemblies\VMuktiAPI.dll"));
                File.Copy(Assembly.GetAssembly(typeof(VMuktiAPI.ClsPeer)).Location, Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", @"CRM_src\CRM.Presentation\ReferencedAssemblies\VMuktiAPI.dll"));

                buildProcess.OutputDataReceived += new DataReceivedEventHandler(buildProcess_OutputDataReceived);
                //TextWriter tw1111 = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\Script\\Build.bat");
                //tw1111.WriteLine("cd\\");
                //tw1111.WriteLine("C:");
                //tw1111.WriteLine("cd \"C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.5\"");
                //tw1111.WriteLine("msbuild \"" + AppDomain.CurrentDomain.BaseDirectory + "\\Script\\Script.sln\" /t:Rebuild /p:Configuration=Debug");
                //tw1111.Close();
                //System.Diagnostics.Process.Start(AppDomain.CurrentDomain.BaseDirectory + "\\Script\\Build.bat");

                try
                {

                    if (System.IO.Directory.Exists(winDir + @"\Microsoft.NET\Framework\v3.5\"))
                    {
                        //buildProcess.StartInfo.UseShellExecute = false;
                        buildProcess.StartInfo.WorkingDirectory = winDir + @"\Microsoft.NET\Framework\v3.5\";
                        buildProcess.StartInfo.FileName = "msbuild";
                        buildProcess.StartInfo.Arguments = @" """ + Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"\CRM_src\CRM.sln"" /t:Rebuild /p:Configuration=Debug";
                        buildProcess.Start();
                        buildProcess.WaitForExit();
                    }
                    else
                    {
                        MessageBox.Show("Microsoft .Net framework is not installed at --> \" " + winDir + @"\Microsoft.NET\Framework\v3.5\" + " \"!!");
                    }
                }
                catch (Exception exp)
                {
                    MessageBox.Show(exp.Message.ToString());
                }

                #endregion

                try
                {

                    if (Directory.Exists(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM"))
                    {
                        Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM", true);
                    }
                    Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM");
                    Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM" + "\\" + crmName + "_CRM");
                    Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM" + "\\" + crmName + "_CRM" + @"\BAL");
                    Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM" + "\\" + crmName + "_CRM" + @"\DAL");
                    Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM" + "\\" + crmName + "_CRM" + @"\Control");


                }
                catch (Exception exp)
                {
                    MessageBox.Show("Creating Directories" + exp.Message);
                }

                try
                {
                    copyDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM_src\CRM.Presentation\bin\Debug", Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM");
                }
                catch (Exception exp)
                {
                    MessageBox.Show("Creating Directories" + exp.Message);
                }

                try
                {
                    string[] filesToDelete = Directory.GetFiles(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM", "*.pdb");
                    for (int i = 0; i < filesToDelete.Length; i++)
                    {
                        File.Delete(filesToDelete[i]);
                    }
                }
                catch (Exception exp)
                {
                    MessageBox.Show("Deleting Files" + exp.Message);
                }

                try
                {

                    string[] filesToMove = Directory.GetFiles(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM", "*.dll");
                    for (int i = 0; i < filesToMove.Length; i++)
                    {
                        if (filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")).Contains("Business"))
                        {
                            File.Move(filesToMove[i], Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM" + "\\" + crmName + "_CRM" + @"\BAL" + filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")));
                        }
                        else if (filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")).Contains("Common"))
                        {
                            File.Move(filesToMove[i], Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM" + "\\" + crmName + "_CRM" + @"\BAL" + filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")));
                        }
                        else if (filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")).Contains("DataAccess"))
                        {
                            File.Move(filesToMove[i], Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM" + "\\" + crmName + "_CRM" + @"\DAL" + filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")));
                        }
                        else if (filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")).Contains("Presentation"))
                        {
                            File.Move(filesToMove[i], Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM" + "\\" + crmName + "_CRM" + @"\Control" + filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")));
                        }
                        else if (filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")).Contains("VMuktiAPI"))
                        {

                            File.Delete(filesToMove[i]);

                            //File.Move(filesToMove[i], Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"Script\Control\" + filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")));
                        }
                    }

                }
                catch (Exception exp)
                {
                    MessageBox.Show("Move Files" + exp.Message);
                }

                try
                {

                    Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM_src\CRM.Presentation\bin", true);
                    Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM_src\CRM.Presentation\obj", true);
                    Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM_src\CRM.Business\bin", true);
                    Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM_src\CRM.Business\obj", true);
                    Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM_src\CRM.Common\bin", true);
                    Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM_src\CRM.Common\obj", true);
                    Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM_src\CRM.DataAccess\bin", true);
                    Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM_src\CRM.DataAccess\obj", true);
                }
                catch (Exception exp)
                {
                    MessageBox.Show("Deleting Files" + exp.Message);
                }

                ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip();
                try
                {
                    fz.CreateZip(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM_src.zip", Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM_src", true, "");
                    //fz.CreateZip(AppDomain.CurrentDomain.BaseDirectory + @"CRM_src.zip", AppDomain.CurrentDomain.BaseDirectory + @"CRM_src", true, "");
                }
                catch (Exception exp)
                {
                    MessageBox.Show("Create Zip" + exp.Message);
                }

                try
                {
                    fz.CreateZip(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM" + @".zip", Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM", true, "");
                    //fz.CreateZip(AppDomain.CurrentDomain.BaseDirectory + @"CRM.zip", AppDomain.CurrentDomain.BaseDirectory + @"CRM", true, "");
                }
                catch (Exception exp)
                {
                    MessageBox.Show("Create Zip" + exp.Message);
                }

                try
                {
                    Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM_src", true);
                    //Directory.Delete(AppDomain.CurrentDomain.BaseDirectory + @"CRM_src", true);
                }
                catch (Exception exp)
                {
                    MessageBox.Show("Delete Directory" + exp.Message);
                }

                try
                {
                    Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM", true);
                    //Directory.Delete(AppDomain.CurrentDomain.BaseDirectory + @"CRM", true);
                }
                catch (Exception exp)
                {
                    MessageBox.Show("Delete Directory" + exp.Message);
                }

                try
                {
                    System.Windows.Forms.DialogResult sfdRes;
                    System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog();
                    sfd.Filter = "Zip file(s) (*.zip)|*.zip";
                    sfd.Title = "Save the source file of script to edit manualy!!";
                    sfd.FileName = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\CRM_src.zip";
                    sfdRes = sfd.ShowDialog();

                    if (sfdRes == System.Windows.Forms.DialogResult.OK)
                    {
                        if (File.Exists(sfd.FileName))
                        {
                            File.Delete(sfd.FileName);
                        }
                        File.Move(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + @"CRM_src.zip", sfd.FileName);
                    }

                    //sfd.Title = "Save the file of script to add as a module in VMukti plateform!!";
                    //sfd.FileName = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + crmName + @".zip";
                    //sfdRes = sfd.ShowDialog();
                    //if (sfdRes == System.Windows.Forms.DialogResult.OK)
                    //{
                    //    if (File.Exists(sfd.FileName))
                    //    {
                    //        File.Delete(sfd.FileName);
                    //    }

                    #region UploadFile

                    System.IO.FileInfo fileInfo = new System.IO.FileInfo(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM" + @".zip");
                    System.IO.FileStream stream = new System.IO.FileStream(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM" + @".zip", System.IO.FileMode.Open, System.IO.FileAccess.Read);
                    RemoteFileInfo rfi = new RemoteFileInfo();
                    rfi.FileName = fileInfo.Name;
                    rfi.Length = fileInfo.Length;
                    rfi.FileByteStream = stream;
                    rfi.FolderNameToStore = "CRMs";
                    clientHttpFileTransfer.svcHTTPFileTransferServiceUploadFileToInstallationDirectory(rfi);
                    stream.Close();
                    if (File.Exists(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM" + @".zip"))
                    {
                        File.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("CRMDesigner.Presentation.dll", "") + crmName + "_CRM" + @".zip");
                    }


                    #endregion

                }
                catch (Exception exp)
                {
                }

            #endregion
            }
        }
Exemplo n.º 28
0
        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);
        }
Exemplo n.º 29
0
 public static void ImportOldMc(string importName, string importFrom, Delegate callback = null)
 {
     var thread = new Thread(() =>
     {
         OnImportProgressChangeEvent(LangManager.GetLangFromResource("ImportMain"));
         Directory.CreateDirectory(".minecraft\\versions\\" + importName);
         File.Copy(importFrom + "\\bin\\minecraft.jar",
             ".minecraft\\versions\\" + importName + "\\" + importName + ".jar");
         OnImportProgressChangeEvent(LangManager.GetLangFromResource("ImportCreateJson"));
         var info = new gameinfo {id = importName};
         string timezone = DateTimeOffset.Now.Offset.ToString();
         if (timezone[0] != '-')
         {
             timezone = "+" + timezone;
         }
         info.time = DateTime.Now.GetDateTimeFormats('s')[0] + timezone;
         info.releaseTime = DateTime.Now.GetDateTimeFormats('s')[0] + timezone;
         info.type = "Port By BMCL";
         info.minecraftArguments = "${auth_player_name}";
         info.mainClass = "net.minecraft.client.Minecraft";
         OnImportProgressChangeEvent(LangManager.GetLangFromResource("ImportSolveNative"));
         var libs = new ArrayList();
         var bin = new DirectoryInfo(importFrom + "\\bin");
         foreach (FileInfo file in bin.GetFiles("*.jar"))
         {
             var libfile = new libraries.libraryies();
             if (file.Name == "minecraft.jar")
                 continue;
             if (
                 !Directory.Exists(".minecraft\\libraries\\" + importName + "\\" +
                                   file.Name.Substring(0, file.Name.Length - 4) + "\\BMCL\\"))
             {
                 Directory.CreateDirectory(".minecraft\\libraries\\" + importName + "\\" +
                                           file.Name.Substring(0, file.Name.Length - 4) + "\\BMCL\\");
             }
             File.Copy(file.FullName,
                 ".minecraft\\libraries\\" + importName + "\\" + file.Name.Substring(0, file.Name.Length - 4) +
                 "\\BMCL\\" + file.Name.Substring(0, file.Name.Length - 4) + "-BMCL.jar");
             libfile.name = importName + ":" + file.Name.Substring(0, file.Name.Length - 4) + ":BMCL";
             libs.Add(libfile);
         }
         var nativejar = new ICSharpCode.SharpZipLib.Zip.FastZip();
         if (!Directory.Exists(".minecraft\\libraries\\" + importName + "\\BMCL\\"))
         {
             Directory.CreateDirectory(".minecraft\\libraries\\" + importName + "\\native\\BMCL\\");
         }
         nativejar.CreateZip(
             ".minecraft\\libraries\\" + importName + "\\native\\BMCL\\native-BMCL-natives-windows.jar",
             importFrom + "\\bin\\natives", false, @"\.dll");
         var nativefile = new libraries.libraryies {name = importName + ":native:BMCL"};
         var nativeos = new libraries.OS {windows = "natives-windows"};
         nativefile.natives = nativeos;
         nativefile.extract = new libraries.extract();
         libs.Add(nativefile);
         info.libraries = (libraries.libraryies[]) libs.ToArray(typeof (libraries.libraryies));
         OnImportProgressChangeEvent(LangManager.GetLangFromResource("ImportWriteJson"));
         var wcfg = new FileStream(".minecraft\\versions\\" + importName + "\\" + importName + ".json",
             FileMode.Create);
         var infojson = new DataContractJsonSerializer(typeof (gameinfo));
         infojson.WriteObject(wcfg, info);
         wcfg.Close();
         OnImportProgressChangeEvent(LangManager.GetLangFromResource("ImportSolveLib"));
         if (Directory.Exists(importFrom + "\\lib"))
         {
             if (!Directory.Exists(".minecraft\\lib"))
             {
                 Directory.CreateDirectory(".minecraft\\lib");
             }
             foreach (
                 string libfile in Directory.GetFiles(importFrom + "\\lib", "*", SearchOption.AllDirectories))
             {
                 if (!File.Exists(".minecraft\\lib\\" + System.IO.Path.GetFileName(libfile)))
                 {
                     File.Copy(libfile, ".minecraft\\lib\\" + System.IO.Path.GetFileName(libfile));
                 }
             }
         }
         OnImportProgressChangeEvent(LangManager.GetLangFromResource("ImportSolveMod"));
         if (Directory.Exists(importFrom + "\\mods"))
             util.FileHelper.dircopy(importFrom + "\\mods", ".minecraft\\versions\\" + importName + "\\mods");
         else
             Directory.CreateDirectory(".minecraft\\versions\\" + importName + "\\mods");
         if (Directory.Exists(importFrom + "\\coremods"))
             util.FileHelper.dircopy(importFrom + "\\coremods",
                 ".minecraft\\versions\\" + importName + "\\coremods");
         else
             Directory.CreateDirectory(".minecraft\\versions\\" + importName + "\\coremods");
         if (Directory.Exists(importFrom + "\\config"))
             util.FileHelper.dircopy(importFrom + "\\config", ".minecraft\\versions\\" + importName + "\\config");
         else
             Directory.CreateDirectory(".minecraft\\versions\\" + importName + "\\configmods");
         OnImportFinish();
         if (callback != null)
         {
             BmclCore.Invoke(callback);
         }
     });
     thread.Start();
 }
Exemplo n.º 30
0
        public static void Pack(string packageCode)
        {
            string path = Storage.GetFullDirectoryPath(packageCode);

            ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip();
            fz.CreateZip(path + ".zip", path, true, "", "");

            // remove directory after zipping
            try {
                if (Directory.Exists(path)) {
                    Directory.Delete(path, true);
                }
            }
            catch (Exception x) {
                log.Error("Unable to delete directory after successfully having zipped it", x);
            }
        }
Exemplo n.º 31
0
 /// <summary>
 /// Zips the folder name to create a zip file
 /// </summary>
 /// <param name="folderName"></param>
 /// <param name="zipFileName"></param>
 public static void Zip(string folderName, string zipFileName)
 {
     try
     {
         ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip();
         fz.CreateZip(zipFileName, folderName, true, "");
     }
     catch (ICSharpCode.SharpZipLib.SharpZipBaseException)
     {
         //Fail silently on cancel
         if (Directory.Exists(folderName))
         {
             Directory.Delete(folderName, true);
         }
         if (System.IO.File.Exists(zipFileName))
         {
             System.IO.File.Delete(zipFileName);
         }
     }
     catch
     {
         //Close silently
     }
 }
Exemplo n.º 32
0
        public static string Backup(
            [Description("choose one of data, uploadedFiles, both")] string backup_what)
        {
            Provider.Server.ScriptTimeout = 300;

            if (string.IsNullOrEmpty(backup_what))
                backup_what = "data";

            // 1. create backup_yyyy_MM_dd folder
            string userFilesPath = Provider.MapPath("UserFiles");
            string backupName = "backup_" + DateTime.Now.ToString("yyyy_MM_dd");
            string backupFilesFolder = userFilesPath.Substring(0, userFilesPath.Length - "UserFiles".Length) + "Backup";
            string newBackupFolder = backupFilesFolder + "\\" + backupName;
            if (Directory.Exists(newBackupFolder)) Directory.Delete(newBackupFolder, true);
            Directory.CreateDirectory(newBackupFolder);

            // 2. create data sql dump into the backup folder
            if (backup_what == "data" || backup_what == "both")
            {
                string newBackupPath = newBackupFolder + "\\dump.sql";
                using (StreamWriter sw = new StreamWriter(newBackupPath, false, Encoding.UTF8))
                {
                    textWriterForDump = sw;
                    sw.WriteLine();
                    Dump("both", "MySQL", "all");
                    sw.Close();
                }
            }

            // 3. copy diff of UserFiles(default) folder into the backup folder,
            // Attention: This process assumes existance of a file is within Cinar.CMS by default, UserFiles.txt file,
            //   containing the default SVN file paths of the /UserFiles directory and it's sub directories.
            // Check Utility.cs for more information. GetFileNames();
            string result = "";
            // changed "image" to user "uploadedFiles", which is more useful for taking backups.
            if (backup_what == "uploadedFiles" || backup_what == "both")
            {

                List<string> fileNames = Regex.Split(Utility.GetFileNames(userFilesPath, "UserFiles"), "\r\n").ToList();
                List<string> defaultFileNames = new List<string>();
                try
                {
                    defaultFileNames = Regex.Split(File.ReadAllText(userFilesPath + ".txt"), "\r\n").ToList();
                }
                catch
                {
                }

                string[] diff = fileNames.Select((name, index) => new { name, index })
                    .Where(x => !defaultFileNames.Contains(x.name))
                    .Select(x => x.name).ToArray();

                foreach (var item in diff)
                {
                    string path = newBackupFolder + "\\" + item.Substring("UserFiles\\".Length);
                    FileInfo fi = new FileInfo(path);
                    if (!Directory.Exists(fi.DirectoryName)) Directory.CreateDirectory(fi.DirectoryName);
                    File.Copy(Provider.MapPath(item), path);
                }

                if (diff.Length == 0) result += "No uploaded file was found!\n";
            }
            // 4. zip the backup folder
            ICSharpCode.SharpZipLib.Zip.FastZip zip = new ICSharpCode.SharpZipLib.Zip.FastZip();
            string zipUrl = newBackupFolder + ".zip";
            zip.CreateZip(zipUrl, newBackupFolder, true, null);
            // 5. delete the backup folder
            Directory.Delete(newBackupFolder, true);
            // write download link
            return result + "Download backup file from : http://" + Provider.Configuration.SiteAddress + zipUrl.Substring(zipUrl.IndexOf("\\Backup")).Replace("\\", "/");
        }
Exemplo n.º 33
0
        /// <summary>
        /// 批量生成代码
        /// </summary>
        /// <param name="tempIDs"></param>
        /// <param name="tablenames"></param>
        /// <param name="forceChange"></param>
        /// <returns></returns>
        public ActionResult GeneratorDataBatch(int[] tempIDs, string[] tablenames, bool forceChange = false)
        {
            string newFolder = "";

            try
            {
                string localURL    = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["tempLocation"]);
                string dllLocation = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["dllLocation"]);
                string connectStr  = System.Configuration.ConfigurationManager.AppSettings["DbConnString"];

                string TemporaryFolder = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["TemporaryFolder"]);

                string dbType = System.Configuration.ConfigurationManager.AppSettings["DBType"];

                if (!FileHelper.IsExistDirectory(TemporaryFolder))
                {
                    FileHelper.CreateDirectory(TemporaryFolder);
                }

                newFolder = TemporaryFolder + "/" + (tempIDs.Length > 0 ? tempIDs[0].ToString() : "Temp") + "_" + (int)(random.NextDouble() * 10000);


                if (tablenames.Length > 0)
                {
                    var tempList = context.TempInfo.Where(u => tempIDs.Contains(u.TP_ID)).ToList();

                    FileHelper.CreateDirectory(newFolder);
                    foreach (var temp in tempList)
                    {
                        FileHelper.CreateDirectory(newFolder + "/" + temp.TP_FolderName);
                        foreach (string tableName in tablenames)
                        {
                            string result = TemplateGenerator.RazorGenerator.DomainHelper.GenetatorTemp(forceChange, dllLocation, Server.MapPath(temp.TP_URL), tableName, connectStr, temp.TP_NameSpace, dbType);

                            string fileName = string.IsNullOrEmpty(temp.TP_FileName) ? tableName : string.Format(temp.TP_FileName, TemplateGenerator.RazorGenerator.RazorHelper.UpperFirstLetter(tableName));

                            string filePath = newFolder + "/" + temp.TP_FolderName + "/" + fileName + "." + temp.TP_Extention;

                            FileHelper.CreateFile(filePath);
                            FileHelper.WriteText(filePath, result);
                        }
                    }

                    //生成压缩包
                    ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip();
                    fz.CreateZip(newFolder + ".zip", newFolder, true, "");

                    #region  除文件及文件夹
                    FileHelper.ClearDirectory(newFolder);
                    FileHelper.DeleteDirectory(newFolder);
                    #endregion

                    MemoryStream memStream = new MemoryStream();
                    using (FileStream fs = new FileStream(newFolder + ".zip", FileMode.Open))
                    {
                        memStream.SetLength(fs.Length);
                        fs.Read(memStream.GetBuffer(), 0, (int)fs.Length);
                    }

                    //删除压缩包
                    FileHelper.DeleteFile(newFolder + ".zip");

                    return(File(memStream, "application/octet-stream", "批量生成代码" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".zip"));
                }
                else
                {
                    Response.Write("没有数据");
                    return(null);
                }
            }
            catch (Exception ex)
            {
                if (!string.IsNullOrEmpty(newFolder))
                {
                    if (FileHelper.IsExistDirectory(newFolder))
                    {
                        #region  除文件及文件夹
                        FileHelper.ClearDirectory(newFolder);
                        FileHelper.DeleteDirectory(newFolder);
                        FileHelper.DeleteFile(newFolder + ".zip");
                        #endregion
                    }
                }

                Response.Write(ex.Message);
                return(null);
            }
        }
Exemplo n.º 34
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            if (cb_periodo.SelectedItem != null && cb_periodo.SelectedItem != "")
            {
                if (acbr_path.Text != null && acbr_path.Text != "")
                {
                    if (Directory.Exists(acbr_path.Text + "\\Fechamento_" + cb_periodo.SelectedItem.ToString().Replace("/", "_")))
                    {
                        Directory.Delete(acbr_path.Text + "\\Fechamento_" + cb_periodo.SelectedItem.ToString().Replace("/", "_"));
                    }

                    Directory.CreateDirectory(acbr_path.Text + "\\Fechamento_" + cb_periodo.SelectedItem.ToString().Replace("/", "_"));

                    // Arquivos de Venda
                    DirectoryInfo dir = new DirectoryInfo("C:\\ACBrMonitorPLUS\\Arqs\\SAT\\Vendas\\" + cnpj + "\\" + cb_periodo.SelectedItem.ToString().Split('/')[1] + cb_periodo.SelectedItem.ToString().Split('/')[0]);
                    if (Directory.Exists(acbr_path.Text + "\\Fechamento_" + cb_periodo.SelectedItem.ToString().Replace("/", "_") + "\\vendas"))
                    {
                        Directory.Delete(acbr_path.Text + "\\Fechamento_" + cb_periodo.SelectedItem.ToString().Replace("/", "_") + "\\vendas");
                    }

                    Directory.CreateDirectory(acbr_path.Text + "\\Fechamento_" + cb_periodo.SelectedItem.ToString().Replace("/", "_") + "\\vendas");


                    foreach (FileInfo file in dir.GetFiles())
                    {
                        try
                        {
                            System.IO.File.Copy(file.FullName, acbr_path.Text + "\\Fechamento_" + cb_periodo.SelectedItem.ToString().Replace("/", "_") + "\\vendas" + "\\" + file.Name, true);
                        }
                        catch
                        {
                        }
                    }
                    // Arquivos de Cancelamento
                    try
                    {
                        dir = new DirectoryInfo("C:\\ACBrMonitorPLUS\\Arqs\\SAT\\Cancelamentos\\" + cnpj + "\\" + cb_periodo.SelectedItem.ToString().Split('/')[1] + cb_periodo.SelectedItem.ToString().Split('/')[0]);
                        if (Directory.Exists(acbr_path.Text + "\\Fechamento_" + cb_periodo.SelectedItem.ToString().Replace("/", "_") + "\\cancelamentos"))
                        {
                            Directory.Delete(acbr_path.Text + "\\Fechamento_" + cb_periodo.SelectedItem.ToString().Replace("/", "_") + "\\cancelamentos");
                        }

                        Directory.CreateDirectory(acbr_path.Text + "\\Fechamento_" + cb_periodo.SelectedItem.ToString().Replace("/", "_") + "\\cancelamentos");


                        foreach (FileInfo file in dir.GetFiles())
                        {
                            try
                            {
                                System.IO.File.Copy(file.FullName, acbr_path.Text + "\\Fechamento_" + cb_periodo.SelectedItem.ToString().Replace("/", "_") + "\\cancelamentos" + "\\" + file.Name, true);
                            }
                            catch
                            {
                            }
                        }
                    }
                    catch { }

                    //var bytes = Directory.r File.ReadAllBytes(this.fileName);
                    //using (FileStream fs =new FileStream(this.newFileName, FileMode.CreateNew))
                    //using (GZipStream zipStream = new GZipStream(fs, CompressionMode.Compress, false))
                    //{
                    //     zipStream.Write(bytes, 0, bytes.Length);
                    //}

                    //String startPath = @"c:\example\start";
                    //string zipPath = @"c:\example\result.zip";
                    //string extractPath = @"c:\example\extract";
                    //

                    ICSharpCode.SharpZipLib.Zip.FastZip c = new ICSharpCode.SharpZipLib.Zip.FastZip();
                    c.CreateZip(acbr_path.Text + "\\Fechamento_" + cb_periodo.SelectedItem.ToString().Replace("/", "_") + ".zip", acbr_path.Text + "\\Fechamento_" + cb_periodo.SelectedItem.ToString().Replace("/", "_"), true, "");
                    MessageBox.Show("Exportação finalizada com sucesso !");
                }
                else
                {
                    MessageBox.Show("Você precisa selecionar o diretório de destino para os arquivos");
                }
            }
            else
            {
                MessageBox.Show("Você precisa selecionar o período para exportação");
            }


            //DirectoryInfo diretorio_emissao = new DirectoryInfo(@acbr_path.Text);
            //FileInfo[] Files = diretorio_emissao.GetFiles("*", SearchOption.AllDirectories);
            //foreach (FileInfo File in Files)
            //{
            //    //XmlTextReader xml_emitido = new XmlTextReader(File.FullName);
            //    Boolean xml_cancelado = false;
            //
            //    XmlDocument xml_emitido = new XmlDocument();
            //    xml_emitido.LoadXml(File.FullName);
            //
            //   //xml_emitido.
            //   //
            //   //System.Xml.XmlElement root = xml_emitido.DocumentElement;
            //   //
            //   //
            //   //System.Xml.XmlNodeList nodeList = root.GetElementsByTagName("infCFe");
            //   //
            //   //XmlAttributeCollection attrColl = DocumentElement.Attributes;
            //
            //
            //
            //
            //}
        }
Exemplo n.º 35
0
        public static string Backup(
            [Description("choose one of data, uploadedFiles, both")] string backup_what)
        {
            Provider.Server.ScriptTimeout = 300;

            if (string.IsNullOrEmpty(backup_what))
            {
                backup_what = "data";
            }

            // 1. create backup_yyyy_MM_dd folder
            string userFilesPath     = Provider.MapPath("UserFiles");
            string backupName        = "backup_" + DateTime.Now.ToString("yyyy_MM_dd");
            string backupFilesFolder = userFilesPath.Substring(0, userFilesPath.Length - "UserFiles".Length) + "Backup";
            string newBackupFolder   = backupFilesFolder + "\\" + backupName;

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

            // 2. create data sql dump into the backup folder
            if (backup_what == "data" || backup_what == "both")
            {
                string newBackupPath = newBackupFolder + "\\dump.sql";
                using (StreamWriter sw = new StreamWriter(newBackupPath, false, Encoding.UTF8))
                {
                    textWriterForDump = sw;
                    sw.WriteLine();
                    Dump("both", "MySQL", "all");
                    sw.Close();
                }
            }

            // 3. copy diff of UserFiles(default) folder into the backup folder,
            // Attention: This process assumes existance of a file is within Cinar.CMS by default, UserFiles.txt file,
            //   containing the default SVN file paths of the /UserFiles directory and it's sub directories.
            // Check Utility.cs for more information. GetFileNames();
            string result = "";

            // changed "image" to user "uploadedFiles", which is more useful for taking backups.
            if (backup_what == "uploadedFiles" || backup_what == "both")
            {
                List <string> fileNames        = Regex.Split(Utility.GetFileNames(userFilesPath, "UserFiles"), "\r\n").ToList();
                List <string> defaultFileNames = new List <string>();
                try
                {
                    defaultFileNames = Regex.Split(File.ReadAllText(userFilesPath + ".txt"), "\r\n").ToList();
                }
                catch
                {
                }

                string[] diff = fileNames.Select((name, index) => new { name, index })
                                .Where(x => !defaultFileNames.Contains(x.name))
                                .Select(x => x.name).ToArray();

                foreach (var item in diff)
                {
                    string   path = newBackupFolder + "\\" + item.Substring("UserFiles\\".Length);
                    FileInfo fi   = new FileInfo(path);
                    if (!Directory.Exists(fi.DirectoryName))
                    {
                        Directory.CreateDirectory(fi.DirectoryName);
                    }
                    File.Copy(Provider.MapPath(item), path);
                }

                if (diff.Length == 0)
                {
                    result += "No uploaded file was found!\n";
                }
            }
            // 4. zip the backup folder
            ICSharpCode.SharpZipLib.Zip.FastZip zip = new ICSharpCode.SharpZipLib.Zip.FastZip();
            string zipUrl = newBackupFolder + ".zip";

            zip.CreateZip(zipUrl, newBackupFolder, true, null);
            // 5. delete the backup folder
            Directory.Delete(newBackupFolder, true);
            // write download link
            return(result + "Download backup file from : http://" + Provider.Configuration.SiteAddress + zipUrl.Substring(zipUrl.IndexOf("\\Backup")).Replace("\\", "/"));
        }
Exemplo n.º 36
0
        public void Backup(BackupMode backupType)
        {
            if (!package.AppDataFolderExists)
            {
                return;
            }

            lock (isBusyLock)
            {
                Directory.CreateDirectory(Path.GetDirectoryName(BackupPath));

                bool exceptionOccured = false;

                var fastZipEvents = new ICSharpCode.SharpZipLib.Zip.FastZipEvents();
                fastZipEvents.FileFailure = (sender, e) =>
                {
                    exceptionOccured  = true;
                    e.ContinueRunning = false;
                };
                var zipFile = new ICSharpCode.SharpZipLib.Zip.FastZip(fastZipEvents)
                {
                    CreateEmptyDirectories = true
                };

                string fileFilter   = null;
                string folderFilter = null;

                switch (backupType)
                {
                case BackupMode.Smart:
                    fileFilter   = @";-Settings\\roaming\.lock$;-Settings\\settings\.dat\.LOG[0-9]*$;-ActivationStore\.dat\.LOG[0-9]*$";
                    folderFilter = @"-AC$;-LocalCache;-TempState";
                    break;

                case BackupMode.Full:
                    break;
                }

                IsBusy = true;
                try
                {
                    zipFile.CreateZip(BackupPath, package.AppDataFolderPath, true, fileFilter, folderFilter);
                }
                finally
                {
                    if (exceptionOccured)
                    {
                        try
                        {
                            File.Delete(BackupPath);
                        }
                        finally
                        {
                            IsBusy = false;
                            throw new InvalidOperationException($"« {package.DisplayName} » must be closed before saving");
                        }
                    }

                    IsBusy = false;
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsBackuped)));
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(BackupDate)));
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(State)));
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Version)));
                }
            }
        }
Exemplo n.º 37
0

        
Exemplo n.º 38
0
        public void CreatePatch(string oldVersionPath, string newVersionPath, string outputFile)
        {
            if (isPathInsidePath(oldVersionPath, newVersionPath))
            {
                throw new ArgumentException("Paths overlapping");
            }

            List <String> oldFiles = new List <string>();

            foreach (string file in GetAllFilesInDirectory(oldVersionPath))
            {
                oldFiles.Add(GetRelativePath(file, oldVersionPath));
            }

            List <string> newFiles = new List <string>();

            foreach (string file in GetAllFilesInDirectory(newVersionPath))
            {
                newFiles.Add(GetRelativePath(file, newVersionPath));
            }

            string patchFolder = GetTemporaryDirectory();

            foreach (string newFileSubPath in newFiles)
            {
                string newFile = Path.Combine(newVersionPath, newFileSubPath);
                string oldFile = Path.Combine(oldVersionPath, newFileSubPath);

                if (!File.Exists(oldFile))
                {
                    string fileTocreate = Path.Combine(patchFolder, newFileSubPath + ".new");
                    Directory.CreateDirectory(Path.GetDirectoryName(fileTocreate));
                    File.Copy(newFile, fileTocreate);
                }
                else
                {
                    if (!FilesAreEqual(oldFile, newFile))
                    {
                        string fileTocreate = Path.Combine(patchFolder, newFileSubPath + ".upd");
                        Directory.CreateDirectory(Path.GetDirectoryName(fileTocreate));
                        DoEncode(fileTocreate, oldFile, newFile);
                    }
                }
            }

            //Get deleted files
            foreach (string oldFileSubPath in oldFiles)
            {
                string newFile = Path.Combine(newVersionPath, oldFileSubPath);
                if (!File.Exists(newFile))
                {
                    //Just create empty file as marker to remove the file while executing the patch.
                    string fileTocreate = Path.Combine(patchFolder, oldFileSubPath + ".del");
                    Directory.CreateDirectory(Path.GetDirectoryName(fileTocreate));
                    using (StreamWriter sw = new StreamWriter(fileTocreate));
                }
            }

            ICSharpCode.SharpZipLib.Zip.FastZip zip = new ICSharpCode.SharpZipLib.Zip.FastZip();
            zip.CreateZip(outputFile, patchFolder, true, "");
            Directory.Delete(patchFolder, true);
        }
        void FncSaveFiles()
        {
            g = 0;
            try
            {
                Assembly ass2 = Assembly.GetEntryAssembly();

                strModPath = ass2.Location.Replace("VMukti.Presentation.exe", @"ScriptModules");

                DirectoryInfo d = new DirectoryInfo(strModPath);


                //  MessageBox.Show(strModPath);
                foreach (DirectoryInfo subDir in d.GetDirectories())
                {
                    // ShowDirectory(subDir);
                    // MessageBox.Show(subDir.Name);
                    foreach (DirectoryInfo subDir2 in subDir.GetDirectories())
                    {
                        string[] del = { str };
                        if (subDir2.Name.Contains(str))
                        {
                            string[] name = null;
                            name = subDir2.Name.Split(del, StringSplitOptions.None);

                            //  MessageBox.Show(name[1]+"   b");
                            if (name[1].Trim().Equals(""))
                            {
                                //do nothing

                            }
                            else
                            {
                                if (Int32.Parse(name[1]) > g)
                                    g = Int32.Parse(name[1]);


                            }

                        }
                    }
                }
                g++;
               // MessageBox.Show(g + "");
                if (g != 0)
                {
                    str += g.ToString();
                   // MessageBox.Show(g.ToString());
                    //if (!Directory.Exists(strModPath + "\\" + str, true))
                    //{
                    //    Directory.CreateDirectory(strModPath+"\\"+str , true);
                    //}
                }
                else
                {


                }
            }
            catch(Exception e)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(e, "FncSaveFiles", "ctlScriptdesigner.xaml.cs");
                g++;
            }
            if (flag == false)
            {
                _ScriptName += "_Script";  //Extending _Script with the script name so that it doesn't create conflicts with CRM with same name.
               server = ScriptName;
                
                _ScriptName += g.ToString();

                
                flag = true;
            }

           #region Create Base Solution

            try
            {
                if (Directory.Exists(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "SS")))
                {
                    Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"SS"), true);
                }
                Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "SS"));
            }
            catch (Exception exp)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "FncSaveFiles", "ctlScriptdesigner.xaml.cs");
            }

            //MessageBox.Show(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "ScriptBase"));
            //MessageBox.Show(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "SS"));

            copyDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "ScriptBase"), Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "SS"));
            if (!Directory.Exists(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"SS\Script.DataAccess\ReferencedAssemblies")))
            {
                Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"SS\Script.DataAccess\ReferencedAssemblies"));
            }

            if (!Directory.Exists(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"SS\Script.Presentation\ReferencedAssemblies")))
            {
                Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"SS\Script.Presentation\ReferencedAssemblies"));
            }
            
           #endregion



            if (startQuestion == "")
            {
                startQuestion = objQueCollection[CurrentQueCount - 1].QuestionName;
                startQuestionID = objQueCollection[CurrentQueCount - 1].ID;
            }

            #region Saving Files

            CurrentQueCount = -1;

            //MessageBox.Show(lstCanvas.Count.ToString());

            for (int j = 0; j < lstCanvas.Count; j++)
            {
                CurrentQueCount++;
                int Counter = 0;
                string strCode = "";
                pageCount++;

                #region Creating .XAML File

                string strXML = "";
                strXML = "<UserControl x:Class=\"Script.Presentation.UserControl" + objQueCollection[CurrentQueCount].ID.ToString() + "\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" Height=\"" + lstCanvas[j].Height + "\" Width=\"" + lstCanvas[j].Width + "\">";
                strXML = strXML + char.ConvertFromUtf32(13) + "<Canvas Name=\"cnvPaint" + "\" Height=\"" + lstCanvas[j].Height + "\" Width=\"" + lstCanvas[j].Width + "\" Background=\"" + lstCanvas[j].Background + "\">";

                foreach (object o in lstCanvas[j].Children)
                {
                    if (o.GetType() == typeof(ctlPOD))
                    {
                        foreach (object chl in ((ctlPOD)o).cnvPOD.Children)
                        {
                            Counter++;
                            if (chl.GetType() == typeof(Button))
                            {
                                if (((Button)chl).Tag != null)
                                {
                                   // if (((Button)chl).Tag.ToString().ToLower() != "")
                                    {
                                     //   MessageBox.Show(((Button)chl).Content.ToString() + "     1");
                                        string[] chkStr = ((Button)chl).Tag.ToString().Split('-');

                                        if (chkStr[0] == "DISPOSITION")
                                        {
                                            strCode = strCode + char.ConvertFromUtf32(13) + " void control" + Counter.ToString() + "_Click(object sender, RoutedEventArgs e)" + char.ConvertFromUtf32(13) +
                                                "{" + char.ConvertFromUtf32(13) +
                                                "clsStartClass.sCurrentDispositionID = \"" + chkStr[1] + "\";" +
                                                char.ConvertFromUtf32(13) +
                                                //"VMuktiAPI.VMuktiHelper.CallEvent(\"HangUp\", this, new VMuktiAPI.VMuktiEventArgs(\"ScriptRender\", int.Parse(clsStartClass.sCurrentChannelID) + 1));" + char.ConvertFromUtf32(13) +
                                                "((MainPage)((Canvas)((Canvas)((Canvas)this.Parent).Parent).Parent).Parent).SetDispositionCanvas();" + char.ConvertFromUtf32(13) +
                                                char.ConvertFromUtf32(13) +
                                                "}";
                                        }
                                        else
                                        {

                                            TextReader tr = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "\\ScriptPages\\FixedCode.txt"));
                                            string abc = tr.ReadToEnd();
                                            tr.Close();

                                            strCode = strCode + char.ConvertFromUtf32(13) + " void control" + Counter.ToString() + "_Click(object sender, RoutedEventArgs e)" + char.ConvertFromUtf32(13) +
                                                "{" + char.ConvertFromUtf32(13) +
                                                "ClsQuestionCollectionR objQueCollection = ClsQuestionCollectionR.GetAll(int.Parse(\"" + _ScriptID.ToString() + "\"));" + char.ConvertFromUtf32(13) +
                                                abc + char.ConvertFromUtf32(13) +
                                                "}";
                                        }
                                        string strContent = ((Button)chl).Content.ToString();
                                        strContent = strContent.Replace("&", "&amp;");
                                        strContent = strContent.Replace("\"", "&quot;");
                                        strContent = strContent.Replace("<", "&lt;");
                                        strContent = strContent.Replace(">", "&gt;");

                                        strXML = strXML + char.ConvertFromUtf32(13) + "<Button Name=\"control" + Counter.ToString() + "\" Height=\"" + ((ctlPOD)o).Height + "\" Width=\"" + ((ctlPOD)o).Width + "\" Canvas.Left=\"" + ((ctlPOD)o).GetValue(Canvas.LeftProperty) + "\" Canvas.Top=\"" + ((ctlPOD)o).GetValue(Canvas.TopProperty) + "\" Background=\"" + ((Button)chl).Background + "\" Foreground=\"" + ((Button)chl).Foreground + "\" Tag=\"" + ((Button)chl).Tag + "\" Content=\"" + strContent + "\" FontFamily=\"" + ((Button)chl).FontFamily + "\" FontSize=\"" + ((Button)chl).FontSize + "\" FontWeight=\"" + ((Button)chl).FontWeight + "\" FontStyle=\"" + ((Button)chl).FontStyle + "\" Click=\"control" + Counter.ToString() + "_Click" + "\"/>";
                                    }
                                    //else
                                    {
                                     //   MessageBox.Show(((Button)chl).Content.ToString() + "     2");
                                    }
                                }
                                else
                                {
                                   // MessageBox.Show(((Button)chl).Content.ToString() + "     3");
                                    string strContent = ((Button)chl).Content.ToString();
                                    strContent = strContent.Replace("&", "&amp;");
                                    strContent = strContent.Replace("\"", "&quot;");
                                    strContent = strContent.Replace("<", "&lt;");
                                    strContent = strContent.Replace(">", "&gt;");

                                    strXML = strXML + char.ConvertFromUtf32(13) + "<Button Name=\"control" + Counter.ToString() + "\" Height=\"" + ((ctlPOD)o).Height + "\" Width=\"" + ((ctlPOD)o).Width + "\" Canvas.Left=\"" + ((ctlPOD)o).GetValue(Canvas.LeftProperty) + "\" Canvas.Top=\"" + ((ctlPOD)o).GetValue(Canvas.TopProperty) + "\" Background=\"" + ((Button)chl).Background + "\" Foreground=\"" + ((Button)chl).Foreground + "\" Tag=\"" + ((Button)chl).Tag + "\" Content=\"" + strContent + "\" FontFamily=\"" + ((Button)chl).FontFamily + "\" FontSize=\"" + ((Button)chl).FontSize + "\" FontWeight=\"" + ((Button)chl).FontWeight + "\" FontStyle=\"" + ((Button)chl).FontStyle + "\"/>";
                                }
                            }

                            else if (chl.GetType() == typeof(TextBox))
                            {
                                string strContent = ((TextBox)chl).Text.ToString();
                                strContent = strContent.Replace("&", "&amp;");
                                strContent = strContent.Replace("\"", "&quot;");
                                strContent = strContent.Replace("<", "&lt;");
                                strContent = strContent.Replace(">", "&gt;");

                                strXML = strXML + char.ConvertFromUtf32(13) + "<TextBox Name=\"control" + Counter.ToString() + "\" Height=\"" + ((ctlPOD)o).Height + "\" Width=\"" + ((ctlPOD)o).Width + "\" Canvas.Left=\"" + ((ctlPOD)o).GetValue(Canvas.LeftProperty) + "\" Canvas.Top=\"" + ((ctlPOD)o).GetValue(Canvas.TopProperty) + "\" Background=\"" + ((TextBox)chl).Background + "\" Foreground=\"" + ((TextBox)chl).Foreground + "\" Tag=\"" + ((TextBox)chl).Tag + "\" Text=\"" + strContent + "\" FontFamily=\"" + ((TextBox)chl).FontFamily + "\" FontSize=\"" + ((TextBox)chl).FontSize + "\" FontWeight=\"" + ((TextBox)chl).FontWeight + "\" FontStyle=\"" + ((TextBox)chl).FontStyle + "\"/>";
                            }

                            else if (chl.GetType() == typeof(TextBlock))
                            {
                                string strContent = ((TextBlock)chl).Text.ToString();
                                strContent = strContent.Replace("&", "&amp;");
                                strContent = strContent.Replace("\"", "&quot;");
                                strContent = strContent.Replace("<", "&lt;");
                                strContent = strContent.Replace(">", "&gt;");

                                strXML = strXML + char.ConvertFromUtf32(13) + "<TextBlock Name=\"control" + Counter.ToString() + "\" Height=\"" + ((ctlPOD)o).Height + "\" Width=\"" + ((ctlPOD)o).Width + "\" Canvas.Left=\"" + ((ctlPOD)o).GetValue(Canvas.LeftProperty) + "\" Canvas.Top=\"" + ((ctlPOD)o).GetValue(Canvas.TopProperty) + "\" Background=\"" + ((TextBlock)chl).Background + "\" Foreground=\"" + ((TextBlock)chl).Foreground + "\" Tag=\"" + ((TextBlock)chl).Tag + "\" Text=\"" + strContent + "\" FontFamily=\"" + ((TextBlock)chl).FontFamily + "\" FontSize=\"" + ((TextBlock)chl).FontSize + "\" FontWeight=\"" + ((TextBlock)chl).FontWeight + "\" FontStyle=\"" + ((TextBlock)chl).FontStyle + "\" TextWrapping=\"Wrap\" />";
                            }

                            else if (chl.GetType() == typeof(Label))
                            {
                                string strContent = ((Label)chl).Content.ToString();
                                strContent = strContent.Replace("&", "&amp;");
                                strContent = strContent.Replace("\"", "&quot;");
                                strContent = strContent.Replace("<", "&lt;");
                                strContent = strContent.Replace(">", "&gt;");

                                strXML = strXML + char.ConvertFromUtf32(13) + "<Label Name=\"control" + Counter.ToString() + "\" Height=\"" + ((ctlPOD)o).Height + "\" Width=\"" + ((ctlPOD)o).Width + "\" Canvas.Left=\"" + ((ctlPOD)o).GetValue(Canvas.LeftProperty) + "\" Canvas.Top=\"" + ((ctlPOD)o).GetValue(Canvas.TopProperty) + "\" Background=\"" + ((Label)chl).Background + "\" Foreground=\"" + ((Label)chl).Foreground + "\" Tag=\"" + ((Label)chl).Tag + "\" Content=\"" + strContent + "\" FontFamily=\"" + ((Label)chl).FontFamily + "\" FontSize=\"" + ((Label)chl).FontSize + "\" FontWeight=\"" + ((Label)chl).FontWeight + "\" FontStyle=\"" + ((Label)chl).FontStyle + "\"/>";
                            }

                            else if (chl.GetType() == typeof(ComboBox))
                            {
                                strXML = strXML + char.ConvertFromUtf32(13) + "<ComboBox Name=\"control" + Counter.ToString() + "\" Height=\"" + ((ctlPOD)o).Height + "\" Width=\"" + ((ctlPOD)o).Width + "\" Canvas.Left=\"" + ((ctlPOD)o).GetValue(Canvas.LeftProperty) + "\" Canvas.Top=\"" + ((ctlPOD)o).GetValue(Canvas.TopProperty) + "\" Background=\"" + ((ComboBox)chl).Background + "\" Foreground=\"" + ((ComboBox)chl).Foreground + "\" Tag=\"" + ((ComboBox)chl).Tag + "\" FontFamily=\"" + ((ComboBox)chl).FontFamily + "\" FontSize=\"" + ((ComboBox)chl).FontSize + "\" FontWeight=\"" + ((ComboBox)chl).FontWeight + "\" FontStyle=\"" + ((ComboBox)chl).FontStyle + "\">";
                                for (int i = 0; i < ((ComboBox)chl).Items.Count; i++)
                                {
                                    Counter++;

                                    string strContent = ((ComboBoxItem)((ComboBox)chl).Items[i]).Content.ToString();
                                    strContent = strContent.Replace("&", "&amp;");
                                    strContent = strContent.Replace("\"", "&quot;");
                                    strContent = strContent.Replace("<", "&lt;");
                                    strContent = strContent.Replace(">", "&gt;");

                                    strXML = strXML + char.ConvertFromUtf32(13) + "<ComboBoxItem Name=\"control" + Counter.ToString() + "\" Background=\"" + ((ComboBoxItem)((ComboBox)chl).Items[i]).Background + "\" Foreground=\"" + ((ComboBoxItem)((ComboBox)chl).Items[i]).Foreground + "\" Tag=\"" + ((ComboBoxItem)((ComboBox)chl).Items[i]).Tag + "\" Content=\"" + strContent + "\" FontFamily=\"" + ((ComboBoxItem)((ComboBox)chl).Items[i]).FontFamily + "\" FontSize=\"" + ((ComboBoxItem)((ComboBox)chl).Items[i]).FontSize + "\" FontWeight=\"" + ((ComboBoxItem)((ComboBox)chl).Items[i]).FontWeight + "\" FontStyle=\"" + ((ComboBoxItem)((ComboBox)chl).Items[i]).FontStyle + "\"/>";
                                }
                                strXML = strXML + char.ConvertFromUtf32(13) + "</ComboBox>";
                            }

                            else if (chl.GetType() == typeof(ListBox))
                            {
                                strXML = strXML + char.ConvertFromUtf32(13) + "<ListBox Name=\"control" + Counter.ToString() + "\" Height=\"" + ((ctlPOD)o).Height + "\" Width=\"" + ((ctlPOD)o).Width + "\" Canvas.Left=\"" + ((ctlPOD)o).GetValue(Canvas.LeftProperty) + "\" Canvas.Top=\"" + ((ctlPOD)o).GetValue(Canvas.TopProperty) + "\" Background=\"" + ((ListBox)chl).Background + "\" Foreground=\"" + ((ListBox)chl).Foreground + "\" Tag=\"" + ((ListBox)chl).Tag + "\" FontFamily=\"" + ((ListBox)chl).FontFamily + "\" FontSize=\"" + ((ListBox)chl).FontSize + "\" FontWeight=\"" + ((ListBox)chl).FontWeight + "\" FontStyle=\"" + ((ListBox)chl).FontStyle + "\">";
                                for (int i = 0; i < ((ListBox)chl).Items.Count; i++)
                                {
                                    Counter++;

                                    string strContent = ((ListBoxItem)((ListBox)chl).Items[i]).Content.ToString();
                                    strContent = strContent.Replace("&", "&amp;");
                                    strContent = strContent.Replace("\"", "&quot;");
                                    strContent = strContent.Replace("<", "&lt;");
                                    strContent = strContent.Replace(">", "&gt;");

                                    strXML = strXML + char.ConvertFromUtf32(13) + "<ListBoxItem Name=\"control" + Counter.ToString() + "\" Background=\"" + ((ListBoxItem)((ListBox)chl).Items[i]).Background + "\" Foreground=\"" + ((ListBoxItem)((ListBox)chl).Items[i]).Foreground + "\" Tag=\"" + ((ListBoxItem)((ListBox)chl).Items[i]).Tag + "\" Content=\"" + strContent + "\" FontFamily=\"" + ((ListBoxItem)((ListBox)chl).Items[i]).FontFamily + "\" FontSize=\"" + ((ListBoxItem)((ListBox)chl).Items[i]).FontSize + "\" FontWeight=\"" + ((ListBoxItem)((ListBox)chl).Items[i]).FontWeight + "\" FontStyle=\"" + ((ListBoxItem)((ListBox)chl).Items[i]).FontStyle + "\"/>";
                                }
                                strXML = strXML + char.ConvertFromUtf32(13) + "</ListBox>";
                            }

                            else if (chl.GetType() == typeof(RadioButton))
                            {
                                string strContent = ((RadioButton)chl).Content.ToString();
                                strContent = strContent.Replace("&", "&amp;");
                                strContent = strContent.Replace("\"", "&quot;");
                                strContent = strContent.Replace("<", "&lt;");
                                strContent = strContent.Replace(">", "&gt;");

                                strXML = strXML + char.ConvertFromUtf32(13) + "<RadioButton Name=\"control" + Counter.ToString() + "\" Height=\"" + ((ctlPOD)o).Height + "\" Width=\"" + ((ctlPOD)o).Width + "\" Canvas.Left=\"" + ((ctlPOD)o).GetValue(Canvas.LeftProperty) + "\" Canvas.Top=\"" + ((ctlPOD)o).GetValue(Canvas.TopProperty) + "\" Background=\"" + ((RadioButton)chl).Background + "\" Foreground=\"" + ((RadioButton)chl).Foreground + "\" Tag=\"" + ((RadioButton)chl).Tag + "\" Content=\"" + strContent + "\" FontFamily=\"" + ((RadioButton)chl).FontFamily + "\" FontSize=\"" + ((RadioButton)chl).FontSize + "\" FontWeight=\"" + ((RadioButton)chl).FontWeight + "\" FontStyle=\"" + ((RadioButton)chl).FontStyle + "\"/>";
                            }

                            else if (chl.GetType() == typeof(CheckBox))
                            {
                                string strContent = ((CheckBox)chl).Content.ToString();
                                strContent = strContent.Replace("&", "&amp;");
                                strContent = strContent.Replace("\"", "&quot;");
                                strContent = strContent.Replace("<", "&lt;");
                                strContent = strContent.Replace(">", "&gt;");

                                strXML = strXML + char.ConvertFromUtf32(13) + "<CheckBox Name=\"control" + Counter.ToString() + "\" Height=\"" + ((ctlPOD)o).Height + "\" Width=\"" + ((ctlPOD)o).Width + "\" Canvas.Left=\"" + ((ctlPOD)o).GetValue(Canvas.LeftProperty) + "\" Canvas.Top=\"" + ((ctlPOD)o).GetValue(Canvas.TopProperty) + "\" Background=\"" + ((CheckBox)chl).Background + "\" Foreground=\"" + ((CheckBox)chl).Foreground + "\" Tag=\"" + ((CheckBox)chl).Tag + "\" Content=\"" + strContent + "\" FontFamily=\"" + ((CheckBox)chl).FontFamily + "\" FontSize=\"" + ((CheckBox)chl).FontSize + "\" FontWeight=\"" + ((CheckBox)chl).FontWeight + "\" FontStyle=\"" + ((CheckBox)chl).FontStyle + "\"/>";
                            }

                        }
                    }
                }
                strXML = strXML + "</Canvas></UserControl>";

                //TextWriter tw = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "\\SS\\Script.Presentation\\" + objQueCollection[CurrentQueCount].QuestionName.ToString() + ".Xaml"));
                TextWriter tw = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "\\SS\\Script.Presentation\\" + objQueCollection[CurrentQueCount].ID.ToString() + ".Xaml"));
                tw.WriteLine(strXML);
                tw.Close();

                TextReader tr101 = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll","\\ScriptPages\\Binded Data.txt"));
                string str101 = tr101.ReadToEnd();
                tr101.Close();


                strXML = "using System;" + char.ConvertFromUtf32(13) +
                         "using System.Collections.Generic;" + char.ConvertFromUtf32(13) +
                         "using System.Linq;" + char.ConvertFromUtf32(13) +
                         "using System.Text;" + char.ConvertFromUtf32(13) +
                         "using System.Windows;" + char.ConvertFromUtf32(13) +
                         "using System.Windows.Controls;" + char.ConvertFromUtf32(13) +
                         "using System.Windows.Data;" + char.ConvertFromUtf32(13) +
                         "using System.Windows.Documents;" + char.ConvertFromUtf32(13) +
                         "using System.Windows.Input;" + char.ConvertFromUtf32(13) +
                         "using System.Windows.Media;" + char.ConvertFromUtf32(13) +
                         "using System.Windows.Media.Imaging;" + char.ConvertFromUtf32(13) +
                         "using System.Windows.Navigation;" + char.ConvertFromUtf32(13) +
                         "using System.Windows.Shapes;" + char.ConvertFromUtf32(13) +
                         "using Script.Business;" + char.ConvertFromUtf32(13) +
                         char.ConvertFromUtf32(13) +

                         "namespace Script.Presentation" + char.ConvertFromUtf32(13) +
                         "{" + char.ConvertFromUtf32(13) + char.ConvertFromUtf32(13) + "public partial class UserControl" + objQueCollection[CurrentQueCount].ID.ToString() + ": UserControl" + char.ConvertFromUtf32(13) +
                           "{" + char.ConvertFromUtf32(13) +
                               "public UserControl" + objQueCollection[CurrentQueCount].ID.ToString() + "()" + char.ConvertFromUtf32(13) +
                                   "{" + char.ConvertFromUtf32(13) +
                                   "InitializeComponent();" + char.ConvertFromUtf32(13) +
                    //"VMuktiAPI.VMuktiHelper.RegisterEvent(\"SetLeadIDCRM\").VMuktiEvent += new VMuktiAPI.VMuktiEvents.VMuktiEventHandler(SetLeadIDCRM_VMuktiEvent);" + char.ConvertFromUtf32(13) +
                                   "FncRefresh();" + char.ConvertFromUtf32(13) +
                                   "}" + char.ConvertFromUtf32(13) +
                                   "public Canvas GetCanvas()" + char.ConvertFromUtf32(13) +
                                   "{" + char.ConvertFromUtf32(13) +
                                        "return this.cnvPaint;" +
                                    "}" + char.ConvertFromUtf32(13) +
                                     str101 + char.ConvertFromUtf32(13) +
                                     strCode + char.ConvertFromUtf32(13) +
                                     //char.ConvertFromUtf32(13) + "}" + char.ConvertFromUtf32(13) + str101 + char.ConvertFromUtf32(13) + strCode + char.ConvertFromUtf32(13) +
                           
                            "}" + char.ConvertFromUtf32(13) +
                            "}";
                //}
                //else {

                    //strXML = strXML + char.ConvertFromUtf32(13) +
                    //   "public partial class UserControl" + objQueCollection[CurrentQueCount].ID.ToString() + ": UserControl" + char.ConvertFromUtf32(13) +
                    //       "{"  + char.ConvertFromUtf32(13) + "ModulePermissions[] _MyPermissions;" + char.ConvertFromUtf32(13) +
                    //           "public UserControl" + objQueCollection[CurrentQueCount].ID.ToString() + "()" + char.ConvertFromUtf32(13) +
                    //               "{" + char.ConvertFromUtf32(13) +
                    //               "InitializeComponent();" + char.ConvertFromUtf32(13) +
                    //               "VMuktiAPI.VMuktiHelper.RegisterEvent(\"SetLeadIDScript\").VMuktiEvent += new VMuktiAPI.VMuktiEvents.VMuktiEventHandler(Script_VMuktiEvent);" + char.ConvertFromUtf32(13) +
                    //               "}" + char.ConvertFromUtf32(13) + str101 + char.ConvertFromUtf32(13) + strCode + char.ConvertFromUtf32(13) +
                    //       "}" + char.ConvertFromUtf32(13) +
                    //        "}";
                //}
                TextWriter tw1 = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "\\SS\\Script.Presentation\\" + objQueCollection[CurrentQueCount].ID.ToString() + ".Xaml.Cs"));
                //TextWriter tw1 = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "\\SS\\Script.Presentation\\" + objQueCollection[CurrentQueCount].QuestionName.ToString() + ".Xaml.Cs"));
                tw1.WriteLine(strXML);
                tw1.Close();

                AddRef1_2 = AddRef1_2 + char.ConvertFromUtf32(13) + "<Page Include=\"" + objQueCollection[CurrentQueCount].ID.ToString() + ".xaml\">"
                + char.ConvertFromUtf32(13) + "<Generator>MSBuild:Compile</Generator>"
                + char.ConvertFromUtf32(13) + "<SubType>Designer</SubType>"
                + char.ConvertFromUtf32(13) + "</Page>";

                AddRef2_3 = AddRef2_3 + char.ConvertFromUtf32(13) + "<Compile Include=\"" + objQueCollection[CurrentQueCount].ID.ToString() + ".Xaml.Cs\">"
                + char.ConvertFromUtf32(13) + "<DependentUpon>" + objQueCollection[CurrentQueCount].ID.ToString() + ".Xaml</DependentUpon>"
                + char.ConvertFromUtf32(13) + "<SubType>Code</SubType>"
                + char.ConvertFromUtf32(13) + "</Compile>";

                #endregion
            }

            //MessageBox.Show("Now Creating Project Files");

            #region Create Project File

            TextWriter tw11 = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll","\\SS\\Script.Presentation\\Script.Presentation.csproj"));

            TextReader tr1 = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "\\ScriptPages\\1.txt"));
            string str1 = tr1.ReadToEnd();
            tr1.Close();

            TextReader tr2 = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll",  "\\ScriptPages\\2.txt"));
            string str2 = tr2.ReadToEnd();
            tr2.Close();

            TextReader tr3 = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "\\ScriptPages\\3.txt"));
            string str3 = tr3.ReadToEnd();
            tr3.Close();

            tw11.WriteLine(str1 + AddRef2_3 + str2 + AddRef1_2 + str3);
            str1 = "";
            str2 = "";
            str3 = "";
            AddRef1_2 = "";
            AddRef2_3 = "";
            tw11.Close();

            TextWriter twStart = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll",  "\\SS\\Script.Presentation\\clsStartClass.cs"));
            TextReader trClassRead = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll","\\ScriptPages\\ClassRead.txt"));
            string strClassRead = trClassRead.ReadToEnd();
            trClassRead.Close();

            string strBetween = char.ConvertFromUtf32(13) + "public static string strStartQuesion = \"UserControl" + startQuestionID.ToString() + "\";" + char.ConvertFromUtf32(13) + "public static int LeadID = 0;" + char.ConvertFromUtf32(13) + "public static string sCurrentChannelID  = \"\";" + char.ConvertFromUtf32(13) + "public static string sCurrentDispositionID  = \"\";" + char.ConvertFromUtf32(13) + "public static string sCallingType  = \"\";" + char.ConvertFromUtf32(13) + "public static int CallID;" + char.ConvertFromUtf32(13) + "public static string StateName = null;" + char.ConvertFromUtf32(13) + "public static string ZipCode = null;" + char.ConvertFromUtf32(13) + "public static string sPhoneNumber = null;" + char.ConvertFromUtf32(13) + "}" + char.ConvertFromUtf32(13) + "}";

            twStart.WriteLine(strClassRead + strBetween);
            twStart.Close();

            #endregion


            #region DLL File Naming

            TextReader txtReader = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "\\SS\\Script.Presentation\\Script.Presentation.csproj"));
            string txtString = txtReader.ReadToEnd();
            txtReader.Close();

            txtString = txtString.Replace("<AssemblyName>Script.Presentation</AssemblyName>", "<AssemblyName>" + _ScriptName + ".Presentation</AssemblyName>");

            TextWriter txtWriter = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "\\SS\\Script.Presentation\\Script.Presentation.csproj"));
            txtWriter.WriteLine(txtString);
            txtWriter.Close();



            TextReader txtReader1 = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "\\SS\\Script.Business\\Script.Business.csproj"));
            string txtString1 = txtReader1.ReadToEnd();
            txtReader1.Close();

            txtString1 = txtString1.Replace("<AssemblyName>Script.Business</AssemblyName>", "<AssemblyName>" + _ScriptName + ".Business</AssemblyName>");

            TextWriter txtWriter1 = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "\\SS\\Script.Business\\Script.Business.csproj"));
            txtWriter1.WriteLine(txtString1);
            txtWriter1.Close();



            TextReader txtReader2 = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "\\SS\\Script.Common\\Script.Common.csproj"));
            string txtString2 = txtReader2.ReadToEnd();
            txtReader2.Close();

            txtString2 = txtString2.Replace("<AssemblyName>Script.Common</AssemblyName>", "<AssemblyName>" + _ScriptName + ".Common</AssemblyName>");

            TextWriter txtWriter2 = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "\\SS\\Script.Common\\Script.Common.csproj"));
            txtWriter2.WriteLine(txtString2);
            txtWriter2.Close();

            TextReader txtReader3 = new StreamReader(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "\\SS\\Script.DataAccess\\Script.DataAccess.csproj"));
            string txtString3 = txtReader3.ReadToEnd();
            txtReader3.Close();

            txtString3 = txtString3.Replace("<AssemblyName>Script.DataAccess</AssemblyName>", "<AssemblyName>" + _ScriptName + ".DataAccess</AssemblyName>");

            TextWriter txtWriter3 = new StreamWriter(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "\\SS\\Script.DataAccess\\Script.DataAccess.csproj"));
            txtWriter3.WriteLine(txtString3);
            txtWriter3.Close();

            #endregion

            //#region Building the solution File

            //TextWriter tw1111 = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\Script\\Build.bat");
            //tw1111.WriteLine("cd\\");
            //tw1111.WriteLine("C:");
            //tw1111.WriteLine("cd \"C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.5\"");
            //tw1111.WriteLine("msbuild \"" + AppDomain.CurrentDomain.BaseDirectory + "\\Script\\Script.sln\" /t:Rebuild /p:Configuration=Debug");
            //tw1111.Close();

            //System.Diagnostics.Process.Start(AppDomain.CurrentDomain.BaseDirectory + "\\Script\\Build.bat");

            //#endregion

            #region Building the solution File

            string winDir = Environment.GetFolderPath(Environment.SpecialFolder.System);
            winDir = winDir.Substring(0, winDir.LastIndexOf(@"\"));

            Process buildProcess = new Process();

            //TextWriter tw1111 = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\Script\\Build.bat");
            //tw1111.WriteLine("cd\\");
            //tw1111.WriteLine("C:");
            //tw1111.WriteLine("cd \"C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.5\"");
            //tw1111.WriteLine("msbuild \"" + AppDomain.CurrentDomain.BaseDirectory + "\\Script\\Script.sln\" /t:Rebuild /p:Configuration=Debug");
            //tw1111.Close();
            //System.Diagnostics.Process.Start(AppDomain.CurrentDomain.BaseDirectory + "\\Script\\Build.bat");

            if (!File.Exists(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"\SS\Script.DataAccess\ReferencedAssemblies\VMuktiAPI.dll")))
                 File.Copy(Assembly.GetAssembly(typeof(VMuktiAPI.ClsPeer)).Location, Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"\SS\Script.DataAccess\ReferencedAssemblies\VMuktiAPI.dll"));
            //MessageBox.Show(Assembly.GetAssembly(typeof(VMuktiAPI.ClsPeer)).Location);
            //MessageBox.Show(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"SS\Script.Presentation\ReferencedAssemblies\VMuktiAPI.dll"));
            if (!File.Exists(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"SS\Script.Presentation\ReferencedAssemblies\VMuktiAPI.dll")))
            File.Copy(Assembly.GetAssembly(typeof(VMuktiAPI.ClsPeer)).Location, Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"SS\Script.Presentation\ReferencedAssemblies\VMuktiAPI.dll"));
            if (!File.Exists(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"SS\Script.Presentation\ReferencedAssemblies\VMukti.CtlDatePicker.Presentation.dll")))
                File.Copy(Assembly.GetExecutingAssembly().Location.Replace("ScriptDesigner.Presentation.dll", "VMukti.CtlDatePicker.Presentation.dll"), Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"SS\Script.Presentation\ReferencedAssemblies\VMukti.CtlDatePicker.Presentation.dll"));
                //File.Copy(Assembly.GetAssembly(typeof(VMuktiAPI.ClsPeer)).Location, Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", @"SS\Script.Presentation\ReferencedAssemblies\VMukti.CtlDatePicker.Presentation.dll"));
            

            if (System.IO.Directory.Exists(winDir + @"\Microsoft.NET\Framework\v3.5\"))
            {
                buildProcess.StartInfo.WorkingDirectory = winDir + @"\Microsoft.NET\Framework\v3.5\";
                buildProcess.StartInfo.FileName = "msbuild";
                buildProcess.StartInfo.Arguments = @" """ + Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll","") + @"\SS\Script.sln"" /t:Rebuild /p:Configuration=Debug";
                buildProcess.Start();
                
                buildProcess.WaitForExit();
            }
            else
            {
                MessageBox.Show("Microsoft .Net framework is not installed at --> \" " + winDir + @"\Microsoft.NET\Framework\v3.5\" + " \"!!");
            }


            #endregion

            try
            {
                if (Directory.Exists(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName))
                {
                    Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName, true);
                }
                Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName);
                Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName + "\\" + ScriptName);
                Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName + "\\" + ScriptName + "\\BAL");
                Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName + "\\" + ScriptName + "\\DAL");
                Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName + "\\" + ScriptName + "\\Control");
                //Directory.CreateDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"Script\Common");
            }
            catch (Exception exp)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "FncSaveFiles", "ctlScriptdesigner.xaml.cs");
            }

            try
            {
                copyDirectory(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS\Script.Presentation\bin\Debug", Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName);
            }
            catch (Exception exp)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "FncsaveFiles", "ctlScriptdesigner.xaml.cs");
            }

            try
            {
                string[] filesToDelete = Directory.GetFiles(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName, "*.pdb");
                for (int i = 0; i < filesToDelete.Length; i++)
                {
                    File.Delete(filesToDelete[i]);
                }
            }
            catch (Exception exp)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "FncSaveFiles", "ctlScriptdesigner.xaml.cs");
            }

            try
            {
                string[] filesToMove = Directory.GetFiles(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName, "*.dll");
                for (int i = 0; i < filesToMove.Length; i++)
                {
                    if (filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")).Contains("Business"))
                    {
                        File.Move(filesToMove[i], Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName + "\\" + ScriptName +  "\\BAL\\" + filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")));
                    }
                    else if (filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")).Contains("Common"))
                    {
                        File.Move(filesToMove[i], Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName + "\\" + ScriptName + "\\BAL\\" + filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")));
                    }
                    else if (filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")).Contains("DataAccess"))
                    {
                        File.Move(filesToMove[i], Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName + "\\" + ScriptName + "\\DAL\\" + filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")));
                    }
                    else if (filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")).Contains("Presentation"))
                    {
                        if (filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")).Contains("CtlDatePicker"))
                        {
                            File.Delete(filesToMove[i]);
                        }
                        else
                        {
                        File.Move(filesToMove[i], Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName + "\\" + ScriptName + "\\Control\\" + filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")));
                        }
                    }
                    else if (filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")).Contains("VMuktiAPI"))
                    {

                        File.Delete(filesToMove[i]);

                        //File.Move(filesToMove[i], Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"Script\Control\" + filesToMove[i].Substring(filesToMove[i].LastIndexOf(@"\")));
                    }
                }
            }
            catch (Exception exp)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "FncSaveFiles", "ctlScriptdesigner.xaml.cs");
            }

            try
            {
                Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS\Script.Presentation\bin", true);
                Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS\Script.Presentation\obj", true);
                Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS\Script.Business\bin", true);
                Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS\Script.Business\obj", true);
                Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS\Script.Common\bin", true);
                Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS\Script.Common\obj", true);
                Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS\Script.DataAccess\bin", true);
                Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS\Script.DataAccess\obj", true);
            }
            catch (Exception exp)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "FncSaveFiles", "ctlScriptdesigner.xaml.cs");
            }

            ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip();
            try
            {
                //MessageBox.Show("File Name - " + Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS.zip");
                //MessageBox.Show("Source - " + Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS");
                fz.CreateZip(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS.zip", Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS", true, "");
                
                
            }
            catch (Exception exp)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "FncSaveFiles", "ctlScriptdesigner.xaml.cs");
            }

            try
            {
                fz.CreateZip(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + server + @".zip", Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName, true, "");
            }
            catch (Exception exp)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "FncSaveFiles", "ctlScriptdesigner.xaml.cs");
            }

            try
            {
                Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS", true);
            }
            catch (Exception exp)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "FncSaveFiles", "ctlScriptdesigner.xaml.cs");
            }

            try
            {
                Directory.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + ScriptName, true);
            }
            catch (Exception exp)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "FncSaveFiles", "ctlScriptdesigner.xaml.cs");
            }
            
            try
            {
                System.Windows.Forms.DialogResult sfdRes;
                System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog();
                sfd.Filter = "Zip file(s) (*.zip)|*.zip";
                sfd.Title = "Save the source file of script to edit manualy!!";
                sfd.FileName = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\SS.zip";
                sfdRes = sfd.ShowDialog();
                if (sfdRes == System.Windows.Forms.DialogResult.OK)
                {
                    if (File.Exists(sfd.FileName))
                    {
                        File.Delete(sfd.FileName);
                    }
                    File.Move(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"SS.zip", sfd.FileName);
                }

                //sfd.Title = "Save the file of script to add as a module in VMukti plateform!!";
                //sfd.FileName = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\ScriptRender.zip";
                //sfdRes = sfd.ShowDialog();
                //if (sfdRes == System.Windows.Forms.DialogResult.OK)
                //{
                //    if (File.Exists(sfd.FileName))
                //    {
                //        File.Delete(sfd.FileName);
                //    }
                //    File.Move(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + @"ScriptRender.zip", sfd.FileName);
                //}

                
                
                #region UploadFile
                try
                {
                    System.IO.FileInfo fileInfo = new System.IO.FileInfo(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + server + @".zip");
                    System.IO.FileStream stream = new System.IO.FileStream(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + server + @".zip", System.IO.FileMode.Open, System.IO.FileAccess.Read);
                RemoteFileInfo rfi = new RemoteFileInfo();
                rfi.FileName = fileInfo.Name;
                rfi.Length = fileInfo.Length;
                rfi.FileByteStream = stream;
                rfi.FolderNameToStore = "Scripts";
                clientHttpFileTransfer.svcHTTPFileTransferServiceUploadFileToInstallationDirectory(rfi);
                stream.Close();
                    if (File.Exists(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + server + @".zip"))
                    {
                        File.Delete(Assembly.GetAssembly(this.GetType()).Location.Replace("ScriptDesigner.Presentation.dll", "") + server + @".zip");
                    }
                }
                catch (Exception er)
                {
                    MessageBox.Show(er.Message);
                }
                #endregion
            }
            catch (Exception exp)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "FncSaveFiles", "ctlScriptdesigner.xaml.cs");
            }
            


            #endregion
        }
        public bool Exportar()
        {
            //Apaga os arquivos temporários caso existam


            if (File.Exists(PastaTrabalho + "/GD_Funcionarios.txt"))
            {
                File.Delete(PastaTrabalho + "/GD_Funcionarios.txt");
            }
            if (File.Exists(PastaTrabalho + "/GD_Cargos.txt"))
            {
                File.Delete(PastaTrabalho + "/GD_Cargos.txt");
            }
            if (File.Exists(PastaTrabalho + "/GD_Empresas.txt"))
            {
                File.Delete(PastaTrabalho + "/GD_Empresas.txt");
            }
            if (File.Exists(PastaTrabalho + "/GD_TipoFuncionario.txt"))
            {
                File.Delete(PastaTrabalho + "/GD_TipoFuncionario.txt");
            }
            if (File.Exists(PastaTrabalho + "/GD_LocalTrabalho.txt"))
            {
                File.Delete(PastaTrabalho + "/GD_LocalTrabalho.txt");
            }
            if (File.Exists(PastaTrabalho + "/GD_Orgaos.txt"))
            {
                File.Delete(PastaTrabalho + "/GD_Orgaos.txt");
            }
            if (File.Exists(PastaTrabalho + "/info.txt"))
            {
                File.Delete(PastaTrabalho + "/info.txt");
            }



            //gera os arquivos
            //para cada arquivo selecionado gera o arquivo e salva na pasta temporária
            if (gFuncionarios)
            {
                if (DataCorte == null)
                {
                    DataCorte = DateTime.Now;
                }
                TextWriter tw = new StreamWriter(PastaTrabalho + "/GD_Funcionarios.txt", false, Encoding.UTF8);
                tw.Write(Arquivos.GD_FUNCIONARIO.Carrega(this.DataCorte));
                tw.Close();
            }


            if (gCargos)
            {
                TextWriter tw = new StreamWriter(PastaTrabalho + "/GD_Cargos.txt", false, Encoding.UTF8);
                tw.Write(Arquivos.GD_CARGOS.Carrega());
                tw.Close();
            }


            if (gEmpresas)
            {
                TextWriter tw = new StreamWriter(PastaTrabalho + "/GD_Empresas.txt", false, Encoding.UTF8);
                tw.Write(Arquivos.GD_EMPRESA.Carrega());
                tw.Close();
            }

            if (gTipoFuncionario)
            {
                TextWriter tw = new StreamWriter(PastaTrabalho + "/GD_TipoFuncionario.txt", false, Encoding.UTF8);
                tw.Write(Arquivos.GD_TIPO_FUNCIONARIO.Carrega());
                tw.Close();
            }


            if (gLocalTrabalho)
            {
                TextWriter tw = new StreamWriter(PastaTrabalho + "/GD_LocalTrabalho.txt", false, Encoding.UTF8);
                tw.Write(Arquivos.GD_LOCAL_TRABALHO.Carrega());
                tw.Close();
            }


            if (gOrgaos)
            {
                TextWriter tw = new StreamWriter(PastaTrabalho + "/GD_Orgaos.txt", false, Encoding.UTF8);
                tw.Write(Arquivos.GD_ORGAOS.Carrega());
                tw.Close();
            }


            System.Threading.Thread.Sleep(3000);


            try
            {
                //cria o ZIP
                ICSharpCode.SharpZipLib.Zip.FastZip objZip = new ICSharpCode.SharpZipLib.Zip.FastZip();
                objZip.CreateZip(PastaTrabalho + "\\ExportacaoGD.zip", PastaTrabalho + "\\", true, @"^.+\.((txt)|(doc)|(kkk)|(rtf)|(xxx))$");
            }
            catch (Exception ex)
            {
                Erro += "Erro ao gerar o ZIP  " + ex.Message + @"<br/>";
            }


            CaminhoZip = PastaTrabalho + "\\ExportacaoGD.zip";

            if (string.IsNullOrEmpty(Erro))
            {
                return(true);
            }
            else
            {
                throw new Exception(Erro);
            }
        }
Exemplo n.º 41
0
 /// <summary>
 /// Compress list of files [sourceFiles] to [zipFileName]
 /// </summary>
 /// <param name="zipFileName"></param>
 /// <param name="sourceFiles"></param>
 public static void Zip(string zipFileName, FileInfo[] sourceFiles)
 {
     try
     {
         // get the root folder. NOTE: it assums that the first file is at the root.
         string rootFolder = Path.GetDirectoryName(sourceFiles[0].FullName);
         // compress
         ICSharpCode.SharpZipLib.Zip.FastZip fz = new ICSharpCode.SharpZipLib.Zip.FastZip();
         fz.CreateZip(zipFileName, rootFolder, true, "");
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }