Exemple #1
0
        public int SaveChanges(Guid UserID)
        {
            var modifiedEntries = ChangeTracker.Entries().Where(x => x.State == EntityState.Modified || x.State == EntityState.Added).ToList();

            string   Identity     = WindowsIdentity.GetCurrent().Name;
            string   ComputerName = Environment.MachineName;
            DateTime dateTime     = DateTime.Now;
            string   ip           = RemoteIp.GetIpAddress();

            foreach (var item in modifiedEntries)
            {
                CoreEntity entity = item.Entity as CoreEntity;
                if (item != null)
                {
                    if (item.State == EntityState.Added)
                    {
                        entity.CreatedADUserName   = Identity;
                        entity.CreatedComputerName = ComputerName;
                        entity.CreatedDate         = dateTime;
                        entity.CreatedBy           = UserID;
                        entity.CreatedIp           = ip;
                    }
                    else if (item.State == EntityState.Modified)
                    {
                        entity.ModifiedADUserName   = Identity;
                        entity.ModifiedBy           = UserID;
                        entity.ModifiedComputerName = ComputerName;
                        entity.ModifiedDate         = dateTime;
                        entity.ModifiedIp           = ip;
                    }
                }
            }
            return(base.SaveChanges());
        }
Exemple #2
0
        public Boolean Open()
        {
            if (IsRunning == false)
            {
                try
                {
                    WinSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    WinSocket.Connect(RemoteIp.ToIpEx(), RemotePort);

                    LocalIp   = (WinSocket.LocalEndPoint as IPEndPoint).Address.ToString();
                    LocalPort = (WinSocket.LocalEndPoint as IPEndPoint).Port;

                    IsRunning = true;

                    ExecuteReceive(WinSocket);
                }
                catch (SocketException ex)
                {
                    LastError = ex.Message;

                    return(false);
                }
                catch (Exception ex)
                {
                    LastError = ex.Message;

                    return(false);
                }
            }

            RaiseOnConnect(WinSocket);

            return(true);
        }
Exemple #3
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (RequestMethod.Length != 0)
            {
                hash ^= RequestMethod.GetHashCode();
            }
            if (RequestUrl.Length != 0)
            {
                hash ^= RequestUrl.GetHashCode();
            }
            if (RequestSize != 0L)
            {
                hash ^= RequestSize.GetHashCode();
            }
            if (Status != 0)
            {
                hash ^= Status.GetHashCode();
            }
            if (ResponseSize != 0L)
            {
                hash ^= ResponseSize.GetHashCode();
            }
            if (UserAgent.Length != 0)
            {
                hash ^= UserAgent.GetHashCode();
            }
            if (RemoteIp.Length != 0)
            {
                hash ^= RemoteIp.GetHashCode();
            }
            if (Referer.Length != 0)
            {
                hash ^= Referer.GetHashCode();
            }
            if (CacheHit != false)
            {
                hash ^= CacheHit.GetHashCode();
            }
            if (ValidatedWithOriginServer != false)
            {
                hash ^= ValidatedWithOriginServer.GetHashCode();
            }
            return(hash);
        }
        public override int SaveChanges()
        {
            //Yeni eklenen veya yeni güncellenen tüm entityleri kayıt edilmeden önce yakalıyoruz ve düzenliyoruz.
            var modifiedEntries = ChangeTracker.Entries().Where(x => x.State == EntityState.Modified || x.State == EntityState.Added).ToList();

            string   identity     = WindowsIdentity.GetCurrent().Name;
            string   computerName = Environment.MachineName;
            DateTime dateTime     = DateTime.Now;
            int      User         = 1;
            string   GetIp        = RemoteIp.GetIpAddress();

            foreach (var item in modifiedEntries)
            {
                CoreEntity entity = item.Entity as CoreEntity;

                if (item != null)
                {
                    if (item.State == EntityState.Added)
                    {
                        entity.CreatedUserName     = identity;
                        entity.CreatedComputerName = computerName;
                        entity.CreatedDate         = dateTime;
                        entity.CreatedBy           = User;
                        entity.CreatedIp           = GetIp;
                    }
                    else if (item.State == EntityState.Modified)
                    {
                        entity.ModifiedUserName     = identity;
                        entity.ModifiedComputerName = computerName;
                        entity.ModifiedDate         = dateTime;
                        entity.ModifiedBy           = User;
                        entity.ModifiedIp           = GetIp;
                    }
                }
            }

            return(base.SaveChanges());
        }
        public override string ToString()
        {
            var sb = new StringBuilder();

            sb.AppendLine(LocalIp.ToString());
            if (RemoteIp != null)
            {
                sb.AppendLine(RemoteIp.ToString());
            }
            if (!String.IsNullOrEmpty(ProcessName))
            {
                sb.AppendLine($"{ProcessName} ({ProcessId})");
                if (ProcessFilename != null)
                {
                    sb.AppendLine(ProcessFilename);
                }
            }
            else
            {
                sb.AppendLine("Process not available");
            }
            sb.AppendLine();
            return(sb.ToString());
        }
Exemple #6
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (RequestMethod.Length != 0)
            {
                hash ^= RequestMethod.GetHashCode();
            }
            if (RequestUrl.Length != 0)
            {
                hash ^= RequestUrl.GetHashCode();
            }
            if (RequestSize != 0L)
            {
                hash ^= RequestSize.GetHashCode();
            }
            if (Status != 0)
            {
                hash ^= Status.GetHashCode();
            }
            if (ResponseSize != 0L)
            {
                hash ^= ResponseSize.GetHashCode();
            }
            if (UserAgent.Length != 0)
            {
                hash ^= UserAgent.GetHashCode();
            }
            if (RemoteIp.Length != 0)
            {
                hash ^= RemoteIp.GetHashCode();
            }
            if (ServerIp.Length != 0)
            {
                hash ^= ServerIp.GetHashCode();
            }
            if (Referer.Length != 0)
            {
                hash ^= Referer.GetHashCode();
            }
            if (latency_ != null)
            {
                hash ^= Latency.GetHashCode();
            }
            if (CacheLookup != false)
            {
                hash ^= CacheLookup.GetHashCode();
            }
            if (CacheHit != false)
            {
                hash ^= CacheHit.GetHashCode();
            }
            if (CacheValidatedWithOriginServer != false)
            {
                hash ^= CacheValidatedWithOriginServer.GetHashCode();
            }
            if (CacheFillBytes != 0L)
            {
                hash ^= CacheFillBytes.GetHashCode();
            }
            if (Protocol.Length != 0)
            {
                hash ^= Protocol.GetHashCode();
            }
            return(hash);
        }
Exemple #7
0
        IEnumerator ClientTcpRoutine()
        {
            bool run = true;

            if (Tcp == null || !Tcp.Connected)
            {
                yield return(null);
            }

            TcpStream = new NetworkStream(Tcp.Client);
            IPEndPoint remote = (IPEndPoint)Tcp.Client.RemoteEndPoint;
            int        dataLen;
            string     msg;
            MsgType    type;

            // Function like a thread; run until terminated
            while (run)
            {
                try
                {
                    if (TcpStream.DataAvailable)
                    {
                        dataLen = TcpStream.Read(TcpRead, 0, TcpRead.Length);
                        byte[] tempBuffer = new byte[dataLen];

                        for (int i = 0; i < tempBuffer.Length; i++)
                        {
                            tempBuffer[i] = TcpRead[i + SUBHEADER_SIZE];
                        }

                        msg  = Encoding.ASCII.GetString(tempBuffer);
                        type = GetMsgType(TcpRead);

                        LocalConsole.Instance.Log("Received [" + type + "] from " + remote.Address + " on port " + remote.Port, true);

                        switch (type)
                        {
                        // Handshake means server is challenging for session id
                        case MsgType.HANDSHAKE:
                            SendMsgTcp(_session, MsgType.HANDSHAKE);
                            break;

                        // Status generally means a heartbeat check from the server
                        case MsgType.STATUS:
                            if (dataLen == SUBHEADER_SIZE)                                       // Empty Status packet is a heartbeat
                            {
                                SendMsgTcp("", MsgType.STATUS);
                            }
                            else
                            {
                                LocalConsole.Instance.Log("Status msg received");
                            }
                            break;

                        // Contains session data
                        case MsgType.SESSION:
                            string[] msgSplit = msg.Split(DELIM);
                            if (msgSplit.Length == 3)                                       // SessionId, Udp port, and Tcp port
                            {
                                if (Int32.TryParse(msgSplit[1], out int nUdp) && Int32.TryParse(msgSplit[2], out int nTcp))
                                {
                                    _session       = msgSplit[0];
                                    _remoteUdpPort = nUdp;
                                    _remoteTcpPort = nTcp;

                                    LocalConsole.Instance.Log("Successfully obtained session data, reconnecting...");

                                    ConnectToRemote(RemoteIp.ToString());
                                }
                                else
                                {
                                    LocalConsole.Instance.Log("Error parsing ports from session data");
                                }
                            }
                            else
                            {
                                LocalConsole.Instance.Log("Error parsing session info from data");
                            }
                            break;

                        case MsgType.MSG:
                        default:
                            LocalConsole.Instance.Log("Msg received");
                            break;
                        }
                    }
                }
                catch (SocketException s)
                {
                    LocalConsole.Instance.LogError("SocketException in ClientTcpRoutine: Code " + s.ErrorCode, true);
                }
                catch (IOException io)
                {
                    LocalConsole.Instance.LogError("IOException in ClientTcpRoutine: " + io.Message, true);
                }
                catch (ObjectDisposedException o)
                {
                    LocalConsole.Instance.LogError("ObjectDisposedException in ClientTcpRoutine: " + o.Message + "," + o.ObjectName, true);
                }

                // yield return null must be in while loop
                yield return(null);
            }
        }