Exemple #1
0
        public static void AddConnection(HubCallerContext context)
        {
            var connectionId   = context.ConnectionId;
            var userIdentifier = context.UserIdentifier;
            var emailClaim     = context.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email)?.Value;

            if (userIdentifier != null)
            {
                var username      = context.User.Identity.Name;
                var websiteClient = new SignalRClient(username, emailClaim, connectionId);

                if (UserConnections.TryGetValue(userIdentifier, out var connectionList))
                {
                    connectionList.Add(websiteClient);
                }
                else
                {
                    UserConnections.TryAdd(userIdentifier, new List <SignalRClient>()
                    {
                        websiteClient
                    });
                }
            }
            else
            {
                VisitorConnections.Add(connectionId);
            }
        }
        internal void AcceptMatch(string steamId)
        {
            lock (_lockObj)
            {
                var lobbyInfo = _lobbyList.FirstOrDefault(l => (l.Player1SteamId == steamId && !l.Player1Left) || (l.Player2SteamId == steamId && !l.Player2Left));
                if (lobbyInfo == null)
                {
                    return;
                }

                if (lobbyInfo.Player1SteamId == steamId)
                {
                    lobbyInfo.Player1MatchAccepted = true;
                }
                if (lobbyInfo.Player2SteamId == steamId)
                {
                    lobbyInfo.Player2MatchAccepted = true;
                }

                if (lobbyInfo.Player1MatchAccepted && lobbyInfo.Player2MatchAccepted)
                {
                    foreach (var client in UserConnections.GetConnections(lobbyInfo.Player1SteamId))
                    {
                        _hubContext.Clients.Client(client).SendAsync("EnterLobby", true);
                    }
                    foreach (var client in UserConnections.GetConnections(lobbyInfo.Player2SteamId))
                    {
                        _hubContext.Clients.Client(client).SendAsync("EnterLobby", true);
                    }
                }
            }
        }
Exemple #3
0
        public static void Start(string connectionString)
        {
            Starter.Start(UserConnections.Replace(connectionString));

            DisconnectedLogic.OfflineMode = true;

            Schema.Current.Initialize();

            stopEvent    = new ManualResetEvent(false);
            startedEvent = new ManualResetEvent(false);

            //http://www.johnplummer.com/dotnet/simple-wcf-service-host.html
            hostThread = new Thread(() =>
            {
                using (ServiceHost host = new ServiceHost(typeof(ServerSouthwindLocal)))
                {
                    host.Open();

                    startedEvent.Set();

                    stopEvent.WaitOne();

                    host.Close();
                }
            });

            hostThread.Start();
            startedEvent.WaitOne();
        }
Exemple #4
0
        }//RegisterRoutes

        protected void Application_Start()
        {
            Statics.SessionFactory = new ScopeSessionFactory(new AspNetSessionFactory());

            Starter.Start(UserConnections.Replace(Settings.Default.ConnectionString));

            using (AuthLogic.Disable())
                Schema.Current.Initialize();

            WebStart();

            ProcessRunnerLogic.StartRunningProcesses(5 * 1000);

            SchedulerLogic.StartScheduledTasks();

            AsyncEmailSenderLogic.StartRunningEmailSenderAsync(5 * 1000);

            RegisterRoutes(RouteTable.Routes);

            AuthLogic.UserLogingIn += user =>
            {
                AllowLogin required = ScopeSessionFactory.IsOverriden ? AllowLogin.WindowsOnly : AllowLogin.WebOnly;

                AllowLogin current = user.Mixin <UserEmployeeMixin>().AllowLogin;

                if (current != AllowLogin.WindowsAndWeb && current != required)
                {
                    throw new UnauthorizedAccessException("User {0} is {1}".FormatWith(user, current.NiceToString()));
                }
            }; //UserLogingIn
        }
Exemple #5
0
        //Commented because of some oddity in NetworkManager that emits these signals multiple times with erroneous data.

        /*
         * void OnConnectionAdded (string objectPath)
         * {
         *      Console.WriteLine ("Connection added: {0}", objectPath);
         * }
         *
         * void OnNetworkConnectionRemoved (object o, NetworkConnection.NetworkConnectionRemovedArgs args)
         * {
         *      Console.WriteLine ("connection removed: {0}", args.ConnectionName);
         * }
         */

        public void UpdateConnections()
        {
            lock (SystemConnections) {
                SystemConnections.Clear();
                try {
                    foreach (string con in SystemConnectionManager.BusObject.ListConnections())
                    {
                        NetworkConnection connection = new NetworkConnection(SystemBus, con, ConnectionOwner.System);
                        if (connection.Settings.ContainsKey("802-11-wireless"))
                        {
                            connection = new WirelessConnection(SystemBus, con, ConnectionOwner.System);
                        }
                        else if (connection.Settings.ContainsKey("802-3-ethernet"))
                        {
                            connection = new WiredConnection(SystemBus, con, ConnectionOwner.System);
                        }
                        else
                        {
                            continue;
                        }
                        //connection.ConnectionRemoved += OnNetworkConnectionRemoved;
                        SystemConnections.Add(connection);
                    }
                } catch (Exception e) {
                    Log <ConnectionManager> .Error(e.Message);

                    Log <ConnectionManager> .Debug(e.StackTrace);
                }
            }

            lock (UserConnections) {
                UserConnections.Clear();
                try {
                    foreach (string con in UserConnectionManager.BusObject.ListConnections())
                    {
                        NetworkConnection connection = new NetworkConnection(UserBus, con, ConnectionOwner.User);
                        if (connection.Settings.ContainsKey("802-11-wireless"))
                        {
                            connection = new WirelessConnection(UserBus, con, ConnectionOwner.User);
                        }
                        else if (connection.Settings.ContainsKey("802-3-ethernet"))
                        {
                            connection = new WiredConnection(UserBus, con, ConnectionOwner.User);
                        }
                        else
                        {
                            continue;
                        }

                        //connection.ConnectionRemoved += OnNetworkConnectionRemoved;
                        UserConnections.Add(connection);
                    }
                } catch (Exception e) {
                    Log <ConnectionManager> .Error(e.Message);

                    Log <ConnectionManager> .Debug(e.StackTrace);
                }
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            UserConnections userConnections = db.UserConnections.Find(id);

            db.UserConnections.Remove(userConnections);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #7
0
 internal void NotifyRequestAdded(int id, ScrimRequestViewModel requestViewModel)
 {
     var recipient = _dbContext.ScrimEvents.FirstOrDefault(e => e.Id == id);
     foreach (var client in UserConnections.GetConnections(recipient.SteamId))
     {
         _hubContext.Clients.Client(client).SendAsync("RequestAdded", requestViewModel);
     }
 }
Exemple #8
0
 public static void RestoreDatabase(string connectionString, string backupFile, string databaseFile, string databaseLogFile)
 {
     DisconnectedLogic.LocalBackupManager.RestoreLocalDatabase(
         UserConnections.Replace(connectionString),
         backupFile,
         databaseFile,
         databaseLogFile);
 }
 public ActionResult Edit([Bind(Include = "ConnectionId,UserId,AppType,AppUrl")] UserConnections userConnections)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userConnections).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UserId = new SelectList(db.UserProfiles, "UserId", "Title", userConnections.UserId);
     return(View(userConnections));
 }
        internal void LeaveLobby(string steamId)
        {
            lock (_lockObj)
            {
                var playerInMatch = _playersInMatch.FirstOrDefault(p => p.SteamId == steamId);
                if (playerInMatch != null)
                {
                    _playersInMatch.Remove(playerInMatch);
                }

                var lobbyInfo      = _lobbyList.FirstOrDefault(l => (l.Player1SteamId == steamId && !l.Player1Left) || (l.Player2SteamId == steamId && !l.Player2Left));
                var pairIdentifier = string.Join('_', new List <string> {
                    lobbyInfo.Player1SteamId, lobbyInfo.Player2SteamId
                }.OrderBy(s => s));
                if (lobbyInfo == null)
                {
                    return;
                }

                if (lobbyInfo.Player1SteamId == steamId)
                {
                    if (lobbyInfo.Player2Left)
                    {
                        _lobbyList.Remove(lobbyInfo);
                        _declineListCache.Set(pairIdentifier, true, DateTime.Now.AddMinutes(30));
                    }
                    else
                    {
                        lobbyInfo.Player1Left = true;
                        foreach (var client in UserConnections.GetConnections(lobbyInfo.Player2SteamId))
                        {
                            _hubContext.Clients.Client(client).SendAsync("OpponentLeftLobby", lobbyInfo.Player1SteamId);
                        }
                    }
                }
                else
                {
                    if (lobbyInfo.Player1Left)
                    {
                        _lobbyList.Remove(lobbyInfo);
                        _declineListCache.Set(pairIdentifier, true, DateTime.Now.AddMinutes(30));
                    }
                    else
                    {
                        lobbyInfo.Player2Left = true;
                        foreach (var client in UserConnections.GetConnections(lobbyInfo.Player1SteamId))
                        {
                            _hubContext.Clients.Client(client).SendAsync("OpponentLeftLobby", lobbyInfo.Player2SteamId);
                        }
                    }
                }
            }
        }
        public ActionResult Create([Bind(Include = "ConnectionId,UserId,AppType,AppUrl")] UserConnections userConnections)
        {
            if (ModelState.IsValid)
            {
                userConnections.UserId = User.Identity.GetUserId();
                db.UserConnections.Add(userConnections);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(userConnections));
        }
Exemple #12
0
        public static void DropDatabase(string connectionString)
        {
            SqlConnectionStringBuilder csb = new SqlConnectionStringBuilder(UserConnections.Replace(connectionString));
            string databaseName            = csb.InitialCatalog;

            csb.InitialCatalog = "";

            using (Connector.Override(new SqlConnector(csb.ToString(), null, null, SqlServerVersion.SqlServer2012)))
            {
                DisconnectedLogic.LocalBackupManager.DropDatabase(new DatabaseName(null, databaseName));
            }
        }
        private bool SearchForOpponent(UserInfo searchingPlayer)
        {
            foreach (var queuedPlayer in _playerQueueList.Where(p => p.SteamId != searchingPlayer.SteamId))
            {
                if (SearchCriteriaMatches(searchingPlayer, queuedPlayer))
                {
                    var matchMakingData = new MatchmakingData
                    {
                        Player1SteamId       = searchingPlayer.SteamId,
                        Player1Mmr           = searchingPlayer.Mmr,
                        Player1Name          = searchingPlayer.DisplayName,
                        Player2SteamId       = queuedPlayer.SteamId,
                        Player2Mmr           = queuedPlayer.Mmr,
                        Player2Name          = queuedPlayer.DisplayName,
                        LobbyName            = $"RLSF{lobbyCounter}",
                        LobbyPassword        = GeneratePassword(),
                        ServerChoices        = queuedPlayer.Servers.Intersect(searchingPlayer.Servers).ToList(),
                        ChatLog              = new List <Models.ChatMessage>(),
                        Player1MatchAccepted = false,
                        Player2MatchAccepted = false,
                    };
                    foreach (var client in UserConnections.GetConnections(searchingPlayer.SteamId))
                    {
                        _hubContext.Clients.Client(client).SendAsync("MatchFound", matchMakingData);
                    }
                    foreach (var client in UserConnections.GetConnections(queuedPlayer.SteamId))
                    {
                        _hubContext.Clients.Client(client).SendAsync("MatchFound", matchMakingData);
                    }
                    lobbyCounter++;
                    if (lobbyCounter == 1000)
                    {
                        lobbyCounter = 1;
                    }

                    //Remove players from queue
                    foreach (var player in _playerQueueList.Where(p => p.SteamId == searchingPlayer.SteamId || p.SteamId == queuedPlayer.SteamId).ToList())
                    {
                        _playerQueueList.Remove(player);
                        _hubContext.Clients.All.SendAsync("PlayerListRemoval", player);
                    }

                    _playersInMatch.Add(searchingPlayer);
                    _playersInMatch.Add(queuedPlayer);
                    _lobbyList.Add(matchMakingData);

                    return(true);
                }
            }
            return(false);
        }
        // GET: UserConnections/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserConnections userConnections = db.UserConnections.Find(id);

            if (userConnections == null)
            {
                return(HttpNotFound());
            }
            return(View(userConnections));
        }
Exemple #15
0
        public static void StartAndLoad()
        {
            if (!startedAndLoaded)
            {
                Start(UserConnections.Replace(Settings.Default.SignumTest));

                Administrator.TotalGeneration();

                Schema.Current.Initialize();

                MusicLoader.Load();

                startedAndLoaded = true;
            }
        }
        // GET: UserConnections/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserConnections userConnections = db.UserConnections.Find(id);

            if (userConnections == null)
            {
                return(HttpNotFound());
            }
            ViewBag.UserId = new SelectList(db.UserProfiles, "UserId", "Title", userConnections.UserId);
            return(View(userConnections));
        }
Exemple #17
0
        public static void Start()
        {
            if (!started)
            {
                var cs = UserConnections.Replace(Settings.Default.ConnectionString);

                if (!cs.Contains("Test")) //Security mechanism to avoid passing test on production
                {
                    throw new InvalidOperationException("ConnectionString does not contain the word 'Test'.");
                }

                Starter.Start(cs);
                started = true;
            }
        }
Exemple #18
0
 internal void DeleteRequest(int id)
 {
     var req = _dbContext.ScrimRequests.Include(r => r.ScrimEvent).FirstOrDefault(r => r.Id == id);
     if (req != null)
     {
         _dbContext.Remove(req);
         _dbContext.SaveChanges();
         foreach (var client in UserConnections.GetConnections(req.ScrimEvent.SteamId))
         {
             _hubContext.Clients.Client(client).SendAsync("RequestDeleted", req.Id);
         }
         foreach (var client in UserConnections.GetConnections(req.SteamId))
         {
             _hubContext.Clients.Client(client).SendAsync("RequestDeleted", req.Id);
         }
     }
 }
 internal void SendMessage(string steamId, string message)
 {
     lock (_lockObj)
     {
         var lobbyInfo  = _lobbyList.FirstOrDefault(l => (l.Player1SteamId == steamId && !l.Player1Left) || (l.Player2SteamId == steamId && !l.Player2Left));
         var newMessage = new Models.ChatMessage {
             SteamId = steamId, Message = message, Sent = DateTime.Now
         };
         lobbyInfo.ChatLog.Add(newMessage);
         foreach (var client in UserConnections.GetConnections(lobbyInfo.Player1SteamId))
         {
             _hubContext.Clients.Client(client).SendAsync("MessageReceived", newMessage);
         }
         foreach (var client in UserConnections.GetConnections(lobbyInfo.Player2SteamId))
         {
             _hubContext.Clients.Client(client).SendAsync("MessageReceived", newMessage);
         }
     }
 }
Exemple #20
0
        void Application_Start(object sender, EventArgs e)
        {
            Starter.Start(UserConnections.Replace(Settings.Default.ConnectionString));

            using (AuthLogic.Disable())
                Schema.Current.Initialize();

            // Code that runs on application startup
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebStart);
            RegisterMvcRoutes(RouteTable.Routes);

            Statics.SessionFactory = new ScopeSessionFactory(new VoidSessionFactory());

            ProcessRunnerLogic.StartRunningProcesses(5 * 1000);

            SchedulerLogic.StartScheduledTasks();

            AsyncEmailSenderLogic.StartRunningEmailSenderAsync(5 * 1000);
        }
        internal void DeclineMatch(string steamId)
        {
            lock (_lockObj)
            {
                var lobbyInfo = _lobbyList.FirstOrDefault(l => (l.Player1SteamId == steamId && !l.Player1Left) || (l.Player2SteamId == steamId && !l.Player2Left));
                if (lobbyInfo == null)
                {
                    return;
                }

                var pairIdentifier = string.Join('_', new List <string> {
                    lobbyInfo.Player1SteamId, lobbyInfo.Player2SteamId
                }.OrderBy(s => s));
                _declineListCache.Set(pairIdentifier, true, DateTime.Now.AddMinutes(30));

                _lobbyList.Remove(lobbyInfo);

                foreach (var client in UserConnections.GetConnections(lobbyInfo.Player1SteamId))
                {
                    _hubContext.Clients.Client(client).SendAsync("DeclinedLobby", true);
                }
                foreach (var client in UserConnections.GetConnections(lobbyInfo.Player2SteamId))
                {
                    _hubContext.Clients.Client(client).SendAsync("DeclinedLobby", true);
                }

                //Place both users back in the queue
                var player1InMatch = _playersInMatch.FirstOrDefault(p => p.SteamId == lobbyInfo.Player1SteamId);
                if (player1InMatch != null)
                {
                    _playersInMatch.Remove(player1InMatch);
                    StartSearch(player1InMatch);
                }
                var player2InMatch = _playersInMatch.FirstOrDefault(p => p.SteamId == lobbyInfo.Player2SteamId);
                if (player2InMatch != null)
                {
                    _playersInMatch.Remove(player2InMatch);
                    StartSearch(player2InMatch);
                }
            }
        }
Exemple #22
0
        public static void RemoveConnection(HubCallerContext context)
        {
            var connectionId   = context.ConnectionId;
            var userIdentifier = context.UserIdentifier;

            if (userIdentifier != null)
            {
                if (UserConnections.TryGetValue(userIdentifier, out var connectionList))
                {
                    connectionList.RemoveAll(x => x.ConnectionId == connectionId);
                    if (!connectionList.Any())
                    {
                        UserConnections.TryRemove(userIdentifier, out _);
                    }
                }
            }
            else
            {
                VisitorConnections.TryRemove(connectionId);
            }
        }
Exemple #23
0
 internal void AddMessage(ChatMessage message)
 {
     _dbContext.ChatMessages.Add(message);
     _dbContext.SaveChanges();
     var scrimEvent = _dbContext.ScrimEvents.FirstOrDefault(e => e.Id == message.ScrimEventId);
     var messageViewModel = new ChatMessageViewModel
     {
         Id = message.Id,
         Message = message.Message,
         Sent = message.Sent,
         SteamId = message.SteamId,
         ScrimEventId = message.ScrimEventId
     };
     foreach (var client in UserConnections.GetConnections(scrimEvent.SteamId))
     {
         _hubContext.Clients.Client(client).SendAsync("MessageReceived", messageViewModel);
     }
     foreach (var client in UserConnections.GetConnections(scrimEvent.OpponentSteamId))
     {
         _hubContext.Clients.Client(client).SendAsync("MessageReceived", messageViewModel);
     }
 }
        public void GetContactsForUser(string userName, char contactType)
        {
            _ua = new UserAccount(userName);

            if (_ua.UserAccountID == 0) return;

            _contacts = new UserAccounts();

            _ucons = new UserConnections();
            _ucons.GetUserConnections(_ua.UserAccountID);

            foreach (UserAccount ua1 in
                _ucons.Where(uc1 => uc1.IsConfirmed && uc1.StatusType == contactType)
                    .Select(uc1 => uc1.FromUserAccountID == _ua.UserAccountID
                        ? new UserAccount(uc1.ToUserAccountID)
                        : new UserAccount(uc1.FromUserAccountID)).Where(ua1 => ua1.IsApproved && !ua1.IsLockedOut))
            {
                _contacts.Add(ua1);
            }

            ViewBag.UserName = _ua.UserName;
            ViewBag.ContactsCount = Convert.ToString(_contacts.Count);
            ViewBag.Contacts = _contacts.ToUnorderdList;
        }
Exemple #25
0
 public static string[] GetConnectionsByUser(string id)
 {
     return(UserConnections.TryGetValue(id, out var connections) ? connections.Select(x => x.ConnectionId).ToArray() : null);
 }
Exemple #26
0
        public ActionResult Visitors()
        {
            mu = Membership.GetUser();
            uad = new UserAccountDetail();
            ua = new UserAccount(Convert.ToInt32(mu.ProviderUserKey));

            if (ua.IsAdmin)
            {
                ViewBag.AdminLink = "/m/auth/default.aspx";
            }

            uad.GetUserAccountDeailForUser(ua.UserAccountID);
            UserAccountDetail uadLooker = new UserAccountDetail();
            uadLooker.GetUserAccountDeailForUser(ua.UserAccountID);

            UserConnections unconfirmedUsers = new UserConnections();
            UserConnections allusrcons = new UserConnections();

            allusrcons.GetUserConnections(Convert.ToInt32(mu.ProviderUserKey));

            foreach (UserConnection uc1 in allusrcons)
            {
                if (!uc1.IsConfirmed && Convert.ToInt32(mu.ProviderUserKey) != uc1.FromUserAccountID)
                {
                    unconfirmedUsers.Add(uc1);
                }
            }

            ViewBag.ApprovalList = unconfirmedUsers.ToUnorderdList;

            ViewBag.BlockedUsers = BootBaronLib.AppSpec.DasKlub.BOL.BlockedUsers.HasBlockedUsers(Convert.ToInt32(mu.ProviderUserKey));

            ViewBag.EnableProfileLogging = uad.EnableProfileLogging;

            LoadVisitorsView(ua.UserName);

            return View();
        }
Exemple #27
0
        public ActionResult MyUsers()
        {
            mu = Membership.GetUser();

            ViewBag.CurrentUserName = mu.UserName;

            if (mu != null)
            {
                uad = new UserAccountDetail();
                uad.GetUserAccountDeailForUser(Convert.ToInt32(mu.ProviderUserKey));

                ViewBag.EnableProfileLogging = uad.EnableProfileLogging;

            }

            UserConnections unconfirmedUsers = new UserConnections();
            UserConnections allusrcons = new UserConnections();

            allusrcons.GetUserConnections(Convert.ToInt32(mu.ProviderUserKey));

            foreach (UserConnection uc1 in allusrcons)
            {
                if (!uc1.IsConfirmed && Convert.ToInt32(mu.ProviderUserKey) != uc1.FromUserAccountID)
                {
                    unconfirmedUsers.Add(uc1);
                }
            }

            ViewBag.ApprovalList = unconfirmedUsers.ToUnorderdList;

            ViewBag.BlockedUsers = BootBaronLib.AppSpec.DasKlub.BOL.BlockedUsers.HasBlockedUsers(Convert.ToInt32(mu.ProviderUserKey));

            return View();
        }
Exemple #28
0
        static int Main(string[] args)
        {
            try
            {
                using (AuthLogic.Disable())
                    using (CultureInfoUtils.ChangeCulture("en"))
                        using (CultureInfoUtils.ChangeCultureUI("en"))
                        {
                            DynamicLogicStarter.AssertRoslynIsPresent();
                            Starter.Start(UserConnections.Replace(Settings.Default.ConnectionString));

                            Console.WriteLine("..:: Welcome to Southwind Loading Application ::..");
                            Console.WriteLine("Database: {0}", Regex.Match(((SqlConnector)Connector.Current).ConnectionString, @"Initial Catalog\=(?<db>.*)\;").Groups["db"].Value);
                            Console.WriteLine();

                            if (args.Any())
                            {
                                switch (args.First().ToLower().Trim('-', '/'))
                                {
                                case "sql": SqlMigrationRunner.SqlMigrations(true); return(0);

                                case "csharp": SouthwindMigrations.CSharpMigrations(true); return(0);

                                case "load": Load(args.Skip(1).ToArray()); return(0);

                                default:
                                {
                                    SafeConsole.WriteLineColor(ConsoleColor.Red, "Unkwnown command " + args.First());
                                    Console.WriteLine("Examples:");
                                    Console.WriteLine("   sql: SQL Migrations");
                                    Console.WriteLine("   csharp: C# Migrations");
                                    Console.WriteLine("   load 1-4,7: Load processes 1 to 4 and 7");
                                    return(-1);
                                }
                                }
                            } //if(args.Any())

                            while (true)
                            {
                                Action action = new ConsoleSwitch <string, Action>
                                {
                                    { "N", NewDatabase },
                                    { "G", CodeGenerator.GenerateCodeConsole },
                                    { "SQL", SqlMigrationRunner.SqlMigrations },
                                    { "CS", () => SouthwindMigrations.CSharpMigrations(false), "C# Migrations" },
                                    { "S", Synchronize },
                                    { "L", () => Load(null), "Load" },
                                }.Choose();

                                if (action == null)
                                {
                                    return(0);
                                }

                                action();
                            }
                        }
            }
            catch (Exception e)
            {
                SafeConsole.WriteColor(ConsoleColor.DarkRed, e.GetType().Name + ": ");
                SafeConsole.WriteLineColor(ConsoleColor.Red, e.Message);
                SafeConsole.WriteLineColor(ConsoleColor.DarkRed, e.StackTrace.Indent(4));
                return(-1);
            }
        }
Exemple #29
0
 public void SaveConnections(UserConnections userConnections)
 {
     SaveObjectToFile(userConnections, _applicationSettings.ConnectionsFile);
 }
        public ActionResult Visitors()
        {
            _uad = new UserAccountDetail();
            if (_mu != null) _ua = new UserAccount(Convert.ToInt32(_mu.ProviderUserKey));

            if (_ua.IsAdmin)
            {
                ViewBag.AdminLink = "/m/auth/default.aspx";
            }

            _uad.GetUserAccountDeailForUser(_ua.UserAccountID);
            var uadLooker = new UserAccountDetail();
            uadLooker.GetUserAccountDeailForUser(_ua.UserAccountID);

            var unconfirmedUsers = new UserConnections();
            var allusrcons = new UserConnections();

            if (_mu != null)
            {
                allusrcons.GetUserConnections(Convert.ToInt32(_mu.ProviderUserKey));

                unconfirmedUsers.AddRange(
                    allusrcons.Where(
                        uc1 => !uc1.IsConfirmed && Convert.ToInt32(_mu.ProviderUserKey) != uc1.FromUserAccountID));
            }

            ViewBag.ApprovalList = unconfirmedUsers.ToUnorderdList;

            ViewBag.BlockedUsers =
                _mu != null &&
                Lib.BOL.BlockedUsers.HasBlockedUsers(Convert.ToInt32(_mu.ProviderUserKey));

            ViewBag.EnableProfileLogging = _uad.EnableProfileLogging;

            if (_mu != null &&
                (Roles.IsUserInRole(_mu.UserName, SiteEnums.RoleTypes.supporter.ToString()) ||
                 Roles.IsUserInRole(_mu.UserName, SiteEnums.RoleTypes.admin.ToString())
                    ))
            {
                LoadVisitorsView(_ua.UserName);
            }

            return View();
        }
Exemple #31
0
 public NorthwindDataContext() :
     base(UserConnections.Replace(global::Southwind.Load.Properties.Settings.Default.NorthwindConnectionString), mappingSource)
 {
     OnCreated();
 }
Exemple #32
0
 public static WebsiteClient[] GetOnlineUsers()
 {
     return(UserConnections.Select(x => new WebsiteClient(x.Key, x.Value)).ToArray());
 }
Exemple #33
0
        public ActionResult ProfileDetail(string userName)
        {
            ViewBag.VideoHeight = (Request.Browser.IsMobileDevice) ? 100 : 277;
            ViewBag.VideoWidth = (Request.Browser.IsMobileDevice) ? 225 : 400;

            ua = new UserAccount(userName);

            UserAccountDetail uad = new UserAccountDetail();
            uad.GetUserAccountDeailForUser(ua.UserAccountID);

            uad.BandsSeen = ContentLinker.InsertBandLinks(uad.BandsSeen, false);
            uad.BandsToSee = ContentLinker.InsertBandLinks(uad.BandsToSee, false);

            MembershipUser mu = Membership.GetUser();

            ProfileModel model = new ProfileModel();

            if (ua.UserAccountID > 0)
            {
                model.UserAccountID = ua.UserAccountID;
                model.PhotoCount = PhotoItems.GetPhotoItemCountForUser(ua.UserAccountID);
                model.CreateDate = ua.CreateDate;
            }

            if (mu != null)
            {
                ViewBag.IsBlocked = BlockedUser.IsBlockedUser(ua.UserAccountID, Convert.ToInt32(mu.ProviderUserKey));
                ViewBag.IsBlocking = BlockedUser.IsBlockedUser(Convert.ToInt32(mu.ProviderUserKey), ua.UserAccountID);

                if (ua.UserAccountID == Convert.ToInt32(mu.ProviderUserKey))
                {
                    model.IsViewingSelf = true;
                }
                else
                {
                    UserConnection ucon = new UserConnection();

                    ucon.GetUserToUserConnection(Convert.ToInt32(mu.ProviderUserKey), ua.UserAccountID);

                    model.UserConnectionID = ucon.UserConnectionID;

                    if (BlockedUser.IsBlockedUser(Convert.ToInt32(mu.ProviderUserKey), ua.UserAccountID))
                    {
                        return RedirectToAction("index", "home");
                    }

                }
            }
            else
            {

                if (uad.MembersOnlyProfile)
                {
                    return RedirectToAction("Account", "LogOn");
                }

            }

            //
            model.UserName = ua.UserName;
            model.CreateDate = ua.CreateDate;
            model.LastActivityDate = ua.LastActivityDate;
            //
            model.DisplayAge = uad.DisplayAge;
            model.Age = uad.YearsOld;
            model.BandsSeen = uad.BandsSeen;
            model.BandsToSee = uad.BandsToSee;
            model.HardwareAndSoftwareSkills = uad.HardwareSoftware;
            model.MessageToTheWorld = uad.AboutDescription;

            model.YouAreFull = uad.Sex;
            model.InterestedInFull = uad.InterestedFull;
            model.RelationshipStatusFull = uad.RelationshipStatusFull ;
            model.RelationshipStatus = uad.RelationshipStatus;
            model.InterestedIn = uad.InterestedIn;
            model.YouAre = uad.YouAre;

            model.Website = uad.ExternalURL;
            model.CountryCode = uad.Country;
            model.CountryName = uad.CountryName;
            model.IsBirthday = uad.IsBirthdayToday;
            model.ProfilePhotoMain = uad.FullProfilePicURL;
            model.ProfilePhotoMainThumb = uad.FullProfilePicThumbURL;
            model.DefaultLanguage = uad.DefaultLanguage;

            model.EnableProfileLogging = uad.EnableProfileLogging;
            model.Handed = uad.HandedFull;
            model.RoleIcon = uad.SiteBages;

            //
            StatusUpdate su = new StatusUpdate();
            su.GetMostRecentUserStatus(ua.UserAccountID);

            if (su.StatusUpdateID > 0)
            {
                model.LastStatusUpdate = su.CreateDate;
                model.MostRecentStatusUpdate = su.Message;
            }

            model.ProfileVisitorCount = ProfileLog.GetUniqueProfileVisitorCount(ua.UserAccountID);

            PhotoItems ptiems = new PhotoItems();
            ptiems.GetUserPhotos(ua.UserAccountID);

            if (ptiems.Count > 0)
            {
                ptiems.Sort((PhotoItem x, PhotoItem y) => (y.CreateDate.CompareTo(x.CreateDate)));

                PhotoItems ptiemsDisplay = new PhotoItems();

                int maxPhotos = 8;

                foreach (PhotoItem pitm1 in ptiems)
                {
                    pitm1.UseThumb = true;
                    if (ptiemsDisplay.Count < maxPhotos)
                    {
                        ptiemsDisplay.Add(pitm1);
                    }
                    else break;
                }

                ptiemsDisplay.UseThumb = true;
                ptiemsDisplay.ShowTitle = false;

                model.HasMoreThanMaxPhotos = (ptiems.Count > maxPhotos);
                ptiemsDisplay.IsUserPhoto = true;
                model.PhotoItems = ptiemsDisplay.ToUnorderdList;
            }

            Contents conts = new Contents();

            conts.GetContentForUser(ua.UserAccountID);

            model.NewsCount = conts.Count;

            if (conts.Count > 0)
            {
                conts.Sort((Content x, Content y) => (y.ReleaseDate.CompareTo(x.ReleaseDate)));

                Contents displayContents = new Contents();
                int maxCont = 1;
                int currentCount = 0;
                foreach (Content ccn1 in conts)
                {
                    currentCount++;
                    if (maxCont >= currentCount)
                    {
                        displayContents.Add(ccn1);
                    }
                    else break;
                }

                displayContents.IncludeStartAndEndTags = false;

                model.NewsArticles = displayContents.ToUnorderdList;

            }

            model.MetaDescription = ua.UserName + " " + BootBaronLib.Resources.Messages.Profile + " " + FromDate.DateToYYYY_MM_DD(ua.LastActivityDate);

            // playlist
            BootBaronLib.AppSpec.DasKlub.BOL.Playlist plyst = new Playlist();

            plyst.GetUserPlaylist(ua.UserAccountID);

            if (plyst.PlaylistID > 0 && PlaylistVideos.GetCountOfVideosInPlaylist(plyst.PlaylistID) > 0)
            {
                ViewBag.AutoPlay = plyst.AutoPlay;
                ViewBag.AutoPlayNumber = (plyst.AutoPlay) ? 1 : 0;
                ViewBag.UserPlaylistID = plyst.PlaylistID;
            }

            if (uad.UserAccountID > 0)
            {
                model.Birthday = uad.BirthDate;

                if (uad.ShowOnMapLegal)
                {

                    byte[] myarray2 = Encoding.Unicode.GetBytes(string.Empty);

                    // because of the foreign cultures, numbers need to stay in the English version unless a javascript encoding could be added
                    string currentLang = Utilities.GetCurrentLanguageCode();

                    Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(SiteEnums.SiteLanguages.EN.ToString());
                    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(SiteEnums.SiteLanguages.EN.ToString());

                    Encoding iso = Encoding.GetEncoding("ISO-8859-1");
                    Encoding utf8 = Encoding.UTF8;

                    model.DisplayOnMap = uad.ShowOnMapLegal;

                    Random rnd = new Random();
                    int offset = rnd.Next(10, 100);

                    SiteStructs.LatLong latlong = GeoData.GetLatLongForCountryPostal(uad.Country, uad.PostalCode);

                    if (latlong.latitude != 0 && latlong.longitude != 0)
                    {
                        model.Latitude = Convert.ToDecimal(latlong.latitude + Convert.ToDouble("0.00" + offset)).ToString();
                        model.Longitude = Convert.ToDecimal(latlong.longitude + Convert.ToDouble("0.00" + offset)).ToString();
                    }
                    else
                    {
                        model.DisplayOnMap = false;
                    }

                    Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(currentLang);
                    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(currentLang);
                }

                ViewBag.ThumbIcon = uad.FullProfilePicThumbURL;

                LoadCurrentImagesViewBag(uad.UserAccountID);
            }

            ViewBag.UserAccountDetail = uad;
            ViewBag.UserAccount = ua;

            UserConnections ucons = new UserConnections();
            ucons.GetUserConnections(ua.UserAccountID);
            ucons.Shuffle();

            UserAccounts irlContacts = new UserAccounts();
            UserAccounts CyberAssociates = new UserAccounts();
            UserAccount userCon = null;

            foreach (UserConnection uc1 in ucons)
            {
                if (!uc1.IsConfirmed) continue;

                switch (uc1.StatusType)
                {
                    case 'C':
                        if (CyberAssociates.Count >= maxcountusers) continue;

                        if (uc1.ToUserAccountID != ua.UserAccountID)
                        {
                            userCon = new UserAccount(uc1.ToUserAccountID);
                        }
                        else
                        {
                            userCon = new UserAccount(uc1.FromUserAccountID);
                        }
                        CyberAssociates.Add(userCon);
                        break;
                    case 'R':
                        if (irlContacts.Count >= maxcountusers) continue;

                        if (uc1.ToUserAccountID != ua.UserAccountID)
                        {
                            userCon = new UserAccount(uc1.ToUserAccountID);
                        }
                        else
                        {
                            userCon = new UserAccount(uc1.FromUserAccountID);
                        }
                        irlContacts.Add(userCon);
                        break;
                    default:
                        break;
                }
            }

            if (irlContacts.Count > 0)
            {
                model.IRLFriendCount = irlContacts.Count;
            }

            if (CyberAssociates.Count > 0)
            {
                // ViewBag.CyberAssociatesCount = Convert.ToString( CyberAssociates.Count );
                model.CyberFriendCount = CyberAssociates.Count;
            }

            mu = Membership.GetUser();
            UserAccountDetail uadLooker = null;

            if (mu != null)
            {
                uadLooker = new UserAccountDetail();
                uadLooker.GetUserAccountDeailForUser(Convert.ToInt32(mu.ProviderUserKey));
            }

            if (mu != null && ua.UserAccountID > 0 &&
                uadLooker.EnableProfileLogging && uad.EnableProfileLogging)
            {
                ProfileLog pl = new ProfileLog();

                pl.LookedAtUserAccountID = ua.UserAccountID;
                pl.LookingUserAccountID = Convert.ToInt32(mu.ProviderUserKey);

                if (pl.LookingUserAccountID != pl.LookedAtUserAccountID) pl.Create();

                ArrayList al = ProfileLog.GetRecentProfileViews(ua.UserAccountID);

                if (al != null && al.Count > 0)
                {
                    UserAccounts uas = new UserAccounts();

                    UserAccount viewwer = null;

                    foreach (int ID in al)
                    {
                        viewwer = new UserAccount(ID);
                        if (!viewwer.IsLockedOut && viewwer.IsApproved)
                        {
                            if (uas.Count >= maxcountusers) break;

                            uas.Add(viewwer);
                        }
                    }

                   // model.ViewingUsers = uas.ToUnorderdList;
                }
            }

            UserAccountVideos uavs = null;

            if (ua.UserAccountID > 0)
            {
                uavs = new UserAccountVideos();

                uavs.GetRecentUserAccountVideos(ua.UserAccountID, 'F');

                if (uavs.Count > 0)
                {
                    Videos favvids = new Videos();
                    Video f1 = new Video();

                    foreach (UserAccountVideo uav1 in uavs)
                    {
                        f1 = new Video(uav1.VideoID);
                        if (f1.IsEnabled) favvids.Add(f1);
                    }

                    SongRecord sng1 = null;
                    SongRecords sngrcds2 = new SongRecords();

                    foreach (Video v1 in favvids)
                    {
                        sng1 = new SongRecord(v1);
                        sngrcds2.Add(sng1);
                    }

                    sngrcds2.IsUserSelected = true;

                    ViewBag.UserFavorites = sngrcds2.VideosList();//.ListOfVideos();
                }
            }

            // this is either a youtube user or this is a band
            Artist art = new Artist(  );
            art.GetArtistByAltname(userName);

            if (art.ArtistID > 0)
            {
                // try this way for dashers
                model.UserName = art.Name;
            }

            Videos vids = new Videos();
            SongRecords sngrs = new SongRecords();

            if (art.ArtistID == 0)
            {
                vids.GetAllVideosByUser(userName);

                uavs = new UserAccountVideos();
                uavs.GetRecentUserAccountVideos(ua.UserAccountID, 'U');

                Video f2 = null;

                foreach (UserAccountVideo uav1 in uavs)
                {
                    f2 = new Video(uav1.VideoID);

                    if (!vids.Contains(f2)) vids.Add(f2);
                }

                vids.Sort((Video x, Video y) => (y.PublishDate.CompareTo(x.PublishDate)));

                model.UserName = userName;

            }
            else
            {
                // photo
                ArtistProperty aprop = new ArtistProperty();
                aprop.GetArtistPropertyForTypeArtist(art.ArtistID, SiteEnums.ArtistPropertyType.PH.ToString());

                if (!string.IsNullOrEmpty(aprop.PropertyContent))
                {
                    ViewBag.ArtistPhoto = System.Web.VirtualPathUtility.ToAbsolute(aprop.PropertyContent);
                    ViewBag.ThumbIcon = System.Web.VirtualPathUtility.ToAbsolute(aprop.PropertyContent);
                }

                // meta descriptione
                aprop = new ArtistProperty();
                aprop.GetArtistPropertyForTypeArtist(art.ArtistID, SiteEnums.ArtistPropertyType.MD.ToString());
                if (!string.IsNullOrEmpty(aprop.PropertyContent)) ViewBag.MetaDescription = aprop.PropertyContent;

                // description
                aprop = new ArtistProperty();
                aprop.GetArtistPropertyForTypeArtist(art.ArtistID, SiteEnums.ArtistPropertyType.LD.ToString());
                if (!string.IsNullOrEmpty(aprop.PropertyContent)) ViewBag.ArtistDescription = ContentLinker.InsertBandLinks(aprop.PropertyContent, false);

                #region rss
                ///// rss
                //RssResources rssrs = new RssResources();

                //rssrs.GetArtistRssResource(art.ArtistID);

                //if (rssrs.Count > 0)
                //{
                //    RssItems ritems = new RssItems();
                //    RssItems ritemsOUT = new RssItems();

                //    foreach (RssResource rssre in rssrs)
                //    {
                //        ritems.GetTopRssItemsForResource(rssre.RssResourceID);
                //        //ritm = new RssItem(rssre..ArtistID);
                //    }

                //    ritems.Sort((RssItem x, RssItem y) => (y.PubDate.CompareTo(x.PubDate)));

                //    foreach (RssItem ritm in ritems)
                //    {
                //        if (ritemsOUT.Count < 10)
                //        {
                //            ritemsOUT.Add(ritm);
                //        }
                //    }

                //    ViewBag.ArtistNews = ritemsOUT.ToUnorderdList;
                //}
                //else
                //{
                //    ViewBag.ArtistNews = null;
                //}

                //ViewBag.DisplayName = art.DisplayName;
                #endregion

                Songs sngss = new Songs();

                sngss.GetSongsForArtist(art.ArtistID);

                SongRecord snrcd = new SongRecord();

                foreach (Song sn1 in sngss)
                {
                    vids.GetVideosForSong(sn1.SongID);
                }
            }

            vids.Sort(delegate(Video p1, Video p2)
            {
                return p2.PublishDate.CompareTo(p1.PublishDate);
            });

            foreach (BootBaronLib.AppSpec.DasKlub.BOL.Video v1 in vids)
            {
                sngrs.Add(new SongRecord(v1));
            }

            if (mu != null && ua.UserAccountID != Convert.ToInt32(mu.ProviderUserKey))
            {
                UserConnection uc1 = new UserConnection();

                uc1.GetUserToUserConnection(ua.UserAccountID, Convert.ToInt32(mu.ProviderUserKey));

                if (uc1.UserConnectionID > 0)
                {

                    switch (uc1.StatusType)
                    {
                        case 'C':
                            if (uc1.IsConfirmed)
                            {
                                model.IsCyberFriend = true;
                            }
                            else
                            {
                                model.IsWatingToBeCyberFriend = true;
                            }
                            break;
                        case 'R':
                            if (uc1.IsConfirmed)
                            {
                                model.IsRealFriend = true;
                            }
                            else
                            {
                                model.IsWatingToBeRealFriend = true;
                            }
                            break;
                        default:
                            model.IsDeniedCyberFriend = true;
                            model.IsDeniedRealFriend = true;
                            break;
                    }
                }
            }

            if (sngrs == null || sngrs.Count == 0 && art.ArtistID == 0 && ua.UserAccountID == 0)
            {
                // no longer exists
                Response.RedirectPermanent("/");
                return new EmptyResult();
            }

            //sngrs.Sort((SongRecord x, SongRecord y) => (y.cre.CompareTo(x.CreateDate)));

            SongRecords sngDisplay = new SongRecords();

            Video vidToShow = null;

            foreach (SongRecord sr1 in sngrs)
            {
                vidToShow = new Video(sr1.VideoID);

                if (vidToShow.IsEnabled)
                {
                    sngDisplay.Add(sr1);
                }
            }

            model.SongRecords = sngDisplay.VideosList();

            return View(model);
        }
Exemple #34
0
        public void GetContactsForUser(string userName, char contactType)
        {
            ua = new UserAccount(userName);

            //  if (Membership.GetUser().UserName != ua.UserName) return View();

            if (ua.UserAccountID == 0) return;

            contacts = new UserAccounts();

            UserAccount ua1 = null;

            ucons = new UserConnections();
            ucons.GetUserConnections(ua.UserAccountID);

            foreach (UserConnection uc1 in ucons)
            {
                if (!uc1.IsConfirmed || uc1.StatusType != contactType) continue;

                if (uc1.FromUserAccountID == ua.UserAccountID)
                {
                    ua1 = new UserAccount(uc1.ToUserAccountID);
                }
                else
                {
                    ua1 = new UserAccount(uc1.FromUserAccountID);
                }

                if (ua1.IsApproved && !ua1.IsLockedOut)
                {
                    contacts.Add(ua1);
                }

            }

            ViewBag.UserName = ua.UserName;
            ViewBag.ContactsCount = Convert.ToString(contacts.Count);
            ViewBag.Contacts = contacts.ToUnorderdList;
        }
        public ActionResult MyUsers()
        {
            if (_mu != null)
            {
                ViewBag.CurrentUserName = _mu.UserName;

                if (_mu != null)
                {
                    _uad = new UserAccountDetail();
                    _uad.GetUserAccountDeailForUser(Convert.ToInt32(_mu.ProviderUserKey));

                    ViewBag.EnableProfileLogging = _uad.EnableProfileLogging;
                }
            }

            var unconfirmedUsers = new UserConnections();
            var allusrcons = new UserConnections();

            if (_mu != null)
            {
                allusrcons.GetUserConnections(Convert.ToInt32(_mu.ProviderUserKey));

                unconfirmedUsers.AddRange(
                    allusrcons.Where(
                        uc1 => !uc1.IsConfirmed && Convert.ToInt32(_mu.ProviderUserKey) != uc1.FromUserAccountID));
            }

            ViewBag.ApprovalList = unconfirmedUsers.ToUnorderdList;

            ViewBag.BlockedUsers =
                _mu != null &&
                Lib.BOL.BlockedUsers.HasBlockedUsers(Convert.ToInt32(_mu.ProviderUserKey));

            return View();
        }
        private void GetUserContacts(ProfileModel model)
        {
            var ucons = new UserConnections();
            ucons.GetUserConnections(_ua.UserAccountID);
            ucons.Shuffle();

            var irlContacts = new UserAccounts();
            var cyberAssociates = new UserAccounts();

            foreach (UserConnection uc1 in ucons.Where(uc1 => uc1.IsConfirmed))
            {
                UserAccount userCon;
                switch (uc1.StatusType)
                {
                    case 'C':
                        if (cyberAssociates.Count >= Maxcountusers) continue;

                        userCon = uc1.ToUserAccountID != _ua.UserAccountID
                            ? new UserAccount(uc1.ToUserAccountID)
                            : new UserAccount(uc1.FromUserAccountID);
                        cyberAssociates.Add(userCon);
                        break;
                    case 'R':
                        if (irlContacts.Count >= Maxcountusers) continue;

                        userCon = uc1.ToUserAccountID != _ua.UserAccountID
                            ? new UserAccount(uc1.ToUserAccountID)
                            : new UserAccount(uc1.FromUserAccountID);
                        irlContacts.Add(userCon);
                        break;
                }
            }

            if (irlContacts.Count > 0)
            {
                model.IRLFriendCount = irlContacts.Count;
            }

            if (cyberAssociates.Count > 0)
            {
                model.CyberFriendCount = cyberAssociates.Count;
            }
        }