/// <summary> /// Loads the model. /// </summary> public void LoadModel() { Dataservices = DataContextObject.Services; var providerFactory = new DataproviderFactory(Dataservices); providerFactory.InitDataProvider(); Feedback = string.Format(@"Press ""{0}"" to begin", ButtonCaption); Application.Current.DoEvents(); Feedback = String.Empty; using (var conn = Dataservices.ConnectionFactory()) { try { using (var cmd = conn.CreateCommand()) { cmd.CommandText = string.Format("select count(*) from [{0}]", Dataservices.Configuration.SelectFrom); conn.Open(); var temp = (int)cmd.ExecuteScalar(); CurrentProgress = new ProgressState(0, temp); // TODO: based on line count and then perform multi-threading for validating and importing dataset. } } finally { conn.Close(); } } }
public void TestCtorStageSizeSetPositive() { var stageSize = 100; var conn = MockRepository.GenerateStub <IDataContextServices>(); var provider = new DataproviderFactory(conn); var stage = new ImportStageModel(provider, stageSize); Assert.AreEqual(stageSize, stage.StageSize); }
public void TestCtorConnectionSetPositive() { var conn = MockRepository.GenerateStub <IDataContextServices>(); var provider = new DataproviderFactory(conn); var stage = new ImportStageModel(provider, 100); var priv = new PrivateObject(stage); Assert.AreSame(provider, priv.GetFieldOrProperty("ProviderFactory")); }
public void TestCtorDefaultStageSize() { var conn = MockRepository.GenerateStub <IDataContextServices>(); var provider = new DataproviderFactory(conn); var stage = new ImportStageModel(provider); var p = new PrivateType(typeof(ImportStageModel)); var expected = p.GetStaticField("DefaultStageSize"); var actual = stage.StageSize; Assert.AreEqual(expected, actual); }
private static ImportStageModel MockTheStage(DataTable dt) { var services = MockRepository.GenerateStub <IDataContextServices>(); var prov = MockRepository.GenerateStub <IDataProviderController>(); var connElement = MockRepository.GenerateStub <INamedConnectionElement>(); connElement.SelectFrom = "foo"; services.Stub(s => s.Configuration).Return(connElement); services.Stub(s => s.Controller).Return(prov); var conn = MockRepository.GenerateStub <IDbConnection>(); conn.ConnectionString = string.Empty; services.ConnectionFactory = () => conn; var factory = new DataproviderFactory(services); prov.Expect(p => p.SelectTable(string.Empty, string.Empty, 100)).IgnoreArguments().Return(dt); return(new ImportStageModel(factory)); }
/// <summary> /// For when yous need to set up some values that can't be directly bound to UI elements. /// </summary> public override void BeforeShow() { _isLoading = true; Dataservices = DataContextObject.Services; var providerFactory = new DataproviderFactory(Dataservices); providerFactory.InitDataProvider(); var stage = new ImportStageModel(providerFactory); var temp = stage.SourceFields.Select(fld => new MOriginalField { Name = fld.Name, Values = new ObservableCollection <string>(stage.GetColumnValues(fld.Name, true)), FieldOrder = fld.Order }).ToList(); var original = new ObservableCollection <MOriginalField>(temp); var factory = ServiceLocator.Current.GetInstance <IDomainSessionFactoryProvider>().SessionFactory; int positionIndex = 0; using (var session = factory.OpenSession()) { DataContextObject.TargetElements = session.Query <Element>() .Where(elem => elem.Owner.Id == DataContextObject.SelectedDataType.Target.Id) .ToList(); } var targetFields = DataContextObject.TargetElements .Where(ElementFilter) .Select(elem => new MTargetField(elem, original) { Position = positionIndex++, IsRequired = elem.IsRequired }) .ToList(); //TargetFields = MakeView(targetFields); DataTypeRequiredFieldCount = MappedFieldsCount = targetFields.Count(f => f.IsRequired); TargetFields = new ListCollectionView(targetFields); SourceFields = MakeView(temp); TotalSourceFields = SourceFields.Count; //ReconcileTargets(); ReconcileTargets2(); foreach (var f in SourceFields.OfType <MOriginalField>()) { f.MappingChanged += f_MappingChanged2; } FilterText = string.Empty; ShowEnumeration = new ObservableCollection <string> { ALL, AUTOMAPPED, MAPPED, UNMAPPED }; SelectedShow = ShowEnumeration[0]; FieldSortOrder = new ObservableCollection <string> { ORDER, NAME }; SelectedSortOrder = FieldSortOrder[0]; TargetFieldModels.ToList().Clear(); var newList = TargetFieldModels.Where(field => !SourceFields.OfType <MOriginalField>() .ToList() .Any(f => f.TargetField != null && f.TargetField.Name.EqualsIgnoreCase(field.Name))) .ToList(); _targetFields = new ListCollectionView(newList); var requiredFields = TargetFieldModels.Where(f => f.IsRequired).OrderBy(f => f.Name).ToList(); RequiredTargetFields = new ListCollectionView(requiredFields) { CustomSort = new MTargetFieldComparer() }; var optionalFields = TargetFieldModels.Where(f => !f.IsRequired).OrderBy(f => f.Name).ToList(); OptionalTargetFields = new ListCollectionView(optionalFields) { CustomSort = new MTargetFieldComparer() }; _isLoading = false; }
/// <summary> /// Perform file operation when loaded /// </summary> public void Loaded() { Dataservices = DataContextObject.Services; var providerFactory = new DataproviderFactory(Dataservices); providerFactory.InitDataProvider(); InitModel(); if (DataContextObject.Histogram != null) { return; } var worker = new BackgroundWorker(); var sync = new object(); var interimProgress = new ProgressState(0, CurrentProgress.Total); Action notifyAction = () => { { lock (sync) { CurrentProgress = interimProgress; Status = string.Format("Progress: {0}", interimProgress.Ratio.ToString("P0")); } } }; var timer = new Timer((state) => { NotifyProgress(this, new ExtendedEventArgs <Action>(notifyAction)); }, null, 1, 1000); worker.WorkerReportsProgress = true; worker.WorkerSupportsCancellation = true; worker.DoWork += (o, e) => { RunWorker(worker, e); }; worker.ProgressChanged += (o, e) => { var temp = (e.UserState as ProgressState) ?? ProgressState.Empty; if (temp.Current > interimProgress.Current) { lock (sync) { interimProgress = temp; } } }; worker.RunWorkerCompleted += (o, e) => { _isValid = !Cancelled; timer.Dispose(); timer = null; NotifyProgress(this, new ExtendedEventArgs <Action>(notifyAction)); if (_isValid) { Verified(this, EventArgs.Empty); } OnPropertyChanged(); // WPF CommandManager periodically calls IsValid to see if the Next/Done button should be enabled. // In multi-threaded wizard steps, IsValid returns the value of the Done flag. Call InvalidateRequerySuggested here // on the UI thread after setting the Done flag to force WPF to call IsValid now so the Next/Done button will become enabled. //Application.Current.DoEvents(); CommandManager.InvalidateRequerySuggested(); }; ServiceLocator.Current.GetInstance <IEventAggregator>() .GetEvent <WizardCancelEvent>().Subscribe(evnt => { Cancelled = true; if (worker.CancellationPending) { return; } worker.CancelAsync(); }); ServiceLocator.Current.GetInstance <IEventAggregator>() .GetEvent <WizardBackEvent>().Subscribe(evnt => { Cancelled = true; if (worker.CancellationPending) { return; } worker.CancelAsync(); }); worker.RunWorkerAsync(new Func <ProgressState>(() => interimProgress)); Thread.Sleep(0); }
/// <summary> /// Initializes a new instance of the <see cref="ImportStageModel"/> class. /// </summary> /// <param name="providerFactory">The provider factory.</param> /// <param name="stageSize">Size of the stage.</param> public ImportStageModel(DataproviderFactory providerFactory, int stageSize = DefaultStageSize) { this.ProviderFactory = providerFactory; this.StageSize = stageSize; DataTable = new Lazy <DataTable>(CreateTable); }