Ejemplo n.º 1
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (this.internalAgent != null)
         {
             SessionInternal.Utility.SafeCloseCommunicateObject(this.internalAgent);
             this.internalAgent = null;
         }
     }
     base.Dispose(disposing);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Recreate the internal DataServiceAgent instance
        /// </summary>
        private void RecreateInternalAgent()
        {
            // close previouus agent instance
            if (this.internalAgent != null)
            {
                this.excludedProxyInstances.Add(this.selectedProxyInstance);
                TraceHelper.TraceSource.TraceEvent(TraceEventType.Error, 0, "[DataProxyAgent] . Proxy instance {0} is excluded", this.selectedProxyInstance);

                SessionInternal.Utility.SafeCloseCommunicateObject(this.internalAgent);
                this.internalAgent = null;
            }

            List <string> proxyInstances = null;

            try
            {
                proxyInstances = proxyFileReader.GetProxyInstances(true);

                // remove excludedProxyInstances from all instance list
                foreach (string excludedInstance in this.excludedProxyInstances)
                {
                    proxyInstances.Remove(excludedInstance);
                }

                if (proxyInstances == null || proxyInstances.Count == 0)
                {
                    throw new Exception("No healthy data proxy instance is available");
                }
            }
            catch (Exception ex)
            {
                throw new DataException(DataErrorCode.ConnectDataServiceFailure, ex);
            }

            // pick a proxy instance at random
            int index = (new Random()).Next(proxyInstances.Count);

            this.selectedProxyInstance = proxyInstances[index];

            string dataProxyAddress = string.Format(Constant.DataProxyEndpointFormat, this.selectedProxyInstance, DataProxyPorts.ProxyPort);

            this.internalAgent = new DataServiceAgent(new Uri(dataProxyAddress));
            this.internalAgent.Endpoint.Behaviors.Add(new DataMessageInspector());
        }