aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.CSV/CsvFileLinqExtensions.cs
blob: 8f99b20142d6dfff20852292e88b741cee6402cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Collections.Concurrent;
using System.Threading.Tasks;
using Tango.CSV;


public static class CsvFileLinqExtensions
{
    /// <summary>
    /// Export the collection to CSV file.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="source">The source.</param>
    /// <param name="csvDestination">The CSV destination.</param>
    public static void ToCsv<T>(this IEnumerable<T> source, CsvDestination csvDestination)
    {
        source.ToCsv(csvDestination, null);
    }

    /// <summary>
    /// Export the collection to CSV file.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="source">The source.</param>
    /// <param name="csvDestination">The CSV destination.</param>
    /// <param name="csvDefinition">The CSV definition.</param>
    public static void ToCsv<T>(this IEnumerable<T> source, CsvDestination csvDestination, CsvDefinition csvDefinition)
    {
        using (var csvFile = new CsvFile<T>(csvDestination, csvDefinition))
        {
            foreach (var record in source)
            {
                csvFile.Append(record);
            }
        }
    }
}
class="w"> NullReferenceException("Credentials were not set."); } if (_azure == null) { return Task.Factory.StartNew<IAzure>(() => { var creds = SdkContext.AzureCredentialsFactory.FromServicePrincipal( _credentials.ClientID, _credentials.ClientSecret, _credentials.TenantID, AzureEnvironment.AzureGlobalCloud); _azure = Azure.Authenticate(creds).WithSubscription(_credentials.SubscriptionID); return _azure; }); } else { return Task.FromResult(_azure); } } public static Task<IAzure> AuthenticateOrGetAsync(AzureUtilsCredentials credentials) { return Task.Factory.StartNew<IAzure>(() => { var creds = SdkContext.AzureCredentialsFactory.FromServicePrincipal( credentials.ClientID, credentials.ClientSecret, credentials.TenantID, AzureEnvironment.AzureGlobalCloud); _azure = Azure.Authenticate(creds).WithSubscription(credentials.SubscriptionID); return _azure; }); } public static async Task<IAzure> AuthenticateOrGetAsync(String gatewayUrl, String email, String password) { using (var http = new HttpClient()) { AzureUtilsWebClient client = new AzureUtilsWebClient(gatewayUrl, http); var response = await client.LoginAsync(new LoginRequest() { Email = email, Password = password }); http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", response.AccessToken); var c = await client.GetCredentialsAsync(); return await AuthenticateOrGetAsync(new AzureUtilsCredentials() { ClientID = c.ClientID, ClientSecret = c.ClientSecret, TenantID = c.TenantID, SubscriptionID = c.SubscriptionID }); } } public static AzureUtilsCredentials GetGlobalCredentials() { return _credentials; } } }