Archive

Posts Tagged ‘HowTo’

HowTo: change color of validation messages in ASP.net MVC

If you need to customize the colors (or do more restyling) of validation messages in ASP.net MVC, the following snippet from a discussion on ASP.net forums should be useful:

Add to Content/Site.css:

/* styles for validation helpers */

.field-validation-error {
    color: #b94a48;
}

.field-validation-valid {
    display: none;
}

input.input-validation-error {
    border: 1px solid #b94a48;
}

select.input-validation-error {
    border: 1px solid #b94a48;
}

input[type="checkbox"].input-validation-error {
    border: 0 none;
}

.validation-summary-errors {
    color: #b94a48;
}

.validation-summary-valid {
    display: none;
}

Other useful replies from there:

@Html.ValidationSummary(true,"",new {@style= "color: red"})

The method for MVC 5 + Bootstrap is:
@Html.ValidationSummary(true, "", new { @class = "text-danger" })

Advertisements

HowTo: Fix DVD/CD with Live filesystem (Packet/UDF) on Windows

The other day I found how easy it is to use a Live CD/DVD (where packet writing occurs when adding stuff) instead of a Mastered one (where all is kept to be written when you close the disk) on Windows.

It feels more like using a USB flash disk and should be more safe regarding losing data in the long run if you want to keep some file archive. In theory at least, since there are cases the live disk last write operation may fail and it may appear as an unreadable disk after one, making funny noises when you insert it and freezing for long time periods Windows Explorer when you try to access it.

However, the UDF filesystem that it uses keeps multiple VAT tables for the blocks written to the disk, which means it can be restored to the last workable state of the disk (you might still lose data from the last block I guess, but you’ll have access to the rest of the files you had written to the disk). For any files you find missing, you can try file recovery software with deep search option, like ISOBuster.

To restore such a disk back to working state, on Windows 10 you can right click the Start menu button and from the context (popup) menu shown, you can select to run PowerShell as Administrator. Then you can write CMD and press ENTER. The classic command-line shell (DOS syntax) will open up, where you should type-in chkdsk /f e: (replacing e: with the letter of the drive where the problematic disk has been inserted – can find that one easily from Windows Explorer / My Computer) and press ENTER again.

The disk should be detected as being of UDF format and the disk checking (chkdsk) command will check for a valid VAT on the last written block and if it can’t will try to revert the media to a previous state, before the corruption occurred by placing at the the end of the disk the last valid VAT.

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

PS C:\WINDOWS\system32> cmd
Microsoft Windows [Version 10.0.17134.165]
(c) 2018 Microsoft Corporation. Με επιφύλαξη κάθε νόμιμου δικαιώματος.

C:\WINDOWS\system32>chkdsk /f e:
The type of the file system is UDF.
Volume Μουσική is UDF version 2.01.

Chkdsk is running on media that does not support writes in place.
On such media chkdsk operation is limited to verifying the presence
of a valid VAT on the last written block and if necessary searching
for the last valid VAT and placing it at the end of the disk.
This could revert the media to a previous state before the corruption
occured.

Chkdsk could not find a valid VAT at the end of the volume.

CHKDSK is searching for a valid VAT …

And after some ages (stayed at 0% for some time and then took around a day progressing slowly on my machine for a DVD) you’ll hopefully see something like:

Search for VAT completed.
Chkdsk is copying last valid VAT at block 1722719 to the end of the
volume. This will revert the volume to its state at 01:13 on
10/09/2018.

Windows has made corrections to the file system.
No further action is required.

   4595200 KB total disk space.
    222240 KB available on disk.

      2048 bytes in each allocation unit.
   2297600 total allocation units on disk.
    111120 allocation units available on disk.

Then type exit followed by ENTER key twice to exit the command processor (cmd) and PowerShell. This will close the console window.

C:\WINDOWS\system32>exit
PS C:\WINDOWS\system32> exit

Enjoy your disk with its files again, hopefully all of them… Plus you’ll be able to add more files to the disk, which could have even been near to empty when the corruption had occurred. Note that when you’re finished and don’t want to write anymore files to the disk, you can right click it and close the session, so that it can be readable on more systems.

HowTo: include MVC model property Display name in Required validation message

Just came across this validation error display in an MVC app I’ve recently started maintaining. The required input field validation seemed to not be localized, resulting in a mixed English and Greek (from the field’s Display name) message:

image

Looking at the MVC model I noticed they were using [Required] attributes for the userName and password properties, together with [Display(Name = "…")] for the displayed property title

public class LoginModel
  {
     [Required]
     [Display(Name = "Όνομα Χρήστη")]
     public string userName { get; set; }

     [Required]
     [DataType(DataType.Password)]
     [Display(Name = "Κωδικός")]
     public string password { get; set; }

     //…

That was changed to:

public class LoginModel
  {
     [Required(ErrorMessage = "Το {0} είναι απαραίτητο.")]
     [Display(Name = "Όνομα Χρήστη")]
     public string userName { get; set; }

     [Required(ErrorMessage = "Το {0} είναι απαραίτητο.")]
     [DataType(DataType.Password)]
     [Display(Name = "Κωδικός")]
     public string password { get; set; }

resulting in a fully localized validation error message with the respective property’s Display name auto-inserted in the validation ErrorMessage, thanks to the {0} used in the message string:

image

Note there’s also the lazy route like in this property:

[Display(Name = "Περίοδος Εγγύησης(Έτη):")]
[Required(ErrorMessage = "Απαραίτητο πεδίο")]
public int warrantyPeriod { get; set; }

where you just say something like “Required field” in the localized error message. This however will work only when you always show the error message next to the input field that fails to pass validation.

If you want to also show a validation summary say at the beginning and/or the end of the page (depending on where your submit button is), you’ll end up with an error summary that may just contain multiple entries of “Required field” text without any indication on what field it was (which would be practically useless that is).

Note that sometimes due to lack of space in a webpage (say if you have lots of input fields in a grid) you can only show say red “*” near input fields that have validation errors and explain them more in the tooltips and in an error summary control.

Even better you can use resource strings to avoid error message string duplication. That approach, though a bit more verbose as implemented in ASP.net means easier centralized maintenance and localization from a per locale/language resource file and less typos or slightly different error messages for the same thing. See example and related screenshots at https://stackoverflow.com/a/22849638

HowTo: Download and install Windows Live Movie Maker

Unfortunately, Microsoft seems to have gone to extra lenghts to make the Windows Live suite of software go away, without anyone thinking that there were people who were using them and without offering file/project-level compatible replacements for user-friendly tools like Windows Live Movie Maker.

Only Windows Live Writer was at some point reincarnated as the Open Live Writer opensource software at http://openlivewriter.org/. Hope Microsoft will do the same at some point (some community pressure and offer for opensource work on it would help of course) with Windows Live Movie Maker at least. I’ve seen that one used by educators since it’s very user friendly. It is a pitty to force them to throw away their older student projects when they get a new machine (I’m not aware of any video editing tool that can import Windows Live Movie Maker’s XML-based project file [.wlmp]).

Luckily, people have managed to locate the latest archived versions of the offline software installers (obviously the web installers won’t work anymore) for various languages (need to pick the same language as the one your OS UI is displaying in) at the Internet Wayback Machine (arthive.org) website.

Copy-pasting the links (they point to archived versions at archive.org) for the latest version released (build 16.4.3528.0331, April 17, 2014) below (in case Microsoft decides to make that discussion thread disappear too in the future) from:

https://answers.microsoft.com/en-us/windowslive/forum/moviemaker-wlinstall/what-to-do-before-movie-maker-goes-away-jan-10/8b3a5345-7840-4a2c-922a-cf24d10771f7?page=2&msgId=7fbd8015-d7af-44ed-b81d-0d73e8abac45

as posted by the user “considerate_guy

updated links to the Archive.org copies of the *latest* versions (build 16.4.3528.0331)

HowTo: Install Skype desktop on Windows 10 (for older webcams)

On Windows 10, Microsoft (they’ve acquired Skype some years ago) provide a Windows Store app for Skype, however Universal Windows Platform (UWP) apps like that one don’t support older webcams (even the ones embedded in not-that-old laptops).

Unfortunately, Microsoft hasn’t bothered to provide some frame grabber driver to bridge with DirectShow-based etc. older webcams that would allow modern UWP apps to work with such older webcams that do function fine with classic (Win32) applications, provided their classic Windows drivers are installed.

What’s worse though is that although Skype provides a Windows desktop application download at their website (https://www.skype.com/en/get-skype/), when that one is launched on Windows 10 (probably that is the can on Windows 8 too), it just shows a message that one should use the respective Store app and takes one to the respective Windows Store webpage. They haven’t bothered to consider all those users that don’t have a supported webcam on UWP and force them to move to the Skype UWP-based Store app. Note that they could have placed the classic (Win32) Skype application on the Windows Store too (which now supports deployment of such applications via a technology called Desktop Bridge), but I don’t think they’ve considered providing that option to the user either.

So a workarround I had to do on my laptop was to trick their desktop application installer into thinking it was running on Windows 7. To achieve this can right click the .exe file of the installer and select “Properties” (should be the last option at the popup menu shown).

Στιγμιότυπο οθόνης (1992)

Then, from the “Compatibility” tab select to run in compatibility mode for “Windows 7”. Press OK to close the dialog and just run the installer again, this time it will proceed fine to install the desktop application for Skype which should work with your older webcam, provided you’ve installed the camera drivers at your system. If it still doesn’t work, checkout the webcam diagnostics tool from http://noeld.com/programs.asp?cat=video (and also try webcam with the classic Win32 AMCap application provided there to see if it does show a video feed or not).

image

HowTo: open older Pi SD card via USB multi-reader on Raspberry Pi

After doing

sudo apt-get update

sudo apt-get upgrade

on an older Raspbian installation (at a 4GB SD Card), some corruption occured (probably due to lack of space, since I see newer NOOBS asks for an 8GB SD Card), making it unbootable. Would only show the NOOBS splash screen, but couldn’t boot into Raspbian.

I just needed some audio files from the desktop of that older installation (it was an unattended looping audio player for an art installation).

So I prepared a new SD Card with the free SD Card Formatter utility and put the latest NOOBS files in it. Booted the Raspberry Pi 2 with it and installed the latest Raspbian OS (full) from the menus. This time doing again the above two commands from a terminal and rebooting didn’t cause any problem.

However, I was searching for the files and couldn’t find them. I had gotten a bit confused at first, since when plugging in the reader it would show a dialog asking whether I wanted to open a file explorer, but then it would keep that dialog again and repeat the action till I closed the dialog. Then I read

…in Linux when there are more slots in a card reader, only the one labelled LUN 0 is read unless other tools are installed to read the other luns. If your SD slot is not LUN 0, then the SD card will not be seen.There are a lot of pages on web about this, I will be installing a package called sg3-utils that is supposed to enable reading other card reader slots.

at this thread https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=11397 and just in case I did:

sudo apt-get install sg3-utils

from a terminal and then tried plugging in again the USB card reader with the older SD card.

This time I was patient and instead of closing the action dialog that was shown after executing the suggested action (open with file explorer), I repeated it for three times and respective file explorer windows came up, then the action dialog closed by itself. The three windows were showing different partitions that had been found in the SD card, and one of those windows was showing “/media/pi/” folder. I navigated from there to “root/home/pi/Desktop” subfolder, where I could see the old desktop contents and drag-drop the audio files I was looking for to the new desktop.

HowTo: Hide HTML markup from non-signedin users at MonoX Social CMS

At MonoX Social CMS, which I use at both ClipFlair Social and Trafilm websites, I was in the need of hiding some HTML markup when the user is not signed-in.

The solution for this is to add runat="server" to the HMTL element one wants to hide and then set the Visible property that the object acquires due to the runat clause. The Visible property is set using some special syntax to access the MonoX API like below:

<ul runat="server"
      Visible="<% $Code: Page.User.Identity.IsAuthenticated %>"  >

</ul>

Categories: Posts Tags: , , , , , , ,
%d bloggers like this: