Beispiel #1
0
        protected async override void OnStartup(StartupEventArgs e)
        {
            if (HasAnotherInstanceRunning())
            {
                Current.Shutdown();
            }

            InitLog();

            base.OnStartup(e);

            this.DispatcherUnhandledException += App_DispatcherUnhandledException;

            var config = DataCache.Load<UserConfig>();
            if (config == null)
            {
                config = new UserConfig();
                config.FirstRun = false;
                StartupRegistration.IsRegisteredForStartup = true;
                DataCache.Save(config);
            }
            if (!StartupRegistration.IsRegisteredForStartMenu)
            {
                StartupRegistration.RegisterForStartMenu();
            }

            user = GetUser();

            if (user == null)
            {
                Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
                var editUser = new EditUser();
                editUser.ShowDialog();
                user = new User()
                {
                    EmailAddress = editUser.FirstName + "." + editUser.LastName + "@placeholder",
                    FullName = editUser.FirstName + " " + editUser.LastName,
                    UserName = editUser.FirstName + "~" + editUser.LastName
                };
                DataCache.Save(user);
                Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
            }

            hub = new Hub(user, Dispatcher);
            groupsCache = new GroupsCache();            
            queueUpdater = new QueueUpdater(hub, user, groupsCache);

            hub.QueueMembershipChanged += QueueMembershipChanged;
            hub.QueueCreated += QueueCreated;
            hub.QueueStatusChanged += QueueStatusChanged;
            hub.QueueMessageReceived += QueueMessageReceived;
            hub.QueueNagged += QueueNagged;

            hub.PropertyChanged += HubPropertyChanged;

            if (hub.ConnectionState == ConnectionState.Connected)
            {
                await queueUpdater.RefreshALl();
            }
        }
Beispiel #2
0
Datei: Hub.cs Projekt: lx223/Q3
        public Hub(User user, Dispatcher dispatcher)
        {
            this.user = user;
            this.dispatcher = dispatcher;

#if DEBUG && !LIVE
            hubConnection = new HubConnection("http://localhost:51443/");
#else
            hubConnection = new HubConnection("http://poolq3.zoo.lan/"); 
#endif

            hubConnection.TraceLevel = TraceLevels.All;
            hubConnection.TraceWriter = new NLogTextWriter("signalr");

            hub = hubConnection.CreateHubProxy("QHub");
            hub.On<Queue>("NewQueue", q => RaiseEvent("created", QueueCreated, q));
            hub.On<Queue>("QueueMembershipChanged", q => RaiseEvent("membershipchanged", QueueMembershipChanged, q));
            hub.On<Queue>("QueueStatusChanged", q => RaiseEvent("statuschanged", QueueStatusChanged, q));
            hub.On<int, User, string>("QueueMessageSent", RaiseMessageEvent);
            hub.On<int>("NagQueue", id => RaiseEvent("nag", QueueNagged, id));
            hubConnection.Headers["User"] = this.user.ToString();
            hubConnection.StateChanged += HubConnectionOnStateChanged;
            hubConnection.Error += e => logger.Error(e, "hub error");

            TryConnect();
        }
Beispiel #3
0
        public ChatControls(User user)
        {
            InitializeComponent();

            AvatarCanvas.Children.Add(new Avatar(user));

            MessageText.KeyUp += MessageTextOnKeyUp;

            this.IsVisibleChanged += ChatControls_IsVisibleChanged;
        }
Beispiel #4
0
        public QueueUpdater(Hub hub, User user, GroupsCache groupsCache)
        {
            this.hub = hub;
            this.user = user;

            this.groupsCache = groupsCache;           

            queueList = new QueueList(hub, groupsCache);
            queueList.Show();

            alertDisplayTimer = new DisplayTimer(queueList);
        }
Beispiel #5
0
        public Avatar(User user)
        {
            this.user = user;
            InitializeComponent();

            var initials = GetInitials();

            InitialsLabel.Content = initials;

            MD5 md5 = MD5.Create();
            byte[] hash = md5.ComputeHash(Encoding.UTF8.GetBytes(user.EmailAddress));
            double hue = hash[0];
            hue = hue / 256d * 360d;

            var hsl = new Spectrum.Color.HSL(hue, 0.8d, 0.3d);
            var rgb = hsl.ToRGB();
            InitialsLabel.Background = new SolidColorBrush(Color.FromRgb(rgb.R, rgb.G, rgb.B));
            InitialsLabel.Foreground = new SolidColorBrush(Colors.White);            
            
            var image = new BitmapImage(new Uri(new Gravatar().GetUrl(user.EmailAddress, 24, GravatarRating.G, "blank" )), new RequestCachePolicy(RequestCacheLevel.Default));
            AvatarImage.Source = image;
            AvatarImage.ToolTip = user.FullName;

        }
Beispiel #6
0
 public void AddQueueMessage(int queueId, User sender, string message)
 {
     logger.Debug(nameof(AddQueueMessage));
     if (queuesById.ContainsKey(queueId))
     { 
         var q = queuesById[queueId];
         q.AddMessage(new Queue.Message() {Sender = sender, Content = message});
     }
 }
Beispiel #7
0
Datei: Hub.cs Projekt: lx223/Q3
 private void RaiseMessageEvent(int queueId, User sender, string message)
 {
     logger.Info("hub messaage " + queueId + " " + sender + " " + message);
     QueueMessageReceived.SafeInvoke(this, new QueueMessageEventArgs(queueId, sender, message));
 }
Beispiel #8
0
 public QueueMessageEventArgs(int queueId, User sender, string message) : base(queueId)
 {
     this.sender = sender;
     this.message = message;
 }
Beispiel #9
0
        private User GetUser()
        {
            User user;

            try
            {
                var principal = UserPrincipal.Current;

                user = new User()
                {
                    UserName = principal.SamAccountName,
                    EmailAddress = principal.EmailAddress,
                    FullName = principal.DisplayName
                };
                DataCache.Save(user);

            }
            catch (Exception e)
            {
                logger.Warn("Failed to read user from AD. Using cache");
                user = DataCache.Load<User>();
            }

#if DEBUG 
            user = user ?? new User();
            var suffix = (DateTime.Now.Ticks % 100).ToString();
            var alphabet = "abcdefghijklmnopqrstuvwxyz";
            user.UserName = user.UserName + suffix;
            user.FullName = user.FullName + suffix;

            var first = (int) (DateTime.Now.Ticks%26);
            var second = (int) ((DateTime.Now.Ticks/26) %26);

            user.EmailAddress = alphabet[first] + "." + alphabet[second] + "@softwire.com";

#endif
            return user;
        }