Beispiel #1
0
    public bool CreateNewChatRequest(ClientInstance clientInst, ClientObj clientDestination)
    {
        NotifyChatEvent(Operation.NewChat, clientInst, clientDestination);
        if (chatReqEvent != null)
        {
            Delegate[] invkList = chatReqEvent.GetInvocationList();

            foreach (ChatRequestHandler handler in invkList)
            {
                Console.WriteLine("[Server]: Chat Event triggered: invoking handler to inform client");
                new Thread(() =>
                {
                    try
                    {
                        handler(clientInst, clientDestination.Port);
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("[TriggerEvent]: Exception");
                        chatReqEvent -= handler;
                    }
                }).Start();
            }
        }
        return(true);
    }
Beispiel #2
0
 public void Repeater(Operation op, ClientInstance clientInst, ClientObj clientDestination)
 {
     if (chatEvent != null)
     {
         chatEvent(op, clientInst, clientDestination);
     }
 }
Beispiel #3
0
    private void saveClient(ClientObj client)
    {
        clients.Add(client);

        FileStream   db = new FileStream(@"users.txt", FileMode.Append, FileAccess.Write, FileShare.None);
        StreamWriter sw = new StreamWriter(db);

        sw.WriteLine(client.Info());
        sw.Flush();
        sw.Close();
    }
 public void TrySpawningClient()
 {
     for (int i = 0; i < SeatOcuppied.Length; i++)
     {
         if (!SeatOcuppied[i])
         {
             SeatOcuppied[i] = true;
             ClientObj newClientObj = Instantiate(client, seats[i], Quaternion.identity);
             newClientObj.Seat = i;
             break;
         }
     }
 }
Beispiel #5
0
    void ChatRequested(Operation op, ClientInstance clientInst, ClientObj clientDestination)
    {
        ChatViewStartDelegate chViStart;

        switch (op)
        {
        case Operation.NewChat:
            if (!clientInst.Name.Equals(self.Name) && clientDestination.Name.Equals(self.Name))
            {
                chViStart = new ChatViewStartDelegate(OpenChatViewOnRequest);
                BeginInvoke(chViStart, clientInst);
            }
            break;
        }
    }
Beispiel #6
0
        public bool ModifyClient(ClientObj param)
        {
            bool success = _client.UpdateClient(param.ClientName, param.ClientAlias, param.ClientBanner, param.RespTime, param.RestTime, param.IsClientActive, param.ExtClientBanner, param.ClientId);

            if (success)
            {
                Log.InfoFormat(param.Computername, param.SystemIp, param.UserName, Constants.ActionType.ModifyClientDetails.ToString());
                _audit.InsertAudit(param.UserName, Constants.ActionType.ModifyClientDetails.ToString(), "Client detail changed", DateTime.Now, param.Computername, param.SystemIp);
                return(true);
            }
            else
            {
                Log.InfoFormat(param.Computername, param.SystemIp, param.UserName, Constants.ActionType.ModifyClientDetails.ToString());
                return(false);
            }
        }
Beispiel #7
0
    /*
     * Recebe um pedido de criacao de instancia de um novo cliente e informa
     * todos os clientes sobre isso
     */
    public ClientInstance AddNewClient(string name, string password, string port)
    {
        ClientObj client    = getClientByName(name, port);
        string    userevent = "login";

        if (client == null)
        {
            client = new ClientObj(name, password, port);
            saveClient(client);
            userevent = "signup";
        }
        else if (client.Password != password)
        {
            return(null);
        }

        ClientInstance clientInst = new ClientInstance(nr, name, port);

        Console.WriteLine("[Server]: New client " + userevent + " (" + name + ")");
        clientsOnline.Add(client);
        nr += 1;
        NotifyClients(Operation.ClientOn, clientInst);

        if (newClientEvent != null)
        {
            Delegate[] invkList = newClientEvent.GetInvocationList();

            foreach (NewClientHandler handler in invkList)
            {
                Console.WriteLine("[Server]: Join Event triggered: invoking handler to inform client");
                new Thread(() =>
                {
                    try
                    {
                        handler(clientInst, clientsOnline);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("[TriggerEvent]: Exception");
                        Console.WriteLine(e.Message);
                        newClientEvent -= handler;
                    }
                }).Start();
            }
        }
        return(clientInst);
    }
Beispiel #8
0
        public bool InsertClient(ClientObj param)
        {
            string banner   = _client.DoFileUpload(param.ClientBanner);
            bool   _clients = _client.InsertClient(param.ClientName, param.ClientAlias, banner, param.RespTime, param.RestTime, param.IsClientActive, param.CreatedBy);

            if (_clients)
            {
                Log.InfoFormat(param.Computername, param.SystemIp, param.UserName, Constants.ActionType.SetupClient.ToString());
                _audit.InsertAudit(param.UserName, Constants.ActionType.SetupClient.ToString(), "Setup client account", DateTime.Now, param.Computername, param.SystemIp);
                return(true);
            }
            else
            {
                Log.InfoFormat(param.Computername, param.SystemIp, param.UserName, Constants.ActionType.SetupClient.ToString());
                return(false);
            }
        }
Beispiel #9
0
    private void loadClients()
    {
        try
        {
            FileStream   db   = new FileStream(@"users.txt", FileMode.Open, FileAccess.Read, FileShare.None);
            StreamReader sr   = new StreamReader(db);
            string       line = sr.ReadLine();
            while (line != null)
            {
                string name     = line.Split('%')[0];
                string password = line.Split('%')[1];
                string port     = line.Split('%')[2];

                ClientObj client = new ClientObj(name, password, port);
                clients.Add(client);

                line = sr.ReadLine();
            }
            sr.Close();
        }
        catch (System.IO.FileNotFoundException e) { }
    }
Beispiel #10
0
    private void button1_Click(object sender, EventArgs e)
    {
        string client = (string)listBox1.SelectedItem;

        if (client != null)
        {
            ClientObj destinationClient = null;
            clientsOnline = server.GetClientsOnline();
            foreach (ClientObj clientObj in clientsOnline)
            {
                if (client.Equals(clientObj.Name))
                {
                    destinationClient = clientObj;
                }
            }
            if (destinationClient != null)
            {
                string destination = destinationClient.Port;
                //server.CreateNewChatRequest(self, destination);
                server.CreateNewChatRequest(self, destinationClient);
                Client.inter.ConnectChat((Chat)RemotingServices.Connect(typeof(Chat),
                                                                        "tcp://localhost:" + Client.port + "/Client/Chat"
                                                                        ));
                //Client.inter.newMessage += Client.handleNewChatMessage;

                /*
                 * Fecha form atual e abre novo
                 */
                //this.Hide();
                var chatView = new ChatView(server, self, destinationClient.Name);
                //onlineList.Closed += (s, args) => this.Close();
                viewChat = chatView;
                chatView.Show();
            }
        }
    }
Beispiel #11
0
    void NotifyChatEvent(Operation op, ClientInstance clientInst, ClientObj clientDestination)
    {
        if (chatEvent != null)
        {
            Delegate[] invkList = chatEvent.GetInvocationList();

            foreach (ChatDelegate handler in invkList)
            {
                new Thread(() =>
                {
                    try
                    {
                        handler(op, clientInst, clientDestination);
                        Console.WriteLine("Invoking event handler (NotifyChatEvent)");
                    }
                    catch (Exception)
                    {
                        chatEvent -= handler;
                        Console.WriteLine("Exception: Removed an event handler (NotifyChatEvent)");
                    }
                }).Start();
            }
        }
    }
Beispiel #12
0
        public JsonResult ProcessEditClientRequest(ClientObj model)
        {
            try
            {
                var userData = MvcApplication.GetUserData(User.Identity.Name) ?? new UserData();

                if (userData.UserId < 1)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }

                var selClient = Session["_CurrentSelClient_"] as ClientObj;
                if (selClient == null || selClient.ClientId < 1)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }

                if (model.ClientId < 1)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid Selection" }));
                }

                if (string.IsNullOrEmpty(model.ClientName) || model.ClientName.Length < 2)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid Client Name" }));
                }
                if (string.IsNullOrEmpty(model.Address) || model.Address.Length < 2)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid Address " }));
                }
                if (string.IsNullOrEmpty(model.MobileNumber) || model.MobileNumber.Length < 7 || model.MobileNumber.Length > 15)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid Mobile Number " }));
                }


                var passObj = new RegResetObj
                {
                    AdminUserId  = userData.UserId,
                    ClientName   = model.ClientName,
                    Address      = model.Address,
                    ClientId     = selClient.ClientId,
                    MobileNumber = model.MobileNumber,
                    Email        = model.Email,
                    Status       = model.StatusVal ? 1 : 0,
                };

                if (!GenericVal.Validate(model, out var msg))
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = $"Validation Error Occurred! Detail: {msg}" }));
                }


                var response = ClientService.UpdateClient(passObj, userData.Username);
                if (response?.Status == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Please try again later" }));
                }

                if (!response.Status.IsSuccessful)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = string.IsNullOrEmpty(response.Status.Message.TechnicalMessage) ? "Process Failed! Unable to add course of study" : response.Status.Message.TechnicalMessage }));
                }

                Session["_CurrentSelClient_"] = null;

                var searchObj = new ClientSearchObj
                {
                    AdminUserId = userData.UserId,
                    ClientId    = 0,
                    Status      = -2
                };

                var retVal = ClientService.LoadClients(searchObj, userData.Username);
                if (retVal?.Status != null && retVal.Clients != null)
                {
                    var clients = retVal.Clients.OrderBy(m => m.ClientId).ToList();
                    Session["_ClientList_"] = clients;
                }
                return(Json(new { IsAuthenticated = true, IsSuccessful = true, IsReload = false, Error = "" }));
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Process Error Occurred! Please try again later" }));
            }
        }
Beispiel #13
0
        public ClientResp ClientDetails(ClientObj param)
        {
            var success = _client.GetClientDetails(param.ClientId);

            return(success);
        }
Beispiel #14
0
 public HeartBeartTask(ClientObj host)
 {
     this.hostObj = host;
 }
 private void Awake()
 {
     clientObj = GetComponentInParent <ClientObj>();
 }
 private void Start()
 {
     SeatOcuppied = new bool[seats.Length];
     client       = Resources.Load <ClientObj>("Prefabs/Client");
     timeForSpawn = Random.Range(timeIntervalBetweenSpawns.x, timeIntervalBetweenSpawns.y);
 }