Skip to content

Commit

Permalink
EasyTests for dynamically install all eXpandFrameowork Modules
Browse files Browse the repository at this point in the history
  • Loading branch information
apobekiaris committed Apr 8, 2017
1 parent 9cc36b4 commit 458a850
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 49 deletions.
19 changes: 7 additions & 12 deletions Demos/SecurityDemo/SecurityDemo.Module.Web/WebModule.cs
Expand Up @@ -5,25 +5,20 @@
using DevExpress.ExpressApp.Updating;
using Xpand.Persistent.Base.General;

namespace SecurityDemo.Module.Web
{
namespace SecurityDemo.Module.Web{
[ToolboxItemFilter("Xaf.Platform.Web")]
public sealed partial class SecurityDemoAspNetModule : ModuleBase
{
public SecurityDemoAspNetModule()
{
public sealed partial class SecurityDemoAspNetModule : ModuleBase{
public SecurityDemoAspNetModule(){
InitializeComponent();
}

public override void Setup(ApplicationModulesManager moduleManager) {
public override void Setup(ApplicationModulesManager moduleManager){
base.Setup(moduleManager);
var xpandDLLPath =AppDomain.CurrentDomain.SetupInformation.ApplicationBase+ @"..\..\..\xpand.dll\";
this.AddModules(xpandDLLPath);

this.AddModules(SecurityDemoModule.GetXpandDllPath());
}

public override IEnumerable<ModuleUpdater> GetModuleUpdaters(IObjectSpace objectSpace, Version versionFromDB) {
public override IEnumerable<ModuleUpdater> GetModuleUpdaters(IObjectSpace objectSpace, Version versionFromDB){
return ModuleUpdater.EmptyModuleUpdaters;
}
}
}
}
5 changes: 4 additions & 1 deletion Demos/SecurityDemo/SecurityDemo.Module.Win/WinModule.cs
Expand Up @@ -3,6 +3,7 @@
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Updating;
using FeatureCenter.Module.Win;
Expand All @@ -21,7 +22,9 @@ public SecurityDemoWindowsFormsModule()

public override void Setup(ApplicationModulesManager moduleManager){
base.Setup(moduleManager);
this.AddModules(@"..\..\..\..\..\xpand.dll\");

var xpandDLLPath = Path.GetFullPath(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"..\..\..\..\..\..\..\xpand.dll\");
this.AddModules(xpandDLLPath);
}


Expand Down
35 changes: 22 additions & 13 deletions Demos/SecurityDemo/SecurityDemo.Module/Module.cs
@@ -1,24 +1,33 @@
using System;
using System.Collections.Generic;

using System.IO;
using System.Linq;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.SystemModule;
using DevExpress.ExpressApp.Updating;

namespace SecurityDemo.Module
{
public sealed partial class SecurityDemoModule : ModuleBase
{
static SecurityDemoModule() {
DevExpress.ExpressApp.SystemModule.ObjectMethodActionsViewController.Enabled = false;
namespace SecurityDemo.Module{
public sealed partial class SecurityDemoModule : ModuleBase{
static SecurityDemoModule(){
ObjectMethodActionsViewController.Enabled = false;
}

public SecurityDemoModule(){
InitializeComponent();
}
public SecurityDemoModule()
{
InitializeComponent();

public static string GetXpandDllPath(){
var xpandDLLPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
while (Directory.GetDirectories(xpandDLLPath).All(s => (new DirectoryInfo(s).Name + "").ToLower() != "xpand.dll")) {
xpandDLLPath = Path.GetFullPath(xpandDLLPath + @"..\");
}
xpandDLLPath += @"Xpand.dll";
return xpandDLLPath;
}
public override IEnumerable<ModuleUpdater> GetModuleUpdaters(IObjectSpace objectSpace, Version versionFromDB) {

public override IEnumerable<ModuleUpdater> GetModuleUpdaters(IObjectSpace objectSpace, Version versionFromDB){
ModuleUpdater updater = new Updater(objectSpace, versionFromDB);
return new ModuleUpdater[] { updater };
return new[]{updater};
}
}
}
}
@@ -1,5 +1,6 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -19,52 +20,65 @@ public interface IModelApplicationScheduler {
IModelScheduler Scheduler { get; }
}

public abstract class ReminderAlertController:WindowController,IModelExtender{
public abstract class ReminderAlertController : WindowController, IModelExtender {
private IObjectSpace _objectSpace;

protected ReminderAlertController(){
TargetWindowType=WindowType.Main;
protected ReminderAlertController() {
TargetWindowType = WindowType.Main;
}

protected override void OnActivated(){
protected override void OnActivated() {
base.OnActivated();
_objectSpace = Application.CreateObjectSpace();
SchedulerStorage.Instance.AppointmentChanging += SchedulerStorageAppointmentChanging;
SchedulerStorage.Instance.ReminderAlert += ShowReminderAlerts;
}

protected override void OnFrameAssigned(){
protected override void OnFrameAssigned() {
base.OnFrameAssigned();
if (Frame.Context==TemplateContext.ApplicationWindow){
Application.ViewShown+=ApplicationOnViewShown;
Frame.Disposing+=FrameOnDisposing;
if (Frame.Context == TemplateContext.ApplicationWindow) {
Application.ViewShown += ApplicationOnViewShown;
Frame.Disposing += FrameOnDisposing;
}
}

private void FrameOnDisposing(object sender, EventArgs eventArgs){
private void FrameOnDisposing(object sender, EventArgs eventArgs) {
Frame.Disposing -= FrameOnDisposing;
Application.ViewShown -= ApplicationOnViewShown;
}

private void ApplicationOnViewShown(object sender, ViewShownEventArgs viewShownEventArgs){
Task.Factory.StartNew(() => Thread.Sleep(2000)).ContinueWith(task => CreateAppoitments(viewShownEventArgs.TargetFrame.View.ObjectSpace),
TaskScheduler.FromCurrentSynchronizationContext());
((XafApplication) sender).ViewShown -= ApplicationOnViewShown;
private void ApplicationOnViewShown(object sender, ViewShownEventArgs viewShownEventArgs) {

Task.Factory.StartNew(() => {
var stopwatch = new Stopwatch();
stopwatch.Start();
while (stopwatch.Elapsed.TotalMilliseconds < 2000) {
Thread.Sleep(100);
}
stopwatch.Stop();
}).ContinueWith(task => {
CreateAppoitments();
}, TaskScheduler.FromCurrentSynchronizationContext());

((XafApplication)sender).ViewShown -= ApplicationOnViewShown;
}

private void CreateAppoitments(IObjectSpace objectSpace){
private void CreateAppoitments() {
var reminderInfos = Application.TypesInfo.PersistentTypes.Select(ReminderMembers).Where(info => info != null);
var reminderController = Frame.GetController<ReminderController>();
foreach (var modelMemberReminderInfo in reminderInfos){
var objectSpace = Application.CreateObjectSpace();
foreach (var modelMemberReminderInfo in reminderInfos) {
var criteriaOperator = reminderController.GetCriteria(modelMemberReminderInfo);
var reminderEvents = objectSpace.GetObjects(modelMemberReminderInfo.ModelClass.TypeInfo.Type, criteriaOperator, false).Cast<IEvent>();
var reminderEvents =
objectSpace.GetObjects(modelMemberReminderInfo.ModelClass.TypeInfo.Type, criteriaOperator, false)
.Cast<IEvent>();
var appointments = reminderController.CreateAppoitments(reminderEvents);
reminderController.UpdateAppoitmentKey(appointments);
}
}


protected override void OnDeactivated(){
protected override void OnDeactivated() {
base.OnDeactivated();
_objectSpace.Dispose();
SchedulerStorage.Instance.AppointmentChanging -= SchedulerStorageAppointmentChanging;
Expand All @@ -77,27 +91,27 @@ public abstract class ReminderAlertController:WindowController,IModelExtender{

protected abstract void ShowReminderAlerts(object sender, ReminderEventArgs e);

private void SchedulerStorageAppointmentChanging(object sender, PersistentObjectCancelEventArgs e){
private void SchedulerStorageAppointmentChanging(object sender, PersistentObjectCancelEventArgs e) {
var appointment = (Appointment)e.Object;
var type = (Type)appointment.CustomFields[SchedulerStorage.BOType];
var key = appointment.CustomFields[SchedulerStorage.BOKey];
var objectSpace = GetObjectSpace();
var eventBO = ((IEvent)objectSpace.GetObjectByKey(type, key));
if (eventBO != null){
if (eventBO != null) {
var reminderInfo = eventBO.GetReminderInfoMemberValue();
reminderInfo.HasReminder = appointment.HasReminder;
reminderInfo.Info = !reminderInfo.HasReminder ? null : new ReminderXmlPersistenceHelper(appointment.Reminder).ToXml();
objectSpace.CommitChanges();
}
}

private IObjectSpace GetObjectSpace(){
private IObjectSpace GetObjectSpace() {
var objectView = Frame.View as ObjectView;
return objectView != null && objectView.ObjectTypeInfo.Implements<IEvent>()
? objectView.ObjectSpace: _objectSpace;
? objectView.ObjectSpace : _objectSpace;
}

public void ExtendModelInterfaces(ModelInterfaceExtenders extenders){
public void ExtendModelInterfaces(ModelInterfaceExtenders extenders) {
extenders.Add<IModelApplication, IModelApplicationScheduler>();
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.cmd
@@ -1,3 +1,3 @@
@echo off
call defines.bat
%msbuild% Xpand.build /fl /p:configuration=debug; %*
%msbuild% Xpand.build /fl /p:configuration=debug

0 comments on commit 458a850

Please sign in to comment.