예제 #1
0
 protected BaseSyncClient(
     ITimedSynchronizerService timedService,
     IPusherService pusherService)
 {
     _timedService  = timedService;
     _pusherService = pusherService;
 }
예제 #2
0
 public static ServiceRegistration Create <TNotification>(IPusherService service, string applicationId = null)
 {
     return(new ServiceRegistration()
     {
         ApplicationId = applicationId,
         Service = service,
         NotificationType = typeof(TNotification)
     });
 }
예제 #3
0
        /// <summary>
        /// Registers the service to be eligible to handle queued notifications of the specified type
        /// </summary>
        /// <param name="pushService">Push service to be registered</param>
        /// <param name="applicationId">Arbitrary Application identifier to register this service with.  When queueing notifications you can specify the same Application identifier to ensure they get queued to the same service instance </param>
        /// <param name="raiseErrorOnDuplicateRegistrations">If set to <c>true</c> raises an error if there is an existing registration for the given notification type.</param>
        /// <typeparam name="TPushNotification">Type of notifications to register the service for</typeparam>
        public void RegisterService <TPushNotification>(IPusherService pushService, string applicationId, bool raiseErrorOnDuplicateRegistrations = true) where TPushNotification : Notification
        {
            if (raiseErrorOnDuplicateRegistrations && GetRegistrations <TPushNotification> (applicationId).Any())
            {
                throw new InvalidOperationException("There's already a service registered to handle " + typeof(TPushNotification).Name + " notification types for the Application Id: " + (applicationId ?? "[ANY].  If you want to register the service anyway, pass in the raiseErrorOnDuplicateRegistrations=true parameter to this method."));
            }

            var registration = ServiceRegistration.Create <TPushNotification> (pushService, applicationId);

            lock (serviceRegistrationsLock)
                serviceRegistrations.Add(registration);

            pushService.OnChannelCreated            += OnChannelCreated;
            pushService.OnChannelDestroyed          += OnChannelDestroyed;
            pushService.OnChannelException          += OnChannelException;
            pushService.OnDeviceSubscriptionExpired += OnDeviceSubscriptionExpired;
            pushService.OnNotificationFailed        += OnNotificationFailed;
            pushService.OnNotificationSent          += OnNotificationSent;
            pushService.OnNotificationRequeue       += OnNotificationRequeue;
            pushService.OnServiceException          += OnServiceException;
            pushService.OnDeviceSubscriptionChanged += OnDeviceSubscriptionChanged;
        }
예제 #4
0
        public MainForm()
        {
            InitializeComponent();

            this.Load += (o, e) => {
                var factory = new ChannelFactory <IPusherService> ("PusherService");
                factory.Endpoint.Behaviors.Add(new WebHttpBehavior());
                _service = factory.CreateChannel();
                _refreshRecipients();
            };

            this.txtNotification.TextChanged += (o, e) =>
                                                this.btnSend.Enabled =
                !String.IsNullOrEmpty(this.txtNotification.Text) ||
                this.imageBox.Image != null
            ;

            this.btnRefresh.Click += (o, e) => _refreshRecipients();

            this.btnSend.Click += (o, e) => {
                try {
                    if (!String.IsNullOrEmpty(txtNotification.Text))
                    {
                        _service.Push(new PusherContent {
                            Text       = txtNotification.Text,
                            Recipients = new PusherRecipient[] {
                                cmbRecipients.SelectedItem as PusherRecipient
                            }
                        });
                        txtNotification.Text = String.Empty;
                    }

                    if (this.imageBox.Image != null)
                    {
                        var thumbNail = this.imageBox.Image.GetThumbnailImage(295, 200, () => false, IntPtr.Zero);
                        using (var stream = new MemoryStream()) {
                            thumbNail.Save(stream, ImageFormat.Jpeg);
                            stream.Seek(0, SeekOrigin.Begin);

                            _service.Push(new PusherContent {
                                Image      = stream.ToArray(),
                                Recipients = new PusherRecipient[] {
                                    cmbRecipients.SelectedItem as PusherRecipient
                                }
                            });
                            this.imageBox.Image = null;
                        }
                    }


                    MessageBox.Show("Message was sent successfully!");
                } catch (Exception ex) {
                    MessageBox.Show(this, ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            };

            ((Control)this.imageBox).AllowDrop = true;
            this.imageBox.DoubleClick         += (o, e) => {
                this.imageBox.Image             = null;
                this.lblDragInstruction.Visible = true;
                if (String.IsNullOrEmpty(this.txtNotification.Text))
                {
                    this.btnSend.Enabled = false;
                }
            };

            this.imageBox.DragEnter += (o, e) => {
                if (e.Data.GetDataPresent(DataFormats.FileDrop))
                {
                    e.Effect = DragDropEffects.Copy;
                }
            };

            this.imageBox.DragDrop += (o, e) => {
                var files = (String[])e.Data.GetData(DataFormats.FileDrop);
                if (files != null && files.Length == 1)
                {
                    this.imageBox.Image             = Image.FromFile(files[0]);
                    this.lblDragInstruction.Visible = false;
                    this.btnSend.Enabled            = true;
                }
            };
        }
예제 #5
0
 public StoreController(IProductService productRepository, IPusherService pusherService)
 {
     _productService = productRepository;
     _pusherService = pusherService;
 }
예제 #6
0
        public MainForm()
        {
            InitializeComponent ();

            this.Load += (o, e) => {
                var factory = new ChannelFactory<IPusherService> ("PusherService");
                factory.Endpoint.Behaviors.Add (new WebHttpBehavior ());
                _service = factory.CreateChannel ();
                _refreshRecipients ();
            };

            this.txtNotification.TextChanged += (o, e) =>
                this.btnSend.Enabled =
                    !String.IsNullOrEmpty (this.txtNotification.Text) ||
                    this.imageBox.Image != null
            ;

            this.btnRefresh.Click += (o, e) => _refreshRecipients ();

            this.btnSend.Click += (o, e) => {
                try {
                    if (!String.IsNullOrEmpty (txtNotification.Text)) {
                        _service.Push (new PusherContent {
                            Text = txtNotification.Text,
                            Recipients = new PusherRecipient[] {
                                cmbRecipients.SelectedItem as PusherRecipient
                            }
                        });
                        txtNotification.Text = String.Empty;
                    }

                    if (this.imageBox.Image != null) {
                        var thumbNail = this.imageBox.Image.GetThumbnailImage (295, 200, () => false, IntPtr.Zero);
                        using (var stream = new MemoryStream ()) {
                            thumbNail.Save (stream, ImageFormat.Jpeg);
                            stream.Seek (0, SeekOrigin.Begin);

                            _service.Push (new PusherContent {
                                Image = stream.ToArray (),
                                Recipients = new PusherRecipient[] {
                                    cmbRecipients.SelectedItem as PusherRecipient
                                }
                            });
                            this.imageBox.Image = null;
                        }
                    }

                    MessageBox.Show ("Message was sent successfully!");

                } catch (Exception ex) {
                    MessageBox.Show (this, ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            };

            ((Control)this.imageBox).AllowDrop = true;
            this.imageBox.DoubleClick += (o, e) => {
                this.imageBox.Image = null;
                this.lblDragInstruction.Visible = true;
                if (String.IsNullOrEmpty (this.txtNotification.Text))
                    this.btnSend.Enabled = false;
            };

            this.imageBox.DragEnter += (o, e) => {
                if (e.Data.GetDataPresent (DataFormats.FileDrop)) {
                    e.Effect = DragDropEffects.Copy;
                }
            };

            this.imageBox.DragDrop += (o, e) => {
                var files = (String[])e.Data.GetData (DataFormats.FileDrop);
                if (files != null && files.Length == 1) {
                    this.imageBox.Image = Image.FromFile (files[0]);
                    this.lblDragInstruction.Visible = false;
                    this.btnSend.Enabled = true;
                }
            };
        }
예제 #7
0
 /// <summary>
 /// Registers the service to be eligible to handle queued notifications of the specified type
 /// </summary>
 /// <param name="pushService">Push service to be registered</param>
 /// <param name="raiseErrorOnDuplicateRegistrations">If set to <c>true</c> raises an error if there is an existing registration for the given notification type.</param>
 /// <typeparam name="TPushNotification">Type of notifications to register the service for</typeparam>
 public void RegisterService <TPushNotification>(IPusherService pushService, bool raiseErrorOnDuplicateRegistrations = true) where TPushNotification : Notification
 {
     RegisterService <TPushNotification> (pushService, null, raiseErrorOnDuplicateRegistrations);
 }
예제 #8
0
 public PictureparkSyncClientImpl(
     ITimedSynchronizerService timedService, IPusherService pusherService
     ) : base(timedService, pusherService)
 {
 }
예제 #9
0
 public ChatController(IPusherService pusherService)
 {
     _pusherService = pusherService;
 }