/// <summary>
        ///     Filters a user's relationship list by a boolean condition.
        /// </summary>
        /// <param name="callback"></param>
        public void Filter(FilterHandler callback)
        {
            GCHandle wrapped = GCHandle.Alloc(callback);

            Methods.Filter(methodsPtr, GCHandle.ToIntPtr(wrapped), FilterCallbackImpl);
            wrapped.Free();
        }
Example #2
0
        private string AddСondition(FilterHandler.FilterDescription filter, List <FindHandler.FieldParameters> listOfField)
        {
            string result     = "";
            var    field      = listOfField.Where(kvp => kvp.application_name == filter.field).First().db_name;
            var    typeFilter = FilterHandler.TakeFilter(filter.typeOfFilter);

            if (filter.typeOfFilter == TypeOfFilter.TypesOfFilter.isFilled)
            {
                result += "NOT ";
            }

            if (!filter.isDate)
            {
                result += string.Format(field + " " + typeFilter + "\"{0}\"", filter.value);
            }
            else
            {
                string day   = filter.value.Substring(0, 2);
                string month = filter.value.Substring(3, 2);
                string year  = filter.value.Substring(6, 4);
                result += string.Format(field + " " + typeFilter + " \'{0}-{1}-{2}\'", year, month, day);
                //result += string.Format(" DATE_FORMAT(" + field + ", '%d.%m.%Y') = \'{0}\'", filter.value);
            }

            /*if (filter.typeOfFilter == TypeOfFilter.TypesOfFilter.contains)
             * {
             *  result += ") ";
             * }*/

            return(result);
        }
Example #3
0
        public virtual void SetAdapter(AbstractTableAdapter tableAdapter)
        {
            if (tableAdapter != null)
            {
                this.mTableAdapter = tableAdapter;
                this.mTableAdapter.SetRowHeaderWidth(mRowHeaderWidth);
                this.mTableAdapter.SetColumnHeaderHeight(mColumnHeaderHeight);
                this.mTableAdapter.SetTableView(this);
                // set adapters
                if (mColumnHeaderRecyclerView != null)
                {
                    mColumnHeaderRecyclerView.SetAdapter(mTableAdapter.ColumnHeaderRecyclerViewAdapter);
                }

                if (mRowHeaderRecyclerView != null)
                {
                    mRowHeaderRecyclerView.SetAdapter(mTableAdapter.RowHeaderRecyclerViewAdapter);
                }

                if (mCellRecyclerView != null)
                {
                    mCellRecyclerView.SetAdapter(mTableAdapter.GetCellRecyclerViewAdapter());
                    // Create Sort Handler
                    mColumnSortHandler = new ColumnSortHandler(this);
                    // Create Filter Handler
                    mFilterHandler = new FilterHandler(this);
                }
            }
        }
Example #4
0
        public List <BuildEntity> GetBuildsToClean()
        {
            var filterHandler  = new FilterHandler(_whitelistHandler.Provider, _commonNameBuildsProvider);
            var buildsToRemove = filterHandler.Execute(_settings.Data.Cleaner);

            return(buildsToRemove);
        }
        private static string HandleUserField(Dictionary <string, string> input, string key, TemplateType type, Card card)
        {
            string fieldName = GetFieldName(key);

            if (!input.TryGetValue(fieldName, out var fieldContent))
            {
                LogTo.Error("Failed to HandleUnknownField");
                return(string.Empty);
            }

            var split = key.Split(':');

            if (split.Length > 1)
            {
                // Has filters
                var filters = split
                              .Skip(1) // Skip the fieldName
                              .Reverse()
                              .ToList();

                if (type == TemplateType.Question)
                {
                    fieldContent = FilterHandler.ApplyQuestionFieldFilters(filters, fieldContent, card);
                }

                else
                {
                    fieldContent = FilterHandler.ApplyAnswerFieldFilters(filters, fieldContent, card);
                }
            }

            return(fieldContent);
        }
Example #6
0
        public KernelBarViewModel(FilterHandler filterHandler, MainWindow mainWindow) : base(filterHandler, FilterType.GaussianBlur)
        {
            _mainWindow          = mainWindow;
            _parametersContainer = filterHandler;

            _parametersContainer.OnParametersChanged += () => OnPropertyChanged("KernelSize");
        }
        public static void UpdateBundleBuildList(FilterHandler filter)
        {
            if (filter == null)
            {
                m_useFilter = false;
                return;
            }
            m_useFilter = true;
            List <BundleImportData> dataList = m_dataControl.DataList;

            for (int l = 0; l < dataList.Count; ++l)
            {
                BundleImportData data = dataList[l];
                if (data == null)
                {
                    continue;
                }
                if (EditorUtility.DisplayCancelableProgressBar("Update Bundle List", data.RootPath, (l * 1.0f) / dataList.Count))
                {
                    Debug.LogWarning("CreateBundles Stop.");
                    break;
                }
                string     parentName = BundleDataManager.GetIndexBundleName(l);
                BundleData parent     = BundleDataManager.GetBundleData(parentName);
                for (int i = 0; parent != null && i < parent.children.Count; ++i)
                {
                    _ProcessUpdateBundleList(parent.children[i], data, filter);
                }
            }
            EditorUtility.ClearProgressBar();
            _ProcessDependBundleList();
        }
        private static bool FilterCallbackImpl(IntPtr ptr, ref Relationship relationship)
        {
            GCHandle      h        = GCHandle.FromIntPtr(ptr);
            FilterHandler callback = (FilterHandler)h.Target;

            return(callback(ref relationship));
        }
Example #9
0
        /// <summary>
        /// Used to filter out properties.
        /// </summary>
        /// <param name="handler">Filter handler.</param>
        /// <exception cref="InvalidOperationException">Handler have already been set.</exception>
        public static void SetFilterHandler(FilterHandler handler)
        {
            if (_handler != null)
                throw new InvalidOperationException("Handler have already been set.");

            _handler = handler;
        }
Example #10
0
 /// <summary>
 /// Add header identity's filter to the chain.
 /// </summary>
 /// <param name="name">Name of identity.</param>
 /// <param name="handler">Filter handler.</param>
 /// <param name="priority">Filter priority.</param>
 public void AddFilter(string name, FilterHandler handler, int priority)
 {
     if (!filters.ContainsKey(name))
     {
         filters[name] = new SortedList <int, FilterHandler>();
     }
     filters[name].Add(priority, handler);
 }
Example #11
0
        public void Process(string path, FilterHandler filterHandler)
        {
            var photo = Photo.Load(path);

            filterHandler(photo);

            photo.Save();
        }
        public ThresholdingParametersViewModel(FilterHandler filterHandler) : base(filterHandler, FilterType.AdaptiveThresholding)
        {
            _parametersContainer = filterHandler;

            _parameters.MeanAreaSize        = _meanAreaSize;
            _parameters.MaxDeviation        = _maxDeviation;
            _parametersContainer.Parameters = _parameters;
        }
        public MainViewModel(MainWindow mainWindow)
        {
            ImageLoader   = new ImageLoader();
            FilterHandler = new FilterHandler(ImageLoader);
            ImageSaver    = new ImageSaver(FilterHandler);

            KernelBarViewModel = new KernelBarViewModel(FilterHandler, mainWindow);
            ThresholdingParametersViewModel = new ThresholdingParametersViewModel(FilterHandler);
        }
Example #14
0
        /// <summary>
        /// Used to filter out properties.
        /// </summary>
        /// <param name="handler">Filter handler.</param>
        /// <exception cref="InvalidOperationException">Handler have already been set.</exception>
        public static void SetFilterHandler(FilterHandler handler)
        {
            if (_handler != null)
            {
                throw new InvalidOperationException("Handler have already been set.");
            }

            _handler = handler;
        }
Example #15
0
 public IEnumerable <T> ApplyFilter(IEnumerable <T> items, FilterHandler filterHandler)
 {
     foreach (var item in items)
     {
         if (filterHandler(item))
         {
             yield return(item);
         }
     }
 }
Example #16
0
        private void FindStudentButton_Click(object sender, EventArgs e)
        {
            consoleTextBox.Clear();

            FilterHandler.ToggleAllFilters();

            List <IStudent> studentListToDisplay = FilterHandler.GetFilteredStudentList();

            PrintStudentList(studentListToDisplay);
        }
        public void FilterHandler_Filter_HeadersImmutable()
        {
            var args = new CmdArguments {
                FilePath = @"..\..\..\Files\Data.tsv", SortByDate = true, Project = 2
            };

            var result = FilterHandler.Filter(output, args);

            Assert.AreSame(output.Headers, result.Headers);
        }
Example #18
0
 public IEnumerable <T> Filter(IEnumerable <T> list, FilterHandler filterFunction)
 {
     foreach (T value in list)
     {
         if (filterFunction(value))
         {
             yield return(value);
         }
     }
 }
Example #19
0
        /// <summary>
        /// Creates a new instance of <see cref="AsyncObservableCollectionView{T}"/>
        /// </summary>
        /// <param name="list">an existed collection to copy</param>
        /// <param name="filterPredicate">The filter handler</param>
        public static AsyncObservableCollectionView <T> Create(FilterHandler <T> filterPredicate, IEnumerable <T> list)
        {
            AsyncObservableCollectionView <T> collection = null;

            ExecuteOnSyncContext(() => { collection = new AsyncObservableCollectionView <T>(list); });
            if (filterPredicate != null)
            {
                collection.FilterItem = (item, term) => filterPredicate(item, term);
            }
            return(collection);
        }
        public void FilterHandler_Filter_FilterSuccess()
        {
            var args = new CmdArguments {
                FilePath = @"..\..\..\Files\Data.tsv", SortByDate = false, Project = 2
            };

            var result = FilterHandler.Filter(output, args);

            Assert.IsTrue(result.Lines.Count == 1);
            Assert.IsTrue(result.Lines.First().Project == 2);
        }
		public void StaticRenderer_WhenExecutingArequest_ShouldApplyFilters()
		{
			var assemblyLocation = Assembly.GetExecutingAssembly().Location;
			var runner = new RunnerForTest();
			NodeMainInitializer.InitializeFakeMain(assemblyLocation, runner);
			var rootDir = InferWebRootDir(assemblyLocation);
			var pathProvider = new StaticContentPathProvider(rootDir);
			var filterHandler = new FilterHandler();

			var globalFilter = new Mock<IFilter>();
			globalFilter.Setup(a => a.OnPreExecute(It.IsAny<IHttpContext>())).Returns(true);
			filterHandler.AddFilter(globalFilter.Object);
			ServiceLocator.Locator.Register<IFilterHandler>(filterHandler);

			var http = new HttpModule();
			http.SetParameter(HttpParameters.HttpPort, 8881);
			http.SetParameter(HttpParameters.HttpVirtualDir, "nodecs");
			http.SetParameter(HttpParameters.HttpHost, "localhost");


			var routingService = new RoutingService();
			http.RegisterRouting(routingService);

			http.Initialize();

			http.RegisterPathProvider(pathProvider);

			const string uri = "http://localhost:8881/nodecs";

			var context = CreateRequest(uri);
			var outputStream = (MockStream)context.Response.OutputStream;
			outputStream.Initialize();


            globalFilter.Setup(a => a.OnPostExecute(It.IsAny<IHttpContext>()))
                .Callback(() =>
                {
                    Console.WriteLine("AAAA");
                });

			//request.
			http.ExecuteRequest(context);
			runner.RunCycleFor(200);
			var os = (MemoryStream)context.Response.OutputStream;
			os.Seek(0, SeekOrigin.Begin);
			var bytes = os.ToArray();
			var result = Encoding.UTF8.GetString(bytes);

			Assert.IsTrue(outputStream.WrittenBytes > 0);
			Assert.IsNotNull(result);

			globalFilter.Verify(a => a.OnPreExecute(It.IsAny<IHttpContext>()), Times.Once);
			globalFilter.Verify(a => a.OnPostExecute(It.IsAny<IHttpContext>()), Times.Once);
		}
Example #22
0
        public List <Item> Filter(List <Item> items, FilterHandler filter)
        {
            foreach (Item item in items)
            {
                if (filter(item) == true)
                {
                    filteredList.Add(item);
                }
            }

            return(filteredList);
        }
Example #23
0
        public async Task <IViewComponentResult> InvokeAsync(string idForm)
        {
            var user = await _userHandler.GetUserAsync(HttpContext.User);

            List <string> partIds = await _userHandler.GetAllowPartsForView(user, idForm);

            FilterHandler handlerFilter = new FilterHandler(_context, idForm, user, _userHandler);
            Incomer       incomer       = await handlerFilter.GetIncomerDataAsync();

            TypeQuery typeQuery = await handlerFilter.GetTypeQueryAsync();

            OutFlow outFlow = await handlerFilter.GetStackFlowAsync(incomer, typeQuery);

            IList <MtdStore> mtdStore = outFlow.MtdStores;

            decimal count = (decimal)outFlow.Count / incomer.PageSize;

            pageCount = Convert.ToInt32(Math.Round(count, MidpointRounding.AwayFromZero));
            pageCount = pageCount == 0 ? 1 : pageCount;

            IList <string> storeIds = mtdStore.Select(s => s.Id).ToList();
            IList <string> fieldIds = fieldIds = incomer.FieldForColumn.Select(x => x.Id).ToList();

            IList <string> allowFiieldIds = await _context.MtdFormPartField.Where(x => partIds.Contains(x.MtdFormPart)).Select(x => x.Id).ToListAsync();

            fieldIds = allowFiieldIds.Where(x => fieldIds.Contains(x)).ToList();

            StackHandler          handlerStack  = new StackHandler(_context);
            IList <MtdStoreStack> mtdStoreStack = await handlerStack.GetStackAsync(storeIds, fieldIds);

            IList <MtdStoreApproval> mtdStoreApprovals = await _context.MtdStoreApproval.Where(x => storeIds.Contains(x.Id)).ToListAsync();

            List <ApprovalStore> approvalStores = await ApprovalHandler.GetStoreStatusAsync(_context, storeIds, user);

            bool isApprovalForm = await ApprovalHandler.IsApprovalFormAsync(_context, idForm);

            RowsModelView rowsModel = new RowsModelView
            {
                IdForm            = idForm,
                SearchNumber      = incomer.SearchNumber,
                PageCount         = pageCount,
                MtdFormPartFields = incomer.FieldForColumn.Where(x => fieldIds.Contains(x.Id)).ToList(),
                MtdStores         = mtdStore,
                MtdStoreStack     = mtdStoreStack,
                WaitList          = incomer.WaitList == 1 ? true : false,
                ShowDate          = await handlerFilter.IsShowDate(),
                ShowNumber        = await handlerFilter.IsShowNumber(),
                ApprovalStores    = approvalStores,
                IsAppromalForm    = isApprovalForm
            };

            return(View("Default", rowsModel));
        }
        public void FilterHandler_Filter_FilterAndSortNoEffect()
        {
            var args = new CmdArguments {
                FilePath = @"..\..\..\Files\Data.tsv", SortByDate = false, Project = null
            };

            var result = FilterHandler.Filter(output, args);

            Assert.IsTrue(result.Lines.Count == output.Lines.Count);
            Assert.IsTrue(result.Lines.First().Project == output.Lines.First().Project);
            Assert.IsTrue(result.Lines.Last().Project == output.Lines.Last().Project);
        }
Example #25
0
        private void Initialize()
        {
            Students = new List <Student>
            {
                new Student("Jesse", "Fredericks")
                {
                    IsInternational = false, Gender = Gender.Male
                },
                new Student("Elenor", "Ruel")
                {
                    IsInternational = true, Gender = Gender.Female
                },
                new Student("Hàn Ngọc", "Trai")
                {
                    IsInternational = true, Gender = Gender.Female
                },
                new Student("Catherine", "Jackson")
                {
                    IsInternational = false, Gender = Gender.Female
                },
                new Student("Mahjub Khalid", "Daher")
                {
                    IsInternational = true, Gender = Gender.Male
                },
                new Student("Ashwaq Jawahir", "Shalhoub")
                {
                    IsInternational = true, Gender = Gender.Female
                },
                new Student("Douglas", "Rego")
                {
                    IsInternational = false, Gender = Gender.Male
                },
                new Student("Jose", "Kitterman")
                {
                    IsInternational = false, Gender = Gender.Female
                },
                new Student("Nancy", "Jackson")
                {
                    IsInternational = false, Gender = Gender.Female
                },
                new Student("Jesse", "Roberts")
                {
                    IsInternational = false, Gender = Gender.Male
                },
                new Student("Bob", "Jackson")
                {
                    IsInternational = false, Gender = Gender.Female
                }
            };

            MyFilterHandler = new FilterHandler <Student>();
        }
Example #26
0
        /// <summary>
        /// Remoce header identity's filter from the chain.
        /// </summary>
        /// <param name="name">Name of identity.</param>
        /// <param name="handler">Filter handler.</param>
        public void RemoveFilter(string name, FilterHandler handler)
        {
            var filterList = filters[name];

            if (filterList != null)
            {
                var position = filterList.IndexOfValue(handler);
                if (position != -1)
                {
                    filterList.RemoveAt(position);
                }
            }
        }
Example #27
0
        public static MyStackList <T> filter(MyStackList <T> list, FilterHandler filterhandler)
        {
            var filtered = new MyStackList <T>();

            foreach (var item in list)
            {
                if (list.filterHandler(item))
                {
                    filtered.Push(item);
                }
            }
            return(filtered);
        }
Example #28
0
        public Money CalculateMoney(FilterHandler filter)
        {
            Money Total = new Money(0);

            foreach (AccountItem acItem in this.Item)
            {
                if (filter(acItem))
                {
                    Total += acItem.Amount;
                }
            }
            return(Total);
        }
Example #29
0
        private static string OnFilter(string input)
        {
            string repl_pattern = input;

            FilterHandler filter_handler = Filter;

            if (filter_handler != null)
            {
                repl_pattern = filter_handler(repl_pattern);
            }

            return(repl_pattern);
        }
Example #30
0
        public SchuelerList Filter(FilterHandler predicate)
        {
            SchuelerList resultList = new SchuelerList();

            foreach (Schueler schueler in this)
            {
                if (predicate(schueler))
                {
                    resultList.Add(schueler);
                }
            }
            return(resultList);
        }
Example #31
0
        public async Task <IActionResult> PostExportAsync()
        {
            var data = Request.Form["InputFormForExport"];

            if (data.FirstOrDefault() == null || data.FirstOrDefault().Equals(string.Empty))
            {
                return(NotFound());
            }
            string idForm = data.FirstOrDefault();

            var user = await _userHandler.GetUserAsync(User);

            List <string> partIds = await _userHandler.GetAllowPartsForView(user, idForm);

            FilterHandler handlerFilter = new FilterHandler(_context, idForm, user, _userHandler);
            MtdFilter     mtdFilter     = await handlerFilter.GetFilterAsync();

            if (mtdFilter == null)
            {
                return(NotFound());
            }
            Incomer incomer = await handlerFilter.GetIncomerDataAsync();

            TypeQuery typeQuery = await handlerFilter.GetTypeQueryAsync();

            incomer.PageSize = 1000;

            OutFlow outFlow = await handlerFilter.GetStackFlowAsync(incomer, typeQuery);

            IList <MtdStore> mtdStore = outFlow.MtdStores;

            IList <string> storeIds = mtdStore.Select(s => s.Id).ToList();
            IList <string> fieldIds = incomer.FieldForColumn.Select(x => x.Id).ToList();

            IList <string> allowFiieldIds = await _context.MtdFormPartField.Where(x => partIds.Contains(x.MtdFormPart)).Select(x => x.Id).ToListAsync();

            fieldIds = allowFiieldIds.Where(x => fieldIds.Contains(x)).ToList();

            StackHandler          handlerStack  = new StackHandler(_context);
            IList <MtdStoreStack> mtdStoreStack = await handlerStack.GetStackAsync(storeIds, fieldIds);

            IList <MtdFormPartField> columns = incomer.FieldForColumn.Where(x => fieldIds.Contains(x.Id)).ToList();

            IWorkbook workbook = CreateWorkbook(mtdStore, columns, mtdStoreStack);

            workbook.WriteExcelToResponse(HttpContext, "OrderMakerList.xlsx");

            return(Ok());
        }
 public CurrentImageHandler() : base()
 {
     CurrentBrightnessHandler = new BrightnessHandler(this);
     CurrentContrastHandler   = new ContrastHandler(this);
     CurrentCropHandler       = new CropHandler(this);
     CurrentFilterHandler     = new FilterHandler(this);
     CurrentGrayscaleHandler  = new GrayscaleHandler(this);
     CurrentFileHandler       = new ImageFileHandler(this);
     CurrentImgInsHandler     = new ImageInsertionHandler(this);
     CurrentInvHandler        = new InversionHandler(this);
     CurrentRotationHandler   = new RotationHandler(this);
     CurrentSepiaToneHandler  = new SepiaToneHandler(this);
     CurrentShapeInsHandler   = new ShapeInsertionHandler(this);
     CurrentTextInsHandler    = new TextInsertionHandler(this);
 }
Example #33
0
        private void RunMainOperation(Snapshots.ISnapshotService snapshot, BackendManager backend)
        {
            var filterhandler = new FilterHandler(snapshot, m_attributeFilter, m_sourceFilter, m_filter, m_symlinkPolicy, m_options.HardlinkPolicy, m_result);

            using(new Logging.Timer("BackupMainOperation"))
            {
                if (m_options.ChangedFilelist != null && m_options.ChangedFilelist.Length >= 1)
                {
                    m_result.AddVerboseMessage("Processing supplied change list instead of enumerating filesystem");
                    m_result.OperationProgressUpdater.UpdatefileCount(m_options.ChangedFilelist.Length, 0, true);

                    foreach(var p in filterhandler.Mixin(m_options.ChangedFilelist))
                    {
                        if (m_result.TaskControlRendevouz() == TaskControlState.Stop)
                        {
                            m_result.AddMessage("Stopping backup operation on request");
                            break;
                        }

                        try
                        {
                            this.HandleFilesystemEntry(snapshot, backend, p, snapshot.GetAttributes(p));
                        }
                        catch (Exception ex)
                        {
                            m_result.AddWarning(string.Format("Failed to process element: {0}, message: {1}", p, ex.Message), ex);
                        }
                    }

                    m_database.AppendFilesFromPreviousSet(m_transaction, m_options.DeletedFilelist);
                }
                else
                {                                    
                    foreach(var path in filterhandler.EnumerateFilesAndFolders())
                    {
                        if (m_result.TaskControlRendevouz() == TaskControlState.Stop)
                        {
                            m_result.AddMessage("Stopping backup operation on request");
                            break;
                        }

                        var fa = FileAttributes.Normal;
                        try { fa = snapshot.GetAttributes(path); }
                        catch { }

                        this.HandleFilesystemEntry(snapshot, backend, path, fa);
                    }

                }

                m_result.OperationProgressUpdater.UpdatefileCount(m_result.ExaminedFiles, m_result.SizeOfExaminedFiles, true);
            }
        }
Example #34
0
        public void Run(string[] sources, Library.Utility.IFilter filter)
        {
            m_result.OperationProgressUpdater.UpdatePhase(OperationPhase.Backup_Begin);

            using(m_database = new LocalBackupDatabase(m_options.Dbpath, m_options))
            {
                m_result.SetDatabase(m_database);
                m_result.Dryrun = m_options.Dryrun;

                Utility.VerifyParameters(m_database, m_options);
                m_database.VerifyConsistency(null);
                // If there is no filter, we set an empty filter to simplify the code
                // If there is a filter, we make sure that the sources are included
                m_filter = filter ?? new Library.Utility.FilterExpression();
                m_sourceFilter = new Library.Utility.FilterExpression(sources, true);

                var lastVolumeSize = -1L;
                m_backendLogFlushTimer = DateTime.Now.Add(FLUSH_TIMESPAN);
                System.Threading.Thread parallelScanner = null;

                try
                {
                    m_snapshot = GetSnapshot(sources, m_options, m_result);

                    // Start parallel scan
                    if (m_options.ChangedFilelist == null || m_options.ChangedFilelist.Length < 1)
                    {
                        parallelScanner = new System.Threading.Thread(CountFilesThread) {
                            Name = "Read ahead file counter",
                            IsBackground = true
                        };
                        parallelScanner.Start();
                    }

                    using(m_backend = new BackendManager(m_backendurl, m_options, m_result.BackendWriter, m_database))
                    using(m_filesetvolume = new FilesetVolumeWriter(m_options, m_database.OperationTimestamp))
                    {
                        var incompleteFilesets = m_database.GetIncompleteFilesets(null).OrderBy(x => x.Value).ToArray();
                        if (incompleteFilesets.Length != 0)
                        {
                            m_result.OperationProgressUpdater.UpdatePhase(OperationPhase.Backup_PreviousBackupFinalize);
                            m_result.AddMessage(string.Format("Uploading filelist from previous interrupted backup"));
                            using(var trn = m_database.BeginTransaction())
                            {
                                var incompleteSet = incompleteFilesets.Last();
                                var badIds = from n in incompleteFilesets select n.Key;

                                var prevs = (from n in m_database.FilesetTimes
                                            where
                                                n.Key < incompleteSet.Key
                                                &&
                                                !badIds.Contains(n.Key)
                                            orderby n.Key
                                            select n.Key).ToArray();

                                var prevId = prevs.Length == 0 ? -1 : prevs.Last();

                                FilesetVolumeWriter fsw = null;
                                try
                                {
                                    var s = 1;
                                    var fileTime = incompleteSet.Value + TimeSpan.FromSeconds(s);
                                    var oldFilesetID = incompleteSet.Key;

                                    // Probe for an unused filename
                                    while (s < 60)
                                    {
                                        var id = m_database.GetRemoteVolumeID(VolumeBase.GenerateFilename(RemoteVolumeType.Files, m_options, null, fileTime));
                                        if (id < 0)
                                            break;

                                        fileTime = incompleteSet.Value + TimeSpan.FromSeconds(++s);
                                    }

                                    fsw = new FilesetVolumeWriter(m_options, fileTime);
                                    fsw.VolumeID = m_database.RegisterRemoteVolume(fsw.RemoteFilename, RemoteVolumeType.Files, RemoteVolumeState.Temporary, m_transaction);
                                    var newFilesetID = m_database.CreateFileset(fsw.VolumeID, fileTime, trn);
                                    m_database.LinkFilesetToVolume(newFilesetID, fsw.VolumeID, trn);
                                    m_database.AppendFilesFromPreviousSet(trn, null, newFilesetID, prevId, fileTime);

                                    m_database.WriteFileset(fsw, trn, newFilesetID);

                                    if (m_options.Dryrun)
                                    {
                                        m_result.AddDryrunMessage(string.Format("Would upload fileset: {0}, size: {1}", fsw.RemoteFilename, Library.Utility.Utility.FormatSizeString(new FileInfo(fsw.LocalFilename).Length)));
                                    }
                                    else
                                    {
                                        m_database.UpdateRemoteVolume(fsw.RemoteFilename, RemoteVolumeState.Uploading, -1, null, trn);

                                        using(new Logging.Timer("CommitUpdateFilelistVolume"))
                                            trn.Commit();

                                        m_backend.Put(fsw);
                                        fsw = null;
                                    }
                                }
                                finally
                                {
                                    if (fsw != null)
                                        try { fsw.Dispose(); }
                                        catch { fsw = null; }
                                }
                            }
                        }

                        if (!m_options.NoBackendverification)
                        {
                            m_result.OperationProgressUpdater.UpdatePhase(OperationPhase.Backup_PreBackupVerify);
                            using(new Logging.Timer("PreBackupVerify"))
                            {
                                try
                                {
                                    FilelistProcessor.VerifyRemoteList(m_backend, m_options, m_database, m_result.BackendWriter);
                                }
                                catch (Exception ex)
                                {
                                    if (m_options.AutoCleanup)
                                    {
                                        m_result.AddWarning("Backend verification failed, attempting automatic cleanup", ex);
                                        m_result.RepairResults = new RepairResults(m_result);
                                        new RepairHandler(m_backend.BackendUrl, m_options, (RepairResults)m_result.RepairResults).Run();

                                        m_result.AddMessage("Backend cleanup finished, retrying verification");
                                        FilelistProcessor.VerifyRemoteList(m_backend, m_options, m_database, m_result.BackendWriter);
                                    }
                                    else
                                        throw;
                                }
                            }
                        }

                        m_database.BuildLookupTable(m_options);
                        m_transaction = m_database.BeginTransaction();

                        m_result.OperationProgressUpdater.UpdatePhase(OperationPhase.Backup_ProcessingFiles);
                        var filesetvolumeid = m_database.RegisterRemoteVolume(m_filesetvolume.RemoteFilename, RemoteVolumeType.Files, RemoteVolumeState.Temporary, m_transaction);
                        m_database.CreateFileset(filesetvolumeid, VolumeBase.ParseFilename(m_filesetvolume.RemoteFilename).Time, m_transaction);

                        m_blockvolume = new BlockVolumeWriter(m_options);
                        m_blockvolume.VolumeID = m_database.RegisterRemoteVolume(m_blockvolume.RemoteFilename, RemoteVolumeType.Blocks, RemoteVolumeState.Temporary, m_transaction);

                        if (m_options.IndexfilePolicy != Options.IndexFileStrategy.None)
                        {
                            m_indexvolume = new IndexVolumeWriter(m_options);
                            m_indexvolume.VolumeID = m_database.RegisterRemoteVolume(m_indexvolume.RemoteFilename, RemoteVolumeType.Index, RemoteVolumeState.Temporary, m_transaction);
                        }

                        var filterhandler = new FilterHandler(m_snapshot, m_attributeFilter, m_sourceFilter, m_filter, m_symlinkPolicy, m_options.HardlinkPolicy, m_result);

                        using(new Logging.Timer("BackupMainOperation"))
                        {
                            if (m_options.ChangedFilelist != null && m_options.ChangedFilelist.Length >= 1)
                            {
                                m_result.AddVerboseMessage("Processing supplied change list instead of enumerating filesystem");
                                m_result.OperationProgressUpdater.UpdatefileCount(m_options.ChangedFilelist.Length, 0, true);

                                foreach(var p in m_options.ChangedFilelist)
                                {
                                    if (m_result.TaskControlRendevouz() == TaskControlState.Stop)
                                    {
                                        m_result.AddMessage("Stopping backup operation on request");
                                        break;
                                    }

                                    FileAttributes fa = new FileAttributes();
                                    try
                                    {
                                        fa = m_snapshot.GetAttributes(p);
                                    }
                                    catch (Exception ex)
                                    {
                                        m_result.AddWarning(string.Format("Failed to read attributes: {0}, message: {1}", p, ex.Message), ex);
                                    }

                                    if (filterhandler.AttributeFilter(null, p, fa))
                                    {
                                        try
                                        {
                                            this.HandleFilesystemEntry(p, fa);
                                        }
                                        catch (Exception ex)
                                        {
                                            m_result.AddWarning(string.Format("Failed to process element: {0}, message: {1}", p, ex.Message), ex);
                                        }
                                    }
                                }

                                m_database.AppendFilesFromPreviousSet(m_transaction, m_options.DeletedFilelist);
                            }
                            else
                            {
                                foreach(var path in m_snapshot.EnumerateFilesAndFolders(filterhandler.AttributeFilter))
                                {
                                    if (m_result.TaskControlRendevouz() == TaskControlState.Stop)
                                    {
                                        m_result.AddMessage("Stopping backup operation on request");
                                        break;
                                    }

                                    this.HandleFilesystemEntry(path, m_snapshot.GetAttributes(path));
                                }

                            }

                            //If the scanner is still running for some reason, make sure we kill it now
                            if (parallelScanner != null && parallelScanner.IsAlive)
                                parallelScanner.Abort();

                            // We no longer need to snapshot active
                            try { m_snapshot.Dispose(); }
                            finally { m_snapshot = null; }

                            m_result.OperationProgressUpdater.UpdatefileCount(m_result.ExaminedFiles, m_result.SizeOfExaminedFiles, true);
                        }

                        m_result.OperationProgressUpdater.UpdatePhase(OperationPhase.Backup_Finalize);
                        using(new Logging.Timer("FinalizeRemoteVolumes"))
                        {
                            if (m_blockvolume.SourceSize > 0)
                            {
                                lastVolumeSize = m_blockvolume.SourceSize;

                                if (m_options.Dryrun)
                                {
                                    m_result.AddDryrunMessage(string.Format("Would upload block volume: {0}, size: {1}", m_blockvolume.RemoteFilename, Library.Utility.Utility.FormatSizeString(new FileInfo(m_blockvolume.LocalFilename).Length)));
                                    if (m_indexvolume != null)
                                    {
                                        m_blockvolume.Close();
                                        UpdateIndexVolume();
                                        m_indexvolume.FinishVolume(Library.Utility.Utility.CalculateHash(m_blockvolume.LocalFilename), new FileInfo(m_blockvolume.LocalFilename).Length);
                                        m_result.AddDryrunMessage(string.Format("Would upload index volume: {0}, size: {1}", m_indexvolume.RemoteFilename, Library.Utility.Utility.FormatSizeString(new FileInfo(m_indexvolume.LocalFilename).Length)));
                                    }

                                    m_blockvolume.Dispose();
                                    m_blockvolume = null;
                                    m_indexvolume.Dispose();
                                    m_indexvolume = null;
                                }
                                else
                                {
                                    m_database.UpdateRemoteVolume(m_blockvolume.RemoteFilename, RemoteVolumeState.Uploading, -1, null, m_transaction);
                                    m_blockvolume.Close();
                                    UpdateIndexVolume();

                                    using(new Logging.Timer("CommitUpdateRemoteVolume"))
                                        m_transaction.Commit();
                                    m_transaction = m_database.BeginTransaction();

                                    m_backend.Put(m_blockvolume, m_indexvolume);

                                    m_blockvolume = null;
                                    m_indexvolume = null;
                                }
                            }
                            else
                            {
                                m_database.RemoveRemoteVolume(m_blockvolume.RemoteFilename, m_transaction);
                                if (m_indexvolume != null)
                                    m_database.RemoveRemoteVolume(m_indexvolume.RemoteFilename, m_transaction);
                            }
                        }

                        using(new Logging.Timer("UpdateChangeStatistics"))
                            m_database.UpdateChangeStatistics(m_result);
                        using(new Logging.Timer("VerifyConsistency"))
                            m_database.VerifyConsistency(m_transaction);

                        var changeCount =
                            m_result.AddedFiles + m_result.ModifiedFiles + m_result.DeletedFiles +
                            m_result.AddedFolders + m_result.ModifiedFolders + m_result.DeletedFolders +
                            m_result.AddedSymlinks + m_result.ModifiedSymlinks + m_result.DeletedSymlinks;

                        //Changes in the filelist triggers a filelist upload
                        if (m_options.UploadUnchangedBackups || changeCount > 0)
                        {
                            using(new Logging.Timer("Uploading a new fileset"))
                            {
                                if (!string.IsNullOrEmpty(m_options.ControlFiles))
                                    foreach(var p in m_options.ControlFiles.Split(new char[] { System.IO.Path.PathSeparator }, StringSplitOptions.RemoveEmptyEntries))
                                        m_filesetvolume.AddControlFile(p, m_options.GetCompressionHintFromFilename(p));

                                m_database.WriteFileset(m_filesetvolume, m_transaction);
                                m_filesetvolume.Close();

                                if (m_options.Dryrun)
                                    m_result.AddDryrunMessage(string.Format("Would upload fileset volume: {0}, size: {1}", m_filesetvolume.RemoteFilename, Library.Utility.Utility.FormatSizeString(new FileInfo(m_filesetvolume.LocalFilename).Length)));
                                else
                                {
                                    m_database.UpdateRemoteVolume(m_filesetvolume.RemoteFilename, RemoteVolumeState.Uploading, -1, null, m_transaction);

                                    using(new Logging.Timer("CommitUpdateRemoteVolume"))
                                        m_transaction.Commit();
                                    m_transaction = m_database.BeginTransaction();

                                    m_backend.Put(m_filesetvolume);
                                }
                            }
                        }
                        else
                        {
                            m_result.AddVerboseMessage("removing temp files, as no data needs to be uploaded");
                            m_database.RemoveRemoteVolume(m_filesetvolume.RemoteFilename, m_transaction);
                        }

                        m_result.OperationProgressUpdater.UpdatePhase(OperationPhase.Backup_WaitForUpload);
                        using(new Logging.Timer("Async backend wait"))
                            m_backend.WaitForComplete(m_database, m_transaction);

                        if (m_result.TaskControlRendevouz() != TaskControlState.Stop)
                        {
                            if (m_options.KeepTime.Ticks > 0 || m_options.KeepVersions != 0)
                            {
                                m_result.OperationProgressUpdater.UpdatePhase(OperationPhase.Backup_Delete);
                                m_result.DeleteResults = new DeleteResults(m_result);
                                using(var db = new LocalDeleteDatabase(m_database))
                                    new DeleteHandler(m_backend.BackendUrl, m_options, (DeleteResults)m_result.DeleteResults).DoRun(db, m_transaction, true, lastVolumeSize <= m_options.SmallFileSize);

                            }
                            else if (lastVolumeSize <= m_options.SmallFileSize && !m_options.NoAutoCompact)
                            {
                                m_result.OperationProgressUpdater.UpdatePhase(OperationPhase.Backup_Compact);
                                m_result.CompactResults = new CompactResults(m_result);
                                using(var db = new LocalDeleteDatabase(m_database))
                                    new CompactHandler(m_backend.BackendUrl, m_options, (CompactResults)m_result.CompactResults).DoCompact(db, true, m_transaction);
                            }
                        }

                        if (m_options.UploadVerificationFile)
                        {
                            m_result.OperationProgressUpdater.UpdatePhase(OperationPhase.Backup_VerificationUpload);
                            FilelistProcessor.UploadVerificationFile(m_backend.BackendUrl, m_options, m_result.BackendWriter, m_database, m_transaction);
                        }

                        if (m_options.Dryrun)
                        {
                            m_transaction.Rollback();
                            m_transaction = null;
                        }
                        else
                        {
                            using(new Logging.Timer("CommitFinalizingBackup"))
                                m_transaction.Commit();

                            m_transaction = null;
                            m_database.Vacuum();

                            if (m_result.TaskControlRendevouz() != TaskControlState.Stop && !m_options.NoBackendverification)
                            {
                                m_result.OperationProgressUpdater.UpdatePhase(OperationPhase.Backup_PostBackupVerify);
                                using(var backend = new BackendManager(m_backendurl, m_options, m_result.BackendWriter, m_database))
                                {
                                    using(new Logging.Timer("AfterBackupVerify"))
                                        FilelistProcessor.VerifyRemoteList(backend, m_options, m_database, m_result.BackendWriter);
                                    backend.WaitForComplete(m_database, null);
                                }

                                if (m_options.BackupTestSampleCount > 0 && m_database.GetRemoteVolumes().Count() > 0)
                                {
                                    m_result.OperationProgressUpdater.UpdatePhase(OperationPhase.Backup_PostBackupTest);
                                    m_result.TestResults = new TestResults(m_result);

                                    using(var testdb = new LocalTestDatabase(m_database))
                                    using(var backend = new BackendManager(m_backendurl, m_options, m_result.BackendWriter, testdb))
                                        new TestHandler(m_backendurl, m_options, new TestResults(m_result))
                                            .DoRun(m_options.BackupTestSampleCount, testdb, backend);
                                }
                            }

                        }

                        m_result.OperationProgressUpdater.UpdatePhase(OperationPhase.Backup_Complete);
                        m_database.WriteResults();
                        return;
                    }
                }
                catch (Exception ex)
                {
                    m_result.AddError("Fatal error", ex);
                    throw;
                }
                finally
                {
                    if (parallelScanner != null && parallelScanner.IsAlive)
                    {
                        parallelScanner.Abort();
                        parallelScanner.Join(500);
                        if (parallelScanner.IsAlive)
                            m_result.AddWarning("Failed to terminate filecounter thread", null);
                    }

                    if (m_snapshot != null)
                        try { m_snapshot.Dispose(); }
                        catch (Exception ex) { m_result.AddError(string.Format("Failed to dispose snapshot"), ex); }
                        finally { m_snapshot = null; }

                    if (m_transaction != null)
                        try { m_transaction.Rollback(); }
                        catch (Exception ex) { m_result.AddError(string.Format("Rollback error: {0}", ex.Message), ex); }
                }
            }
        }
Example #35
0
 public void Initialize()
 {
     //OUI lookup
     _av.LoadFromOui();
     _filterHandler = ItsFilterViewController.ItsFilterHandler;
     HookUpEvents();
 }
        private void Initialize()
        {
            Students = new List<Student>
                           {
                               new Student("Jesse", "Fredericks") {IsInternational = false, Gender = Gender.Male},
                               new Student("Elenor", "Ruel") {IsInternational = true, Gender = Gender.Female},
                               new Student("Hàn Ngọc", "Trai") {IsInternational = true, Gender = Gender.Female},
                               new Student("Catherine", "Jackson") {IsInternational = false, Gender = Gender.Female},
                               new Student("Mahjub Khalid", "Daher") {IsInternational = true, Gender = Gender.Male},
                               new Student("Ashwaq Jawahir", "Shalhoub")
                                   {IsInternational = true, Gender = Gender.Female},
                               new Student("Douglas", "Rego") {IsInternational = false, Gender = Gender.Male},
                               new Student("Jose", "Kitterman") {IsInternational = false, Gender = Gender.Female},
                               new Student("Nancy", "Jackson") {IsInternational = false, Gender = Gender.Female},
                               new Student("Jesse", "Roberts") {IsInternational = false, Gender = Gender.Male},
                               new Student("Bob", "Jackson") {IsInternational = false, Gender = Gender.Female}
                           };

            MyFilterHandler = new FilterHandler<Student>();
        }