public string UploadImg(string UploadPath, string file_name, int height, int width) { DirectoryHandler dir = new DirectoryHandler(); dir.CreateDirectory(Server.MapPath("~" + UploadPath)); foreach (string item in Request.Files) { int counter = 1; string tempUploadPath = "~" + UploadPath; HttpPostedFileBase file = Request.Files[item] as HttpPostedFileBase; if (file.ContentLength == 0) { continue; } if (file.ContentLength > 0) { ImageUpload imageUpload = new ImageUpload { Width = width, Height = height }; ImageResult imageResult = new ImageResult(); string fileName = Path.GetFileName(file.FileName); if (file_name == null) { string prepend = "Sec_"; string finalFileName = prepend + ((counter).ToString()) + "_" + fileName; imageResult = imageUpload.UploadFile(file, finalFileName, tempUploadPath); } if (!string.IsNullOrEmpty(file_name)) { var Extension = Path.GetExtension(file.FileName); imageResult = imageUpload.UploadFile(file, file_name + Extension, tempUploadPath); } if (imageResult.Success) { return(imageResult.ImageName); } else { return(imageResult.ErrorMessage); } } } return(null); }
public JsonResult CreateKML(int VehicleId, DateTime FromDate, DateTime ToDate, Nullable <bool> tripStatus = null) { FM_KML_VM finalObject = new FM_KML_VM(); finalObject.KML = model.Get_KML("Get_Drive_Date_KML", VehicleId, FromDate, ToDate, tripStatus); string address = "/Areas/Fleet/TrackerKML/"; DirectoryHandler dh = new DirectoryHandler(); dh.CreateDirectory(Server.MapPath(address)); System.IO.File.WriteAllText(Server.MapPath(address) + "TrackerDriveRoute" + ".kml", finalObject.KML.KML); finalObject.IsKML = true; /* == Fetch KML Information == */ finalObject.Vehicle = model.Get_KML_details("Get_Drive_Date_KML_details", VehicleId, FromDate, ToDate); var jsonResult = Json(finalObject, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return(jsonResult); }
public Response UploadFiles() { Response r = new Response(); try { string sPath = ""; sPath = System.Web.Hosting.HostingEnvironment.MapPath("~/Content/AirViewLogs/"); System.Web.HttpFileCollection hfc = System.Web.HttpContext.Current.Request.Files; for (int iCnt = 0; iCnt <= hfc.Count - 1; iCnt++) { System.Web.HttpPostedFile hpf = hfc[iCnt]; if (hpf.ContentLength > 0) { DirectoryHandler dh = new DirectoryHandler(); myFile file = new myFile(); string FileText = file.StreamToString(hpf.InputStream); XML xml = new XML(); string asAscii = Encoding.ASCII.GetString( Encoding.Convert(Encoding.UTF8, Encoding.GetEncoding(Encoding.ASCII.EncodingName, new EncoderReplacementFallback(string.Empty), new DecoderExceptionFallback() ), Encoding.UTF8.GetBytes(FileText) ) ); string json = xml.ToJson(FileText); string[] FileName = hpf.FileName.Split('_'); if (FileName.Length > 6) { AV_SitesBL sitb = new AV_SitesBL(); var SiteRecord = sitb.ToList("BySiteCodeWithLayer", FileName[3], null, null, null, null, null).FirstOrDefault(); if (SiteRecord != null) { // var fileList = new DirectoryInfo(sPath + SiteRecord.ClientPrefix + "\\" + FileName[2]).GetFiles("*.xml", SearchOption.AllDirectories); string BAlpha = System.Text.RegularExpressions.Regex.Replace(FileName[5], "[^a-zA-Z]", ""); string BNumaric = System.Text.RegularExpressions.Regex.Replace(FileName[5], "[^0-9]", ""); string Band = (!string.IsNullOrEmpty(BAlpha.Trim())) ? BAlpha.Trim() + " " + BNumaric : BNumaric; //string Band = ""; //if (FileName[3].Equals("LTE")) //{ // Band = FileName[4].Substring(0, 3) + " " + FileName[4].Substring(3, FileName[4].Length - 3); //} //else if (FileName[3].Equals("WCDMA")) //{ // Band = FileName[4].Substring(0, 4) + " " + FileName[4].Substring(4, FileName[4].Length - 4); //} //else if (FileName[3].Equals("GSM")) //{ // Band = FileName[4].Substring(0, 3) + " " + FileName[4].Substring(3, FileName[4].Length - 3); //} string Alpha = System.Text.RegularExpressions.Regex.Replace(FileName[6], "[^a-zA-Z]", ""); string Numaric = System.Text.RegularExpressions.Regex.Replace(FileName[6], "[^0-9]", ""); string Carrier = (!string.IsNullOrEmpty(Alpha.Trim()))? Alpha.Trim() + " " + Numaric:Numaric; sPath = sPath + SiteRecord.ClientPrefix + "\\" + FileName[3] + "\\" + FileName[4] + "_" + Band + "_" + Carrier + "\\"; dh.CreateDirectory(sPath); string[] files = Directory.GetFiles(sPath, "*.xml"); string TempFileName = hpf.FileName.Replace(FileName[6], Carrier); TempFileName = hpf.FileName.Replace(FileName[5], Band); TempFileName = TempFileName.Replace("PSC1900", "PSC 1900"); file.Write(sPath, TempFileName, "json", json); file.Write(sPath, TempFileName, "xml", FileText); // hpf.SaveAs(sPath + Path.GetFileName(hpf.FileName)); r.Status = "success"; r.Message = "files save successfully."; } else { r.Status = "error"; r.Message = "Site not found."; } } else { r.Status = "error"; r.Message = "File name not correct"; } } else { r.Status = "error"; r.Message = "File not found."; } } } catch (Exception ex) { r.Status = "error"; r.Message = ex.Message; } return(r); }
public Response DriveRoute(DriveRoute driveRoute) { List <Cordinates> cordinates = driveRoute.cordinates; List <Cordinates> pathJson = driveRoute.pathJson; Response res = new Response(); DirectoryHandler dh = new DirectoryHandler(); string CompleteKml = null; string ClientPrefix = ""; string SiteCode = ""; long RouteId = 0; string Delete = ""; long SiteId = 0; string TestType = ""; int ScopeId = 0; long UserId = 0; string Filter = ""; ClientPrefix = driveRoute.ClientPrefix; SiteCode = driveRoute.SiteCode; RouteId = driveRoute.RouteId; Delete = ""; SiteId = driveRoute.SiteId; TestType = driveRoute.TestType; ScopeId = driveRoute.ScopeId; UserId = driveRoute.UserId; Filter = "Insert"; KML km = new KML(); try { CompleteKml += km.Open("Routes", "Routes For Site"); int count = 1; #region Existing File Coordinates string Path = "/Content/AirViewLogs/" + ClientPrefix + "/" + SiteCode; if (dh.FileExist(HttpContext.Current.Server.MapPath("~" + Path + "/route-" + RouteId + ".kml"))) { string text; var fileStream = new FileStream(HttpContext.Current.Server.MapPath("~" + Path + "/route-" + RouteId + ".kml"), FileMode.Open, FileAccess.Read); using (var streamReader = new StreamReader(fileStream, Encoding.UTF8)) { text = streamReader.ReadToEnd(); } MyString ms = new MyString(); string MyPlacemarks = ""; string[] MyPlacemarksSplit; int MyIndex = 5782; if (Delete != "") { MyPlacemarks = ms.BetweenTag(text, "Placemark", "&"); MyPlacemarksSplit = MyPlacemarks.Split('&'); int counter = 0; foreach (var item in MyPlacemarksSplit) { if (item.Contains(Delete)) { MyIndex = counter; } counter++; } } string Cordinate = ms.BetweenTag(text, "coordinates", "&"); string Colors = ms.BetweenTag(text, "color", "&"); string[] ColorsArr = Colors.Split('&'); //Cordinate = Cordinate.Replace(",0", ","); //Cordinate = Cordinate.Replace(",-", "-"); //Cordinate = Cordinate.Replace("-", ",-"); //Cordinate = Cordinate.Replace(",,", ","); string[] Tags = Cordinate.Split('&'); string cords;; string[] Cordinates; for (int i = 0; i < Tags.Length; i++) { if (Delete == "" || (i != MyIndex && MyIndex != 5782)) { if (Tags[i].Trim().Length > 0) { cords = null; Cordinates = Tags[i].Split('\n'); for (int j = 0; j < Cordinates.Length; j++) { if (Cordinates[j].Trim().Length > 0) { cords += Cordinates[j] + "0\n"; } } CompleteKml += km.Style("LineId" + count, "LineStyle", "color", "FFA9A9A9", "width", "4"); CompleteKml += km.Placemark("LineId" + count, "LineId" + count, "LineString", "relative", cords); count++; } } } } #endregion if (cordinates != null || Delete != "") { if (Delete == "") { // foreach (var jk in cordinates) // { string cords = null; string plotColor = "FFA9A9A9"; //(!string.IsNullOrEmpty(r.Color)) ? r.Color.Replace("#", "") : plotColor = "ff" + plotColor.Substring(4, 2) + plotColor.Substring(2, 2) + plotColor.Substring(0, 2); CompleteKml += km.Style("LineId" + count, "LineStyle", "color", plotColor, "width", "4"); foreach (var cor in cordinates) { cords += cor.location.lng + "," + cor.location.lat + ",0\n"; } CompleteKml += km.Placemark("LineId" + count, "LineId" + count, "LineString", "relative", cords); // CompleteKml += km.Placemarks("LineId" + count, "#LineStyle", "relativeToGround", cords); count++; // } } AV_DriveRoutesBL drb = new AV_DriveRoutesBL(); AV_DriveRoutes dr = new AV_DriveRoutes(); dr.CreatedDate = DateTime.Now; dr.RouteId = RouteId; dr.SiteId = Convert.ToInt64(SiteId); dr.CreatedBy = UserId; dr.RoutePath = Path; if (TestType.Length > 1) { dr.TestType = TestType; //.Remove(TestType.Length - 1); } dr.ScopeId = ScopeId; RouteId = drb.Manage(Filter, dr); if (RouteId > 0) { res.Status = "success"; res.Value = RouteId; CompleteKml += km.Close(); dh.CreateDirectory(HttpContext.Current.Server.MapPath(Path)); km.SaveKml2(CompleteKml, "route-" + RouteId, HttpContext.Current.Server.MapPath(Path)); if (pathJson != null) { string jsonpath = "~" + Path; string fname = HttpContext.Current.Server.MapPath(jsonpath); if (!Directory.Exists(fname)) { // if it doesn't exist, create System.IO.Directory.CreateDirectory(fname); } string json = JsonConvert.SerializeObject(pathJson.ToArray()); //write string to file System.IO.File.WriteAllText(fname + "/route-" + RouteId + ".txt", json); } } GC.Collect(); GC.WaitForPendingFinalizers(); if (Delete == "") { res.Message = "Drive Route Planned Successfully."; } else { res.Message = "Drive Route Deleted Successfully."; } } else { res.Status = "danger"; res.Message = "No Route Selected."; } } catch (Exception ex) { res.Status = "danger"; res.Message = ex.Message; } //return Json(res, JsonRequestBehavior.AllowGet); return(res); }