Solved.
Just add "--mono:framework" in mtouch additional arguments, uncheck PNG optimization and "don't link" in the routing.
Works fine!
Hi,
this is the error ever appear when try to debug in my iPhone 6. In iOS Simulator works fine, but not in device (never run):
/Users/...................../src/GenTime.Mobile.iOS/MTOUCH: Error MT2101: Can't resolve the reference '!!0 Castle.Windsor.IWindsorContainer::Resolve(System.Object)', referenced from the method 'T Abp.Dependency.IocManager::Resolve(System.Object)' in 'Castle.Windsor, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc'. (MT2101) (GenTime.Mobile.iOS)
Working with Mac. All SDK and libraries up to date. Xamarin.Forms 3.6 Xamarin.Forms.Maps 3.6 Essentials 1.0
Any solution?
Thanks
Great It's working fine!!
Very, very thanks.
Regards
The TenantId and UserId of the AbpSession is null.
How do I inject the AbpSession?
I do the following:
private readonly IRepository<Machine> _machineRepository;
private readonly IAbpSession _session;
private readonly HubConnection _connection;
#endregion
#region "Constructor"
public SignalRExtensionAppService(
IRepository<Machine> machineRepository,
IAbpSession session,
HubConnection connection
)
{
_machineRepository = machineRepository;
_connection = connection;
_session = session;
//_sampleDbContextProvider = sampleDbContextProvider;
log = NullLogger.Instance;
InvokedOn();
}
Dto
[AutoMapTo(typeof(Machine))]
public class CreateMachineDto
{
public int? Id { get; set; }
[Required]
[StringLength(AbpTenantBase.MaxNameLength)]
public string Name { get; set; }
public string Description { get; set; }
public bool? Active { get; set; }
public int? TenantId { get; set; }
public DateTime InstallDate { get; set; }
public DateTime LastLogin { get; set; }
public DateTime? LastLogout { get; set; }
public bool? IsBlocked { get; set; }
public string ReasonIsBlocked { get; set; }
// OperatingSystem
public string OperationSystem { get; set; }
public string OSVersion { get; set; }
public string OSArchitecture { get; set; }
public string OSSerialNumber { get; set; }
public string OSLanguage { get; set; }
public string OSTotalVisibleMemorySize { get; set; }
public string OSSystemDrive { get; set; }
//ComputerSystem
public string CSNumberOfLogicalProcessors { get; set; }
public string CSManufacturer { get; set; }
public string CSModel { get; set; }
//LogicalDisk
public string LDDiskSize { get; set; }
public string LDFreeSpaceDisk { get; set; }
public DateTime? DateWasBlocked { get; set; }
public int? LicenseId { get; set; }
public CreateApplicationDto Application { get; set; }
public ICollection<TagDto> Tags { get; set; }
}
Model:
public partial class Machine : FullAuditedEntity, IMayHaveTenant
{
public Machine()
{
Events = new HashSet<Event>();
MachineAppVersions = new HashSet<MachineAppVersion>();
TagMachines = new HashSet<TagMachine>();
}
public string Name { get; set; }
public string Description { get; set; }
public bool? Active { get; set; }
public DateTime? InstallDate { get; set; }
public DateTime? LastLogin { get; set; }
public DateTime? LastLogout { get; set; }
public bool? IsBlocked { get; set; }
public string ReasonIsBlocked { get; set; }
public DateTime? DateWasBlocked { get; set; }
// OperatingSystem
public string OperationSystem { get; set; }
public string OSVersion { get; set; }
public string OSArchitecture { get; set; }
public string OSSerialNumber { get; set; }
public string OSLanguage { get; set; }
public string OSTotalVisibleMemorySize { get; set; }
public string OSSystemDrive { get; set; }
//ComputerSystem
public string CSNumberOfLogicalProcessors { get; set; }
public string CSManufacturer { get; set; }
public string CSModel { get; set; }
//LogicalDisk
public string LDDiskSize { get; set; }
public string LDFreeSpaceDisk { get; set; }
public int? TenantId { get; set; }
public int? LicenseId { get; set; }
public License License { get; set; }
public ICollection<Event> Events { get; set; }
public ICollection<MachineAppVersion> MachineAppVersions { get; set; }
public ICollection<TagMachine> TagMachines { get; set; }
}
I've tried to do it, but I don't know what I'm doing wrong.
WebHostModule
IocManager.Resolve<AppService.ISignalRExtensionAppService>();
ISignalRExtensionAppService
public interface ISignalRExtensionAppService : IApplicationService
{
Task Create(CreateMachineDto input);
}
SignalRExtensionAppService
public class SignalRExtensionAppService : ISignalRExtensionAppService
{
#region "Members"
public ILogger log { get; set; }
private readonly IDbContextProvider<GenTimeDbContext> _sampleDbContextProvider;
private readonly IRepository<Machine> _machineRepository;
private readonly HubConnection _connection;
#endregion
#region "Constructor"
public SignalRExtensionAppService(
IRepository<Machine> machineRepository,
IDbContextProvider<GenTimeDbContext> sampleDbContextProvider,
HubConnection connection
)
{
_machineRepository = machineRepository;
_connection = connection;
_sampleDbContextProvider = sampleDbContextProvider;
log = NullLogger.Instance;
InvokedOn();
}
#endregion
#region "Private Method"
#region "SignalR"
private async Task InvokedOn()
{
_connection.On<string, string, string, int>("GetMessage", (from, to, message, type) =>
{
Task.Run(async () =>
{
var newMessage = $"{"SIG"}: {message}";
log.Info(newMessage);
Recieve_SendMessageToUser(from, to, message, type);
});
});
}
private async Task Recieve_SendMessageToUser(string from, string to, string message, int type)
{
string action = message.Split('@')[0];
switch (action)
{
case "ActualizeRegisterDB":
ActualizeRegisterDB(message.Split('@')[1], message.Split('@')[2], message);
break;
default:
break;
}
}
private async Task ActualizeRegisterDB(string machineName, string tenant, string message)
{
int tenantId = 0;
try
{
var lastLogin = DateTime.ParseExact(message.Split('@')[3], "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
var lastLogout = DateTime.ParseExact(message.Split('@')[4], "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
int.TryParse(message.Split('@')[2], out tenantId);
CreateMachineDto createMachine = new CreateMachineDto()
{
Name = message.Split('@')[1],
LastLogin = lastLogin,
LastLogout = lastLogout,
TenantId = tenantId
};
await Create(createMachine);
}
catch (Exception ex)
{
log.Error(ex.Message, ex);
}
}
#endregion
#endregion
#region "Interface Implementation Method"
public async Task Create(CreateMachineDto input)
{
try
{
log.Debug(string.Format("Machine: {0} with TenantId is {1} send: {2} - {3}", input.Name, input.TenantId, input.LastLogin, input.LastLogin));
var machine = _machineRepository.GetAll().Where(x => x.Name == input.Name && x.TenantId == input.TenantId).FirstOrDefault();
machine.LastLogin = input.LastLogin;
machine.LastLogout = input.LastLogout;
await _machineRepository.InsertOrUpdateAsync(machine);
}
catch (Exception ex)
{
log.Error(ex.Message, ex);
}
}
#endregion
}
SignalR events arrive without problem. But when the "Create" is done, I have the following error:
Cannot access a disposed object. A common cause of this error is disposing a context that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling Dispose() on the context, or wrapping the context in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances. Object name: 'GenTimeDbContext'.
Thanks for all
Regards
Ok thanks... I try it
How can I call AppService from the beginning? How can I do it from the Web.Host?
Startup
services.AddSignalR(_appConfiguration);
Static Class
public static class SignalRExtension
{
private const string WEBAPI = "!GSSYSTEM_WAPI";
private static SignalRExtensionAppService _signalRExtensionAppService;
private static IRepository<Machine> _machineRepository;
public static void AddSignalR(this IServiceCollection services, IConfiguration configuration)
{
var url = configuration["SignalR:Url"];
//_signalRExtensionAppService = signalRExtensionAppService;
//_machineRepository = machineRepository;
HubConnection connection = null;
connection = new HubConnectionBuilder()
.WithUrl(url)
.Build();
connection.On<string, string, string, int>("GetMessage", (from, to, message, type) =>
{
Task.Run(async () =>
{
var newMessage = $"{"SIG"}: {message}";
//log.Info(newMessage);
//Console.WriteLine(newMessage);
Recieve_SendMessageToUser(from, to, message, type);
});
});
connection.Closed += async (error) =>
{
await Task.Delay(new Random().Next(0, 5) * 1000);
await connection.StartAsync();
connection.InvokeAsync<string>("JoinGroup", "monitor", WEBAPI, "1");
};
connection.StartAsync();
connection.InvokeAsync<string>("JoinGroup", "monitor", WEBAPI, "1");
services.AddSingleton(connection);
}
public static void Recieve_SendMessageToUser(string from, string to, string message, int type)
{
string action = message.Split('@')[0];
switch (action)
{
case "ActualizeRegisterDB":
ActualizeRegisterDB(message.Split('@')[1], message.Split('@')[2], message);
break;
default:
break;
}
}
private static async Task ActualizeRegisterDB(string machineName, string tenant, string message)
{
int tenantId = 0;
try
{
var lastLogin = DateTime.ParseExact(message.Split('@')[3], "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
var lastLogout = DateTime.ParseExact(message.Split('@')[4], "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
int.TryParse(message.Split('@')[2], out tenantId);
CreateMachineDto createMachine = new CreateMachineDto()
{
Name = message.Split('@')[1],
LastLogin = lastLogin,
LastLogout = lastLogout,
TenantId = tenantId
};
//Call to SignalRExtensionAppService
}
catch (Exception ex)
{
throw;
}
}
}
AppService
[AbpAuthorize(AppPermissions.Pages_Administration_Users)]
public class MachineAppService : AsyncCrudAppService<Machine, MachineDto, int, ControllerInputDto, CreateMachineDto, UpdateMachineDto>, IMachineAppService
{
#region "Members"
public ILogger log { get; set; }
private readonly IRepository<Application> _applicationRepository;
private readonly IRepository<Machine> _machineRepository;
private readonly IRepository<AppVersion> _appVersionRepository;
private readonly IRepository<Tag> _tagRepository;
private readonly IRepository<License> _licenseRepository;
private readonly IRepository<Tenant> _tenantRepository;
private readonly IRepository<AppVendor> _appVendorRepository;
private readonly IRepository<Active> _activeRepository;
private readonly IRepository<SamAudit> _samAuditRepository;
private readonly IRepository<ProductGroup> _productGroupRepository;
private readonly IObjectMapper _objectMapper;
private readonly HubConnection _connection;
private readonly IFileProvider _fileProvider;
#endregion
#region "Constructor"
public MachineAppService(
IRepository<Machine> machineRepository,
IRepository<Application> applicationRepository,
IRepository<AppVersion> appVersionRepository,
IRepository<Tag> tagRepository,
IRepository<License> licenseRepository,
IRepository<Tenant> tenantRepository,
IRepository<AppVendor> appVendorRepository,
IRepository<Active> activeRepository,
IRepository<SamAudit> samAuditRepository,
IRepository<ProductGroup> productGroupRepository,
IObjectMapper objectMapper,
HubConnection connection,
IFileProvider fileProvider
) : base(machineRepository)
{
_applicationRepository = applicationRepository;
_machineRepository = machineRepository;
_appVersionRepository = appVersionRepository;
_tagRepository = tagRepository;
_licenseRepository = licenseRepository;
_tenantRepository = tenantRepository;
_appVendorRepository = appVendorRepository;
_activeRepository = activeRepository;
_samAuditRepository = samAuditRepository;
_productGroupRepository = productGroupRepository;
_objectMapper = objectMapper;
_connection = connection;
_fileProvider = fileProvider;
log = NullLogger.Instance;
}
#endregion
#region "Calls to SignalR"
public async Task UpdateSigToMachine(List<UpdateMachineDto> input)
{
// signal => SIG_SHUTDOWN / SIG_STARTUP
var tenantId = AbpSession.TenantId;
try
{
var machines = (from a in input
select a);
foreach (var item in machines)
{
var signal = item.Active == true ? "SIG_STARTUP" : "SIG_SHUTDOWN";
await Update(item);
await _connection.InvokeAsync("SendSIGToMachine", item.Name, signal, tenantId.ToString());
}
return;
}
catch (Exception ex)
{
log.Error(ex.Message, ex);
return;
}
}
public async Task UpdateSigToAll(string signal)
{
var tenantId = AbpSession.TenantId;
//int tenantId = 0;
//int.TryParse(TenantId, out tenantId);
// signal => SIG_SHUTDOWN / SIG_STARTUP
bool recibeSignal = signal == "SIG_SHUTDOWN" ? false : true;
await _connection.InvokeAsync("SendSIGToEverybody", tenantId, signal);
try
{
//var allMachines = _machineRepository.GetAll()
// .Where(x => x.TenantId == tenantId);
var allMachines = _machineRepository.Query(a => a.Where(x => x.TenantId == tenantId));
foreach (var machine in allMachines)
{
if (recibeSignal)
machine.LastLogin = DateTime.Now;
else
machine.LastLogout = DateTime.Now;
machine.Active = recibeSignal;
_machineRepository.InsertOrUpdate(machine);
}
}
catch (Exception ex)
{
log.Error(ex.Message, ex);
}
}
//[AbpAllowAnonymousAttribute]
[AbpAuthorize(AppPermissions.Pages_Administration_Users)]
public async Task<List<string>> GetSignalRConnections()
{
return await _connection.InvokeAsync<List<string>>("GetConnectedUsers");
}
//[AbpAllowAnonymousAttribute]
[AbpAuthorize(AppPermissions.Pages_Administration_Users)]
public async Task<List<string>> GetSignalRMachineConnections()
{
var tenantId = AbpSession.TenantId;
return await _connection.InvokeAsync<List<string>>("GetConnectedMachines", tenantId);
}
//[AbpAllowAnonymousAttribute]
[AbpAuthorize(AppPermissions.Pages_Administration_Users)]
public async Task<List<string>> GetAvailableApplicationsLogs(string machineName)
{
var tenantId = AbpSession.TenantId;
return await _connection.InvokeAsync<List<string>>("GetAvailableApplicationsLogs", machineName, tenantId);
}
//[AbpAllowAnonymousAttribute]
[AbpAuthorize(AppPermissions.Pages_Administration_Users)]
public async Task<IActionResult> GetServiceLog(string machineName, string serviceName)
{
var tenantId = AbpSession.TenantId;
var pathlog = await _connection.InvokeAsync<string>("GetServiceLog", machineName, tenantId, serviceName);
FileStreamingAppService fileStreamingAppService = new FileStreamingAppService(_fileProvider);
return await fileStreamingAppService.DownloadFile(pathlog.Split("@")[1]);
}
//[AbpAllowAnonymousAttribute]
[AbpAuthorize(AppPermissions.Pages_Administration_Users)]
public async Task UpdateApplicationsLogLevel(string machineName, string logLevel)
{
var tenantId = AbpSession.TenantId;
await _connection.InvokeAsync<List<string>>("SendUpdateApplicationsLogLevel", machineName, logLevel, tenantId);
}
#endregion