Example #1
0
        //private static void SavePositions(List<PositionViewModel> positions)
        //{

        //    ThreadPool.QueueUserWorkItem(delegate(object r)
        //    {

        //        lock (PositionSaveLock)
        //        {

        //            string fileName = "positions.xml";

        //            XmlSerializer serializer = new XmlSerializer(typeof(List<PositionViewModel>));

        //            FileInfo info = new FileInfo(fileName);

        //            if (!File.Exists(fileName))
        //            {

        //                StreamWriter writer = info.CreateText();

        //                serializer.Serialize(writer, positions);

        //                writer.Close();

        //            }

        //            else
        //            {

        //                info.Delete();

        //                StreamWriter writer2 = info.CreateText();

        //                serializer.Serialize(writer2, positions);

        //                writer2.Close();

        //            }

        //        }

        //    });

        //}



        private static void SendMessageReceipt(MessageViewModel message, bool updateList = true)
        {
            var client = new ServiceClient();

            try
            {
                client.MessageRead(message.ID);
            }

            catch (TimeoutException exception)
            {
                Console.WriteLine("Got {0}", exception.GetType());
                client.Abort();
            }

            catch (CommunicationException exception2)
            {
                Console.WriteLine("Got {0}", exception2.GetType());
                client.Abort();
            }

            if (updateList)
            {
                UnProcessedMessages.Remove(message);
            }
        }
Example #2
0
        private void SendKeepAliveMessage()
        {
            ServiceClient client = new ServiceClient("BasicHttpBinding_IService", Constants.ServerAddress);

            try
            {
                if (client.ClientCredentials != null)
                {
                    client.ClientCredentials.Windows.ClientCredential.UserName = "******";
                    client.ClientCredentials.Windows.ClientCredential.Password = "******";
                }
                if (client.SayHiKey(new HardwareKey().Key) != "Hi there")
                {
                    Console.WriteLine("Server_Down");
                }
                else if (!this._checkedForNewMessages)
                {
                    this._checkedForNewMessages = true;
                }
            }
            catch (TimeoutException exception)
            {
                Console.WriteLine("Got {0}", exception.GetType());
                client.Abort();
            }
            catch (CommunicationException exception2)
            {
                Console.WriteLine("Got {0}", exception2.GetType());
                client.Abort();
            }
            catch (Exception exception3)
            {
                Console.WriteLine("Server Down" + exception3.Message + exception3.StackTrace);
            }
        }
Example #3
0
        private void ProcessInformationMessage(MessageViewModel message)
        {
            MessageBox.Show(this, message.Text, message.Type, MessageBoxButton.OKCancel, MessageBoxImage.Exclamation);
            ServiceClient client = new ServiceClient();

            try
            {
                try
                {
                    client.MessageRead(message.ID);
                }
                catch (TimeoutException exception)
                {
                    Console.WriteLine("Got {0}", exception.GetType());
                    client.Abort();
                }
                catch (CommunicationException exception2)
                {
                    Console.WriteLine("Got {0}", exception2.GetType());
                    client.Abort();
                }
            }
            finally
            {
            }
        }
Example #4
0
        private void StartKeepAliveThread()
        {
            ThreadPool.QueueUserWorkItem(delegate(object state)
            {
                this.PlayCurrentMosaic();

                ThreadPool.QueueUserWorkItem(delegate(object e)
                {
                    LoadMosaic(null);
                });

                while (true)
                {
                    ServiceClient client = new ServiceClient("BasicHttpBinding_IService", Constants.ServerAddress);

                    try
                    {
                        client.ClientCredentials.Windows.ClientCredential.UserName = "******";

                        client.ClientCredentials.Windows.ClientCredential.Password = "******";

                        if (client.SayHi(Constants.MyStationID) != "Hi there")
                        {
                            Console.WriteLine("Server Down");
                        }

                        else if (!this.CheckedForNewMessages)
                        {
                            this.GetMedia(null);

                            this.CheckedForNewMessages = true;
                        }
                    }

                    catch (TimeoutException exception)
                    {
                        Console.WriteLine("Got {0}", exception.GetType());

                        client.Abort();
                    }

                    catch (CommunicationException exception2)
                    {
                        Console.WriteLine("Got {0}", exception2.GetType());

                        client.Abort();
                    }

                    catch (Exception exception3)
                    {
                        Console.WriteLine("Server Down" + exception3.Message + exception3.StackTrace);
                    }

                    Thread.Sleep(0x2710);
                }
            });
        }
Example #5
0
        private static void LoadMosaic(MessageViewModel message)
        {
            ThreadPool.QueueUserWorkItem(delegate(object state)
            {
                try
                {
                    ServiceClient client = new ServiceClient("BasicHttpBinding_IService", Constants.ServerAddress);

                    long mosaicID = client.GetMosaicIDForStation(Constants.MyStationID);

                    Constants.CurrentClientConfiguration.CurrentMosaic = mosaicID;

                    Constants.SaveDefaults();

                    Positions = client.GetPositionsForMosaic(mosaicID);

                    SavePositions(new List <PositionViewModel>(Positions));

                    MainWindow.Instance.LoadPositions(null);

                    client.SetStationStatus(Constants.MyStationID, "Positions Loaded, Now Playing");
                }

                catch (Exception)
                {
                }

                ServiceClient client2 = new ServiceClient();

                try
                {
                    if (message != null)
                    {
                        client2.MessageRead(message.ID);
                    }
                }

                catch (TimeoutException exception)
                {
                    Console.WriteLine("Got {0}", exception.GetType());

                    client2.Abort();
                }

                catch (CommunicationException exception2)
                {
                    Console.WriteLine("Got {0}", exception2.GetType());

                    client2.Abort();
                }
            });
        }
 private static void CloseChannel()
 {
     try
     {
         if (objDistributed != null)
         {
             if (objDistributed.State != CommunicationState.Faulted)
             {
                 objDistributed.Close();
             }
             else
             {
                 objDistributed.Abort();
             }
         }
     }
     catch (CommunicationException ex)
     {
         new CustomLog().CommunicationException(ex);
         new CustomLog().ProxyException(System.Reflection.MethodBase.GetCurrentMethod().Name, 0, true);
         // Communication exceptions are normal when
         // closing the connection.
         objDistributed.Abort();
     }
     catch (TimeoutException ex)
     {
         new CustomLog().TimeoutException(ex, Types.ErrorLevel.Error);
         new CustomLog().ProxyException(System.Reflection.MethodBase.GetCurrentMethod().Name, 0, true);
         // Timeout exceptions are normal when closing
         // the connection.
         objDistributed.Abort();
     }
     catch (Exception ex)
     {
         new CustomLog().Exception(ex, Types.ErrorLevel.Error);
         // Any other exception and you should
         // abort the connection and rethrow to
         // allow the exception to bubble upwards.
         objDistributed.Abort();
         throw;
     }
     finally
     {
         // This is just to stop you from trying to
         // close it again (with the null check at the start).
         // This may not be necessary depending on
         // your architecture.
         objDistributed = null;
     }
 }
Example #7
0
 public void JoinToServer()
 {
     try
     {
         if (!_isJoined)
         {
             ServiceClient.Join();
             _isJoined = true;
         }
     }
     catch (MessageSecurityException ex)
     {
         //FredroMessageBox.ShowError("Не удаётся войти. Пожалуйста, проверьте правильность написания\r\nлогина и пароля");
         ServiceClient.Abort();
         throw new ServerException("Не удаётся войти. Пожалуйста, проверьте правильность написания\r\nлогина и пароля", ex);
     }
     catch (TimeoutException ex)
     {
         //FredroMessageBox.ShowError($"Timeout error: {ex.Message}");
         ServiceClient.Abort();
         throw new ServerException("Возникла внутрення ошибка сервера. Timeout error.", ex);
     }
     catch (FaultException ex)
     {
         //FredroMessageBox.ShowError(ex.Message + ex.Code.Name);
         ServiceClient.Abort();
         throw new ServerException("Возникла внутрення ошибка сервера.", ex);
     }
     catch (CommunicationException ex)
     {
         //FredroMessageBox.ShowError($"Communication error: {ex.Message}");
         ServiceClient.Abort();
         throw new ServerException("Возникла внутрення ошибка сервера. Communication error.", ex);
     }
 }
        public static void SaveFamilyMember(Guid userId, Guid Person, Guid?Family_Membership,
                                            Guid?Disability, Guid Application_State, Guid?DisabilityType, decimal?Family_MemberKON,
                                            Guid?DisablilityGroupe, Guid?employment, string DeadInfoFamMem, out string errorMessage)
        {
            errorMessage = "";
            string processName = "название не указано";

            using (var client = new ServiceClient())
            {
                try
                {
                    client.Open();

                    processName = "Сохранение члена д/х";
                    client.SaveFamilyMember(userId, Person, Family_Membership, Disability, Application_State, DisabilityType, Family_MemberKON, DisablilityGroupe, employment, DeadInfoFamMem);
                }
                catch (Exception e)
                {
                    client.Abort();

                    while (e.InnerException != null)
                    {
                        e = e.InnerException;
                    }
                    errorMessage = "Ошибка при вызове асинхронного процесса \"" + processName + "\". Текст ошибки: " + e.Message + "; stacktrace: " + e.StackTrace;
                }
                finally
                {
                    if (client.State != System.ServiceModel.CommunicationState.Closed)
                    {
                        client.Close();
                    }
                }
            }
        }
        public static string GetTaskState(string name, out string errorMessage)
        {
            errorMessage = "";
            string processName = "название не указано";

            using (var client = new ServiceClient())
            {
                try
                {
                    client.Open();

                    processName = "Тестовый процесс (GetTaskState)";
                    return(client.GetTaskState(name));
                }
                catch (Exception e)
                {
                    client.Abort();

                    while (e.InnerException != null)
                    {
                        e = e.InnerException;
                    }
                    errorMessage = "Ошибка при вызове асинхронного процесса \"" + processName + "\". Текст ошибки: " + e.Message + "; stacktrace: " + e.StackTrace;
                }
                finally
                {
                    if (client.State != System.ServiceModel.CommunicationState.Closed)
                    {
                        client.Close();
                    }
                }
                return(default(string));
            }
        }
        public void WorkflowExtensionsBehaviorAddsExtension()
        {
            WorkflowServiceTestHost host = null;

            // TODO: Test with multiple extensions
            // TODO: Test with bad config file entries
            var serviceEndpoint1 = ServiceTest.GetUniqueEndpointAddress();
            using (host = WorkflowServiceTestHost.Open("ServiceExtensionTest.xamlx", serviceEndpoint1))
            {
                try
                {
                    var proxy = new ServiceClient(ServiceTest.Pipe, serviceEndpoint1);
                    try
                    {
                        proxy.GetData(1);
                        proxy.Close();
                    }
                    catch (Exception)
                    {
                        proxy.Abort();
                        throw;
                    }
                }
                finally
                {
                    if (host != null)
                    {
                        host.Tracking.Trace();
                    }
                }
            }
        }
Example #11
0
        private void GetMedia(MessageViewModel message = null)
        {
            ServiceClient client = new ServiceClient("BasicHttpBinding_IService", Constants.ServerAddress);

            try
            {
                MediaListModel[] mediaList = client.GetMyMedia(Constants.MyStationID);

                if (message != null)
                {
                    client.MessageRead(message.ID);
                }

                ThreadPool.QueueUserWorkItem(delegate(object e4)
                {
                    MediaListModel[] modelArray1 = mediaList;

                    for (int j = 0; j < modelArray1.Length; j++)
                    {
                        MediaListModel model1 = modelArray1[j];
                    }
                });
            }

            catch (TimeoutException exception)
            {
                Console.WriteLine("Got {0}", exception.GetType());

                client.Abort();
            }

            catch (CommunicationException exception2)
            {
                Console.WriteLine("Got {0}", exception2.GetType());

                client.Abort();
            }

            finally
            {
                if (client != null)
                {
                    //   client.Dispose();
                }
            }
        }
Example #12
0
        private void StartKeepAliveThread()
        {
            System.Timers.Timer timer = new Timer();

            timer.Interval = (10000);
            timer.Elapsed += delegate
            {
                ServiceClient client = new ServiceClient("BasicHttpBinding_IService", Constants.ServerAddress);
                try
                {
                    if (client.ClientCredentials != null)
                    {
                        client.ClientCredentials.Windows.ClientCredential.UserName = "******";
                        client.ClientCredentials.Windows.ClientCredential.Password = "******";
                    }
                    if (client.SayHiKey(new HardwareKey().Key) != "Hi there")
                    {
                        Console.WriteLine("Server_Down");
                    }
                    else if (!_checkedForNewMessages)
                    {
                        //          this.GetMedia(null);
                        _checkedForNewMessages = true;
                    }
                }

                catch (TimeoutException exception)
                {
                    Console.WriteLine("Got {0}", exception.GetType());
                    client.Abort();
                }

                catch (CommunicationException exception2)
                {
                    Console.WriteLine("Got {0}", exception2.GetType());
                    client.Abort();
                }

                catch (Exception exception3)
                {
                    Console.WriteLine("Server Down" + exception3.Message + exception3.StackTrace);
                }
            };
            timer.Start();
        }
Example #13
0
        private void ChannelFactory_Faulted(object sender, EventArgs e)
        {
            Trace.WriteLine("Channel Faulted " + DateTime.Now.ToShortDateString() + "  " + DateTime.Now.ToShortTimeString());

            c.Abort();
            c = new ServiceClient(iC);
            ((ICommunicationObject)c).Faulted += new EventHandler(ChannelFactory_Faulted);
            c.RegisterClient(deviceID, false);
            //c.ChannelFactory.CreateChannel();
        }
Example #14
0
 public void UpdateMail(TheMail mail)
 {
     try
     {
         ServiceClient.UpdateMail(mail);
     }
     catch (FaultException ex)
     {
         TwinkleMessageBox.ShowError(ex.Message);
         ServiceClient.Abort();
     }
 }
Example #15
0
        public static void UploadFile(string localFileName, FileTypeEnum fileType)
        {
            eAdDataAccess.ServiceClient service = new ServiceClient("BasicHttpBinding_IService", Constants.ServerAddress);
            try
            {
                using (Stream fileStream = new FileStream(localFileName, FileMode.Open, FileAccess.Read))
                {
                    //    var request = new FileUploadMessage();
                    string remoteFileName = null;
                    if (fileType == FileTypeEnum.Generic)
                    {
                        // WE ARE USING THE SERVICE AS A "FTP ON WCF"
                        // GIVE THE REMOTE FILE THE SAME NAME AS THE LOCAL ONE
                        remoteFileName = Path.GetFileName(localFileName);
                    }

                    var fileMetadata = new FileMetaData {
                        LocalFilename = localFileName, RemoteFilename = remoteFileName, FileType = fileType
                    };
                    //     request.MetaData = fileMetadata;
                    //     request.FileByteStream = fileStream;

                    //service.UploadFile(fileMetadata,fileStream);
                    service.Close();
                }
            }
            catch (TimeoutException exception)
            {
                Console.WriteLine("Got {0}", exception.GetType());
                service.Abort();
            }
            catch (CommunicationException exception)
            {
                Console.WriteLine("Got {0}", exception.GetType());
                service.Abort();
            }
        }
Example #16
0
        public static void syncOperation()
        {
            //client.ServiceReference1.ServiceClient client = new client.ServiceReference1.ServiceClient(new BasicHttpBinding(),new EndpointAddress(""));

            client.ServiceReference1.ServiceClient client = new ServiceClient("NetTcpBinding_IService");
            try
            {
                Data s1 = new Data() { name="saeid1"};
                Data s2 = new Data() { name = "saeid2" };

                client.addData(s1);
                client.addData(s2);

                Data[] result = client.getList();
                Console.WriteLine("number of entries: " + result.Length);

                client.Close();

            }
            catch (FaultException fe)
            {
                Console.WriteLine(fe.GetType());

                client.Abort();
            }
            catch (CommunicationException ce)
            {
                Console.WriteLine(ce.GetType());
                Console.WriteLine(ce.Message);
                client.Abort();
            }
            catch (TimeoutException te)
            {
                Console.WriteLine(te.GetType());
                client.Abort();
            }
        }
Example #17
0
    public static void UploadFile(string localFileName,FileTypeEnum fileType)
    {
        eAdDataAccess.ServiceClient service = new ServiceClient("BasicHttpBinding_IService", Constants.ServerAddress);
        try
        {
            using (Stream fileStream = new FileStream(localFileName, FileMode.Open, FileAccess.Read))
            {
                //    var request = new FileUploadMessage();
                string remoteFileName = null;
                if (fileType == FileTypeEnum.Generic)
                {
                    // WE ARE USING THE SERVICE AS A "FTP ON WCF"
                    // GIVE THE REMOTE FILE THE SAME NAME AS THE LOCAL ONE
                    remoteFileName = Path.GetFileName(localFileName);
                }

                var fileMetadata = new FileMetaData { LocalFilename = localFileName, RemoteFilename = remoteFileName,FileType = fileType};
                //     request.MetaData = fileMetadata;
                //     request.FileByteStream = fileStream;

                //service.UploadFile(fileMetadata,fileStream);
                service.Close();

            }
        }
        catch (TimeoutException exception)
        {
            Console.WriteLine("Got {0}", exception.GetType());
            service.Abort();
        }
        catch (CommunicationException exception)
        {
            Console.WriteLine("Got {0}", exception.GetType());
            service.Abort();
        }
    }
Example #18
0
 protected void ButtonSubmit_Click(object sender, EventArgs e)
 {
     var proxy = new ServiceClient();
     try
     {
         var sampleResponse = proxy.GetData(TextBoxKey.Text);
         LabelValue.Text = sampleResponse.Data.Value;
         RadioButtonHit.Checked = sampleResponse.CacheHit;
         RadioButtonMiss.Checked = !sampleResponse.CacheHit;
         proxy.Close();
     }
     catch (Exception)
     {
         proxy.Abort();
         throw;
     }
 }
Example #19
0
        public JsonResult EliminarCliente(Cliente cliente)
        {
            ServiceClient servicioWCF = new ServiceClient();

            try
            {
                return(this.Json(servicioWCF.EliminarCliente(cliente.ClienteId), JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                servicioWCF.Abort();
                throw;
            }
            finally
            {
                servicioWCF.Close();
            }
        }
Example #20
0
 /// <summary>
 /// The button test w s_ click.
 /// </summary>
 /// <param name="sender">
 /// The sender.
 /// </param>
 /// <param name="e">
 /// The e.
 /// </param>
 protected void buttonTestWS_Click(object sender, EventArgs e)
 {
     var proxy = new ServiceClient();
     try
     {
         var resolutionInfo = proxy.GetAssemblyNames();
         this.labelWebAssembly.Text = resolutionInfo.WebAssembly.Name;
         this.labelWebPath.Text = resolutionInfo.WebAssembly.Path;
         this.labelWebVersion.Text = resolutionInfo.WebAssembly.Version;
         this.labelActivityAssembly.Text = resolutionInfo.ActivityAssembly.Name;
         this.labelActivityPath.Text = resolutionInfo.ActivityAssembly.Path;
         this.labelActivityVersion.Text = resolutionInfo.ActivityAssembly.Version;
     }
     catch (Exception)
     {
         proxy.Abort();
         throw;
     }
 }
Example #21
0
        private void RegisterClient()
        {
            if ((_service != null))
            {
                _service.Abort();
                _service = null;
            }

            BroadcastorCallback cb = new BroadcastorCallback();

            cb.SetHandler(HandleBroadcast);

            System.ServiceModel.InstanceContext context =
                new System.ServiceModel.InstanceContext(cb);
            _service =
                new ServiceClient(context, "TCPEndpoint");

            _service.RegisterClient(_dataStorage.UserId);
        }
 private void Correct()
 {
     string data;
     bool success = false;
     ServiceClient client = null;
     try
     {
         client = new ServiceClient().GetProxy();
         data = client.GetData(int.Parse(txtData.Text));
         client.Close();
         success = true;
     }
     finally
     {
         if (!success && client != null)
         {
             client.Abort();
         }
     }
     ltlData.Text = data;
 }
        private void Correct()
        {
            string        data;
            bool          success = false;
            ServiceClient client  = null;

            try
            {
                client = new ServiceClient().GetProxy();
                data   = client.GetData(int.Parse(txtData.Text));
                client.Close();
                success = true;
            }
            finally
            {
                if (!success && client != null)
                {
                    client.Abort();
                }
            }
            ltlData.Text = data;
        }
Example #24
0
        public void ShouldInvokeAverageExtensionWithService()
        {
            const string Expected1 = "Stored 33, Average:33";
            const string Expected2 = "Stored 44, Average:38.5";
            const string Expected3 = "Stored 55, Average:44";

            // Reset the static collection
            AverageExtension.Reset();

            // Self-Host Service1.xamlx using Named Pipes
            var address = ServiceTest.GetUniqueEndpointAddress();
            using (WorkflowServiceTestHost.Open("Service1.xamlx", address))
            {
                string result1;
                string result2;
                string result3;

                // Use the generated proxy with named pipes
                var proxy = new ServiceClient(ServiceTest.Pipe, address);

                try
                {
                    result1 = proxy.GetData(33);
                    result2 = proxy.GetData(44);
                    result3 = proxy.GetData(55);
                    proxy.Close();
                }
                catch (Exception)
                {
                    proxy.Abort();
                    throw;
                }

                Assert.AreEqual(Expected1, result1);
                Assert.AreEqual(Expected2, result2);
                Assert.AreEqual(Expected3, result3);
            }
        }
        public void BehaviorCanBeAddedViaConfig()
        {
            // Arrange
            var serviceEndpoint = ServiceTest.GetUniqueEndpointAddress();
            using (WorkflowServiceTestHost.Open(Constants.DefaultServiceXamlx, serviceEndpoint))
            {
                var proxy = new ServiceClient(ServiceTest.Pipe, serviceEndpoint);
                try
                {
                    // Act
                    var result = proxy.GetData(123);
                    proxy.Close();

                    // Assert
                    Assert.AreEqual("123", result);
                }
                catch
                {
                    proxy.Abort();
                    throw;
                }
            }
        }
Example #26
0
        protected void LinkButtonTest_Click(object sender, EventArgs e)
        {
            var proxy = new ServiceClient();

            try
            {
                int num;

                if (!Int32.TryParse(TextBoxNum.Text, out num))
                {
                    LabelResult.Text = "Text cannot be converted to a number";
                }
                else
                {
                    LabelResult.Text = proxy.GetData(num);
                    proxy.Close();
                }
            }
            catch (Exception)
            {
                proxy.Abort();
                throw;
            }
        }
Example #27
0
 public void Dispose()
 {
     try
     {
         _client.Close();
     }
     catch (Exception ex)
     {
         string message = string.Format("{0} \n {1},\n {2}", ex.Message,
                                        ex.ToString(), ex.StackTrace);
         Logger.WriteLineError(message);
         try
         {
             _client.Abort();
         }
         catch (Exception e)
         {
             string m = string.Format("{0} \n {1},\n {2}", e.Message,
                                      e.ToString(), e.StackTrace);
             Logger.WriteLineError(message);
         }
     }
     _client = null;
 }
Example #28
0
 private void SendKeepAliveMessage()
 {
     ServiceClient client = new ServiceClient("BasicHttpBinding_IService", Constants.ServerAddress);
     try
     {
         if (client.ClientCredentials != null)
         {
             client.ClientCredentials.Windows.ClientCredential.UserName = "******";
             client.ClientCredentials.Windows.ClientCredential.Password = "******";
         }
         if (client.SayHiKey(new HardwareKey().Key) != "Hi there")
         {
             Console.WriteLine("Server_Down");
         }
         else if (!this._checkedForNewMessages)
         {
             this._checkedForNewMessages = true;
         }
     }
     catch (TimeoutException exception)
     {
         Console.WriteLine("Got {0}", exception.GetType());
         client.Abort();
     }
     catch (CommunicationException exception2)
     {
         Console.WriteLine("Got {0}", exception2.GetType());
         client.Abort();
     }
     catch (Exception exception3)
     {
         Console.WriteLine("Server Down" + exception3.Message + exception3.StackTrace);
     }
 }
Example #29
0
    private void ProcessInformationMessage(MessageViewModel message)
    {

        MessageBox.Show(this, message.Text, message.Type, MessageBoxButton.OKCancel, MessageBoxImage.Exclamation);

        ServiceClient client = new ServiceClient();

        try
        {

            client.MessageRead(message.ID);

        }

        catch (TimeoutException exception)
        {

            Console.WriteLine("Got {0}", exception.GetType());

            client.Abort();

        }

        catch (CommunicationException exception2)
        {

            Console.WriteLine("Got {0}", exception2.GetType());

            client.Abort();

        }

        finally
        {

            if (client != null)
            {

                //  client.Dispose();

            }

        }

    }
Example #30
0
    private static void LoadMosaic(MessageViewModel message)
    {

        ThreadPool.QueueUserWorkItem(delegate(object state)
        {

            try
            {

                ServiceClient client = new ServiceClient("BasicHttpBinding_IService", Constants.ServerAddress);

                long mosaicID = client.GetMosaicIDForStation(Constants.MyStationID);

                Constants.CurrentClientConfiguration.CurrentMosaic=mosaicID;

                Constants.SaveDefaults();

                Positions = client.GetPositionsForMosaic(mosaicID);

                SavePositions(new List<PositionViewModel>(Positions));

                MainWindow.Instance.LoadPositions(null);

                client.SetStationStatus(Constants.MyStationID, "Positions Loaded, Now Playing");

            }

            catch (Exception)
            {

            }

            ServiceClient client2 = new ServiceClient();

            try
            {

                if (message != null)
                {

                    client2.MessageRead(message.ID);

                }

            }

            catch (TimeoutException exception)
            {

                Console.WriteLine("Got {0}", exception.GetType());

                client2.Abort();

            }

            catch (CommunicationException exception2)
            {

                Console.WriteLine("Got {0}", exception2.GetType());

                client2.Abort();

            }

        });

    }
Example #31
0
    private void GetMedia(MessageViewModel message = null)
    {

        ServiceClient client = new ServiceClient("BasicHttpBinding_IService", Constants.ServerAddress);

        try
        {

            MediaListModel[] mediaList = client.GetMyMedia(Constants.MyStationID);

            if (message != null)
            {

                client.MessageRead(message.ID);

            }

            ThreadPool.QueueUserWorkItem(delegate(object e4)
            {

                MediaListModel[] modelArray1 = mediaList;

                for (int j = 0; j < modelArray1.Length; j++)
                {

                    MediaListModel model1 = modelArray1[j];

                }

            });

        }

        catch (TimeoutException exception)
        {

            Console.WriteLine("Got {0}", exception.GetType());

            client.Abort();

        }

        catch (CommunicationException exception2)
        {

            Console.WriteLine("Got {0}", exception2.GetType());

            client.Abort();

        }

        finally
        {

            if (client != null)
            {

                //   client.Dispose();

            }

        }

    }
Example #32
0
    private void StartKeepAliveThread()
    {

        ThreadPool.QueueUserWorkItem(delegate(object state)
        {

            this.PlayCurrentMosaic();

            ThreadPool.QueueUserWorkItem(delegate(object e)
            {

                LoadMosaic(null);

            });

            while (true)
            {

                ServiceClient client = new ServiceClient("BasicHttpBinding_IService", Constants.ServerAddress);

                try
                {

                    client.ClientCredentials.Windows.ClientCredential.UserName = "******";

                    client.ClientCredentials.Windows.ClientCredential.Password = "******";

                    if (client.SayHi(Constants.MyStationID) != "Hi there")
                    {

                        Console.WriteLine("Server Down");

                    }

                    else if (!this.CheckedForNewMessages)
                    {

                        this.GetMedia(null);

                        this.CheckedForNewMessages = true;

                    }

                }

                catch (TimeoutException exception)
                {

                    Console.WriteLine("Got {0}", exception.GetType());

                    client.Abort();

                }

                catch (CommunicationException exception2)
                {

                    Console.WriteLine("Got {0}", exception2.GetType());

                    client.Abort();

                }

                catch (Exception exception3)
                {

                    Console.WriteLine("Server Down" + exception3.Message + exception3.StackTrace);

                }

                Thread.Sleep(0x2710);

            }

        });

    }
Example #33
0
    private static void SendMessageReceipt(MessageViewModel message, bool updateList = true)
    {

        ServiceClient client = new ServiceClient();

        try
        {

            client.MessageRead(message.ID);

        }

        catch (TimeoutException exception)
        {

            Console.WriteLine("Got {0}", exception.GetType());

            client.Abort();

        }

        catch (CommunicationException exception2)
        {

            Console.WriteLine("Got {0}", exception2.GetType());

            client.Abort();

        }

        if (updateList)
        {

            UnProcessedMessages.Remove(message);

        }

    }
Example #34
0
        /// <summary>
        /// Authorizes a card key
        /// </summary>
        private void AuthorizeCard()
        {
            var proxy = new ServiceClient();
            try
            {
                proxy.OpenDoorCompleted += this.OnOpenDoorCompleted;
                proxy.OpenDoorAsync(
                    new OpenDoor
                        {
                           CardKey = Guid.Parse(this.textKey.Text), RoomNumber = Int32.Parse(this.textRoom.Text)
                        });

                proxy.Close();
            }
            catch (Exception ex)
            {
                proxy.Abort();
                MessageBox.Show("Unable to authorize card " + ex.Message);
            }
        }
Example #35
0
    private void StartKeepAliveThread()
    {
        System.Timers.Timer timer = new Timer();

        timer.Interval = (10000);
        timer.Elapsed += delegate
        {
            ServiceClient client = new ServiceClient("BasicHttpBinding_IService", Constants.ServerAddress);
            try
            {
                if (client.ClientCredentials != null)
                {
                    client.ClientCredentials.Windows.ClientCredential.UserName = "******";
                    client.ClientCredentials.Windows.ClientCredential.Password = "******";
                }
                if (client.SayHiKey(new HardwareKey().Key) != "Hi there")
                {
                    Console.WriteLine("Server_Down");
                }
                else if (!_checkedForNewMessages)
                {
                    //          this.GetMedia(null);
                    _checkedForNewMessages = true;
                }
            }

            catch (TimeoutException exception)
            {
                Console.WriteLine("Got {0}", exception.GetType());
                client.Abort();
            }

            catch (CommunicationException exception2)
            {
                Console.WriteLine("Got {0}", exception2.GetType());
                client.Abort();
            }

            catch (Exception exception3)
            {
                Console.WriteLine("Server Down" + exception3.Message + exception3.StackTrace);
            }
        };
        timer.Start();

    }
        /// <summary>
        ///   Given
        ///   * A WorkflowService configured to use the StateMachineStateTracker
        ///   * An instance store with 2 persisted instances with state tracker information
        ///   When
        ///   * LoadInstances is called using the xamlx file
        ///   Then
        ///   * The list of StateMachineStateTracker instances is returned with 2 instances
        /// </summary>
        /// <summary>
        ///   Runs the sample service through the list of triggers
        /// </summary>
        /// <param name="testdb"> The test database </param>
        /// <param name="exampleTriggers"> The triggers. </param>
        private static void RunSampleStateMachineService(
            SqlWorkflowInstanceStoreTest testdb, params ExampleTrigger[] exampleTriggers)
        {
            Debug.Assert(testdb != null, "TestInstanceStore != null");
            var instanceStore = new SqlWorkflowInstanceStore(testdb.ConnectionString);

            WorkflowServiceTestHost host = null;
            var serviceEndpoint = ServiceTest.GetUniqueEndpointAddress();

            var proxy = new ServiceClient(ServiceTest.Pipe, serviceEndpoint);
            var instanceId = Guid.Empty;
            try
            {
                using (
                    host =
                    WorkflowServiceTestHost.Open(
                        Constants.StateMachineServiceExampleXamlx,
                        serviceEndpoint,
                        instanceStore,
                        new StateMachineTrackingBehavior(),
                        new WorkflowIdleBehavior { TimeToPersist = TimeSpan.Zero, TimeToUnload = TimeSpan.Zero }))
                {
                    Debug.Assert(exampleTriggers != null, "exampleTriggers != null");
                    foreach (var trigger in exampleTriggers)
                    {
                        switch (trigger)
                        {
                            case ExampleTrigger.T1:
                                instanceId = proxy.T1().GetValueOrDefault();
                                break;

                            case ExampleTrigger.T2:
                                proxy.T2(instanceId);
                                break;

                            case ExampleTrigger.T3:
                                proxy.T3(instanceId);
                                break;

                            case ExampleTrigger.T4:
                                proxy.T4(instanceId);
                                break;
                            case ExampleTrigger.T5:
                                proxy.T5(instanceId);
                                break;
                            case ExampleTrigger.T6:
                                proxy.T6(instanceId);
                                break;
                            case ExampleTrigger.T7:
                                proxy.T7(instanceId);
                                break;
                        }
                    }

                    proxy.Close();
                }
            }
            catch (Exception)
            {
                proxy.Abort();
                throw;
            }
            finally
            {
                if (host != null)
                {
                    Debug.Assert(host.Tracking != null, "host.Tracking != null");
                    host.Tracking.Trace();
                }
            }
        }
        /// <summary>
        ///   Runs the sample service through the list of triggers
        /// </summary>
        /// <param name="address"> The host address </param>
        /// <param name="exampleTriggers"> The triggers. </param>
        private void RunSampleStateMachineService(EndpointAddress address, params ExampleTrigger[] exampleTriggers)
        {
            var proxy = new ServiceClient(ServiceTest.Pipe, address);
            var instanceId = Guid.Empty;
            try
            {
                Debug.Assert(exampleTriggers != null, "exampleTriggers != null");
                foreach (var trigger in exampleTriggers)
                {
                    switch (trigger)
                    {
                        case ExampleTrigger.T1:
                            instanceId = proxy.T1().GetValueOrDefault();
                            break;

                        case ExampleTrigger.T2:
                            proxy.T2(instanceId);
                            break;

                        case ExampleTrigger.T3:
                            proxy.T3(instanceId);
                            break;

                        case ExampleTrigger.T4:
                            proxy.T4(instanceId);
                            break;
                        case ExampleTrigger.T5:
                            proxy.T5(instanceId);
                            break;
                        case ExampleTrigger.T6:
                            proxy.T6(instanceId);
                            break;
                        case ExampleTrigger.T7:
                            proxy.T7(instanceId);
                            break;
                    }
                }

                proxy.Close();
            }
            catch (Exception)
            {
                proxy.Abort();
                throw;
            }
        }