private static HttpPilotClient Reconnect(HttpContext context, IServerCallback callback)
        {
            var client = new HttpPilotClient();

            client.Connect(ApplicationConst.PilotServerUrl);

            var serverApi = client.GetServerApi(callback);

            var dbName            = context.User.FindFirstValue(ClaimTypes.Surname);
            var login             = context.User.FindFirstValue(ClaimTypes.Name);
            var protectedPassword = context.User.FindFirstValue(ClaimTypes.UserData);
            var useWindowsAuth    = login.Contains("/") || login.Contains("\\");
            var dbInfo            = serverApi.OpenDatabase(dbName, login, protectedPassword, useWindowsAuth);

            if (dbInfo == null)
            {
                throw new TransportException();
            }

            var clientIdString = context.User.FindFirstValue(ClaimTypes.Sid);

            ClientsDictionary[Guid.Parse(clientIdString)] = client;

            DMetadata dMetadata = serverApi.GetMetadata(dbInfo.MetadataVersion);

            context.Session.SetSessionValues(SessionKeys.MetaTypes, dMetadata.Types.ToDictionary(x => x.Id, y => y));

            return(client);
        }
예제 #2
0
        public Boolean Registration(String CompName, String IPaddress)
        {
            AccessClient = CheckRegistration(CompName, IPaddress);
            IServerCallback IsrvCB = OperationContext.Current.GetCallbackChannel <IServerCallback>();

            if (AccessClient)
            {
                IsrvCB.ServerQuery(222);
            }
            return(AccessClient);
        }
예제 #3
0
        /// <summary>
        /// 构造函数
        /// </summary>
        static WcfMainHelper()
        {
            try
            {
                _callBack = new BackupClass(SynchronizationContext.Current);

                Open();

                InitTimer();
            }
            catch { }
        }
예제 #4
0
 private void OnTimerElapsed(Object source, System.Timers.ElapsedEventArgs e)
 {
     try
     {
         IServerCallback callBack     = _context.GetCallbackChannel <IServerCallback>();
         int             randomNumber = _randomNumbers.Next();
         callBack.ReceiveInt(randomNumber);
         Console.WriteLine("Sending random number: {0}", randomNumber);
     }
     catch (Exception ex)
     { Console.WriteLine("Error sending number"); }
 }
예제 #5
0
 public GenericServer(Socket socket, IServerCallback <T> callback)
 {
     if (socket == null)
     {
         throw new ArgumentNullException("socket");
     }
     if (callback == null)
     {
         throw new ArgumentNullException("callback");
     }
     listen_socket  = socket;
     serverCallback = callback;
 }
        public static IServerApi GetServerApi(this HttpContext context, IServerCallback callback = null)
        {
            if (callback == null)
            {
                callback = CallbackFactory.Get <IServerCallback>();
            }
            var client = context.GetClient();

            if (client == null)
            {
                client = Reconnect(context, callback);
            }
            return(client.GetServerApi(callback));
        }
예제 #7
0
        public void StartDataTransfer()
        {
            try
            {
                IServerCallback callBack = _context.GetCallbackChannel <IServerCallback>();

                _sendData = true;
                byte[] bytes;
                while (_sendData)
                {
                    bytes = new byte[1000];
                    _randomBytes.NextBytes(bytes);
                    callBack.ReceiveData(bytes);
                }
            }
            catch (Exception ex)
            { Console.WriteLine("Error sending data"); }
        }
예제 #8
0
 public IServerApi GetServerApi(IServerCallback callback)
 {
     _serverCallback = callback;
     return(_marshaller.Get <IServerApi>());
 }
예제 #9
0
        public async Task <Tuple <ObjectId, string> > Subscribe(string userName, string password, string ip, IServerCallback desktopCallback)
        {
            userId = await GetUserId(userName, password);

            if (!userId.Equals(ObjectId.Empty))
            {
                if (subscribers.ContainsKey(userId))
                {
                    Console.WriteLine(userName + " is already connected");
                    return(new Tuple <ObjectId, string>(ObjectId.Empty, "Sie sind schon angemeldet"));
                }
                else
                {
                    FilterDefinition <BsonDocument> filter = Builders <BsonDocument> .Filter.Eq("_id", userId);

                    UpdateDefinition <BsonDocument> update = Builders <BsonDocument> .Update.Set("ip", ip);

                    await dataBaseService.UserBsonCollection.UpdateOneAsync(filter, update);

                    ClientCallback callback = new ClientCallback(desktopCallback);

                    ICommunicationObject obj = (ICommunicationObject)desktopCallback;
                    obj.Closed += async(s, e) =>
                    {
                        await Unsubscribe();
                    };

                    subscribers.TryAdd(userId, callback);

                    await ChangeStatus(Status.Online);

                    Console.WriteLine(userName + " successfully connected with id: " + userId.ToString());

                    return(new Tuple <ObjectId, string>(userId, string.Empty));
                }
            }
            else
            {
                return(new Tuple <ObjectId, string>(ObjectId.Empty, "Passwort oder Benutzername falsch"));
            }
        }
예제 #10
0
 public ClientCallback(IWebsocketCallback websocketCallback)
 {
     this.desktopCallback   = null;
     this.websocketCallback = websocketCallback;
 }
예제 #11
0
 public ClientCallback(IServerCallback serverCallback)
 {
     this.desktopCallback   = serverCallback;
     this.websocketCallback = null;
 }
예제 #12
0
        public async Task <Tuple <ObjectId, string> > Subscribe(string userName, string password, string ip)
        {
            IServerCallback desktopClientCallback = OperationContext.Current.GetCallbackChannel <IServerCallback>();

            return(await loginService.Subscribe(userName, password, ip, desktopClientCallback));
        }