Ejemplo n.º 1
0
        // --------------------------------------------------------------------------------------------------
        //  Function: SearchForWalks
        //            Search for walks based upon keywords
        //
        //  NOTE: This only works for one keyword at present, and there is no whitelisting.
        // --------------------------------------------------------------
        public IQueryable <Walk> SearchForWalks(string searchTerms)
        {
            if (!WalkingStick.WhiteListFormInput(searchTerms))
            {
                return(null);
            }
            IQueryable <Walk> walks = from mywalk in this.myWalkingDB.Walks
                                      where mywalk.WalkDescription.Contains(searchTerms)
                                      select mywalk;

            return(walks);
        }
Ejemplo n.º 2
0
        public void UpdateWalkDetails(Walk walk, NameValueCollection oForm, string strRootPath)
        {
            //---Want to avoid a situation where form has been left overnight, and connection lost
            if (this.myWalkingDB.Connection.State != ConnectionState.Open)
            {
                this.myWalkingDB.Connection.Close();
                this.myWalkingDB.Connection.Open();
            }

            // ----Update the walk object. Unit of work pattern ensures the changes made are committed below-----
            WalkingStick.FillWalkFromFormVariables(ref walk, oForm);

            // -----Delete existing hill ascents. Do this better in future-----------------
            this.DeleteHillAscentsForWalk(walk.WalkID);

            // ---Add hill ascents as per updated form-----------------
            List <HillAscent> arHillAscents = WalkingStick.FillHillAscentsFromFormVariables(walk.WalkID, oForm);

            this.AddWalkSummitsVisited(arHillAscents);

            // ---Delete the existing associated files---------
            this.DeleteAssociateFilesForWalk(walk.WalkID);

            // ----Add updated existing associated files--------
            List <Walk_AssociatedFile> arAssociatedFiles = WalkingStick.FillExistingAssociatedFilesFromFormVariables(walk.WalkID, oForm, strRootPath);

            this.AddWalkAssociatedFiles(arAssociatedFiles);

            // ---Add the any new associated files-----
            arAssociatedFiles = WalkingStick.FillHillAssociatedFilesFromFormVariables(walk.WalkID, oForm, strRootPath);
            this.AddWalkAssociatedFiles(arAssociatedFiles);

            // ---update any markers created by ajax call with walk id, and add any marker observations----------------
            this.AssociateMarkersWithWalk(oForm, walk.WalkID);
            this.myWalkingDB.SubmitChanges();
        }
Ejemplo n.º 3
0
        /// <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);
        }