8 Aralık 2020 Salı

Git ssl kapatma

 

Devops self-signed sertifika olduğu için aşağıdaki git ayarını yapmak lazım. Cmd ekranından aşağıdaki komutu yazabilirsiniz

git config --global http.sslVerify false

3 Aralık 2020 Perşembe

MSSQL Email Gönderme

DECLARE @body NVARCHAR(MAX)
DECLARE @mSubject VARCHAR(MAX);
DECLARE @date DATETIME;
SET @date = CAST(CONVERT(CHAR(10), GETDATE(), 101) AS DATETIME);

SET @body = '<html><head>
                    <title>Email Başlık</title>
                    </head><body>
                    <table border="1" cellpadding="0" cellspacing="0" width="100%">
                    <tr style="text-align:left";>
                    <th>Plaka</th>
                    <th>İl</th>
                    <th>İlçe</th>
                    <th>Adres</th>
                </tr>';

SET @body = @body + CAST(
                    (
                        SELECT

                        'td/@align' = 'left',
                        td = T.Plaka,
                        '',                    
            
                        'td/@align' = 'left',
                        td = T.IlAdi,
                        '',            
            
                        'td/@align' = 'left',
                        td = T.IlceAdi,
                        '',            
            
                        'td/@align' = 'left',
                        td = T.Adres,
                        ''
                        From (
                        SELECT * FROM Adres
                       ) T  
                        FOR XML PATH('tr'), ELEMENTS
                    )
                    AS NVARCHAR(MAX))

    
SET @body = @body + '</table></body></html>';
SET @mSubject = 'Falcon - ' + CONVERT(CHAR(10), DATEADD(dd, -1, @date), 104) + ' Konumu Çekilemeyen Adresler';

EXEC msdb.dbo.sp_send_dbmail
@recipients = N'akifyanbak@mail.com',    
@copy_recipients =N'cc@mail.com',    
@body = @body,
@body_format = 'HTML',
@subject = @mSubject,
@profile_name = 'sql_email_profile';

8 Kasım 2020 Pazar

QueryParamsModel

using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; namespace Model.Model { public class QueryParamsModel { public string Filter { get; set; } public string SortOrder { get; set; } public string SortField { get; set; } public int PageSize { get; set; } public int PageNumber { get; set; } public IQueryable Sort(IQueryable query) { if (!string.IsNullOrEmpty(this.SortField)) { var entityType = typeof(T); var property = entityType .GetProperties() .FirstOrDefault(c => c.Name.ToLowerInvariant() == this.SortField.ToLowerInvariant()); if (property != null) { var parameterExp = Expression.Parameter(entityType); var memberExp = Expression.MakeMemberAccess(parameterExp, property); var bodyExp = Expression.Convert(memberExp, typeof(object)); var lambdaExp = Expression.Lambda>(bodyExp, parameterExp); if (this.SortOrder == "desc") { query = query.OrderByDescending(lambdaExp); } else { query = query.OrderBy(lambdaExp); } } } return query; } } }

7 Ekim 2020 Çarşamba

KONUMA GÖRE MESAFE HESAPLAMA

 

function getDistanceFromLatLongInKm(originLat, originLong, destinationLat, destinationLong)
{
    var Radius = 6371; // dünya yarıçapı km
    var dLat = deg2rad(destinationLat-originLat);
    var dLong = deg2rad(destinationLong-originLong);
    var a =
        Math.sin(dLat/2) * Math.sin(dLat/2) +
        Math.cos(deg2rad(originLat)) * Math.cos(deg2rad(destinationLat)) * Math.sin(dLong/2) * Math.sin(dLong/2);
    var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
    var result = Radius * c; // KM cinsinden mesafe
    return result;
}
 
function deg2rad(mDeg) {
    return mDeg* (Math.PI/180)
}
 

2 Ekim 2020 Cuma

IIS Site Yedek Alma - Siteyi Güncelleme PowerShell Script

Yedek alıyor, uygulamayı durduruyor, dosyaları güncelliyor, uygulamayı açıyor.

WebApi

if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")){
    Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit
}

Write-Host "Yedekleniyor...";
$from = "C:\WebSites\akifsite.com\_Current\*"
$to = "C:\WebSites\akifsite.com\_Old\"+(get-date).ToString('yyyy_MM_dd-hh_mm_ss')+"\"  
New-Item -ItemType Directory -Force -Path $to
Copy-Item $from $to -recurse
Write-Host $to  " klasorune yedeklendi";

$FileName = "C:\WebSites\akifsite.com\_New\Api\web.config"
if (Test-Path $FileName) {
  Remove-Item $FileName
}

$FileName = "C:\WebSites\akifsite.com\_New\Api\appsettings.json"
if (Test-Path $FileName) {
  Remove-Item $FileName
}

$siteName = "akifsite.com"; #poolState name aynı diye bunu kullanıyorum, farklı olsa poolName eklemek lazım - akif 30.09.2020
$poolState="";
$siteState ="";
$currentRetry = 0;
Write-Host  $siteName " durduruluyor...";
do{
    $siteState = (Get-WebsiteState $siteName).Value;
    $poolState = (Get-WebAppPoolState $siteName).Value
    if($siteState -eq "Started"){
        STOP-Website $siteName;
    }
    if($poolState -eq "Started"){
        Stop-WebAppPool -Name $siteName;
    }
    if($siteState -eq "Started" -or $poolState -eq "Started"){
        Start-Sleep -s 5;
    }

    $currentRetry = $currentRetry + 1;
}while ($siteState -eq "Started" -and $currentRetry -le 20)

Write-Host $siteName " Durdu (" $currentRetry "sn)";

Write-Host "Uygulama guncelleniyor...";
$from = "C:\WebSites\akifsite.com\_New\Api\*"
$to = "C:\WebSites\akifsite.com\_Current\Api\"  
New-Item -ItemType Directory -Force -Path $to
Copy-Item $from $to -recurse
Write-Host "Uygulama guncellendi";

Write-Host $siteName " calistiriliyor.."
if($siteState -eq "Stopped"){
    Start-Website $siteName;
}
if($poolState -eq "Stopped"){
    Start-WebAppPool -Name $siteName;
}
Write-Host $siteName " calisiyor"

Write-Host "Bitti"
Read-Host

 

 UiUpdate

if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")){
    Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit
}

Write-Host "Yedekleniyor...";
$from = "C:\WebSites\akifsite.com\_Current\*"
$to = "C:\WebSites\akifsite.com\_Old\"+(get-date).ToString('yyyy_MM_dd-hh_mm_ss')+"\"  
New-Item -ItemType Directory -Force -Path $to
Copy-Item $from $to -recurse
Write-Host $to  " klasorune yedeklendi";

$siteName = "akifsite.com"; #poolState name aynı diye bunu kullanıyorum, farklı olsa poolName eklemek lazım - akif 30.09.2020
$poolState="";
$siteState ="";
$currentRetry = 0;
Write-Host  $siteName " durduruluyor...";
do{
    $siteState = (Get-WebsiteState $siteName).Value;
    $poolState = (Get-WebAppPoolState $siteName).Value
    if($siteState -eq "Started"){
        STOP-Website $siteName;
    }
    if($poolState -eq "Started"){
        Stop-WebAppPool -Name $siteName;
    }
    if($siteState -eq "Started" -or $poolState -eq "Started"){
        Start-Sleep -s 5;
    }

    $currentRetry = $currentRetry + 1;
}while ($siteState -eq "Started" -and $currentRetry -le 20)

Write-Host $siteName " Durdu (" $currentRetry "sn)";

Get-ChildItem "C:\WebSites\akifsite.com\_Current" -Exclude api,web.config | Remove-Item -Recurse; #api uygulamsı ve config ayarları olduğu için onları silmiyoruz

Write-Host "Uygulama guncelleniyor...";
$from = "C:\WebSites\akifsite.com\_New\ui\*"
$to = "C:\WebSites\akifsite.com\_Current\"  
New-Item -ItemType Directory -Force -Path $to
Copy-Item $from $to -recurse
Write-Host "Uygulama guncellendi";

Write-Host $siteName " calistiriliyor.."
if($siteState -eq "Stopped"){
    Start-Website $siteName;
}
if($poolState -eq "Stopped"){
    Start-WebAppPool -Name $siteName;
}
Write-Host $siteName " calisiyor"

Write-Host "Bitti"
Read-Host

 

.net 6 mapget kullanımı

 app.UseEndpoints(endpoints => {     endpoints.MapGet("/", async context =>     {         var response = JsonConvert.Seriali...