Friday, October 25, 2019

RENAME FROM LIST

@echo off
set "File2Read=mkv.txt"
If Not Exist "%File2Read%" (Goto :Error)

rem iterpiame 0
setlocal EnableDelayedExpansion
for /f "tokens=*" %%f in ('dir /b *.mkv ^| sort') do (
    SET var=%%f
    if  "!var:~7,1!" == "_" move %%f "!var:~0,6!0!var:~6!"
)

setlocal EnableExtensions EnableDelayedExpansion
for /f "delims=" %%a in ('Type "%File2Read%"') do (
    set /a count+=1
    set "Line[!count!]=%%a"
)

for /f "tokens=*" %%f in ('dir /b *.mkv ^| sort') do (
    set /a num+=1
    set "Out[!num!]=%%f"
)

if %count% neq %num% (Goto :Error)

for /l %%n in (1 1 %num%) do (
    echo mklink /h "!Line[%%n]!".mkv "!Out[%%n]!"
    mklink /h "!Line[%%n]!".mkv "!Out[%%n]!"
)

endlocal

rem # end #
pause>nul
Exit
For /L %%i in (1,1,%Count%) do (
    echo "Var%%i" is assigned to ==^> "!Line[%%i]!"
)

:Error
cls & Color 4C
echo(
echo   Failas "%File2Read%" nerastas arba klaidingas eiluciu skaicius count=%count% num=%num%
Pause>nul
exit /b

RENAME

@echo off
setlocal EnableDelayedExpansion
for /f "tokens=*" %%f in ('dir /b *.mkv ^| sort') do (
    SET var=%%f
    rem move "%%f" "2%%f"
    rem move "%%f" "1!var:~3!"
    rem mklink /h "2%%f" "%%f"
    rem if  "!var:~7,1!" == "_" move %%f "!var:~0,6!0!var:~6!"
echo "3!var:~0,2! !var:~4!"
move "%%f" "3!var:~0,2! !var:~4!"
)

Pause>nul
exit /b

MPEG 2 MKV

setlocal EnableDelayedExpansion
@echo off
FOR %%f IN (*.mpg) DO (
 echo %%f

 "C:\Program Files (x86)\ffmpeg\bin\ffmpeg.exe" -i "%%f" 2>&1 | FINDSTR mpeg2video >temp.txt
 set /p VIDEO=<temp.txt

 "C:\Program Files (x86)\ffmpeg\bin\ffmpeg.exe" -i "%%f" 2>&1 | FINDSTR pcm_dvd >temp.txt
 set /p AUDIO=<temp.txt
 if "!AUDIO:~30,7!" == "pcm_dvd" "C:\Program Files (x86)\ffmpeg\bin\ffmpeg.exe" -i "%%f" -map !VIDEO:~12,3! -vcodec libx264 -map !AUDIO:~12,3! -acodec pcm_s16le "%%f".mkv 2>nul

 "C:\Program Files (x86)\ffmpeg\bin\ffmpeg.exe" -i "%%f" 2>&1 | FINDSTR ac3 | FINDSTR stereo >temp.txt
 set /p AUDIO=<temp.txt

 if NOT "!AUDIO:~30,3!" == "ac3" (goto ac3)
 "C:\Program Files (x86)\ffmpeg\bin\ffmpeg.exe" -i "%%f" 2>&1 | FINDSTR ac3 >temp.txt
:ac3
 set /p AUDIO=<temp.txt
 if "!AUDIO:~30,3!" == "ac3" "C:\Program Files (x86)\ffmpeg\bin\ffmpeg.exe" -i "%%f" -map !VIDEO:~12,3! -vcodec libx264 -map !AUDIO:~12,3! -acodec copy "%%f".mkv 2>nul

 echo "!AUDIO!"
)
pause

AVIDEMUX 2 MKV

FOR %%f IN (*.vob) DO "C:\Program Files\Avidemux 2.7 VC++ 64bits\avidemux.exe" --load "%%f" \
  --audio-codec AC3 --audio-resample 44100  --audio-bitrate 224 --audio-normalize \
  --video-codec x264 --save "%%f".mkv --quit
del *.idx2
pause

AV-CD-DVD-BD

CD 2352
A 700MB CD is 80 minutes long, which works out to about 800MB of audio data.  ~100MB less is available for storing regular files in order to provide better error correction.

DVD 2048
4,707,319,808 DVD-R
4,700,372,992 DVD+R
8,543,666,176 DVD-R DL
8,547,991,552 DVD+R DL

BD 2048
 9,414,639,616 DVD-R DS
 9,400,745,984 DVD+R DS
17,087,332,352 DVD-R DS DL
17,095,983,104 DVD+R DS DL
24,220,008,448 BD-R
25,025,314,816 BD+R

Monday, September 10, 2018

Asp core AD

using System.DirectoryServices;

            DirectoryEntry ldap = new DirectoryEntry("LDAP://10.102.172.250:389/OU=VPGTUsers,DC=vpgt,DC=local");
            DirectorySearcher lookFor = new DirectorySearcher(ldap);

            string user = User.Identity.Name; user = user.Substring(user.LastIndexOf("\\") + 1);
            lookFor.Filter = String.Format("(&(objectClass=user)(objectCategory=person)(sAMAccountName={0}))", user);
            lookFor.SearchScope = SearchScope.Subtree;
            SearchResultCollection results = lookFor.FindAll();
            SearchResult result = (results.Count == 1) ? results[0] : null;
            //foreach (string property in result.Properties.PropertyNames)
            //    Debug.WriteLine("\t{0} : {1} ", property, result.Properties[property][0]);

            ModelState.AddModelError("", (string)result.Properties["department"][0]);
            ModelState.AddModelError("", (string)result.Properties["title"][0]);

When to use Include()

http://foreverframe.net/when-use-include-with-entity-framework/

class Program
{
    static void Main(string[] args)
    {
        using (var context = new BookStoreContext())
        {
            var author = context.Authors
                .Include(a => a.Books)
                .FirstOrDefault();
           
            foreach (var book in author.Books)
                Console.WriteLine(book.Title);
        }
        Console.ReadLine();
    }    
}

Making JOIN without Include method

Frankly, I would say that the following solution should be your default way of dealing with IQuerable. Let’s modify our Program class one, last time:
class Program
{
    static void Main(string[] args)
    {
        using (var context = new BookStoreContext())
        {
            var author = context.Authors
                .Select(a => new AuthorReadModel
                {
                    FirstName = a.FirstName,
                    LastName = a.LastName,
                    BookTitles = a.Books
                    .AsQueryable()
                    .Select(b => b.Title)
                    .ToList()
                })
                .FirstOrDefault();
           
            foreach (var title in author.BookTitles)
                Console.WriteLine(title);
        }
        Console.ReadLine();
    }    
}
 In this case, we created a dedicated ReadModel for all needed data, and we specified all “mappings” inside the Select method. This one tells EF exactly what we need, so it does not need yet another help as Include method. Let’s run the following code and inspect the query:
SELECT
    [Project1].[Id] AS [Id],
    [Project1].[FirstName] AS [FirstName],
    [Project1].[LastName] AS [LastName],
    [Project1].[C1] AS [C1],
    [Project1].[Title] AS [Title]
    FROM ( SELECT
        [Limit1].[Id] AS [Id],
        [Limit1].[FirstName] AS [FirstName],
        [Limit1].[LastName] AS [LastName],
        [Extent2].[Title] AS [Title],
        CASE WHEN ([Extent2].[AuthorId] IS NULL) THEN CAST(NULL AS int) ELSE 1 END AS [C1]
        FROM   (SELECT TOP (1) .[Id] AS [Id], .[FirstName] AS [FirstName], .[LastName] AS [LastName]
            FROM [dbo].[Authors] AS  ) AS [Limit1]
        LEFT OUTER JOIN [dbo].[Books] AS [Extent2] ON [Limit1].[Id] = [Extent2].[AuthorId]
    AS [Project1]
    ORDER BY [Project1].[Id] ASC, [Project1].[C1] ASC