static class on .web project silverlight - wcf

I have been having a problem for a long time , but so far have not got a solution and I hope you can help me .
I have a Silverlight application where I use WCF for queries to retrieve information from the database and also for the communication between client ( Duplex ) and Socket (receive and send information between my application and others).
To control Duplex , when the client accesses a specific module of my application , I link that customer to a static class that I have on my Projeto.Web ( Application start ) , as in the code below :
//static Class
public static class ncClientes
{
private static List<IncServicoDuplex> clientesSupRecAlarme = new List<IncServicoDuplex>();
public static List<IncServicoDuplex> ClientesSupRecAlarme
{
get { return ncClientes.clientesSupRecAlarme; }
set { ncClientes.clientesSupRecAlarme = value; }
}
}
//Método chamado pelo WCF quando o cliente acessa o módulo
public void VinculaCliente(string strProjeto)
{
//GetCallbackChannel - obter o canal de comunicação entre o serviço e o cliente - retornará a instância do canal entre o serviço e o cliente.
IncServicoDuplex cliente = OperationContext.Current.GetCallbackChannel<IncServicoDuplex>();
//A palavra-chave lock marca um bloqueio de instruções como uma seção crítica, obter o bloqueio de exclusão de mútua para um determinado objeto,
//executar uma instrução e, em seguida, liberar o bloqueio.
switch (strProjeto)
{
case "ncPrincipal|Alarme":
case "ncAlarme":
case "ncConfiguracao|Supervisao":
lock (ncClientes.ClientesSupRecAlarme)
{
ncClientes.ClientesSupRecAlarme.Add(cliente);
}
break;
}
}
When I make a change to the database , all of my online customers who are at the receiving module that change the WCF service , use the following code :
//Método no meu WCF que transmite a informação de alteração, inclusão ou exclusão de um cliente para os outros
public void SupervisaoAlarmeOnline(ncAlarme objAlarme)
{
var varClientesAlarme = new List<IncServicoDuplex>(ncClientes.ClientesSupRecAlarme);
foreach (var item in varClientesAlarme)
{
try
{
item.SupervisaoAlarmeOnlineRetorno(objAlarme);
}
catch
{
ncClientes.ClientesSupRecAlarme.Remove(item);
}
}
}
My problem happens when I get some information by Socket ( class located in projeto.Web ) that creates an instance of my ServicoWCF and call the method to send the received information to clients. Apparently, my static variable is being reset when called on this side of the application.
Is there any difference on " which side " I call the service ? When I call it on WCF client side my static variable gets the correct count , but when I call it on the Socket class , count is set to 0.
I hope you can help me , I tried to be as clear as possible , if there is any doubt please let me know.
Thanks in advance !

Related

Diplay loading indicator for FullCalendar and Vuejs

is there a way to display a loading indicator on FullCalendar 5 and VueJS ?
https://fullcalendar.io/docs/loading
I checked the documentation and it states it works via AJAX request, but don't say anything about other technologies.
Is there any way to have something similar and easy to implement ?
Regards.
When i get my agendas entries, i update my calendars with the events.
entreesAgenda() {
// Ajout des evenements dans le(s) calendrier(s)
let entrees = []
if (this.entreesAgenda) {
for (let i = 0; i < this.utilisateurs.length; i++) {
entrees = this.data.items.filter(
(f) => f.idPersonnel === this.utilisateurs[i].id
)
// Mise à jour des businessHours
this.$refs.utilisateur[i]
.getApi()
.setOption('businessHours', this.calculBusinessHours(entrees))
// Insertion des entrees d'agenda dans le calendrier
for (let m = 0; m < entrees.length; m++) {
this.$refs.utilisateur[i].getApi().addEvent(entrees[m])
}
}
}
this.updateView()
},
But i don't know how to use the loading.

Plc4x addressing system

I am discovering the Plc4x java implementation which seems to be of great interest in our field. But the youth of the project and the documentation makes us hesitate. I have been able to implement the basic hello world for reading out of our PLCs, but I was unable to write. I could not find how the addresses are handled and what the maskwrite, andMask and orMask fields mean.
Please can somebody explain to me the following example and detail how the addresses should be used?
#Test
void testWriteToPlc() {
// Establish a connection to the plc using the url provided as first argument
try( PlcConnection plcConnection = new PlcDriverManager().getConnection( "modbus:tcp://1.1.2.1" ) ){
// Create a new read request:
// - Give the single item requested the alias name "value"
var builder = plcConnection.writeRequestBuilder();
builder.addItem( "value-" + 1, "maskwrite:1[1]/2/3", 2 );
var writeRequest = builder.build();
LOGGER.info( "Synchronous request ..." );
var syncResponse = writeRequest.execute().get();
}catch(Exception e){
e.printStackTrace();
}
}
I have used PLC4x for writing using the modbus driver with success. Here is some sample code I am using:
public static void writePlc4x(ProtocolConnection connection, String registerName, byte[] writeRegister, int offset)
throws InterruptedException {
// modbus write works ok writing one record per request/item
int size = 1;
PlcWriteRequest.Builder writeBuilder = connection.writeRequestBuilder();
if (writeRegister.length == 2) {
writeBuilder.addItem(registerName, "register:" + offset + "[" + size + "]", writeRegister);
}
...
PlcWriteRequest request = writeBuilder.build();
request.execute().whenComplete((writeResponse, error) -> {
assertNotNull(writeResponse);
});
Thread.sleep((long) (sleepWait4Write * writeRegister.length * 1000));
}
In the case of modbus writing there is an issue regarding the return of the writer Future, but the write is done. In the modbus use case I don't need any mask stuff.

optaplanner can't find annotated planning varible

I want to delete or add some ProblemFacts to the solver while the solver solve my patient admission solution.
In the documentation from optaplanner I can add about solver.addProblemFactChange some ProblemFacs, but it doesn't work in my PAS example.
Here is a snippet of my code of PatientAdmissionScheduleGenerator
public void addBedDesignation(final BedDesignation bedDesignation){
this.solver.addProblemFactChange(scoreDirector -> {
PatientAdmissionScheduleSolution patientAdmissionScheduleSolution = scoreDirector.getWorkingSolution();
patientAdmissionScheduleSolution.getBedDesignationList().add(bedDesignation);
});
}
public void deleteBedDesignation(final BedDesignation bedDesignation){
// Neues Problem dem Solver zuführen
this.solver.addProblemFactChange(scoreDirector -> {
// Erstelle eine neue PAS-Solution auf Basis der gerade läuft
PatientAdmissionScheduleSolution patientAdmissionScheduleSolution = scoreDirector.getWorkingSolution();
// Erstelle eine neue Bettzuweisung auf Basis der
BedDesignation workingBedDesignation = scoreDirector.lookUpWorkingObject(bedDesignation);
for(BedDesignation designation : patientAdmissionScheduleSolution.getBedDesignationList()){
if(designation.equals(bedDesignation)){
scoreDirector.beforeVariableChanged(designation, "Bed");
designation = null;
scoreDirector.afterVariableChanged(designation,"Bed");
}
}
ArrayList<BedDesignation> bedDesignationArrayList = new ArrayList<>(patientAdmissionScheduleSolution.getBedDesignationList());
patientAdmissionScheduleSolution.setBedDesignationList(bedDesignationArrayList);
scoreDirector.beforeProblemFactRemoved(workingBedDesignation);
bedDesignationArrayList.remove(workingBedDesignation);
scoreDirector.afterProblemFactRemoved(workingBedDesignation);
scoreDirector.triggerVariableListeners();
});
}
Here is a snippet of my changed Object BedDesignation
#PlanningVariable(nullable = true, valueRangeProviderRefs = {"bedRange"}, strengthComparatorClass = BedStrengthComparator.class)
public Bed getBed() {
return bed;
}
An here is my error message when I want to delete a BedDesignation Object
Exception in thread "main" java.lang.IllegalArgumentException: The variableName (Bed) for entityClass (class pas.entity.domain.BedDesignation) exists as a property (getter/setter) on that class, but not as an annotated as a planning variable.
Check if your planning entity's getter has the annotation PlanningVariable (or a shadow variable annotation).
I have annotated bed as PlanningVariable. What is wrong?
The error message is blaming the wrong reason. I created a jira.
Use "bed" instead of "Bed".

How can i display multiple views with ModuleFrontController in PS 1.6

With my Module Front Controller, i need to initialize it to display a form (formulaire.tpl) that the customer has to fill. Then the controller processes the data posted from the form using methods defines in my model (Formulaire.php) and then i would like to make it display another view (recapitulatif.tpl) that displays a reminder of data sent, an add to cart button for example or the possibility to fill the form in again.
As i would like to implement it the MVC way, i don't want to create a new php page to redirect my customer to but i would like to display somehow this second template after processing the data. Is there any way to do so with the controller? Here below, you can find my code, it doesn't work and it displays my first template and below my second..
class FormulaireModuleDefaultModuleFrontController extends ModuleFrontController
{
public $ssl = true;
private $done_traitement = false;
public function postProcess()
{
//On vérifie le bouton submit du formulaire
if(Tools::isSubmit('bouton'))
{
// On va commencer en premier par récupérer l'id customer avec la variable cookie
// et vérifier que la personnes est bien loggée
global $cookie;
if(!isset($cookie->id_customer))
{
$message='Aucun client loggé';
}
else
{
$errors=array();
$id_cart=$this->context->cart->id;
$customer=$cookie->id_customer;
//On récupère les valeurs du formulaire
$prix=Tools::getValue('resultat');
$titre='porte_test';
$desc='Largeur de passage de '.Tools::getValue('largeur_passage').' mm, hauteur de passage de '.Tools::getValue('hauteur_passage')
.' mm, hauteur de linteau de '.Tools::getValue('hauteur_linteau').' mm, ecoinçon gauche de '.Tools::getValue('ecoincon_gauche')
.' mm, ecoincon_droit de '.Tools::getValue('ecoincon_droit'). ' mm, motif en '.Tools::getValue('motif_porte').' et de couleur '
.Tools::getValue('couleur_porte');
//On va vérifier les champs obligatoires
//Les champs sont remplis, on va faire le traitement des données.
$idprod=Formulaire::creerProduct($titre,0,13,$prix,$desc, 'mod_100',$customer);
Formulaire::addProduitauPanier($idprod);
$this->done_traitement=true;
}
//On envoie le message si il existe:
if(isset($message))self::$smarty->assign('message',$message);
if(isset($errors))self::$smarty->assign('erreurs',$errors);
}
}
public function initContent()
{
parent::initContent();
if($this->done_traitement)
$this->display(__FILE__,'recapitulatif.tpl');
}
public function init(){
$this->display_column_left = false;
$this->display_column_right = false;
$this->page_name = 'Configurateur';
parent::init();
$this->setTemplate('formulaire.tpl');
}
}
Thanks in advance for your help !
EDIT :
Ok sorry for the question. It just took me 2 minutes to figure it out after posting the question. I only needed to change:
$this->display(__FILE__,'recapitulatif.tpl');
by :
$this->setTemplate('recapitulatif.tpl');
And now it works. Sorry for the inconvenience !

SharpArch.Data.NHibernate.Repository.SaveOrUpdate() don't save

I have this code for filling DB, but after finish, DB is still empty. Only number in hibernate_unique_key table is higher.
The next thing which is interesting is, that during debugging instances has id, after save, but not like 1,2,3... but very high like 60083, 60084, ... etc. (It not seems normal, because there is only several rows for save).
Before that, there was some problems with references and so on, but now there is no error message or exception.
code is there:
using System;
using NHibernate.Cfg;
using SharpArch.Data.NHibernate;
using LaboratorniMetody.Data.NHibernateMaps;
using SharpArch.Core.PersistenceSupport;
using LaboratorniMetody.Core;
namespace LaboratorniMetody.FillSchema
{
class Program
{
private static Configuration configuration;
static void Main(string[] args)
{
configuration = NHibernateSession.Init(new SimpleSessionStorage(), new String[] { "LaboratorniMetody.Data" },
new AutoPersistenceModelGenerator().Generate(),
"../../../../app/LaboratorniMetody.Web/NHibernate.config");
IRepository<Laboratory> LaboratoryRepository = new Repository<Laboratory>();
Laboratory Laboratory1 = new Laboratory() { Name = "Hematologie" };//Method
Laboratory l = LaboratoryRepository.SaveOrUpdate(Laboratory1);
Laboratory Laboratory2 = new Laboratory() { Name = "Patologie" };//Method
LaboratoryRepository.SaveOrUpdate(Laboratory2);
Laboratory Laboratory3 = new Laboratory() { Name = "Laboratoře" };//Method
LaboratoryRepository.SaveOrUpdate(Laboratory3);
}
}
}
I use DB schema genereted by NUnit from Project.Core classes.
Do you have any ideas where i should find problem? I have 2 very similar project which working with no problem. I Copyed this code from one of them and there is practicly no differents (except DB model and so on.)
You need to do your changes in a transaction and commit the transaction afterwards.
using(var tx = NHibernateSession.Current.BeginTransaction())
{
IRepository<Laboratory> LaboratoryRepository = new Repository<Laboratory>();
Laboratory Laboratory1 = new Laboratory() { Name = "Hematologie" };//Method
Laboratory l = LaboratoryRepository.SaveOrUpdate(Laboratory1);
Laboratory Laboratory2 = new Laboratory() { Name = "Patologie" };//Method
LaboratoryRepository.SaveOrUpdate(Laboratory2);
Laboratory Laboratory3 = new Laboratory() { Name = "Laboratoře" };//Method
LaboratoryRepository.SaveOrUpdate(Laboratory3);
tx.Commit();
}
I advise to look at the SharpArchContrib project wiki, which has some samples on using SharpArch in a windows app/service and how to use Transaction attributes from there.
https://github.com/sharparchitecture/Sharp-Architecture-Contrib/wiki/