コード例 #1
0
 /// <summary>
 /// Construtor padrão.
 /// </summary>
 /// <param name="communicationObject"></param>
 /// <param name="endpoint"></param>
 public ConfigureRemoteClientEventArgs(
     System.ServiceModel.ICommunicationObject communicationObject,
     System.ServiceModel.Description.ServiceEndpoint endpoint)
 {
     _communicationObject = communicationObject;
     _endpoint            = endpoint;
 }
コード例 #2
0
ファイル: Proxy.cs プロジェクト: rneilturner/win-tools
        //protected Proxy(System.Uri uriEndpoint, System.ServiceModel.ICommunicationObject comms, TProxyInterface_ proxy)
        //{
        //    this.comms = comms;
        //    this.proxy = proxy;
        //}
        #endregion // Constructors

        #region Open Connection
        internal static void AttemptClientOpen <T>(ref System.ServiceModel.ICommunicationObject comms, ref T proxy, System.ServiceModel.ChannelFactory <T> factory, uint maxTries, int wait)
        {
            uint attempts = 0;

            while (attempts < maxTries)
            {
                try
                {
                    comms.Open();
                    break;
                }
                catch (System.ServiceModel.EndpointNotFoundException /*exNoEndpoint*/)
                {
                    comms.Abort();

                    if (attempts == maxTries - 1)
                    {
                        throw;
                    }

                    proxy = factory.CreateChannel();
                    comms = proxy as System.ServiceModel.ICommunicationObject;
                    System.Threading.Thread.Sleep(wait);
                    //Console.WriteLine(string.Format("{0} Attempt {1}", proxy.GetType().Name, attempts + 1));
                    ++attempts;
                }
            }
            //Console.WriteLine("{0} Proxy State after opening: {1}", proxy.GetType().Name, comms.State);
        }
コード例 #3
0
        private int Save()
        {
            int re = 0;

            System.ServiceModel.ICommunicationObject commObject = _ClientRuleObject.CreateServerCommunicationObject();
            try {
                int index = 0;
                foreach (TreeListNode node in this.trvLstMain.Nodes)
                {
                    int    id   = (int)node.GetValue(_TreeListHoster.TreeViewCfg.KeyFieldName);
                    string name = (string)node.GetValue(_TreeListHoster.TreeViewCfg.DisplayFieldName);//调试用

                    IList dataSource = _BindingSource.DataSource as IList;
                    foreach (object data in dataSource)
                    {
                        int dataId = (int)MB.Util.MyReflection.Instance.InvokePropertyForGet(data, _TreeListHoster.TreeViewCfg.KeyFieldName);
                        if (id == dataId)
                        {
                            MB.Util.Model.EntityState entityState = MB.WinBase.UIDataEditHelper.Instance.GetEntityState(data);
                            if (entityState == MB.Util.Model.EntityState.Persistent)
                            {
                                MB.WinBase.UIDataEditHelper.Instance.SetEntityState(data, MB.Util.Model.EntityState.Modified);
                            }

                            MB.Util.MyReflection.Instance.InvokePropertyForSet(data, _TreeListHoster.TreeViewCfg.OrderFieldName, index);
                            _ClientRuleObject.AddToCache(commObject, (int)_ClientRuleObject.MainDataTypeInDoc, data, false, (string[])null);
                            index++;
                            break;
                        }
                    }
                }
                re = _ClientRuleObject.Flush(commObject);
            }
            catch (Exception ex) {
                MB.WinBase.ApplicationExceptionTerminate.DefaultInstance.ExceptionTerminate(ex);
            }
            finally {
                try {
                    commObject.Close();
                }
                catch { }
            }
            if (re > 0)
            {
                try {
                    _IsMainTreeNeedRefreshed = true;
                    MB.WinBase.MessageBoxEx.Show("数据保存成功");
                }
                catch (Exception ex) {
                    MB.Util.TraceEx.Write(ex.Message);
                    throw new MB.Util.APPException("数据保存成功,但本地数据更新有误,请关闭窗口手动完成刷新", MB.Util.APPMessageType.DisplayToUser);
                }
            }
            return(re);
        }
コード例 #4
0
ファイル: Proxy.cs プロジェクト: rneilturner/win-tools
        private void InitialiseProxyImpl()
        {
            TProxyInterface_ proxy;

            System.ServiceModel.ICommunicationObject commsProxy;

            BuildProxy(this.uriEndpoint, this.bindingFactory, out proxy, out commsProxy
                       , this.MaxClientAttempts, this.WaitForNextClientAttemptInMilliseconds);

            this.proxyInterface = proxy;
            this.comms          = commsProxy;
        }
コード例 #5
0
ファイル: Proxy.cs プロジェクト: rneilturner/win-tools
 static private void BuildProxy <TProxyInterface>(System.Uri uriEndpoint, IBindingFactory bindingFactory, out TProxyInterface proxy, out System.ServiceModel.ICommunicationObject comms
                                                  , uint maxTries, int wait)
     where TProxyInterface : class
 {
     System.ServiceModel.Channels.Binding binding = bindingFactory.Create();
     System.ServiceModel.ChannelFactory <TProxyInterface> factory = new System.ServiceModel.ChannelFactory <TProxyInterface>(
         binding
         , new System.ServiceModel.EndpointAddress(uriEndpoint)
         );
     proxy = factory.CreateChannel();
     comms = proxy as System.ServiceModel.ICommunicationObject;
     AttemptClientOpen(ref comms, ref proxy, factory, maxTries, wait);
 }
コード例 #6
0
        public override int Save()
        {
            if (!this.ExistsUnSaveData())
            {
                return(0);
            }

            int re = 0;

            System.ServiceModel.ICommunicationObject commObject = _ClientRuleObject.CreateServerCommunicationObject();
            try {
                foreach (object editEntity in _UnSaveEditEntitys)
                {
                    //判断并追加登录用户的相关信息( 实体数据的登录用户操作信息一般只在主表中存在 )
                    MB.WinBase.UIDataEditHelper.Instance.AppendLoginUserInfo(editEntity);

                    //增加主表实体对象
                    _ClientRuleObject.AddToCache(commObject, (int)_ClientRuleObject.MainDataTypeInDoc, editEntity, false, (string[])null);
                }
                re = _ClientRuleObject.Flush(commObject);
            }
            catch (Exception ex) {
                MB.WinBase.ApplicationExceptionTerminate.DefaultInstance.ExceptionTerminate(ex);
            }
            finally {
                try {
                    commObject.Close();
                }
                catch { }
            }
            if (re > 0)
            {
                try {
                    foreach (object entity in _UnSaveEditEntitys)
                    {
                        _ClientRuleObject.RefreshEntity((int)_ClientRuleObject.MainDataTypeInDoc, entity);
                    }
                    _UnSaveEditEntitys.Clear();
                    MB.WinBase.AppMessenger.DefaultMessenger.Publish(XtraRibbonMdiMainForm.MSG_REQUIRE_REFRESH_BUTTONS);

                    MB.WinBase.MessageBoxEx.Show("数据保存成功");
                }
                catch (Exception ex) {
                    MB.Util.TraceEx.Write(ex.Message);
                    throw new MB.Util.APPException("数据保存成功,但本地数据更新有误,请关闭窗口手动完成刷新", MB.Util.APPMessageType.DisplayToUser);
                }

                //this.Refresh();
            }
            return(re);
        }
コード例 #7
0
        public override int Save()
        {
            if (!this.ExistsUnSaveData())
            {
                return(0);
            }
            //先进行数据检查
            bool check = MB.WinBase.UIDataInputValidated.DefaultInstance.DetailGridDataValidated(_ClientRuleObject.ClientLayoutAttribute.UIXmlConfigFile, grdCtlMain.DataSource, _ClientRuleObject.ModuleTreeNodeInfo.Name);

            if (!check)
            {
                return(0);
            }

            int re = 0;

            System.ServiceModel.ICommunicationObject commObject = _ClientRuleObject.CreateServerCommunicationObject();
            try {
                foreach (object editEntity in _UnSaveEditEntitys)
                {
                    //判断并追加登录用户的相关信息( 实体数据的登录用户操作信息一般只在主表中存在 )
                    MB.WinBase.UIDataEditHelper.Instance.AppendLoginUserInfo(editEntity);

                    //增加主表实体对象
                    _ClientRuleObject.AddToCache(commObject, (int)_ClientRuleObject.MainDataTypeInDoc, editEntity, false, (string[])null);
                }
                re = _ClientRuleObject.Flush(commObject);
            }
            catch (Exception ex) {
                MB.WinBase.ApplicationExceptionTerminate.DefaultInstance.ExceptionTerminate(ex);
            }
            finally {
                try {
                    commObject.Close();
                }
                catch { }
            }
            if (re > 0)
            {
                _UnSaveEditEntitys.Clear();
                this.Refresh();
                MB.WinBase.AppMessenger.DefaultMessenger.Publish(XtraRibbonMdiMainForm.MSG_REQUIRE_REFRESH_BUTTONS);
                MB.WinBase.MessageBoxEx.Show("数据保存成功");
            }
            return(re);
        }
コード例 #8
0
 /// <summary>
 /// Libera a instancia.
 /// </summary>
 public void Dispose()
 {
     if (_instance != null)
     {
         try
         {
             _instance.Abort();
             _instance.Close();
         }
         catch
         {
         }
         finally
         {
             _instance = null;
         }
     }
 }
コード例 #9
0
ファイル: Proxy.cs プロジェクト: rneilturner/win-tools
        public void Close()
        {
            if (this.proxyInterface != null) // If got a proxy
            {
                System.ServiceModel.ICommunicationObject commsProxy = this.comms;
                this.comms          = null;
                this.proxyInterface = null;

                if (commsProxy.State == System.ServiceModel.CommunicationState.Faulted)
                {
                    commsProxy.Abort();
                }
                else
                {
                    commsProxy.Close();
                }
            } // Ends if got a proxy
        }
コード例 #10
0
        /// <summary>
        /// 从中间层缓存中删除实体对象。
        /// </summary>
        /// <returns></returns>
        public virtual int Delete()
        {
            bool deleteFirstPositionData = false;

            if (!_EditBindingSource.CheckExistsCurrentItem())
            {
                return(0);
            }

            if (!_MainBindingGridView.CheckIsLeafDataRow())
            {
                DialogResult dre = MB.WinBase.MessageBoxEx.Question("存在下级节点,删除当前节点将把下级节点一起删除,是否继续");
                if (dre != DialogResult.Yes)
                {
                    return(0);
                }
            }
            DialogResult ddre = MB.WinBase.MessageBoxEx.Question("数据删除操作不可逆,是否继续?");

            if (ddre != DialogResult.Yes)
            {
                return(0);
            }
            deleteFirstPositionData = _MainGridBindingSource.Position == 0;
            int re = 0;

            System.ServiceModel.ICommunicationObject commObject = _ClientRuleObject.CreateServerCommunicationObject();
            try {
                _ClientRuleObject.AddToCache(commObject, (int)_ClientRuleObject.MainDataTypeInDoc, _EditBindingSource.Current, true, null);

                re = _ClientRuleObject.Flush(commObject);

                commObject.Close();
            }
            catch (Exception ex) {
                try {
                    commObject.Close();
                }
                catch { }
                MB.WinBase.ApplicationExceptionTerminate.DefaultInstance.ExceptionTerminate(ex, "数据删除出错,请重试!");
            }
            if (re > 0)
            {
                if (_MainGridBindingSource.Count == 1)
                {
                    this.Close();
                    _MainBindingGridView.RemoveFocusedRow(_MainGridBindingSource);
                    return(1);
                }
                _BeforeSaveDetailEntityCache.RaiseListChangedEvents = false;
                _BeforeSaveDetailEntityCache.Clear();
                _BeforeSaveDetailEntityCache.RaiseListChangedEvents = true;
                _MainBindingGridView.RemoveFocusedRow(_MainGridBindingSource);

                _MainGridBindingSource.EndEdit();
                if (deleteFirstPositionData)
                {
                    OnBindingSourcePositionChanged();
                    OnToolsButtonValidate();
                }
            }
            return(0);
        }
コード例 #11
0
        /// <summary>
        ///  对象数据保存。
        /// </summary>
        /// <param name="editEntity"></param>
        /// <param name="propertys"></param>
        /// <returns></returns>
        protected virtual int ObjectDataSave(object editEntity, string[] propertys)
        {
            int re = 0;

            System.ServiceModel.ICommunicationObject commObject = _ClientRuleObject.CreateServerCommunicationObject();
            try {
                if (!_DataValidated.DataValidated(this.ClientRuleObject as IClientRule, _EditColumnCtlBinding, _EditBindingSource.Current))
                {
                    throw new MB.Util.APPException("单据主体数据检验不成功,请检查", Util.APPMessageType.DisplayToUser);
                }
                _EditBindingSource.EndEditNoRaiseEvent();
                _BeforeSaveDetailEntityCache.RaiseBeforeDataSave();

                //判断并追加登录用户的相关信息( 实体数据的登录用户操作信息一般只在主表中存在 )
                if (propertys == null || propertys.Length == 0)
                {
                    MB.WinBase.UIDataEditHelper.Instance.AppendLoginUserInfo(editEntity);
                }
                //增加主表实体对象
                _ClientRuleObject.AddToCache(commObject, (int)_ClientRuleObject.MainDataTypeInDoc, editEntity, false, propertys);
                //增加明细数据
                foreach (KeyValuePair <int, object> detailInfo in _BeforeSaveDetailEntityCache)
                {
                    bool isDelete = false;
                    if (MB.WinBase.UIDataEditHelper.Instance.CheckExistsEntityState(detailInfo.Value))
                    {
                        if (MB.WinBase.UIDataEditHelper.Instance.GetEntityState(detailInfo.Value) == MB.Util.Model.EntityState.Deleted)
                        {
                            isDelete = true;
                        }
                    }
                    _ClientRuleObject.AddToCache(commObject, detailInfo.Key, detailInfo.Value, isDelete, null);
                }
                re = _ClientRuleObject.Flush(commObject);
            }
            catch (Exception ex) {
                MB.WinBase.ApplicationExceptionTerminate.DefaultInstance.ExceptionTerminate(ex);
            }
            finally {
                try {
                    commObject.Close();
                }
                catch { }
            }
            if (re > 0)
            {
                try {
                    ////刷新当前编辑的对象。
                    AcceptDataChanged(true);
                }
                catch (Exception x) {
                    MB.WinBase.MessageBoxEx.Show("对象数据库保存已经成功,但本地化更新时出错,请关闭窗口后重新刷新!");
                    MB.Util.TraceEx.Write("对象数据库保存已经成功,但本地化更新时出错." + x.Message);
                    return(0);
                }
            }
            else
            {
                MB.WinBase.MessageBoxEx.Show("对象数据库保存不成功,请重试");
            }
            return(re);
        }
コード例 #12
0
 static private void BuildProxy <TProxyInterface, TCallback>(System.Uri uriEndpoint, Udbus.WCF.Client.IBindingFactory bindingFactory
                                                             , TCallback callback
                                                             , out TProxyInterface proxy, out System.ServiceModel.ICommunicationObject comms
                                                             , uint maxTries, int wait)
     where TProxyInterface : class
 {
     System.ServiceModel.Channels.Binding binding = bindingFactory.Create();
     System.ServiceModel.InstanceContext  context = new System.ServiceModel.InstanceContext(callback);
     System.ServiceModel.DuplexChannelFactory <TProxyInterface> factory = new System.ServiceModel.DuplexChannelFactory <TProxyInterface>(
         context
         , binding
         , new System.ServiceModel.EndpointAddress(uriEndpoint)
         );
     proxy = factory.CreateChannel();
     comms = proxy as System.ServiceModel.ICommunicationObject;
     Proxy <TProxyInterface_> .AttemptClientOpen(ref comms, ref proxy, factory, maxTries, wait);
 }
コード例 #13
0
        public virtual int Delete()
        {
            if (_BindingSource.Current == null)
            {
                return(0);
            }
            if (this.GetViewDataNavigator().FocusedRowHandle < 0)
            {
                return(0);
            }

            if (MB.WinBase.UIDataEditHelper.Instance.CheckExistsDocState(_BindingSource.Current))
            {
                var docState = MB.WinBase.UIDataEditHelper.Instance.GetEntityDocState(_BindingSource.Current);
                if (docState != MB.Util.Model.DocState.Progress)
                {
                    MB.WinBase.MessageBoxEx.Show("当前单据已在提交状态,不能进行删除操作!");
                    return(0);
                }
            }
            //add by aifang 增加逻辑:如果数据未提交保存,直接进行删除 begin
            if (MB.WinBase.UIDataEditHelper.Instance.CheckExistsEntityState(_BindingSource.Current))
            {
                var entityState = MB.WinBase.UIDataEditHelper.Instance.GetEntityState(_BindingSource.Current);
                if (entityState == Util.Model.EntityState.New)
                {
                    MB.WinBase.UIDataEditHelper.Instance.SetEntityState(_BindingSource.Current, Util.Model.EntityState.Deleted);
                    this.GetViewDataNavigator().RemoveFocusedRow(_BindingSource);
                    _BindingSource.EndEdit();
                    return(0);
                }
            }
            //end

            DialogResult dre = MB.WinBase.MessageBoxEx.Question("删除操作不可逆,是否继续?");

            if (dre != DialogResult.Yes)
            {
                return(0);
            }

            int re = 0;

            System.ServiceModel.ICommunicationObject commObject = _ClientRuleObject.CreateServerCommunicationObject();
            try {
                _ClientRuleObject.AddToCache(commObject, (int)_ClientRuleObject.MainDataTypeInDoc, _BindingSource.Current, true, null);

                re = _ClientRuleObject.Flush(commObject);

                commObject.Close();
            }
            catch (Exception ex) {
                try {
                    commObject.Close();
                }
                catch { }

                MB.WinBase.ApplicationExceptionTerminate.DefaultInstance.ExceptionTerminate(ex, "数据删除出错,请重试!");
            }
            if (re > 0)
            {
                // _BindingSource.RemoveCurrent();
                this.GetViewDataNavigator().RemoveFocusedRow(_BindingSource);
                _BindingSource.EndEdit();
            }
            return(0);
        }