/// <summary> /// Given the walk details form, prepare the DAL objects for insertion /// </summary> /// <param name="iWalkID"></param> /// <param name="oForm"></param> /// <param name="strRootpath"></param> /// <returns></returns> public static List <Walk_AssociatedFile> FillHillAssociatedFilesFromFormVariables(int iWalkID, NameValueCollection oForm, string strRootpath) { var collHillAssociatedFiles = new List <Walk_AssociatedFile>(); int iCounter = 1; int iNumImages; bool bContinue = true; while (bContinue) { if ((oForm[("imagerelpath" + iCounter)] != null && (oForm[("imagerelpath" + iCounter)]).Length > 0)) { var oHillAssociateFile = new Walk_AssociatedFile(); oHillAssociateFile.WalkID = iWalkID; oHillAssociateFile.Walk_AssociatedFile_Name = CleanUpAssociateFilePath(oForm[("imagerelpath" + iCounter)], "Content/images/"); oHillAssociateFile.Walk_AssociatedFile_Type = "Image"; oHillAssociateFile.Walk_AssociatedFile_Caption = oForm[("imagecaption" + iCounter)]; oHillAssociateFile.Walk_AssociatedFile_Sequence = (short)(iCounter); if ((oForm[("imageismarker" + iCounter)] != null && (oForm[("imageismarker" + iCounter)].Length > 0))) { oHillAssociateFile.Walk_AssociatedFile_MarkerID = Int32.Parse(oForm[("imagemarkerid" + iCounter)]); } collHillAssociatedFiles.Add(oHillAssociateFile); iCounter = (iCounter + 1); } else { bContinue = false; } } iNumImages = (iCounter - 1); iCounter = 1; bContinue = true; while (bContinue) { if ((oForm[("auxilliary_file" + iCounter)] != null && (oForm[("auxilliary_file" + iCounter)].Length > 0))) { Walk_AssociatedFile oHillAssociateFile = new Walk_AssociatedFile(); oHillAssociateFile.WalkID = iWalkID; oHillAssociateFile.Walk_AssociatedFile_Name = CleanUpAssociateFilePath(oForm[("auxilliary_file" + iCounter)], "Content/images/"); oHillAssociateFile.Walk_AssociatedFile_Type = oForm[("auxilliary_filetype" + iCounter)]; oHillAssociateFile.Walk_AssociatedFile_Sequence = (short)(iCounter + iNumImages); oHillAssociateFile.Walk_AssociatedFile_Caption = oForm[("auxilliary_caption" + iCounter)]; collHillAssociatedFiles.Add(oHillAssociateFile); iCounter = (iCounter + 1); } else { bContinue = false; } } return(collHillAssociatedFiles); }
public static List <Walk_AssociatedFile> FillExistingAssociatedFilesFromFormVariables(int iWalkID, NameValueCollection oForm, string strRootpath) { List <Walk_AssociatedFile> collHillAssociatedFiles = new List <Walk_AssociatedFile>(); int iCounter = 1; int iNumExistingImages = 0; int iSequenceCounter = 1; bool bContinue = true; try { iNumExistingImages = int.Parse(oForm["NumExistingImages"]); } catch (Exception) { } for (int iExistingImagesCount = 1; (iExistingImagesCount <= iNumExistingImages); iExistingImagesCount++) { if ((oForm[("existingimagename" + iExistingImagesCount)] != null && ((oForm[("existingimagename" + iExistingImagesCount)].Length > 0) && (oForm[("deletexistingimage" + iExistingImagesCount)] != "on")))) { Walk_AssociatedFile oHillAssociateFile = new Walk_AssociatedFile(); oHillAssociateFile.WalkID = iWalkID; oHillAssociateFile.Walk_AssociatedFile_Name = oForm[("existingimagename" + iExistingImagesCount)]; oHillAssociateFile.Walk_AssociatedFile_Type = "Image"; oHillAssociateFile.Walk_AssociatedFile_Caption = oForm[("existingimagecaption" + iExistingImagesCount)]; oHillAssociateFile.Walk_AssociatedFile_Sequence = (short)iSequenceCounter; if ((oForm[("existingimageismarker" + iExistingImagesCount)] != null && (oForm[("existingimageismarker" + iExistingImagesCount)].Length > 0))) { oHillAssociateFile.Walk_AssociatedFile_MarkerID = int.Parse(oForm[("existingimagemarkerid" + iExistingImagesCount)]); } iSequenceCounter = (iSequenceCounter + 1); collHillAssociatedFiles.Add(oHillAssociateFile); } } iCounter = 1; bContinue = true; while (bContinue) { if ((oForm[("existingauxfilename" + iCounter)] != null && ((oForm[("existingauxfilename" + iCounter)].Length > 0) && (oForm[("delexisting_auxilliary_file" + iCounter)] != "on")))) { var oHillAssociateFile = new Walk_AssociatedFile(); oHillAssociateFile.WalkID = iWalkID; oHillAssociateFile.Walk_AssociatedFile_Name = oForm[("existingauxfilename" + iCounter)]; oHillAssociateFile.Walk_AssociatedFile_Type = oForm[("existingauxfiletype" + iCounter)]; oHillAssociateFile.Walk_AssociatedFile_Sequence = (short)(iCounter + iSequenceCounter); collHillAssociatedFiles.Add(oHillAssociateFile); iCounter = (iCounter + 1); } else { bContinue = false; } } return(collHillAssociatedFiles); }
/// <summary> /// Given the walk details form, prepare the DAL objects for insertion /// TODO: In particular, given a directory in which the walk associated files have been prepared, examine the directory and add the files /// found to the walk /// </summary> /// <param name="iWalkID"></param> /// <param name="oForm"></param> /// <param name="strRootpath"></param> /// <returns></returns> public static List <Walk_AssociatedFile> FillWalkAssociatedFilesByExaminingDirectory(int iWalkID, NameValueCollection oForm, string strRootPath) { var collWalkAssociatedFiles = new List <Walk_AssociatedFile>(); short siFileSequenceCounter = 1; string walkfiles_fullpathprefix = oForm["walkfiles_reldir"]; string walkfiles_nameprefix; if (walkfiles_fullpathprefix.Trim().Length == 0) { return(collWalkAssociatedFiles); } walkfiles_fullpathprefix = walkfiles_fullpathprefix.Replace("\\", "/"); int iLoc; try { iLoc = walkfiles_fullpathprefix.LastIndexOf("/", StringComparison.Ordinal); } catch (Exception) { iLoc = 0; } string strRelPath = walkfiles_fullpathprefix.Substring(0, iLoc); walkfiles_nameprefix = walkfiles_fullpathprefix.Substring(iLoc + 1, walkfiles_fullpathprefix.Length - iLoc - 1); // -----Check that the path specified is valid------------------------ if (!WalkingStick.DetermineIfDirectoryExists(strRootPath + strRelPath)) { throw new Exception("Could not find directory when looking for image files: dir:[" + strRootPath + strRelPath + "]" + " strRootPath = [" + strRootPath + "]"); } //-----First add all the walk image files---- string[] filesindir = Directory.GetFiles(strRootPath + strRelPath, walkfiles_nameprefix + "_*"); // go through looking for each number, assigning an order number to the unsorted list for (int imageNumber = 1; imageNumber < filesindir.Length + 1; imageNumber++) { // Look for image number imageNumber in the unordered list for (int iCount = 0; iCount < filesindir.Length; iCount++) { // Construct full file name to look for - jpgs and pngs are allowed, either case if (filesindir[iCount].Equals(strRootPath + strRelPath + "\\" + walkfiles_nameprefix + "_" + imageNumber.ToString() + ".jpg") || filesindir[iCount].Equals(strRootPath + strRelPath + "\\" + walkfiles_nameprefix + "_" + imageNumber.ToString() + ".JPG") || filesindir[iCount].Equals(strRootPath + strRelPath + "\\" + walkfiles_nameprefix + "_" + imageNumber.ToString() + ".png") || filesindir[iCount].Equals(strRootPath + strRelPath + "\\" + walkfiles_nameprefix + "_" + imageNumber.ToString() + ".PNG")) { // filesindir[iCount] = filesindir[iCount].Replace("\\","/"); int iLocFileExtStart = 0; iLocFileExtStart = filesindir[iCount].LastIndexOf("."); string strImageFileExt = filesindir[iCount].Substring(iLocFileExtStart, 4); var oHillAssociateFile = new Walk_AssociatedFile(); oHillAssociateFile.WalkID = iWalkID; oHillAssociateFile.Walk_AssociatedFile_Name = CleanUpAssociateFilePath(strRelPath + "/" + walkfiles_nameprefix + "_" + imageNumber.ToString() + strImageFileExt, "Content/images/"); oHillAssociateFile.Walk_AssociatedFile_Type = "Image"; oHillAssociateFile.Walk_AssociatedFile_Sequence = siFileSequenceCounter++; collWalkAssociatedFiles.Add(oHillAssociateFile); break; } } } // Look for any auxilliary files (not walk images) present matching the nameprefix. filesindir = Directory.GetFiles(strRootPath + strRelPath, walkfiles_nameprefix + "-*"); // for each aux file, create object and add to result list. for (int iCount = 0; iCount < filesindir.Length; iCount++) { filesindir[iCount] = filesindir[iCount].Replace("\\", "/"); int iLocNamePrefix = filesindir[iCount].IndexOf(walkfiles_nameprefix); filesindir[iCount] = filesindir[iCount].Substring(iLocNamePrefix); string strDesc = ""; var oHillAssociateFile = new Walk_AssociatedFile(); oHillAssociateFile.WalkID = iWalkID; oHillAssociateFile.Walk_AssociatedFile_Name = CleanUpAssociateFilePath(strRelPath + "/" + filesindir[iCount], "Content/images/"); oHillAssociateFile.Walk_AssociatedFile_Type = DetermineAuxFileType(filesindir[iCount], walkfiles_nameprefix, ref strDesc); oHillAssociateFile.Walk_AssociatedFile_Sequence = siFileSequenceCounter++; oHillAssociateFile.Walk_AssociatedFile_Caption = strDesc; collWalkAssociatedFiles.Add(oHillAssociateFile); } return(collWalkAssociatedFiles); }