Skip to content
Permalink
Browse files

ModelMapper: CheckXpandVSIXInstalled #518

  • Loading branch information...
apobekiaris committed Aug 20, 2019
1 parent c40aa70 commit 602a5e534719b29872c3b22bb01cf5733bdf1a1e
@@ -1,14 +1,19 @@
using System;
using System.IO;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Reactive.Threading.Tasks;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Model;
using DevExpress.ExpressApp.Model.Core;
using Xpand.XAF.Modules.ModelMapper.Services;
using Xpand.XAF.Modules.Reactive;
using Xpand.XAF.Modules.Reactive.Extensions;

namespace Xpand.XAF.Modules.ModelMapper {
namespace Xpand.XAF.Modules.ModelMapper
{
public sealed class ModelMapperModule : ReactiveModuleBase {
private readonly IConnectableObservable<Unit> _modelExtended;
public ModelMapperModule(){
@@ -25,13 +30,38 @@ public sealed class ModelMapperModule : ReactiveModuleBase {

public override void Setup(ApplicationModulesManager moduleManager){
base.Setup(moduleManager);

CheckXpandVSIXInstalled();
moduleManager.ConnectExtendingService()
.Merge(Application.BindConnect())
.TakeUntilDisposed(this)
.Subscribe();
.Subscribe(unit => {},exception => {});
}


private static void CheckXpandVSIXInstalled(){
if (DesignerOnlyCalculator.IsRunFromDesigner){
var result = Observable.Range(15, 10)
.SelectMany(i => Observable
.Start(() => System.Runtime.InteropServices.Marshal.GetActiveObject($"VisualStudio.DTE.{i}.0"))
.OnErrorResumeNext(Observable.Never<object>())
.Select(o => i)).FirstAsync()
.SelectMany(i => {
return Observable.Start(() => {
var installed = Directory.GetDirectories($@"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}\appdata\local\microsoft\visualstudio")
.Where(s => {
var directoryName = $"{new DirectoryInfo(s).Name}";
return !directoryName.EndsWith("Exp") &&directoryName.StartsWith(i.ToString());
})
.Any(s => Directory.GetFiles(s, "Xpand.VSIX.pkgdef", SearchOption.AllDirectories).Any());
return (vs: i, installed);
});
}).FirstAsync()
.ToTask().Result;
if (!result.installed){
throw new NotSupportedException($"ModelMapper requires Xpand.VSIX which is not installed in VS {result.vs}");
}
}
}
}


@@ -20,7 +20,6 @@
using Xpand.XAF.Modules.ModelMapper.Services.Predefined;
using Xpand.XAF.Modules.ModelMapper.Services.TypeMapping;
using Xpand.XAF.Modules.Reactive;
using Xpand.XAF.Modules.Reactive.Extensions;

namespace Xpand.XAF.Modules.ModelMapper.Services{
public static class PredefinedMapService{
@@ -51,6 +50,7 @@ public static class PredefinedMapService{
private static Assembly _dxUtilsAssembly;
private static Assembly _dashboardWebWebFormsAssembly;
private static string _dxAssemblyNamePostfix;



static PredefinedMapService(){
@@ -209,13 +209,13 @@ public static class PredefinedMapService{
if (mapperModule == null){
throw new NotSupportedException($"{nameof(ModelMapperModule)} not installed");
}
if (AppDomain.CurrentDomain.GetAssemblies()
.Count(_ => _.GetName().Name == typeof(ModelMapperModule).Assembly.GetName().Name) > 1){
throw new NotSupportedException(
"Multiple ModelMapper assemblies in the domain check your Model.DesignedDiffs.log if you are at design time. Make sure ModelMapper is referenced from the same path.");
}
// if (AppDomain.CurrentDomain.GetAssemblies()
// .Count(_ => _.GetName().Name == typeof(ModelMapperModule).Assembly.GetName().Name) > 1){
// throw new NotSupportedException(
// "Multiple ModelMapper assemblies in the domain check your Model.DesignedDiffs.log if you are at design time. Make sure ModelMapper is referenced from the same path. Try deleting *ModelMapper*.dll from your system.");
// }
try{
mapperModule.SetupCompleted.FirstAsync().Select(_ => _).Wait(TimeSpan.FromSeconds(1));
// mapperModule.SetupCompleted.FirstAsync().Select(_ => _).Wait(TimeSpan.FromSeconds(1));
}
catch (TimeoutException){
throw new NotSupportedException($"{nameof(ModelMapperModule)} API consumers must have the module installed.");
@@ -246,11 +246,8 @@ public static class PredefinedMapService{

private static ModelMapperConfiguration ModelMapperConfiguration(this PredefinedMap predefinedMap,Action<ModelMapperConfiguration> configure=null){
var mapperConfiguration = predefinedMap.GetModelMapperConfiguration();
if (mapperConfiguration != null){
configure?.Invoke(mapperConfiguration);
return mapperConfiguration;
}
throw new NotImplementedException(predefinedMap.ToString());
configure?.Invoke(mapperConfiguration);
return mapperConfiguration;
}

public static IModelNode AddControlsNode(this IModelNode modelNode, PredefinedMap predefinedMap,string id = null){
@@ -570,8 +567,10 @@ public static class PredefinedMapService{
}

public static ModelMapperConfiguration GetModelMapperConfiguration(this PredefinedMap predefinedMap){
if (ModelExtendingService.Platform==Platform.Win){
if (true){
if (new[]{PredefinedMap.GridView,PredefinedMap.GridColumn}.Any(map => map==predefinedMap)){
// _xafWinAssembly=AppDomain.CurrentDomain.GetAssemblies().First(assembly => assembly.GetName().Name==$"DevExpress.ExpressApp.Win{_versionSuffix}");
// _gridViewAssembly=AppDomain.CurrentDomain.GetAssemblies().First(assembly => assembly.GetName().Name==$"DevExpress.XtraGrid{_versionSuffix}");
CheckRequiredParameters(nameof(_xafWinAssembly), nameof(_gridViewAssembly));
return GetListViewConfiguration(predefinedMap,_xafWinAssembly, _gridViewAssembly, "DevExpress.ExpressApp.Win.Editors.GridListEditor",
PredefinedMap.GridView.GetTypeName(),PredefinedMap.GridColumn.GetTypeName() );
@@ -56,7 +56,12 @@ public static partial class TypeMappingService{
}

internal static void Init(){
var path = DesignerOnlyCalculator.IsRunFromDesigner?Path.GetTempPath():AppDomain.CurrentDomain.ApplicationPath();
var tempPath = $@"{Path.GetTempPath()}\{nameof(ModelMapperModule)}";
if (!Directory.Exists(tempPath)){
Directory.CreateDirectory(tempPath);
}

var path = DesignerOnlyCalculator.IsRunFromDesigner?tempPath:AppDomain.CurrentDomain.ApplicationPath();
_outPutAssemblyNamePattern=$"{MapperAssemblyName}{ModelMapperAssemblyName}{ModelExtendingService.Platform}";
_outputAssembly = $@"{path}\{_outPutAssemblyNamePattern}.dll";
_customizeContainerCode=new Subject<(Type type, Result<(string key, string code)> data)>();

0 comments on commit 602a5e5

Please sign in to comment.
You can’t perform that action at this time.