コード例 #1
0
        private void LoadConfig()
        {
            if (ConfigTable.ContainsKey("Application"))
            {
                TomlTable appSettings = ConfigTable.Get <TomlTable>("Application");

                if (appSettings.ContainsKey("ListenPort"))
                {
                    ServerPort = (int)appSettings.Get <TomlInt>("ListenPort").Value;
                    Messenger.Default.ServerPort = ServerPort;
                }
            }

            foreach (var item in Items)
            {
                (item as IConfigViewModel).LoadConfigs(ConfigTable);
            }
        }
コード例 #2
0
        internal static ServicePoint FindServicePoint(string host, int port)
        {
            if (host == null)
            {
                throw new ArgumentNullException("address");
            }
            string lookupString      = null;
            bool   proxyServicePoint = false;

            lookupString = "ByHost:" + host + ":" + port.ToString(CultureInfo.InvariantCulture);
            ServicePoint target = null;

            lock (s_ServicePointTable)
            {
                WeakReference reference = s_ServicePointTable[lookupString] as WeakReference;
                if (reference != null)
                {
                    target = (ServicePoint)reference.Target;
                }
                if (target != null)
                {
                    return(target);
                }
                if ((s_MaxServicePoints <= 0) || (s_ServicePointTable.Count < s_MaxServicePoints))
                {
                    int    internalConnectionLimit = InternalConnectionLimit;
                    bool   userChangedLimit        = s_UserChangedLimit;
                    string key = host + ":" + port.ToString(CultureInfo.InvariantCulture);
                    if (ConfigTable.ContainsKey(key))
                    {
                        internalConnectionLimit = (int)ConfigTable[key];
                        userChangedLimit        = true;
                    }
                    target    = new ServicePoint(host, port, s_ServicePointIdlingQueue, internalConnectionLimit, lookupString, userChangedLimit, proxyServicePoint);
                    reference = new WeakReference(target);
                    s_ServicePointTable[lookupString] = reference;
                    return(target);
                }
                Exception exception = new InvalidOperationException(SR.GetString("net_maxsrvpoints"));
                throw exception;
            }
            return(target);
        }
コード例 #3
0
        private void SaveConfig()
        {
            TomlTable appSettings = Toml.Create();

            appSettings.Add("ListenPort", ServerPort);

            if (ConfigTable.ContainsKey("Application"))
            {
                ConfigTable.Remove("Application");
            }

            ConfigTable.Add("Application", appSettings);

            foreach (var item in Items)
            {
                (item as IConfigViewModel).SaveConfig(ConfigTable);
            }

            Toml.WriteFile(ConfigTable, CONFIG_FILE);
        }
コード例 #4
0
        private static ServicePoint FindServicePointHelper(Uri address, bool isProxyServicePoint)
        {
            if (isProxyServicePoint && (address.Scheme != Uri.UriSchemeHttp))
            {
                Exception exception = new NotSupportedException(SR.GetString("net_proxyschemenotsupported", new object[] { address.Scheme }));
                throw exception;
            }
            string       lookupString = MakeQueryString(address, isProxyServicePoint);
            ServicePoint target       = null;

            lock (s_ServicePointTable)
            {
                WeakReference reference = s_ServicePointTable[lookupString] as WeakReference;
                if (reference != null)
                {
                    target = (ServicePoint)reference.Target;
                }
                if (target != null)
                {
                    return(target);
                }
                if ((s_MaxServicePoints <= 0) || (s_ServicePointTable.Count < s_MaxServicePoints))
                {
                    int    internalConnectionLimit = InternalConnectionLimit;
                    string key = MakeQueryString(address);
                    bool   userChangedLimit = s_UserChangedLimit;
                    if (ConfigTable.ContainsKey(key))
                    {
                        internalConnectionLimit = (int)ConfigTable[key];
                        userChangedLimit        = true;
                    }
                    target    = new ServicePoint(address, s_ServicePointIdlingQueue, internalConnectionLimit, lookupString, userChangedLimit, isProxyServicePoint);
                    reference = new WeakReference(target);
                    s_ServicePointTable[lookupString] = reference;
                    return(target);
                }
                Exception exception2 = new InvalidOperationException(SR.GetString("net_maxsrvpoints"));
                throw exception2;
            }
            return(target);
        }
コード例 #5
0
        private static ServicePoint FindServicePointHelper(Uri address, bool isProxyServicePoint)
        {
            GlobalLog.Enter("ServicePointManager::FindServicePointHelper() address:" + address.ToString());

            if (isProxyServicePoint)
            {
                if (address.Scheme != Uri.UriSchemeHttp)
                {
                    // <



                    Exception exception = new NotSupportedException(SR.GetString(SR.net_proxyschemenotsupported, address.Scheme));
                    GlobalLog.LeaveException("ServicePointManager::FindServicePointHelper() proxy has unsupported scheme:" + address.Scheme.ToString(), exception);
                    throw exception;
                }
            }

            //
            // Search for the correct proxy host,
            //  then match its acutal host by using ConnectionGroups
            //  which are located on the actual ServicePoint.
            //
            string tempEntry = MakeQueryString(address, isProxyServicePoint);

            // lookup service point in the table
            ServicePoint servicePoint = null;

            GlobalLog.Print("ServicePointManager::FindServicePointHelper() locking and looking up tempEntry:[" + tempEntry.ToString() + "]");
            lock (s_ServicePointTable) {
                // once we grab the lock, check if it wasn't already added
                WeakReference servicePointReference = s_ServicePointTable[tempEntry] as WeakReference;
                GlobalLog.Print("ServicePointManager::FindServicePointHelper() lookup returned WeakReference#" + ValidationHelper.HashString(servicePointReference));
                if (servicePointReference != null)
                {
                    servicePoint = (ServicePoint)servicePointReference.Target;
                    GlobalLog.Print("ServicePointManager::FindServicePointHelper() successful lookup returned ServicePoint#" + ValidationHelper.HashString(servicePoint));
                }
                if (servicePoint == null)
                {
                    // lookup failure or timeout, we need to create a new ServicePoint
                    if (s_MaxServicePoints <= 0 || s_ServicePointTable.Count < s_MaxServicePoints)
                    {
                        // Determine Connection Limit
                        int    connectionLimit = InternalConnectionLimit;
                        string schemeHostPort  = MakeQueryString(address);
                        bool   userDefined     = s_UserChangedLimit;
                        if (ConfigTable.ContainsKey(schemeHostPort))
                        {
                            connectionLimit = (int)ConfigTable[schemeHostPort];
                            userDefined     = true;
                        }
                        servicePoint = new ServicePoint(address, s_ServicePointIdlingQueue, connectionLimit, tempEntry, userDefined, isProxyServicePoint);
                        GlobalLog.Print("ServicePointManager::FindServicePointHelper() created ServicePoint#" + ValidationHelper.HashString(servicePoint));
                        servicePointReference          = new WeakReference(servicePoint);
                        s_ServicePointTable[tempEntry] = servicePointReference;
                        GlobalLog.Print("ServicePointManager::FindServicePointHelper() adding entry WeakReference#" + ValidationHelper.HashString(servicePointReference) + " key:[" + tempEntry + "]");
                    }
                    else
                    {
                        Exception exception = new InvalidOperationException(SR.GetString(SR.net_maxsrvpoints));
                        GlobalLog.LeaveException("ServicePointManager::FindServicePointHelper() reached the limit count:" + s_ServicePointTable.Count.ToString() + " limit:" + s_MaxServicePoints.ToString(), exception);
                        throw exception;
                    }
                }
            }

            GlobalLog.Leave("ServicePointManager::FindServicePointHelper() servicePoint#" + ValidationHelper.HashString(servicePoint));
            return(servicePoint);
        }
コード例 #6
0
        //
        // FindServicePoint - Query using an Uri for a given server point
        //

        /// <devdoc>
        /// <para>Findes an existing <see cref='System.Net.ServicePoint'/> or creates a new <see cref='System.Net.ServicePoint'/> to manage communications to the specified <see cref='System.Uri'/>
        /// instance.</para>
        /// </devdoc>
        internal static ServicePoint FindServicePoint(string host, int port)
        {
            if (host == null)
            {
                throw new ArgumentNullException("address");
            }
            GlobalLog.Enter("ServicePointManager::FindServicePoint() host:" + host.ToString());

            string tempEntry           = null;
            bool   isProxyServicePoint = false;


            //
            // Search for the correct proxy host,
            //  then match its acutal host by using ConnectionGroups
            //  which are located on the actual ServicePoint.
            //
            tempEntry = "ByHost:" + host + ":" + port.ToString(CultureInfo.InvariantCulture);
            // lookup service point in the table
            ServicePoint servicePoint = null;

            GlobalLog.Print("ServicePointManager::FindServicePoint() locking and looking up tempEntry:[" + tempEntry.ToString() + "]");
            lock (s_ServicePointTable) {
                // once we grab the lock, check if it wasn't already added
                WeakReference servicePointReference = s_ServicePointTable[tempEntry] as WeakReference;
                GlobalLog.Print("ServicePointManager::FindServicePoint() lookup returned WeakReference#" + ValidationHelper.HashString(servicePointReference));
                if (servicePointReference != null)
                {
                    servicePoint = (ServicePoint)servicePointReference.Target;
                    GlobalLog.Print("ServicePointManager::FindServicePoint() successfull lookup returned ServicePoint#" + ValidationHelper.HashString(servicePoint));
                }
                if (servicePoint == null)
                {
                    // lookup failure or timeout, we need to create a new ServicePoint
                    if (s_MaxServicePoints <= 0 || s_ServicePointTable.Count < s_MaxServicePoints)
                    {
                        // Determine Connection Limit
                        int    connectionLimit = InternalConnectionLimit;
                        bool   userDefined     = s_UserChangedLimit;
                        string schemeHostPort  = host + ":" + port.ToString(CultureInfo.InvariantCulture);

                        if (ConfigTable.ContainsKey(schemeHostPort))
                        {
                            connectionLimit = (int)ConfigTable[schemeHostPort];
                            userDefined     = true;
                        }
                        servicePoint = new ServicePoint(host, port, s_ServicePointIdlingQueue, connectionLimit, tempEntry, userDefined, isProxyServicePoint);
                        GlobalLog.Print("ServicePointManager::FindServicePoint() created ServicePoint#" + ValidationHelper.HashString(servicePoint));
                        servicePointReference          = new WeakReference(servicePoint);
                        s_ServicePointTable[tempEntry] = servicePointReference;
                        GlobalLog.Print("ServicePointManager::FindServicePoint() adding entry WeakReference#" + ValidationHelper.HashString(servicePointReference) + " key:[" + tempEntry + "]");
                    }
                    else
                    {
                        Exception exception = new InvalidOperationException(SR.GetString(SR.net_maxsrvpoints));
                        GlobalLog.LeaveException("ServicePointManager::FindServicePoint() reached the limit count:" + s_ServicePointTable.Count.ToString() + " limit:" + s_MaxServicePoints.ToString(), exception);
                        throw exception;
                    }
                }
            }

            GlobalLog.Leave("ServicePointManager::FindServicePoint() servicePoint#" + ValidationHelper.HashString(servicePoint));
            return(servicePoint);
        }
コード例 #7
0
        //
        // FindServicePoint - Query using an Uri for a given server point
        //

        /// <include file='doc\ServicePointManager.uex' path='docs/doc[@for="ServicePointManager.FindServicePoint2"]/*' />
        /// <devdoc>
        /// <para>Findes an existing <see cref='System.Net.ServicePoint'/> or creates a new <see cref='System.Net.ServicePoint'/> to manage communications to the specified <see cref='System.Uri'/>
        /// instance.</para>
        /// </devdoc>
        public static ServicePoint FindServicePoint(Uri address, IWebProxy proxy)
        {
            if (address == null)
            {
                throw new ArgumentNullException("address");
            }
            GlobalLog.Enter("ServicePointManager::FindServicePoint() address:" + address.ToString());

            string tempEntry;
            bool   isProxyServicePoint = false;

            ScavengeIdleServicePoints();

            //
            // find proxy info, and then switch on proxy
            //
            if (proxy != null && !proxy.IsBypassed(address))
            {
                // use proxy support
                // rework address
                Uri proxyAddress = proxy.GetProxy(address);
                if (proxyAddress.Scheme != Uri.UriSchemeHttps && proxyAddress.Scheme != Uri.UriSchemeHttp)
                {
                    Exception exception = new NotSupportedException(SR.GetString(SR.net_proxyschemenotsupported, proxyAddress.Scheme));
                    GlobalLog.LeaveException("ServicePointManager::FindServicePoint() proxy has unsupported scheme:" + proxyAddress.Scheme.ToString(), exception);
                    throw exception;
                }
                address = proxyAddress;

                isProxyServicePoint = true;

                //
                // Search for the correct proxy host,
                //  then match its acutal host by using ConnectionGroups
                //  which are located on the actual ServicePoint.
                //

                tempEntry = MakeQueryString(proxyAddress);
            }
            else
            {
                //
                // Typical Host lookup
                //
                tempEntry = MakeQueryString(address);
            }

            //
            // lookup service point in the table
            //
            ServicePoint servicePoint = null;

            lock (s_ServicePointTable) {
                //
                // once we grab the lock, check if it wasn't already added
                //
                WeakReference servicePointReference = (WeakReference)s_ServicePointTable[tempEntry];

                if (servicePointReference != null)
                {
                    servicePoint = (ServicePoint)servicePointReference.Target;
                }

                if (servicePoint == null)
                {
                    //
                    // lookup failure or timeout, we need to create a new ServicePoint
                    //
                    if (s_MaxServicePoints <= 0 || s_ServicePointTable.Count < s_MaxServicePoints)
                    {
                        //
                        // Determine Connection Limit
                        //
                        int    connectionLimit = InternalConnectionLimit;
                        string schemeHostPort  = MakeQueryString(address);

                        if (ConfigTable.ContainsKey(schemeHostPort))
                        {
                            connectionLimit = (int)ConfigTable[schemeHostPort];
                        }

                        // Note: we don't check permissions to access proxy.
                        //      Rather, we should protect proxy property from being changed

                        servicePoint          = new ServicePoint(address, s_MaxServicePointIdleTime, connectionLimit);
                        servicePointReference = new WeakReference(servicePoint);

                        // only set this when created, donates a proxy, statt Server
                        servicePoint.InternalProxyServicePoint = isProxyServicePoint;

                        s_ServicePointTable[tempEntry] = servicePointReference;
                    }
                    else
                    {
                        Exception exception = new InvalidOperationException(SR.GetString(SR.net_maxsrvpoints));
                        GlobalLog.LeaveException("ServicePointManager::FindServicePoint() reached the limit count:" + s_ServicePointTable.Count.ToString() + " limit:" + s_MaxServicePoints.ToString(), exception);
                        throw exception;
                    }
                }
            } // lock

            GlobalLog.Leave("ServicePointManager::FindServicePoint() servicePoint#" + ValidationHelper.HashString(servicePoint));

            return(servicePoint);
        }