Skip to content

Instantly share code, notes, and snippets.

@LinZap
Last active August 2, 2024 10:22
Show Gist options
  • Save LinZap/ece1a8c6ac04a49b6348dc071a946c3f to your computer and use it in GitHub Desktop.
Save LinZap/ece1a8c6ac04a49b6348dc071a946c3f to your computer and use it in GitHub Desktop.

Revisions

  1. LinZap revised this gist Aug 2, 2024. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -99,13 +99,17 @@ DriveConnectionString : Data Source=10.190.173.134;Min Pool Size=0;Max Pool Size

    ### 使用範例 - 刪除指定的 `appSettings` 中的特定參數

    > 版本:ZapLib v2.4.8
    ```csharp
    string key = "CurrentTime";
    Config.Delete(key);
    ```

    ### 使用範例 - 刪除指定的 `connectionStrings` 區域中的特定參數

    > 版本:ZapLib v2.4.8
    ```csharp
    string key = "KB52ConnectionString";
    Config.DeleteConnectionString(key);
  2. LinZap revised this gist Aug 2, 2024. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -97,7 +97,20 @@ LocalSqlServer : data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilen
    DriveConnectionString : Data Source=10.190.173.134;Min Pool Size=0;Max Pool Size=100;Pooling=true;Initial Catal....
    ```

    ### 使用範例 - 刪除指定的 `appSettings` 中的特定參數

    ```csharp
    string key = "CurrentTime";
    Config.Delete(key);
    ```

    ### 使用範例 - 刪除指定的 `connectionStrings` 區域中的特定參數

    ```csharp
    string key = "KB52ConnectionString";
    Config.DeleteConnectionString(key);
    ```

    ---

    [回 ZapLib v2.4.7 changelog](https://github.com/LinZap/ZapLib/blob/master/CHANGELOG.md#247)
  3. LinZap revised this gist Jul 23, 2024. No changes.
  4. LinZap revised this gist Jul 23, 2024. 1 changed file with 103 additions and 1 deletion.
    104 changes: 103 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1 +1,103 @@
    讀寫
    # 讀寫應用程式的自己的 Config 檔案

    > 版本:ZapLib v2.4.7
    新增了 `Config` class 中的 3 個新功能 (以下功能皆可在 Config 檔案被加密的狀況下正常運作)
    1. **`Config.SetOrAdd(key, val)`**:設定既有的或新增全新的 `appSettings` 中的參數 (已存在則會修改,不存在則會新增)
    2. **`Config.SetOrAddConnectionString(key, val, providerName)`**:設定既有的或新增全新的 `connectionStrings` 資料庫連線字串 (已存在則會修改,不存在則會新增)
    3. **`Config.GetConnectionStrings()`**:取得所有資料庫連線字串設定,如果無法取得則回傳 `null`



    ---

    ### 使用範例 - 新增或修改 `appSettings` 中的特定參數

    ```csharp
    string key = "CurrentTime";
    string timestamp = DateTime.Now.ToString("yyyyMMddHHmmss");
    // 新增或修改 CurrentTime 的數值
    bool res = Config.SetOrAdd(key, timestamp);

    // 取得 CurrentTime 的數值
    string actual_timestamp = Config.Get(key);
    Trace.WriteLine(actual_timestamp);
    ```

    **輸出結果**

    ```
    20240723165257
    ```


    ---

    ### 使用範例 - 新增或修改 `connectionStrings` 中的特定參數


    ```csharp
    string key = "KB52ConnectionString";
    string connectionstring = "Data Source=10.190.173.134;Min..."
    // 新增或修改 KB52ConnectionString 的資料庫連線字串
    bool res = Config.SetOrAddConnectionString(key, connectionstring);

    // 取得 KB52ConnectionString 的資料庫連線字串
    string actual_connectionstring = Config.GetConnectionString(key);
    Trace.WriteLine(actual_connectionstring);
    ```

    **輸出結果**

    ```
    Data Source=10.190.173.134;Min...
    ```


    ---

    ### 使用範例 - 列出所有 `appSettings` 區域中的所有參數設定

    ```csharp
    NameValueCollection collection = Config.Get();
    foreach (string key in collection.AllKeys)
    {
    foreach (string value in collection.GetValues(key))
    {
    Trace.WriteLine(key + " : " + value);
    }
    }
    ```

    **輸出結果**

    ```
    Storage : D:\Storage
    ForceLog : True
    SilentMode : False
    ```


    ---

    ### 使用範例 - 列出所有 `connectionStrings` 區域中的所有參數設定

    ```csharp
    var cscolleciton = Config.GetConnectionStrings();
    foreach (ConnectionStringSettings cs in cscolleciton)
    {
    Trace.WriteLine(cs.Name + " : " + cs.ConnectionString);
    }
    ```

    **輸出結果**

    ```
    LocalSqlServer : data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDir...
    DriveConnectionString : Data Source=10.190.173.134;Min Pool Size=0;Max Pool Size=100;Pooling=true;Initial Catal....
    ```


    ---

    [回 ZapLib v2.4.7 changelog](https://github.com/LinZap/ZapLib/blob/master/CHANGELOG.md#247)
  5. LinZap created this gist Jul 23, 2024.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    讀寫