/// <summary>
        /// Initializes a new instance of the <see cref="AssassinDataService" /> class.
        /// </summary>
        /// <param name="appId">The application identifier.</param>
        /// <param name="remoteEndPoint">The remote end point.</param>
        /// <param name="apiConnectionType">Type of the API connection.</param>
        public AssassinDataService(string appId, string remoteEndPoint, ApiConnectionType apiConnectionType, int syncIntervalInSeconds) : this(appId)
        {
            this.QuantWebClient = new AssassinWebClient(remoteEndPoint, apiConnectionType);
            this.IsConnected    = false;

            // If an entity was send to the server it will be marked as synced
            StreamQueueWorker <WebPackage> .OnPackageSend = async(package) =>
            {
                try
                {
                    OnNotify?.Invoke(this, "Package send" + package.Method, LogLevel.Debug);
                    if (package.Method == PackageMethod.Insert || package.Method == PackageMethod.Update &&
                        package.EntityData != null)
                    {
                        var unknownObject = package.EntityData.CastAs(Type.GetType(package.EntityData.TypeDiscriptor)) as BaseModel;
                        unknownObject.Synced = true;
                        await DataHandler.Update(unknownObject);
                    }
                }
                catch (Exception ex)
                {
                    OnNotify?.Invoke(this, ex.ToText("Package error."), LogLevel.Error);
                }
            };

            // Start the observer
            new Thread(() =>
            {
                this.DataObserver = new Timer(RunTimer, null, 2000, syncIntervalInSeconds * 1000);
            }).Start();
        }
示例#2
0
 /// <summary>
 /// Prevents a default instance of the <see cref="AssassinWebClient"/> class from being created.
 /// </summary>
 /// <param name="webservice">The <see cref="IWebservice"/></param>
 internal AssassinWebClient(string endPoint, ApiConnectionType apiConnectionType)
 {
     if (apiConnectionType == ApiConnectionType.Socket)
     {
         this.webservice = SocketClient.Create(endPoint);
     }
     this.webservice.OnConnected    = () => { Debug.WriteLine("Connected to server."); };
     this.webservice.OnDisconnected = () => { Debug.WriteLine("Disconnected from server."); };
 }
示例#3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AssassinWebServer" /> class.
 /// </summary>
 /// <param name="apiConnectionType">Type of the API connection.</param>
 /// <param name="socketServerEndpoint">The socket server endpoint.</param>
 public AssassinWebServer(ApiConnectionType apiConnectionType, string serverEndpoint)
 {
     this.webServer                = SocketServer.Create(serverEndpoint);
     this.webServer                = SocketServer.Create(serverEndpoint);
     this.webServer.OnNotify       = AssassinDataService.OnNotify;
     this.webServer.OnAuthenticate = async(package) =>
     {
         return(await OnAuthenticate(package));
     };
     this.webServer.OnStreaming = async(package, stream) =>
     {
         await OnStreaming(package, stream);
     };
     this.webServer.OnFetch = async(package) =>
     {
         return(await OnFetchRequest(package));
     };
 }