public static object CallRemoteService(string AssemblyName, string MethodName, object[] Parameters)
        {
            try
            {
                var configFile = AppDomain.CurrentDomain.BaseDirectory + "\\" + System.Windows.Forms.Application.ProductName + ".exe.config";
                configFile = System.IO.Path.GetFullPath(configFile);

                var proxy = WcfClientHelper.GetProxy <ITransferService>(configFile);
                System.Collections.Hashtable hashtable = new System.Collections.Hashtable();
                hashtable["assembly_name"]     = AssemblyName;
                hashtable["method_name"]       = MethodName;
                hashtable["method_paremeters"] = Parameters;
                //DateTime time = DateTime.Now;
                //logger.Error("Method CallRemoteServer In");
                System.IO.Stream             source_stream = Serialize.SerializeToStream(hashtable);
                System.IO.Stream             zip_stream    = Compression.CompressStream(source_stream); source_stream.Dispose();
                System.IO.Stream             stream_result = proxy.InvokeMethod(zip_stream); zip_stream.Dispose();
                System.IO.Stream             ms            = ReadMemoryStream(stream_result); stream_result.Dispose();
                System.IO.Stream             unzip_stream  = Compression.DeCompressStream(ms); ms.Dispose();
                System.Collections.Hashtable Result        = Serialize.DeSerializeFromStream(unzip_stream) as System.Collections.Hashtable;
                //logger.Error((DateTime.Now - time).Seconds.ToString() + " cast by CallRemoteServer");
                return(Result["return_value"]);
            }
            catch (Exception ex)
            {
                return(null);
                //throw new System.Exception ServiceAccessException(ex.Message, ex);
            }
        }
        private bool Save()
        {
            if (this.ValidateChildren())
            {
                AppendLog("Client", "Saving settings");
                btnSave.Enabled = false;

                bool restartPlink = false;

                if (btnChangeTunnelStatus.Text == "Stop Tunnel")
                {
                    restartPlink = (MessageBox.Show("Would you like to reset plink.exe with the settings you specified?  If no, it will use the settings next time Plink.exe gets recycled or when you restart the service", "Restart plink.exe?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==
                                    DialogResult.Yes);
                }

                WcfClientHelper.ExecuteRemoteAction(x => x.SaveSettings(_currentSettings, restartPlink), true);

                return(true);
            }
            else
            {
                MessageBox.Show("Validation errors exist.  Please verify that you have entered valid information into each form field.", "Form validation error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return(false);
            }
        }
Example #3
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;

            WcfClientHelper.FaultMessage = null;

            if (_loadingControl == null)
            {
                _loadingControl = new LoadingControl();

                int loadingControlX = (this.Width / 2) - (_loadingControl.Width / 2);
                int loadingControlY = ((this.Height / 2) - (_loadingControl.Height / 2)) - 20;
                _loadingControl.Location = new Point(loadingControlX, loadingControlY);

                this.Controls.Add(_loadingControl);
            }

            _loadingControl.BringToFront();
            _loadingControl.Visible = true;

            Task connectingTask = Task.Factory.StartNew <bool>(() =>
            {
                ServiceRemotingCallback callback = new ServiceRemotingCallback();

                WcfClientHelper.ConnectIpc(callback);
                ((ICommunicationObject)WcfClientHelper.PipeFactory).Closing += PipeFactory_Closing;
                ((ICommunicationObject)WcfClientHelper.PipeFactory).Faulted += PipeFactory_Faulted;

                return(WcfClientHelper.IsConnected);
            }).ContinueWith(x =>
            {
                HandleConnectionResult(x.Result);
            });
        }
Example #4
0
        public static object CallRemoteService(string AssemblyName, string MethodName, object[] Parameters)
        {
            try
            {
                var configFile = AppDomain.CurrentDomain.BaseDirectory + "\\" + Application.ProductName + ".exe.config";
                configFile = Path.GetFullPath(configFile);
                var proxy = WcfClientHelper.GetProxy <ITransferService>(configFile);

                Hashtable hashtable = new Hashtable();
                hashtable["assembly_name"]     = AssemblyName;
                hashtable["method_name"]       = MethodName;
                hashtable["method_paremeters"] = Parameters;

                Stream    source_stream = Yqun.Common.Encoder.Serialize.SerializeToStream(hashtable);
                Stream    zip_stream    = Yqun.Common.Encoder.Compression.CompressStream(source_stream);
                Stream    stream_result = proxy.InvokeMethod(zip_stream);
                Stream    ms            = ReadMemoryStream(stream_result);
                Stream    unzip_stream  = Yqun.Common.Encoder.Compression.DeCompressStream(ms);
                Hashtable Result        = Yqun.Common.Encoder.Serialize.DeSerializeFromStream(unzip_stream) as Hashtable;

                return(Result["return_value"]);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                throw new Exception(ex.Message, ex);
            }
        }
Example #5
0
 public object CallRemoteService(string AssemblyName, string MethodName, object[] Parameters)
 {
     try
     {
         var configFile = AppDomain.CurrentDomain.BaseDirectory + "\\" + ApplicationHelper.GetApplicationName(updateFlag) + ".exe.config";
         configFile = System.IO.Path.GetFullPath(configFile);
         logger.Error(configFile);
         var proxy = WcfClientHelper.GetProxy <ITransferService>(configFile);
         System.Collections.Hashtable hashtable = new System.Collections.Hashtable();
         hashtable["assembly_name"]     = AssemblyName;
         hashtable["method_name"]       = MethodName;
         hashtable["method_paremeters"] = Parameters;
         System.IO.Stream             source_stream = Serialize.SerializeToStream(hashtable);
         System.IO.Stream             zip_stream    = Compression.CompressStream(source_stream); source_stream.Dispose();
         System.IO.Stream             stream_result = proxy.InvokeMethod(zip_stream); zip_stream.Dispose();
         System.IO.Stream             ms            = ReadMemoryStream(stream_result); stream_result.Dispose();
         System.IO.Stream             unzip_stream  = Compression.DeCompressStream(ms); ms.Dispose();
         System.Collections.Hashtable Result        = Serialize.DeSerializeFromStream(unzip_stream) as System.Collections.Hashtable;
         return(Result["return_value"]);
     }
     catch (Exception ex)
     {
         logger.Error(ex.Message);
         return(null);
     }
 }
Example #6
0
        public void ChangePassword(string username, string newPassword, string oldPassword)
        {
            ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => true;
            var client = new UserManagementServiceClient();

            WcfClientHelper.CallMethod((c, u, n, o) => c.SetPassword(username, newPassword, oldPassword), client,
                                       username, newPassword, oldPassword, errorAdapter);
        }
Example #7
0
        public CalculationEngineState GetCalculationState(Domain.Model.Calculations.CalculationId calculationId)
        {
            var client   = new CalculationEngineRef.CalculationEngineServiceClient();
            var progress = WcfClientHelper.CallMethod((c, id) => c.CheckStatus(id.Id), client, calculationId, errorAdapter);
            var msgList  = progress.MessageList.ToList();

            return(new CalculationEngineState
            {
                MessageList = msgList,
                Percent = progress.Percent,
                StateName = progress.StateName
            });
        }
        private void pingTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (this.IsDisposed)
            {
                return;
            }

            WcfClientHelper.ExecuteRemoteAction(x => x.Ping(), true);

            if ((DateTime.Now - ServiceRemotingCallback.LastPingDateTime).TotalSeconds > Constants.ClientPingTimeout)
            {
                AppendLog("Client", "Re-Register Client Callback");
                WcfClientHelper.ExecuteRemoteAction(x => x.RegisterCallbackClient(), true);
            }
        }
        private void btnTestSshConnection_Click(object sender, EventArgs e)
        {
            picLoadingTestConnection.Visible = true;
            btnTestSshConnection.Enabled     = false;

            Task.Factory.StartNew(() =>
            {
                int sshPort = 22;
                int.TryParse(txtSshPort.Text, out sshPort);

                WcfClientHelper.ExecuteRemoteAction(x => x.TestConnection(new ServiceSettings()
                {
                    PlinkExecutable = txtPathToPlink.Text, SshHostname = txtSshHost.Text, SshPort = sshPort, SshUsername = txtSshUsername.Text, SshPassword = txtSshPassword.Text
                }));
            });
        }
 private void GetFile()
 {
     try
     {
         var configFile = AppDomain.CurrentDomain.BaseDirectory + "..\\..\\WcfClientConfiguration.xml";
         configFile = Path.GetFullPath(configFile);
         var proxy      = WcfClientHelper.GetProxy <IFileService>(configFile);
         var fileName   = "Spring1.2.chm";
         var fileAsByte = proxy.GetFile(fileName);
         var filePath   = AppDomain.CurrentDomain.BaseDirectory + "..\\..\\" + fileName;
         filePath = Path.GetFullPath(filePath);
         File.WriteAllBytes(filePath, fileAsByte);
         Process.Start(filePath);
     }
     catch (Exception exception)
     {
         ShowMessage(string.Format("Exception Type: {0}, Exception message: {1}", exception.GetType().AssemblyQualifiedName, exception.Message), true);
     }
 }
Example #11
0
        /// <summary>新建一个WCF的通道,返回通道是否有效</summary>
        private static bool CreatNewChannel()
        {
            lock (_ans)
            {
                try
                {
                    WcfClientHelper.SetWCFParas(_ipAdress, _portNum, _binding);

                    _backupsClass = WcfClientHelper.CreateDuplexService <IPluginCtrInterface>("IPluginCtrInterface", _callBack);

                    IClientChannel channel = _backupsClass as IClientChannel;

                    if (channel == null)
                    {
                        return(false);
                    }

                    channel.Faulted += ChannelFaulted;

                    if (channel.State != CommunicationState.Opened)
                    {
                        channel.Open();
                    }

                    if (!_channelState)
                    {
                        _channelState = true;
                    }

                    return(true);
                }
                catch { if (_channelState)
                        {
                            _channelState = false;
                        }
                        return(false); }
            }
        }
        private void btnChangeTunnelStatus_Click(object sender, EventArgs e)
        {
            if (btnChangeTunnelStatus.Text == "Start Tunnel" && (string.IsNullOrWhiteSpace(_currentSettings.PlinkExecutable) || string.IsNullOrWhiteSpace(_currentSettings.SshHostname) || string.IsNullOrWhiteSpace(_currentSettings.SshUsername) || _currentSettings.SshPort == 0))
            {
                MessageBox.Show("Before you can start the tunnel you must first fill in your SSH connection information on the Settings tab", "Connection info missing", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                if (btnChangeTunnelStatus.Text == "Start Tunnel" && _currentSettings.IsDirty)
                {
                    DialogResult dialogResult = MessageBox.Show("You have unsaved changes.  Would you like to save them before starting the tunnel?", "Save changes?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                    if (dialogResult == DialogResult.Yes)
                    {
                        bool saveSuccess = Save();

                        if (!saveSuccess)
                        {
                            return;
                        }
                    }
                    else if (dialogResult == DialogResult.Cancel)
                    {
                        return;
                    }
                }

                btnChangeTunnelStatus.Enabled = false;

                if (btnChangeTunnelStatus.Text == "Stop Tunnel")
                {
                    WcfClientHelper.ExecuteRemoteAction(x => x.ChangeTunnelStatus(TunnelStatuses.Paused), true);
                }
                else if (btnChangeTunnelStatus.Text == "Start Tunnel")
                {
                    WcfClientHelper.ExecuteRemoteAction(x => x.ChangeTunnelStatus(TunnelStatuses.Started), true);
                }
            }
        }
        private void Disconnect(bool unregister = true)
        {
            try
            {
                this.Invoke(new MethodInvoker(() =>
                {
                    this.Cursor = Cursors.WaitCursor;
                }));

                WcfClientHelper.DisconnectIpc(unregister);
            }
            catch
            {
            }
            finally
            {
                _pingTimer.Stop();

                this.Invoke(new MethodInvoker(() =>
                {
                    this.Cursor = Cursors.Default;
                }));
            }
        }
Example #14
0
        public PeriodEngineState GetPeriodCopyingStateProgress(Domain.Model.Periods.PeriodId periodId)
        {
            var client = new CalculationEngineRef.PeriodEngineServiceClient();

            return(WcfClientHelper.CallMethod((c, id) => c.GetPeriodCopyingStateProgress(id.Id), client, periodId, errorAdapter));
        }
Example #15
0
        public void CopyBasicData(Domain.Model.Periods.PeriodId sourcePeriodId, Domain.Model.Periods.PeriodId destionationPeriodId)
        {
            var client = new CalculationEngineRef.PeriodEngineServiceClient();

            WcfClientHelper.CallMethod((c, id1, id2) => c.CopyBasicData(id1.Id, id2.Id), client, sourcePeriodId, destionationPeriodId, errorAdapter);
        }
Example #16
0
        public void InitializeInquiry(Domain.Model.Periods.PeriodId periodId)
        {
            var client = new CalculationEngineRef.PeriodEngineServiceClient();

            WcfClientHelper.CallMethod((c, id) => c.InitializeInquiry(id.Id), client, periodId, errorAdapter);
        }
Example #17
0
        public PeriodEngineState GetIntializeInquiryState(Domain.Model.Periods.PeriodId periodId)
        {
            var client = new CalculationEngineRef.PeriodEngineServiceClient();

            return(WcfClientHelper.CallMethod((c, id) => c.GetIntializeInquiryState(id.Id), client, periodId, errorAdapter));
        }
Example #18
0
        public void PauseCalculation(Domain.Model.Calculations.CalculationId calculationId)
        {
            var client = new CalculationEngineRef.CalculationEngineServiceClient();

            WcfClientHelper.CallMethod((c, id) => c.Pause(id.Id), client, calculationId, errorAdapter);
        }
Example #19
0
        public IList <string> GetRolesForUser(string userName)
        {
            var client = new UserManagementServiceClient();

            return(WcfClientHelper.CallMethod((c, u) => c.GetRolesForUser(userName), client, userName, errorAdapter));
        }