File Process in C - c

I wrote these codes for my project but I have error in these codes.
This function's purpose is to add new client in this file. When I process it, it's okay but if I want to see my clients from file I process search function it gets to me more than my clients like that. I tried to work it by using fscanf but when I tried it, my addition function isn't working completely because it is not read 'kisiler.iz' (means registration track).
Like that
void ekle(struct kisiyapi kisiler)
{
char secenek;
dosya=fopen("kisiler.txt","a+");
do
{
kisiler.iz=' ';
printf("Kisi no giriniz\n");
scanf("%d",&kisiler.kisino);
kaypos=(kisiler.kisino-1) * sizeof(kisiler);
fseek(dosya,kaypos,SEEK_SET);
fread(&kisiler,sizeof(kisiler),1,dosya);
if(kisiler.iz!='*')
{
printf("Kisinin adini giriniz\n");
scanf("%s",&kisiler.ad);
printf("Kisinin soyadini giriniz\n");
scanf("%s",&kisiler.soyad);
printf("Kisinin Ev Telefonunu giriniz\n");
scanf("%s",&kisiler.evtel);
printf("Kisinin Cep Telefonunu giriniz\n");
scanf("%s",&kisiler.ceptel);
printf("Kisinin Is Telefonunu giriniz\n");
scanf("%s",&kisiler.istel);
printf("Kisinin Dogum tarihini sirasiyla gun/ay/yil olarak giriniz\n");
scanf("%d",&kisiler.dogumgunu);
scanf("%d",&kisiler.dogumayi);
scanf("%d",&kisiler.dogumyili);
printf("Kisinin yasadigi Il girin\n");
scanf("%s",&kisiler.il);
printf("Kisinin yasadigi Ilce girin\n");
scanf("%s",&kisiler.ilce);
printf("Kisinin yasadigi mahalleyi girin\n");
scanf("%s",&kisiler.mahalle);
printf("Kisinin yasadigi sokak no girin\n");
scanf("%s",&kisiler.sokak);
kisiler.iz='*';
fseek(dosya,kaypos,SEEK_SET);
fwrite(&kisiler,sizeof(kisiler),1,dosya);
}
else
{
printf("Mevcut kayit var\n");
}
printf("\nTekrar ekleme yapmak istiyor musunuz ? [e veya h]");
secenek=getch();
}
while(secenek!='h');
fclose(dosya);
}
and these codes' purpose is update information of any client but it's not working because my feof loop isn't working or work forever.
Therefore, I can't update my informations.
void guncelle(struct kisiyapi kisiler)
{
char aranan[20];
int i=0;
dosya=fopen("kisiler.txt","r");
yeni=fopen("temp.txt","w");
if(dosya==NULL)
printf("Dosyaya ulasilamadi\n");
printf("Guncellemek istediginiz kisinin adini giriniz\n");
scanf("%s",aranan);
while(!feof(dosya))
{
i++;
}
/*
while(!feof(dosya))
{
fread(&kisiler,sizeof(kisiler),1,dosya);
kaypos=(kisiler.kisino-1) * sizeof(kisiler);
if(strcmp(aranan,kisiler.ad)==0)
{
printf("Kisinin adini giriniz\n");
scanf("%s",&kisiler.ad);
printf("Kisinin soyadini giriniz\n");
scanf("%s",&kisiler.soyad);
printf("Kisinin Ev Telefonunu giriniz\n");
scanf("%s",&kisiler.evtel);
printf("Kisinin Cep Telefonunu giriniz\n");
scanf("%s",&kisiler.ceptel);
printf("Kisinin Is Telefonunu giriniz\n");
scanf("%s",&kisiler.istel);
printf("Kisinin Dogum tarihini sirasiyla gun/ay/yil olarak giriniz\n");
scanf("%d",&kisiler.dogumgunu);
scanf("%d",&kisiler.dogumayi);
scanf("%d",&kisiler.dogumyili);
printf("Kisinin yasadigi Il girin\n");
scanf("%s",&kisiler.il);
printf("Kisinin yasadigi Ilce girin\n");
scanf("%s",&kisiler.ilce);
printf("Kisinin yasadigi mahalleyi girin\n");
scanf("%s",&kisiler.mahalle);
printf("Kisinin yasadigi sokak no girin\n");
scanf("%s",&kisiler.sokak);
kisiler.iz='*';
fseek(yeni,kaypos,SEEK_SET);
fprintf(dosya,"%s\t%s\t%s\t%s\t%s\t%d %d %d\t%s\t%s\t%s\t%s\t%c",kisiler.ad,kisiler.soyad,kisiler.evtel,kisiler.ceptel,kisiler.istel
,*kisiler.dogumgunu,*kisiler.dogumayi,*kisiler.dogumyili,kisiler.il,kisiler.ilce,kisiler.mahalle,kisiler.sokak,kisiler.iz);
}
else if(strcmp(aranan,kisiler.ad)!=0)
{
fseek(yeni,kaypos,SEEK_SET);
fseek(dosya,kaypos,SEEK_SET);
fwrite(&kisiler,sizeof(kisiler),1,yeni);
}
}
fclose(dosya);
fclose(yeni);
*/
}
If you understand my codes please help me I have no time to prepare it.

The "eof" flag is only set once you try to read from beyond the end of the file. Your loop doesn't read anything from the file so it will never reach the end and will continue forever.
And very much related, you should read Why is “while ( !feof (file) )” always wrong?.

Related

discord.js declaration or statement expected problem

What is wrong with this code? All the else get the problem "declaration or statement expected'. Please help me, I am new in discord.js. I needed to take all the links away to post this here.
switch(args[0]){
case 'gymlista':
const embed0 = new Discord.RichEmbed()
embed0.setTitle('Gymlista')
embed0.setColor('#0099ff')
embed0.setURL('')
embed0.setAuthor('POGO Huddinge', '')
embed0.setDescription('En karta samt lista över alla gym i Huddinges chattar. Klicka på länken ovan!')
embed0.setThumbnail('')
embed0.setTimestamp('')
embed0.setFooter('!hjälp för en lista över fler commands.', '');
msg.channel.send(embed0);
break;
case 'hjälp':
const embedh = new Discord.RichEmbed()
embedh.setTitle('Allmänt')
embedh.setColor('#0099ff')
embedh.setAuthor('POGO Huddinge', '')
embedh.setDescription('POGO HUDDINGE BOT är skapad och programmerad av #Pushos och är avsedd till Pokémon Go Huddinges discord server. Kontakta gärna mig om du har några frågor eller funderingar. :blush:')
embedh.setThumbnail('')
embedh.setTimestamp('')
embedh.setFooter('!hjälp för en lista över fler commands.', '');
embedh.addField('Version', 'v. 1.0 5');
embedh.addField('Datum skapad', '26/12 -2019')
embedh.addField('Skapad av', '#Pushos')
embedh.addField('Prefix', '!')
embedh.addField('Fungerar i (kanal)', '#botcommands')
msg.channel.send(embedh);
const embedh2 = new Discord.RichEmbed()
embedh2.setTitle('Commands')
embedh2.setColor('#0099ff')
embedh2.setAuthor('POGO Huddinge', '')
embedh2.setDescription('Nedan kommer en lista över alla commands som går att använda med denna bot. Alla commands skrivs i kanalen #botcommands med ett ! innan kommandot.')
embedh2.setThumbnail('')
embedh2.setTimestamp('')
embedh2.setFooter('!hjälp för en lista över alla commands, samt information.', '');
embedh2.addField('!hittagym <gymnamn>', 'Tar upp vägbeskrivning över gymmet du letar efter.');
embedh2.addField('!gymlista', 'Karta samt lista över alla gym i Huddinges chattar.')
msg.channel.send(embedh2);
break;
case 'hittagym':
if(args[1] === 'Asmunds'){
if(args[2] === 'häst'){
const embed = new Discord.RichEmbed()
embed.setTitle('Asmunds häst')
embed.setColor('#0099ff')
embed.setURL('')
embed.setAuthor('POGO Huddinge', '')
embed.setDescription('**EX Raid Gym**')
embed.setThumbnail('')
embed.setTimestamp('')
embed.setFooter('!hjälp för en lista över fler commands.', '');
embed.addField('Nära:', 'Fullersta gårdsväg 18');
embed.addField('Koordinater:', '59.23911, 17.97408')
embed.addField('Centrala Huddinge', '#centrala_huddinge')
msg.channel.send(embed);
}}else{
if(args[1] === 'Sjödalsparkens'){
if(args[2] === 'Utomhusscen'){
const embed2 = new Discord.RichEmbed()
embed2.setTitle('Sjödalsparkens Utomhusscen')
embed2.setColor('#0099ff')
embed2.setURL('')
embed2.setAuthor('POGO Huddinge', '')
embed2.setDescription('**Ex Raid Gym**')
embed2.setThumbnail('')
embed2.setTimestamp('')
embed2.setFooter('!hjälp för en lista över fler commands.', '');
embed2.addField('Nära:', 'Klockarvägen 2');
embed2.addField('Koordinater:', '59.23698, 17.98447')
embed2.addField('Centrala Huddinge', '#centrala_huddinge')
msg.channel.send(embed2);
}}else{
if(args[1] === 'Rådsparkens'){
if(args[2] === 'Utegym'){
const embed3 = new Discord.RichEmbed()
embed3.setTitle('Rådsparkens Utegym')
embed3.setColor('#0099ff')
embed3.setURL('')
embed3.setAuthor('POGO Huddinge', '')
embed3.setDescription('**Ex Raid Gym**')
embed3.setThumbnail('')
embed3.setTimestamp('')
embed3.setFooter('!hjälp för en lista över fler commands.', '');
embed3.addField('Nära:', 'Kommunalvägen 27A');
embed3.addField('Koordinater:', '59.23994, 17.98693')
embed3.addField('Centrala Huddinge', '#centrala_huddinge')
msg.channel.send(embed3);
}}else{
if(args[1] === 'Fullersta'){
if(args[2] === 'Bio'){
const embed4 = new Discord.RichEmbed()
embed4.setTitle('Fullersta Bio')
embed4.setColor('#0099ff')
embed4.setURL('')
embed4.setAuthor('POGO Huddinge', '')
')
embed4.setTimestamp('')
embed4.setFooter('!hjälp för en lista över fler commands.', '');
embed4.addField('Nära:', 'Norrängsvägen 1');
embed4.addField('Koordinater:', '59.24016, 17.97292')
embed4.addField('Centrala Huddinge', '#centrala_huddinge')
msg.channel.send(embed4);
}}else{
if(args[1] === 'Elhus'){
const embed5 = new Discord.RichEmbed()
embed5.setTitle('Elhus')
embed5.setColor('#0099ff')
embed5.setURL('')
embed5.setAuthor('POGO Huddinge', '')
embed5.setThumbnail('')
embed5.setTimestamp('')
embed5.setFooter('!hjälp för en lista över fler commands.', '');
embed5.addField('Nära:', 'Mossvägen 3');
embed5.addField('Koordinater:', '59.23909, 17.97096')
embed5.addField('Centrala Huddinge', '#centrala_huddinge')
msg.channel.send(embed5);
}}else{
if(args[1] === 'Rådjur'){
const embed6 = new Discord.RichEmbed()
embed6.setTitle('Rådjur')
embed6.setColor('#0099ff')
embed6.setURL('')
embed6.setAuthor('POGO Huddinge', '')
embed6.setThumbnail('')
embed6.setTimestamp('')
embed6.setFooter('!hjälp för en lista över fler commands.', '');
embed6.addField('Nära:', 'Britas gränd 8');
embed6.addField('Koordinater:', '59.23779, 17.97002')
embed6.addField('Centrala Huddinge', '#centrala_huddinge')
msg.channel.send(embed6);
}}else{
if(args[1] === 'Växthus1'){
const embed7 = new Discord.RichEmbed()
embed7.setTitle('Växthus1')
embed7.setColor('#0099ff')
embed7.setURL('')
embed7.setAuthor('POGO Huddinge', '')
')
embed7.setTimestamp('')
embed7.setFooter('!hjälp för en lista över fler commands.', '');
embed7.addField('Nära:', 'Patron Pehrs väg 5');
embed7.addField('Koordinater:', '59.23631, 17.9767')
embed7.addField('Centrala Huddinge', '#centrala_huddinge')
msg.channel.send(embed7);
}}else{
if(args[1] === 'Snäckan'){
const embed8 = new Discord.RichEmbed()
embed8.setTitle('Snäckan')
embed8.setColor('#0099ff')
embed8.setURL('')
embed8.setAuthor('POGO Huddinge', '')
embed8.setThumbnail('')
embed8.setTimestamp('')
embed8.setFooter('!hjälp för en lista över fler commands.', '');
embed8.addField('Nära:', 'Huddinge Stationsplan 2');
embed8.addField('Koordinater:', '59.23691, 17.97956')
embed8.addField('Centrala Huddinge', '#centrala_huddinge')
msg.channel.send(embed8);
}}else{
if(args[1] === 'Sälfontänen'){
const embed9 = new Discord.RichEmbed()
embed9.setTitle('Sälfontänen')
embed9.setColor('#0099ff')
embed9.setURL('')
embed9.setAuthor('POGO Huddinge', '')
embed9.setThumbnail('')
embed9.setTimestamp('')
embed9.setFooter('!hjälp för en lista över fler commands.', '');
embed9.addField('Nära:', 'Sjödalstorget 9');
embed9.addField('Koordinater:', '59.23615, 17.98252')
embed9.addField('Centrala Huddinge', '#centrala_huddinge')
msg.channel.send(embed9);
}}else{
if(args[1] === 'Mimi'){
const embed10 = new Discord.RichEmbed()
embed10.setTitle('Mimi')
embed10.setColor('#0099ff')
embed10.setURL(')
embed10.setAuthor('POGO Huddinge', '')
embed10.setThumbnail('')
embed10.setTimestamp('')
embed10.setFooter('!hjälp för en lista över fler commands.', '');
embed10.addField('Nära:', 'Sjödalsvägen 16');
embed10.addField('Koordinater:', '59.23475, 17.98312')
embed10.addField('Centrala Huddinge', '#centrala_huddinge')
msg.channel.send(embed10);
}}else{
if(args[1] === 'Stenfontän'){
const embed1 = new Discord.RichEmbed()
embed1.setTitle('Stenfontän')
embed1.setColor('#0099ff')
embed1.setURL('')
embed1.setAuthor('POGO Huddinge', '')
embed1.setThumbnail('')
embed1.setTimestamp('')
embed1.setFooter('!hjälp för en lista över fler commands.', '');
embed1.addField('Nära:', 'Gymnasietorget 5');
embed1.addField('Koordinater:', '59.24311, 17.99626')
embed1.addField('Centrala Huddinge', '#centrala_huddinge')
msg.channel.send(embed1);
}}else{
if(args[1] === 'Stenfontän3'){
}}else{
if(args[1] === 'Stenfontän4'){
}}}}
break;
case 'clear':
if(!args[1]) return msg.reply('Error please define second arg')
msg.channel.bulkDelete(args[1]);
break;
}
})
Show pls your import block
And you have SyntaxError at setAuthor block in this partt of code
if(args[1] === 'Fullersta'){
if(args[2] === 'Bio'){
const embed4 = new Discord.RichEmbed()
embed4.setTitle('Fullersta Bio')
embed4.setColor('#0099ff')
embed4.setURL('')
embed4.setAuthor('POGO Huddinge', '')
')
embed4.setTimestamp('')
embed4.setFooter('!hjälp för en lista över fler commands.', '');
embed4.addField('Nära:', 'Norrängsvägen 1');
embed4.addField('Koordinater:', '59.24016, 17.97292')
embed4.addField('Centrala Huddinge', '#centrala_huddinge')
msg.channel.send(embed4);
And this
const embed7 = new Discord.RichEmbed()
embed7.setTitle('Växthus1')
embed7.setColor('#0099ff')
embed7.setURL('')
embed7.setAuthor('POGO Huddinge', '')
')
embed7.setTimestamp('')
embed7.setFooter('!hjälp för en lista över fler commands.', '');
embed7.addField('Nära:', 'Patron Pehrs väg 5');
embed7.addField('Koordinater:', '59.23631, 17.9767')
embed7.addField('Centrala Huddinge', '#centrala_huddinge')
msg.channel.send(embed7);

Rename file Preoperation Windows Minifilter driver

I have a minifilter driver and would like to action file renames but i am unsure how to get the new file name. I would like to run the new filename through the same criteria as Creating a file - IRP_MJ_CREATE.
I currently monitor all files within the filter and move accordingly on a set of rules.
I have found a link on SO that relates to cancelling a rename, but unsure how to get the new filename.
The link is How to cancel a rename operation in minifilter driver
At this moment i can get the existing file name in case FileRenameInformation but i need to know what the new file name information is.
I have tried using :
PFILE_RENAME_INFORMATION renameInfo
Iopb->Parameters.SetFileInformation.InfoBuffer;
In the switch - FileRenameInformation, but the output is always empty.
My PreOperation callback is as follows:
FLT_PREOP_CALLBACK_STATUS PreOperationCallback(_Inout_
PFLT_CALLBACK_DATA Data,
_In_ PCFLT_RELATED_OBJECTS FltObjects,
_Flt_CompletionContext_Outptr_ PVOID* CompletionContext)
{
PFILE_RENAME_INFORMATION renameInfo;
//WCHAR buf[4096] = { 0 };
/* IRP-based I/O operation? */
if (FLT_IS_IRP_OPERATION(Data)) {
/* Open file? */
if (Data->Iopb->MajorFunction == IRP_MJ_CREATE) {
/* Open file for writing/appending? */
if (Data->Iopb->Parameters.Create.SecurityContext->DesiredAccess &
(FILE_WRITE_DATA | FILE_APPEND_DATA)) {
return process_irp(Data, FltObjects, CompletionContext, DEFERRED_IO, FALSE);
}
} else if (Data->Iopb->MajorFunction == IRP_MJ_SET_INFORMATION) {
switch (Data->Iopb->Parameters.SetFileInformation.FileInformationClass) {
case FileDispositionInformation:
if (((FILE_DISPOSITION_INFORMATION*) Data->Iopb->Parameters.SetFileInformation.InfoBuffer)->DeleteFile) {
return process_irp(Data, FltObjects, CompletionContext, FALSE, FALSE);
}
break;
case FileEndOfFileInformation:
case FileRenameInformation:
//https://stackoverflow.com/questions/40564824/how-to-cancel-a-rename-operation-in-minifilter-driver
renameInfo = Data->Iopb->Parameters.SetFileInformation.InfoBuffer;
//memcpy(buf, renameInfo->FileName, renameInfo->FileNameLength);
DbgPrint("Rename info - '%wZ'", renameInfo->FileName);
return process_irp(Data, FltObjects, CompletionContext, FALSE, TRUE);
}
}
}
return FLT_PREOP_SUCCESS_NO_CALLBACK;
}
The issue lies in the DbgPrint you need to use %ws
FLT_PREOP_CALLBACK_STATUS PreOperationCallback(_Inout_
PFLT_CALLBACK_DATA Data,
_In_ PCFLT_RELATED_OBJECTS FltObjects,
_Flt_CompletionContext_Outptr_ PVOID* CompletionContext)
{
PFILE_RENAME_INFORMATION renameInfo;
//WCHAR buf[4096] = { 0 };
/* IRP-based I/O operation? */
if (FLT_IS_IRP_OPERATION(Data)) {
/* Open file? */
if (Data->Iopb->MajorFunction == IRP_MJ_CREATE) {
/* Open file for writing/appending? */
if (Data->Iopb->Parameters.Create.SecurityContext->DesiredAccess &
(FILE_WRITE_DATA | FILE_APPEND_DATA)) {
return process_irp(Data, FltObjects, CompletionContext, DEFERRED_IO,
FALSE);
}
} else if (Data->Iopb->MajorFunction == IRP_MJ_SET_INFORMATION) {
switch (Data->Iopb->Parameters.SetFileInformation.FileInformationClass) {
case FileDispositionInformation:
if (((FILE_DISPOSITION_INFORMATION*) Data->Iopb->Parameters.SetFileInformation.InfoBuffer)->DeleteFile) {
return process_irp(Data, FltObjects, CompletionContext, FALSE, FALSE);
}
break;
case FileEndOfFileInformation:
case FileRenameInformation:
DbgPrint("Original file - '%wZ'", name_info->Name);
renameInfo = Data->Iopb->Parameters.SetFileInformation.InfoBuffer;
DbgPrint("Rename info length- '%u'", renameInfo->FileNameLength);
DbgPrint("Rename File info - '%ws'", renameInfo->FileName);
return process_irp(Data, FltObjects, CompletionContext, FALSE, TRUE);
}
}
}
return FLT_PREOP_SUCCESS_NO_CALLBACK;
}
You can call get_file_name_information to get the original file location in the code above like:
PFLT_FILE_NAME_INFORMATION name_info;
get_file_name_information(Data, &name_info);
//Release
FltReleaseFileNameInformation(name_info);
Now there is one problem the rename->FileName is in a different format to name_info->Name
The example below rename C:\temp\1.rtf to C:\temp\12.rtf
DbgPrint("Original file - '%wZ'", name_info->Name);
Will be in the format\output of:
\Device\HarddiskVolume4\Temp\1.rtf
Where as the
DbgPrint("Rename File info - '%ws'", renameInfo->FileName);
Will be in the format\output of:
\??\C:\Temp\12.rtf
BOOLEAN get_file_name_information(PFLT_CALLBACK_DATA data,
PFLT_FILE_NAME_INFORMATION* name_info)
{
/* Get name information. */
if (NT_SUCCESS(FltGetFileNameInformation(
data,
FLT_FILE_NAME_NORMALIZED |
FLT_FILE_NAME_QUERY_ALWAYS_ALLOW_CACHE_LOOKUP,
name_info
))) {
/* Parse file name information. */
if (NT_SUCCESS(FltParseFileNameInformation(*name_info))) {
return TRUE;
}
FltReleaseFileNameInformation(*name_info);
#if OSVER(NTDDI_VERSION) > NTDDI_WIN2K
} else {
/*
* We couldn't get the "normalized" name, try to get the "opened"
* name.
*/
if (NT_SUCCESS(FltGetFileNameInformation(data,
FLT_FILE_NAME_OPENED |
FLT_FILE_NAME_QUERY_ALWAYS_ALLOW_CACHE_LOOKUP,
name_info
))) {
if (NT_SUCCESS(FltParseFileNameInformation(*name_info))) {
return TRUE;
}
FltReleaseFileNameInformation(*name_info);
}
#endif /* OSVER(NTDDI_VERSION) > NTDDI_WIN2K */
}
return FALSE;
}
Not sure whether this needs to be another post on Stack overflow, but if anyone knows how to change the rename->FileName to the same format/structure as name_info->Name, can they update the answer.

Datatables change interface language

I am currently using angular-datatables.
How can I see the interface of the table in other languages?
I mean the "Show entries", "Search:", "Showing 1 to 10 of 20 entries" literals fore example in Spanish.
You need to define a language struct like this (danish implementation, what I am using in my angular-datatables apps) :
var language = {
"sEmptyTable": "Ingen tilgængelige data (prøv en anden søgning)",
"sInfo": "Viser _START_ til _END_ af _TOTAL_ rækker",
"sInfoEmpty": "Viser 0 til 0 af 0 rækker",
"sInfoFiltered": "(filtreret ud af _MAX_ rækker ialt)",
"sInfoPostFix": "",
"sInfoThousands": ",",
"sLengthMenu": "Vis _MENU_ rækker",
"sLoadingRecords": "Henter data...",
"sProcessing": "Processing...",
"sSearch": "Filter:",
"sZeroRecords": "Ingen rækker matchede filter",
"oPaginate": {
"sFirst": "Første",
"sLast": "Sidste",
"sNext": "Næste",
"sPrevious": "Forrige"
},
"oAria": {
"sSortAscending": ": activate to sort column ascending",
"sSortDescending": ": activate to sort column descending"
}
}
There is a bunch of languages here -> https://www.datatables.net/plug-ins/i18n/
And then you include the language using the withLanguage() option method
.withLanguage(language)
demo -> http://plnkr.co/edit/RCrqM3z7qwsUfFwy8HE6?p=preview
I created a .ts file like this:
export class LanguageApp {
public static spanish_datatables = {
processing: "Procesando...",
search: "Buscar:",
lengthMenu: "Mostrar _MENU_ &elementos",
info: "Mostrando desde _START_ al _END_ de _TOTAL_ elementos",
infoEmpty: "Mostrando ningún elemento.",
infoFiltered: "(filtrado _MAX_ elementos total)",
infoPostFix: "",
loadingRecords: "Cargando registros...",
zeroRecords: "No se encontraron registros",
emptyTable: "No hay datos disponibles en la tabla",
paginate: {
first: "Primero",
previous: "Anterior",
next: "Siguiente",
last: "Último"
},
aria: {
sortAscending: ": Activar para ordenar la tabla en orden ascendente",
sortDescending: ": Activar para ordenar la tabla en orden descendente"
}
}
}
Then in the component that was loading the DataTable just put that config inside dtOptions:
this.dtOptions = {
language: LanguageApp.spanish_datatables
};
In Angular2+ what worked for me is quite the same as mentioned by #davidkonrad, but without the starting letters (s and o), and adding the language as an attribute of the dtOptions. I.e.:
this.dtOptions = {
pagingType: 'full_numbers',
pageLength: 10,
dom: 'Bfrtip',
buttons: [
/*'print',
'csv'*/
],
responsive: true,
/* below is the relevant part, e.g. translated to spanish */
language: {
processing: "Procesando...",
search: "Buscar:",
lengthMenu: "Mostrar _MENU_ éléments",
info: "Mostrando desde _START_ al _END_ de _TOTAL_ elementos",
infoEmpty: "Mostrando ningún elemento.",
infoFiltered: "(filtrado _MAX_ elementos total)",
infoPostFix: "",
loadingRecords: "Cargando registros...",
zeroRecords: "No se encontraron registros",
emptyTable: "No hay datos disponibles en la tabla",
paginate: {
first: "Primero",
previous: "Anterior",
next: "Siguiente",
last: "Último"
},
aria: {
sortAscending: ": Activar para ordenar la tabla en orden ascendente",
sortDescending: ": Activar para ordenar la tabla en orden descendente"
}
}
};

EasyNetQ - how can I include the original queue name in the EasyNetQ_Default_Error_Queue message?

When using the Publisher/Subscriber pattern and an exception is throwed during a subscriber handling, EasyNetQ, by default, put a message in the EasyNetQ_Default_Error_Queue.
The problem is I only have the original exchange name in the error message. What I really need is the original queue name, so I can republish the message to the queue, not to the exchange.
How can I include the queue name in the error message?
Sample error message in the EasyNetQ_Default_Error_Queue:
{
   "RoutingKey": "",
   "Exchange": "EiHD.Application.Restaurant.Events.RestaurantDeliveryMailChanged:EiHD",
   "Exception": "System.AggregateException: Um ou mais erros. ---> System.NullReferenceException: Referência de objeto não definida para uma instância de um objeto.\r\n em EiHD.Infrastructure.Mailing.EmailSender.OnEvent(RestaurantDeliveryMailChanged evt) na d:\\Projetos\\EatInHouseDelivery\\sln\\Infrastructure\\Mailing\\EmailSender.cs:linha 136\r\n em EiHD.Infrastructure.EventDispatching.EasyNeqQEventDispatcher.<>c__DisplayClass5`1.<RegisterListener>b__4(T evt) na d:\\Projetos\\EatInHouseDelivery\\sln\\Infrastructure\\EventDispatching\\EasyNeqQEventDispatcher.cs:linha 68\r\n em EasyNetQ.RabbitBus.<>c__DisplayClass6`1.<Subscribe>b__5(T msg)\r\n --- Fim do rastreamento de pilha de exceções internas ---\r\n---> (Exceção Interna N° 0) System.NullReferenceException: Referência de objeto não definida para uma instância de um objeto.\r\n em EiHD.Infrastructure.Mailing.EmailSender.OnEvent(RestaurantDeliveryMailChanged evt) na d:\\Projetos\\EatInHouseDelivery\\sln\\Infrastructure\\Mailing\\EmailSender.cs:linha 136\r\n em EiHD.Infrastructure.EventDispatching.EasyNeqQEventDispatcher.<>c__DisplayClass5`1.<RegisterListener>b__4(T evt) na d:\\Projetos\\EatInHouseDelivery\\sln\\Infrastructure\\EventDispatching\\EasyNeqQEventDispatcher.cs:linha 68\r\n em EasyNetQ.RabbitBus.<>c__DisplayClass6`1.<Subscribe>b__5(T msg)<---\r\n",
   "Message": "{\"FromEmail\":\"someemail#gmail.com\",\"ToEmail\":\"anotheremail#gmail.com\",\"RestaurantName\":\"SomeRestaurant\"}",
   "DateTime": "2015-10-25T19:20:17.2317949Z",
   "BasicProperties": {
      "ContentType": null,
      "ContentEncoding": null,
      "Headers": {},
      "DeliveryMode": 2,
      "Priority": 0,
      "CorrelationId": "f212f734-6cd7-41fe-ac71-09335f44bb2c",
      "ReplyTo": null,
      "Expiration": null,
      "MessageId": null,
      "Timestamp": 0,
      "Type": "EiHD.Application.Restaurant.Events.RestaurantDeliveryMailChanged:EiHD",
      "UserId": null,
      "AppId": null,
      "ClusterId": null,
      "ContentTypePresent": false,
      "ContentEncodingPresent": false,
      "HeadersPresent": true,
      "DeliveryModePresent": true,
      "PriorityPresent": false,
      "CorrelationIdPresent": true,
      "ReplyToPresent": false,
      "ExpirationPresent": false,
      "MessageIdPresent": false,
      "TimestampPresent": false,
      "TypePresent": true,
      "UserIdPresent": false,
      "AppIdPresent": false,
      "ClusterIdPresent": false
   }
}
I figured out a solution.
I had to register an extended version of the DefaultConsumerErrorStrategy class to IConsumerErrorStrategy of my bus:
this.bus = RabbitHutch.CreateBus(this.connectionString, (serviceRegister) => {
serviceRegister.Register<IConsumerErrorStrategy>((sp) => new ExtendedConsumerErrorStrategy(sp.Resolve<IConnectionFactory>(), sp.Resolve<ISerializer>(), sp.Resolve<IEasyNetQLogger>(), sp.Resolve<IConventions>(), sp.Resolve<ITypeNameSerializer>()));
});
public class ExtendedConsumerErrorStrategy : DefaultConsumerErrorStrategy
{
public ExtendedConsumerErrorStrategy(IConnectionFactory connectionFactory, ISerializer serializer, IEasyNetQLogger logger, IConventions conventions, ITypeNameSerializer typeNameSerializer)
: base(connectionFactory, serializer, logger, conventions, typeNameSerializer)
{
}
public override AckStrategy HandleConsumerError(ConsumerExecutionContext context, Exception exception)
{
context.Properties.Headers.Add("OriginalQueue", context.Info.Queue);
return base.HandleConsumerError(context, exception);
}
}
Now I have the original queue name in my message Headers property. Works for me.

Cakephp Data validation - This field cannot be left blank

I'm using cakephp and I get a strange behavior with it.
Here is my validation rule in the Model:
public $validate = array(
'flyer' => array(
'rule' => array('fileValidation', 'flyer', array('image/jpeg', 'image/pjpeg'), NULL, TRUE)
)
// Other rules...
);
Here is the fileValidation method (yes I'm french =) )
public function fileValidation(array $check, $field, array $allowedMimeTypes = NULL, $maxFileSize = NULL, $allowEmpty = FALSE)
{
$file = array_shift($check);
$message = NULL;
if($file['error'] === UPLOAD_ERR_OK){
// checking uploaded file
if(empty($file['tmp_name']) || empty($file['tmp_name']) || $file['tmp_name'] === 'none' || !is_uploaded_file($file['tmp_name'])){
$message = "Une erreur est survenue lors de l'envoi du fichier, veuillez réessayer à nouveau. Si le problème persiste, merci de contacter le support technique.";
}
// checking mimeTypes if required
elseif(!empty($allowedMimeTypes) && !in_array($file['type'], $allowedMimeTypes)){
$message = "Le type de fichier envoyé n'est pas celui attendu.";
}
// checking file size if required
elseif(!empty($maxFileSize) && $file['size'] > $maxFileSize){
$message = "Le fichier envoyé est trop volumineux, réduisez sa taille et réessayez.";
}
else{
return TRUE;
}
}
elseif($file['error'] === UPLOAD_ERR_NO_FILE){
// validates if no upload is allowed
if(!$allowEmpty){
$message = "Une erreur est survenue lors de l'envoi du fichier, veuillez réessayer à nouveau. Si le problème persiste, merci de contacter le support technique.";
}
else{
return TRUE;
}
}
elseif($file['error'] === UPLOAD_ERR_INI_SIZE){
$message = "Le fichier envoyé est trop volumineux, réduisez sa taille et réessayez.";
}
elseif($file['error'] === UPLOAD_ERR_FORM_SIZE){
$message = "Le fichier envoyé est trop volumineux, réduisez sa taille et réessayez.";
}
elseif($file['error'] === UPLOAD_ERR_PARTIAL){
$message = "Une erreur est survenue lors de l'envoi du fichier, le serveur n'a reçu qu'une partie du fichier, veuillez réessayer à nouveau.";
}
elseif($file['error'] >= UPLOAD_ERR_NO_TMP_DIR){
$message = "Une erreur interne est survenue, veuillez réessayer à nouveau. Si le problème persiste, merci de contacter le support technique.";
}
// Here is the problem
$this->validationErrors[$field][] = $message;
return FALSE;
}
So far so good, my Validation rule seems to work correctly but when à get an error, I have two messages: "My custom message" and "This file cannot be left blank".
How to remove this message, where am I wrong?
Thanks in advance.
May be it will works for you
$this->validationErrors[$field][] = $message; // comment this Line
return FALSE // comment this Line
And Add the following line at last of your fileValidation function
return implode("\n", $message);
Cakephp.Saint's solution doesn't work because $message is a string, not an array but this works fine:
return $message;

Resources