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(originLatoriginLongdestinationLatdestinationLong)
{
    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

 

24 Eylül 2020 Perşembe

IIS HTTPS Yönlendirme - ReWrite

<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="HTTPS force" enabled="true" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="^OFF$" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

17 Eylül 2020 Perşembe

IIS Üzerinde Ücretsiz SSL alma (90 günlük) sslforfree

https://manage.sslforfree.com/certificate/new sayfasından sihirbazı izleyip domain onayını aldıktan sonra indirme yapıyoruz.Domain onayı almak için "/.well-known/pki-validation/{key}" altında bir doğrulama dosyası isteyecek. Bunun için uygulama altına Virtual Directory açmamız gerekiyor ".well-known" sanal yolunu "C:\VirtualDirectory\well-known" yapabilirsin kafana göre. Sonra onay çin gerekli dosyayı istediği yola atıp onaylaman gerekiyor.

https://decoder.link/converter adresinden tamamlanacak olan sertifikayı convert ediyoruz

 ca_bundle.crt

Certificate File to Convert = certificate.crt 

Chain Certificate File (optional) Private Key File= private.key

Type To Convert To = PFX/PKCS#12

PFX Password = (Boş bırakılabilir)

seçiyoruz, convert dediğimizde "certificate.pfx" adında bir dosya oluşturacak. Bunu IIS üzerinde SSL Sertifikaları bölümünden "Complete Certificate Request" veya "Sertifika İsteğini Tamamla" diyip, sertifikaya akılda kalıcı bir isim verdikten sonra işlemi tamamlıyorsunuz. Artık uygulamanızın bindings kısmında 443 olan https domainin SSL certificate'ini yüklediğiniz sertifikayı atayabilirsiniz.

 



.net 6 mapget kullanımı

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