Beispiel #1
0
        /// <summary>
        /// Retrieve any instances of objects at this Station with the specified criteria.
        /// </summary>
        /// <returns>Set of instances found at this Station</returns>
        public override InstanceRefList DoSearch(ICollection<Criterion> crit)
        {
            InstanceRefList results = new InstanceRefList(this);

            string possibleError;
            var unc = ConnectUnc(out possibleError);

            try
            {
                // build extension filter
                Expression<Func<FileInfo, bool>> extFilter = null;
                if (Extensions.Count > 0)
                {
                    extFilter = PredicateBuilder.False<FileInfo>();
                    foreach (string ext in Extensions)
                    {
                        // The temporary variable in the loop is required to avoid the outer variable trap,
                        // where the same variable is captured for each iteration of the foreach loop.
                        string temp = ext;
                        extFilter = extFilter.Or(f => temp.Equals(f.Extension, StringComparison.InvariantCultureIgnoreCase));
                    }
                }

                foreach (Folder folder in Folders)
                    if (IncludeFolder(folder, crit))
                    {
                        if (results.List.Count >= MaxSearchResults)
                            break;

                        SearchFolder(crit, folder, extFilter, results);

                        if (IncludeSubFolders(folder))
                        {
                            List<Folder> subFolders = GetSubFolders(folder);
                            foreach (var subFolder in subFolders)
                            {
                                if (results.List.Count >= MaxSearchResults)
                                    break;

                                SearchFolder(crit, subFolder, extFilter, results);
                            }
                        }
                    }
            }
            finally
            {
                if (unc != null) unc.Dispose();
            }
            return results;
        }
Beispiel #2
0
        /// <summary>
        /// Search one folder, add to results
        /// </summary>
        /// <param name="crit"></param>
        /// <param name="folder"></param>
        /// <param name="extFilter"></param>
        /// <param name="results"></param>
        protected virtual void SearchFolder(ICollection<Criterion> crit, Folder folder, Expression<Func<FileInfo, bool>> extFilter, InstanceRefList results)
        {
            DirectoryInfo dir = new DirectoryInfo(folder.Path);

            var query = (from file in dir.EnumerateFiles() select file).AsQueryable();

            if (extFilter != null)
            {
                query = query.Where(extFilter);
            }

            query = ApplyFileInfoCriteria(crit, query, folder);

            foreach (FileInfo f in query.ToList()) // TODO speed up; taking 14% of search time
            {
                if (results.List.Count >= MaxSearchResults)
                    break;

                if (Valid(f, crit)) // apply other criteria that need to be done on the file content
                {
                    FileFolderInstance i = CreateInstance();

                    // populate properties

                    // Method to be overridden in subclass.  Default = filename without extension.
                    i.ID = MapFileToId(f, folder);

                    i.EntityName = EntityName;
                    i.FileName = f.Name;
                    i.Status = MapFileToStatus(f, folder);
                    i.UniqueId = MapFileToUniqueId(f, folder);
                    i.UpdateDate = f.LastWriteTime;
                    i.ArrivalDate = f.CreationTime;
                    i.Location = folder.Name + "/" + f.Name;
                    i.Path = folder.Path + "/" + f.Name;
                    i.FileSize = f.Length;
                    i.User = User;
                    i.Password = Password;

                    PopulateCustomProperties(i);

                    InstanceRef iref = Memory.AddRef(i, this);
                    results.AddInstanceRef(iref);
                }
            }
        }
Beispiel #3
0
        private void SearchStation(string role, Station s, ConcurrentBag<InstanceRefList> results)
        {
            // TODO  first check if the station supports the object type ???
            //       or is this part of criteria? e.g. TYPE = 'ORDER'

            InstanceRefList irl = null;
            try
            {
                s.CheckSupportedCriteria(crit); // will throw exception if not supported

                if (!UnsupportedCustomFields(s) && (string.IsNullOrEmpty(role) || s.HasRole(role)))
                    irl = DoSearchWithRetry(s);
            }
            catch (StationUnsupportedCriterionException ex)
            {
                irl = new InstanceRefList(s);
                irl.Error = "Station skipped: " + Util.ExceptionMessageIncludingInners(ex);
            }
            catch (Exception ex)
            {
                irl = new InstanceRefList(s);
                irl.Error = Util.ExceptionMessageIncludingInners(ex);
            }
            finally
            {
                if (irl != null)
                    results.Add(irl);
            }
        }