Table of Contents

Anleitung: Mit C# auf die API von time cockpit zugreifen

Sie können nicht nur mit IronPython auf die API von time cockpit zugreifen, sondern auch mit Ihrer bevorzugten .NET-Programmiersprache (z. B. C#).

Hinweis

Beachten Sie, dass sich der Code in diesem Beispiel mit dem Server-Datenspeicher eines Benutzers verbindet. Das ist die empfohlene Vorgehensweise, um Schnittstellen umzusetzen, die Daten importieren oder exportieren.

Projektreferenzen

Bevor Sie aus C# auf den Datenspeicher von time cockpit zugreifen können, müssen Sie Ihrem Projekt bestimmte Referenzen hinzufügen:

Hinweis

Die in dieser Liste genannten Assemblies finden Sie im Installationsverzeichnis von time cockpit.

  • Antlr3.Runtime
  • Antlr3.StringTemplate
  • IronPython
  • log4net.dll
  • Microsoft.Dynamic
  • Microsoft.Scripting
  • Newtonsoft.Json.Net35
  • System.CoreEx.dll
  • System.Data.SqlServerCe.dll
  • System.Reactive.dll
  • TimeCockpit.Common
  • TimeCockpit.Data
  • TimeCockpit.Data.QueryLanguage
  • TimeCockpit.Data.RoutingService

Definition des Webservice-Endpunkts

time cockpit verwendet einen Webservice, um den Server-Datenspeicher des Benutzers zu ermitteln. Daher muss der Webservice-Endpunkt in der Konfigurationsdatei der Anwendung definiert werden:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
        <client> 
            <endpoint name="" address="https://management.timecockpit.com/ManagementService.svc" binding="customBinding" 
                bindingConfiguration="CustomBinding_IManagementService" contract="WebManagementService.IManagementService" /> 
        </client> 

        <bindings> 
            <customBinding> 
                <binding name="CustomBinding_IManagementService"> 
                    <security defaultAlgorithmSuite="Default" authenticationMode="UserNameOverTransport" requireDerivedKeys="true" 
                        securityHeaderLayout="Strict" includeTimestamp="true" keyEntropyMode="CombinedEntropy" 
                        messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"> 

                        <localClientSettings cacheCookies="true" detectReplays="false" replayCacheSize="900000" maxClockSkew="23:00:00" 
                            maxCookieCachingTime="Infinite" replayWindow="00:05:00" sessionKeyRenewalInterval="10:00:00" 
                            sessionKeyRolloverInterval="00:05:00" reconnectTransportOnFailure="true" timestampValidityDuration="00:05:00" 
                            cookieRenewalThresholdPercentage="60"/> 

                        <localServiceSettings detectReplays="false" issuedCookieLifetime="10:00:00" maxStatefulNegotiations="128" 
                            replayCacheSize="900000" maxClockSkew="23:00:00" negotiationTimeout="01:01:00" replayWindow="00:05:00" 
                            inactivityTimeout="00:02:00" sessionKeyRenewalInterval="15:00:00" sessionKeyRolloverInterval="00:05:00" 
                            reconnectTransportOnFailure="true" maxPendingSessions="128" maxCachedCookies="1000" timestampValidityDuration="00:05:00"/> 
                        <secureConversationBootstrap/> 
                    </security> 

                    <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" messageVersion="Soap11" writeEncoding="utf-8"> 
                        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/> 
                    </textMessageEncoding> 

                    <httpsTransport manualAddressing="false" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" allowCookies="false" 
                        authenticationScheme="Anonymous" bypassProxyOnLocal="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard" 
                        keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous" realm="" transferMode="Buffered" 
                        unsafeConnectionNtlmAuthentication="false" useDefaultWebProxy="false" requireClientCertificate="false" /> 
                </binding> 
            </customBinding> 

            <wsHttpBinding> 
                <remove name="WorkflowControlHttpsBinding"/> 
                <binding name="WorkflowControlHttpsBinding" transactionFlow="true"> 
                    <security mode="Transport"/> 
                </binding> 

                <remove name="WorkflowControlHttpBinding"/> 
                <binding name="WorkflowControlHttpBinding" transactionFlow="true"/> 
            </wsHttpBinding> 
        </bindings> 
    </system.serviceModel> 
</configuration>

Daten abfragen

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TimeCockpit.Data;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                var dataContext = DataContext.Create("user@demo.com", "myPassword");
                var projects = dataContext.Select("From P In Project Select P").Cast<dynamic>();
                projects.ToList().ForEach(p => Console.WriteLine(p.ProjectName));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: {0}", ex.ToString());
            }

            Console.ReadKey();
        }
    }
}