Thursday, December 12, 2019

Cách update password cho Git khi dùng SourceTree

Tìm đến thư mục C:\Users\USERNAME\AppData\Local\Atlassian\SourceTree

Xóa hoặc đổi tên file passwd.

Thoát ra SourceTree sau đó mở lại, thực hiện các action như Pull, Push, SourceTree sẽ yêu cầu nhập lại username và password. Khi đó sẽ update được.

Nguồn tham khảo:
https://stackoverflow.com/questions/45821037/how-do-i-set-my-password-in-sourcetree

Ngoài ra còn 1 cách nữa là vào Tools -> Options -> tab Authentication, xóa hết các tài khoản Git Saved Password.

Sau đó Pull lại sẽ hỏi user và pass. Nhập vào là xong


Host Web Core trên WindowsService

Tạo 1 project web hoặc web API Core.

class Program sửa thành

public class Program
    {
        public static void Main(string[] args)
        {

            CreateWebHostBuilder(args).Build().RunAsService();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseContentRoot(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName))
                .UseStartup<Startup>().
                UseUrls("http://localhost:5000");
    }

Mở file project, sửa lại giống như sau sau

<PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <RuntimeIdentifiers>win10-x64;</RuntimeIdentifiers>
    <OutputType>Exe</OutputType>
  </PropertyGroup>

Chuyển vào thư mục project, chạy lệnh sau:
dotnet publish --configuration Release --self-contained -r win10-x64

Mở cmd lần nữa để chạy lệnh cài đặt service

sc create WindowsServiceHosted binPath= "C:\WindowsServiceHosted\bin\Debug\netcoreapp2.1\win7-x64\publish\WindowsServiceHosted.exe"

Chạy sc start WindowsServiceHosted để start service.
Chạy sc description WindowsServiceHosted "This is the description of the service.." để gán mô tả cho service

http://localhost:5000 để chạy web

Thursday, June 06, 2019

Sửa lỗi tạo project bị Access Denied

Tắt VS. Tìm file privateregistry.bin trong ổ C. Xóa đi rồi khởi động lại VS

Monday, January 14, 2019

Cách tạo link custom Uri scheme để chạy app như skype

Tạo Uri custom bằng cách đăng ký registry

private static void WriteRegistry()
        {
            try
            {
                using (var key = Registry.CurrentUser.CreateSubKey("SOFTWARE\\Classes\\" + UriScheme))
                {
                    string applicationLocation = Path.Combine(System.Windows.Forms.Application.StartupPath, "TestApp.exe");

                    key.SetValue("", "URL:" + FriendlyName);
                    key.SetValue("URL Protocol", "");

                    using (var defaultIcon = key.CreateSubKey("DefaultIcon"))
                    {
                        defaultIcon.SetValue("", applicationLocation + ",1");
                    }

                    using (var commandKey = key.CreateSubKey(@"shell\open\command"))
                    {
                        commandKey.SetValue("", "\"" + applicationLocation + "\" \"%1\"");
                    }
                }
            }
            catch (Exception objEx)
            {
                ExceptionManger.WriteLog(objEx, "Exception happended in WriteRegistry.");
            }
        }

Như vậy khi mở trình duyệt gõ testapp: thì TestApp.exe sẽ chạy.

Muốn truyền thêm tham số cho TestApp thì hàm main cần nhận tham số string[] args. Sau đó xử lý tham số truyền vào trong mảng args.