public string GetFile()
        {
            if (!Directory.Exists(Constans.Constans.PathToSaveFile))
            {
                throw new Exception(Constans.Constans.AppDataFolderDosentExists);
            }
            string       resultGeoJson = "";
            var          stream        = HttpContext.Current.Request.GetBufferedInputStream();
            StreamReader reader        = new StreamReader(stream);

            reader.ReadToEnd();

            var postedFile = HttpContext.Current.Request.Files[Constans.Constans.FormObjectName];
            var ignore     = HttpContext.Current.Request.InputStream;

            if (postedFile != null)
            {
                ClearDataDirectory(Constans.Constans.PathToSaveFile);
                var pathToZipFile = Path.Combine(Constans.Constans.PathToSaveFile, postedFile.FileName);
                postedFile.SaveAs(pathToZipFile);

                string fullPathToShpFile = ZipFileHelper.ExtractZipFile(pathToZipFile);

                IGeometryServices geometryServices = new NtsGeometryServices();

                ShapeFileHelper shapeFileHelper = new ShapeFileHelper(fullPathToShpFile);
                resultGeoJson = shapeFileHelper.ConvertShapeFileToGeoJson();
                ClearDataDirectory(Constans.Constans.PathToSaveFile);
            }
            return(resultGeoJson);
        }
Example #2
0
        private void UnZipFiles()
        {
            string zippath     = GetPath("IZ");
            string extractPath = GetPath("IE");

            if (String.IsNullOrEmpty(zippath) || String.IsNullOrEmpty(extractPath))
            {
                return;
            }
            string unzipped = zippath + "UnZipped\\";

            if (!Directory.Exists(unzipped))
            {
                Directory.CreateDirectory(unzipped);
            }
            string moveTo = zippath + "Temp\\";

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

            foreach (string file in Directory.GetFiles(moveTo))
            {
                FileInfo info = new FileInfo(file);
                if (info.Extension.ToLower() != ".jtzip")
                {
                    continue;
                }
                string dir       = info.DirectoryName;
                string movedFile = file.Replace(dir, unzipped);
                if (File.Exists(movedFile))
                {
                    File.Delete(movedFile);
                }
                File.Move(file, movedFile);
            }

            foreach (string file in Directory.GetFiles(zippath))
            {
                FileInfo info = new FileInfo(file);
                if (info.Extension.ToLower() != ".jtzip")
                {
                    continue;
                }
                string dir       = info.DirectoryName;
                string movedFile = file.Replace(dir, moveTo);
                if (File.Exists(movedFile))
                {
                    File.Delete(movedFile);
                }
                File.Move(file, movedFile);
            }
            foreach (string file in Directory.GetFiles(moveTo))
            {
                ZipFileHelper.ExtractZipFile(file, extractPath);
            }

            ArrayList emailList = new ArrayList();

            AddItemsToEmail(extractPath, emailList);


            if (!fromCMD)
            {
                return;
            }

            string subject = "Images Unzipped by " + Environment.MachineName;
            string message = "<br />" + emailList.Count + " " + subject;

            message += "<br /><a href=\"http://SSLog/log.aspx?d=" + DateTime.Now.ToString("yyyy/MM/dd") + "&a=" + (int)Actions.Unzip + "\">Click to see which files were Unzipped</>";

            SendEmail(subject, message, MailPriority.Normal);
            Application.Exit();
        }