Пример #1
0
        public void Pilot_test3()
        {
            var     envmap = new System.Collections.Generic.Dictionary <Area, Sensor.ScanResult>();
            Vector3 dest   = new Vector3(1, 0, 0);
            Vector3 here   = new Vector3(0, 5, 0);

            for (int i = 0; i < 5; ++i)
            {
                for (int j = 0; j < 6; ++j)
                {
                    envmap.Add(new Area(i, j, 0), (Sensor.ScanResult.nothingFound));
                }
            }
            // h * * * *
            // - - - - -
            // * - * - -
            // * - - - -
            // - - * * -
            // - d - - -
            envmap[new Area(1, 5, 0)] = (Sensor.ScanResult.somethingFound);
            envmap[new Area(2, 5, 0)] = (Sensor.ScanResult.somethingFound);
            envmap[new Area(3, 5, 0)] = (Sensor.ScanResult.somethingFound);
            envmap[new Area(4, 5, 0)] = (Sensor.ScanResult.somethingFound);
            envmap[new Area(0, 3, 0)] = (Sensor.ScanResult.somethingFound);
            envmap[new Area(2, 3, 0)] = (Sensor.ScanResult.somethingFound);
            envmap[new Area(0, 2, 0)] = (Sensor.ScanResult.somethingFound);
            envmap[new Area(2, 1, 0)] = (Sensor.ScanResult.somethingFound);
            envmap[new Area(3, 1, 0)] = (Sensor.ScanResult.somethingFound);
            var map   = new System.Collections.ObjectModel.ReadOnlyDictionary <Area, Sensor.ScanResult>(envmap);
            var route = new Pilot().getPath(dest, here, map);

            Assert.AreEqual(7, route.Count());
        }
Пример #2
0
        //public GsaModel(Model model)
        //{
        //    m_model = model;
        //}

        public GsaModel Duplicate()
        {
            Model dup = new Model();

            //duplicate the incoming model ### Shallow copy funcitonality in GsaAPI welcome here....
            if (m_model != null)
            {
                System.Collections.ObjectModel.ReadOnlyDictionary <int, Node> nodes = m_model.Nodes();
                dup.SetNodes(nodes);

                System.Collections.ObjectModel.ReadOnlyDictionary <int, Element> elems = m_model.Elements();
                dup.SetElements(elems);

                System.Collections.ObjectModel.ReadOnlyDictionary <int, Member> mems = m_model.Members();
                dup.SetMembers(mems);

                //ToDo
                //model.SetAnalysisCaseDescription;
                //model.SetAxes;
                //model.SetBeamLoad;
                //model.SetFaceLoad;
                //model.SetGravityLoad;
                //model.SetGridAreaLoad;
                //model.SetGridLineLoad;
                //model.SetGridPlanes;
                //model.SetGridSurfaces;
                //model.SetNodeLoad;
                //model.SetProp2Ds;
                //model.SetSections;
            }
            this.Model = dup;
            return(this);
        }
Пример #3
0
            public static Dictionary <string, IfcProperty> ToIfcPropertyDic(System.Collections.ObjectModel.ReadOnlyDictionary <string, IfcProperty> properties)
            {
                Dictionary <string, IfcProperty> dic = new Dictionary <string, IfcProperty>();

                properties.Keys.ForEach(k =>
                {
                    dic.Add(k, properties[k]);
                });
                return(dic);
            }
Пример #4
0
 public async Task SetRemoteIdGuid(ContactStore store)
 {
     IDictionary<string, object> properties;
     properties = await store.LoadExtendedPropertiesAsync().AsTask<IDictionary<string, object>>();
     if (!properties.ContainsKey(ContactStoreLocalInstanceIdKey))
     {
         // the given store does not have a local instance id so set one against store extended properties
         Guid guid = Guid.NewGuid();
         properties.Add(ContactStoreLocalInstanceIdKey, guid.ToString());
         System.Collections.ObjectModel.ReadOnlyDictionary<string, object> readonlyProperties = new System.Collections.ObjectModel.ReadOnlyDictionary<string, object>(properties);
         await store.SaveExtendedPropertiesAsync(readonlyProperties).AsTask();
     }
 }
Пример #5
0
        public async Task SetRemoteIdGuid(ContactStore store)
        {
            IDictionary <string, object> properties;

            properties = await store.LoadExtendedPropertiesAsync().AsTask <IDictionary <string, object> >();

            if (!properties.ContainsKey(ContactStoreLocalInstanceIdKey))
            {
                // the given store does not have a local instance id so set one against store extended properties
                Guid guid = Guid.NewGuid();
                properties.Add(ContactStoreLocalInstanceIdKey, guid.ToString());
                System.Collections.ObjectModel.ReadOnlyDictionary <string, object> readonlyProperties = new System.Collections.ObjectModel.ReadOnlyDictionary <string, object>(properties);
                await store.SaveExtendedPropertiesAsync(readonlyProperties).AsTask();
            }
        }
Пример #6
0
        public Spellbook()
        {
            energies = new SortedDictionary <SpellAttribute, int>(Comparer <SpellAttribute> .Create((x, y) => x.CompareTo(y)));
            Energies = new System.Collections.ObjectModel.ReadOnlyDictionary <SpellAttribute, int>(energies);
            foreach (SpellAttribute energy in energies.Keys)
            {
                energies[energy] = 0;
            }

            castRuneModifiers = new List <ICastRuneModifier>();
            CastRuneModifiers = castRuneModifiers.AsReadOnly();

            storedRunes = new List <Rune>();
            StoredRunes = storedRunes.AsReadOnly();

            spellpages = new Spellpage[MaxPageNumber + 1]; //+1 is because API is one-indexed; note that we "waste" the zeroth index
        }
Пример #7
0
        public void Transform_NonAnonymousTypeAllPropertiesPresent_SetsAllPropertyValuesAndReturnsInstance()
        {
            //prepare
            _properties = new Dictionary <string, string>
            {
                { "Property1", "Property1" },
                { "Property2", "Property2" },
                { "Property3", "Property3" },
                { "Property4", "Property4" }
            }.ToReadOnlyDictionary();
            _transformer = new ResultTransformer(_properties, _mapping.Object);

            var instance = new object();

            _mapping.Setup(m => m.Create(It.IsAny <object[]>(), null))
            .Returns(instance);
            _mapping.Setup(m => m.IsForAnonymousType)
            .Returns(false);

            var searchResultAttributesCollection =
                typeof(SearchResultAttributeCollection).Create <SearchResultAttributeCollection>();

            searchResultAttributesCollection
            .Call("Add", new object[] { "Property1", new DirectoryAttribute("Property1", "prop1") });
            searchResultAttributesCollection
            .Call("Add", new object[] { "Property2", new DirectoryAttribute("Property2", "2") });
            searchResultAttributesCollection
            .Call("Add", new object[] { "Property3", new DirectoryAttribute("Property3", _bytes) });
            searchResultAttributesCollection
            .Call("Add", new object[] { "Property4", new DirectoryAttribute("Property4", _strings) });

            var searchResultsEntry =
                typeof(SearchResultEntry).Create <SearchResultEntry>(
                    new object[] { "dn", searchResultAttributesCollection });

            //act
            var transformed = _transformer.Transform(searchResultsEntry);

            //assert
            transformed.Should().Be.SameInstanceAs(instance);
            _property1.Verify(p => p.SetValue(instance, "prop1"));
            _property2.Verify(p => p.SetValue(instance, "2"));
            _property3.Verify(p => p.SetValue(instance, _bytes));
            _property4.Verify(p => p.SetValue(instance, _strings));
        }
Пример #8
0
        internal ZoneInfo(DeviceProviders.AllJoynMessageArgStructure arg)
        {
            ZoneId         = (string)arg[0];
            TimeStamp      = (int)arg[1];
            LeadPlayerName = arg[2] as string;                                  // Name of master this is slaved to
            var slavesArg = arg[2] as DeviceProviders.AllJoynMessageArgVariant; // Names of slaves to this player

            if (slavesArg != null)
            {
                var value   = slavesArg.Value as IList <KeyValuePair <object, object> >;
                var players = new Dictionary <string, int>();
                foreach (var item in value)
                {
                    players.Add((string)item.Key, (int)item.Value);
                }
                PlayerNames = new System.Collections.ObjectModel.ReadOnlyDictionary <string, int>(players);
            }
        }
Пример #9
0
        public void Transform_AnonymousTypeSomePropertiesPresent_SetsPresentPropertyValuesAndReturnsInstance()
        {
            //prepare
            _properties = new Dictionary <string, string>
            {
                { "Property1", "Property1" },
                { "Property2", "Property2" },
                { "Property3", "Property3" },
                { "Property4", "Property4" }
            }.ToReadOnlyDictionary();
            _transformer = new ResultTransformer(_properties, _mapping.Object);

            var instance = new object();

            _mapping.Setup(m => m.Properties)
            .Returns(_properties);
            _mapping.Setup(m => m.Create(new object[] { "prop1", default(int), default(byte[]), default(string[]) }, null))
            .Returns(instance);
            _mapping.Setup(m => m.IsForAnonymousType)
            .Returns(true);

            var searchResultAttributesCollection =
                typeof(SearchResultAttributeCollection).Create <SearchResultAttributeCollection>();

            searchResultAttributesCollection
            .Call("Add", new object[] { "Property1", new DirectoryAttribute("Property1", "prop1") });

            var searchResultsEntry =
                typeof(SearchResultEntry).Create <SearchResultEntry>(
                    new object[] { "dn", searchResultAttributesCollection });

            //act
            var transformed = _transformer.Transform(searchResultsEntry);

            //assert
            transformed.Should().Be.SameInstanceAs(instance);
        }
Пример #10
0
        public void Transform_non_anonymous_type_with_catch_all_mapping_sets_present_properties_and_sets_catch_all_and_returns_instance()
        {
            //prepare
            _properties = new Dictionary <string, string>
            {
                { "Property1", "Property1" },
                { "Property2", "Property2" }
            }.ToReadOnlyDictionary();

            _mapping.Setup(m => m.GetPropertyMappingByAttribute("property1", typeof(object)))
            .Returns(_property1.Object);

            _mapping.Setup(m => m.GetPropertyMappingByAttribute("property2", typeof(object)))
            .Returns(_property2.Object);

            _mapping.Setup(m => m.GetPropertyMappingByAttribute("property3", typeof(object)))
            .Returns(_property3.Object);

            _mapping.Setup(m => m.GetPropertyMappingByAttribute("property4", typeof(object)))
            .Returns(_property4.Object);

            _transformer = new ResultTransformer(_properties, _mapping.Object);

            var instance = new object();

            _mapping.Setup(m => m.Create(It.IsAny <object[]>(), null))
            .Returns(instance);
            _mapping.Setup(m => m.IsForAnonymousType)
            .Returns(false);

            _mapping.Setup(x => x.HasCatchAllMapping)
            .Returns(true);

            var catchAll = new Mock <IPropertyMapping>();

            _mapping.Setup(x => x.GetCatchAllMapping())
            .Returns(catchAll.Object);

            var searchResultAttributesCollection =
                typeof(SearchResultAttributeCollection).Create <SearchResultAttributeCollection>();

            searchResultAttributesCollection
            .Call("Add", new object[] { "Property1", new DirectoryAttribute("Property1", "prop1") });
            searchResultAttributesCollection
            .Call("Add", new object[] { "Property2", new DirectoryAttribute("Property2", "2") });
            searchResultAttributesCollection
            .Call("Add", new object[] { "OtherProperty", new DirectoryAttribute("OtherProperty", "2") });

            var searchResultsEntry =
                typeof(SearchResultEntry).Create <SearchResultEntry>(
                    new object[] { "dn", searchResultAttributesCollection });

            //act
            var transformed = _transformer.Transform(searchResultsEntry);

            //assert
            transformed.Should().Be.SameInstanceAs(instance);
            _property1.Verify(p => p.SetValue(instance, "prop1"));
            _property2.Verify(p => p.SetValue(instance, "2"));
            _property3.Verify(p => p.SetValue(instance, _bytes), Times.Never());
            _property4.Verify(p => p.SetValue(instance, _strings), Times.Never());
            catchAll.Verify(
                p => p.SetValue(instance, It.Is <IDirectoryAttributes>(da => da.Entry == searchResultsEntry)), Times.Once());
        }
Пример #11
0
 public static System.Collections.ObjectModel.ReadOnlyDictionary <string, int> CastValueToInt(this System.Collections.ObjectModel.ReadOnlyDictionary <string, string> dictionary)
 {
     return(new System.Collections.ObjectModel.ReadOnlyDictionary <string, int>(System.Linq.Enumerable.ToDictionary(dictionary, x => x.Key, x => int.Parse(x.Value), System.StringComparer.InvariantCultureIgnoreCase)));
 }
Пример #12
0
 private Session()
 {
     m_CommandLineOptions = (0 >= (CommandLineOptions?.Count ?? 0) ? null : new System.Collections.ObjectModel.ReadOnlyDictionary <string, string>(new Dictionary <string, string>(Session.CommandLineOptions)));
     Reset();
 }
        /// <summary>
        /// Monta uma List<Dictionary<string, object>> onde tem nome da aggregação e o valor
        /// </summary>
        /// <param name="aggregates">Aggregates do retorno do elastic</param>
        /// <param name="props">passe nulo na primeira chamada</param>
        /// <returns></returns>
        public List <Dictionary <string, object> > ConvertAggregateResult(IReadOnlyDictionary <string, IAggregate> aggregates, Dictionary <string, object> props = null)
        {
            var list = new List <Dictionary <string, object> >();

            if (props == null)
            {
                props = new Dictionary <string, object>();
            }

            var add = false;

            foreach (var item in aggregates)
            {
                //Se o item for um bucket
                if (item.Value is BucketAggregate && !item.Key.EndsWith("Count"))
                {
                    var bucket = item.Value as BucketAggregate;
                    //Para receber as Aggregadas do item
                    IReadOnlyDictionary <string, IAggregate> _subAggregates = null;

                    foreach (var itemBucket in bucket.Items)
                    {
                        if (props.Any(w => w.Key == item.Key))
                        {
                            props.Remove(item.Key);
                        }

                        //Caso seja usado um novo tipo adicionar outra condição

                        //Usado no TermsAggregation
                        if (itemBucket is KeyedBucket <object> )
                        {
                            var _temp = itemBucket as KeyedBucket <object>;
                            props.Add(item.Key, _temp.Key);
                            //_subAggregates = _temp.Aggregations;

                            var t = (from a in _temp.Keys
                                     join b in _temp.ToList() on a equals b.Key
                                     select new { Key = a, Value = b.Value });
                            var _dc = new Dictionary <string, IAggregate>();
                            foreach (var _item in t)
                            {
                                _dc.Add(_item.Key, _item.Value);
                            }

                            _subAggregates = new System.Collections.ObjectModel.ReadOnlyDictionary <string, IAggregate>(_dc);
                        }
                        else if (itemBucket is RangeBucket)
                        {
                            var _temp = itemBucket as RangeBucket;
                            props.Add(item.Key, _temp.Key);
                            //_subAggregates = _temp.Aggregations;
                            var t = (from a in _temp.Keys
                                     join b in _temp.ToList() on a equals b.Key
                                     select new { Key = a, Value = b.Value });
                            var _dc = new Dictionary <string, IAggregate>();
                            foreach (var _item in t)
                            {
                                _dc.Add(_item.Key, _item.Value);
                            }

                            _subAggregates = new System.Collections.ObjectModel.ReadOnlyDictionary <string, IAggregate>(_dc);
                        }
                        //Usado no DateHistogramAggregation
                        else if (itemBucket is DateHistogramBucket)
                        {
                            var _temp = itemBucket as DateHistogramBucket;
                            props.Add(item.Key, _temp.Date);
                            //_subAggregates = _temp.Aggregations;
                            var t = (from a in _temp.Keys
                                     join b in _temp.ToList() on a equals b.Key
                                     select new { Key = a, Value = b.Value });
                            var _dc = new Dictionary <string, IAggregate>();
                            foreach (var _item in t)
                            {
                                _dc.Add(_item.Key, _item.Value);
                            }

                            _subAggregates = new System.Collections.ObjectModel.ReadOnlyDictionary <string, IAggregate>(_dc);
                        }

                        list.AddRange(ConvertAggregateResult(_subAggregates, props));
                    }
                }
                //Quando ele for um Value considera sendo o ultimo nivel
                else if (item.Value is ValueAggregate)
                {
                    add = true;
                    var _temp = item.Value as ValueAggregate;

                    if (props.Any(w => w.Key == item.Key))
                    {
                        props.Remove(item.Key);
                    }

                    props.Add(item.Key, _temp.Value);
                }
                else if (item.Value is BucketAggregate && item.Key.EndsWith("Count"))
                {
                    add = true;
                    var _temp = item.Value as BucketAggregate;

                    if (props.Any(w => w.Key == item.Key))
                    {
                        props.Remove(item.Key);
                    }

                    props.Add(item.Key, _temp.Items.Select(s => (s as KeyedBucket <object>).Key).Distinct().Count());
                }
            }

            //Adicionar o item na lista
            if (add)
            {
                var _temp = new Dictionary <string, object>();

                foreach (var item in props)
                {
                    _temp.Add(item.Key, item.Value);
                }

                list.Add(_temp);
            }

            return(list);
        }
Пример #14
0
        /// <summary>
        ///  Called on the network thread when it is time to receive an HTTP response from the host/server.
        /// </summary>
        /// <param name="result">Provides the HttpWebRequest object that invoked this method.</param>
        private void OnAsyncGetResponse(IAsyncResult result)
        {
            // Fetch the HTTP request implementation object and settings.
            var httpWebRequest = fHttpWebRequest;
            var settings       = fClonedSettings;

            if ((httpWebRequest == null) || (settings == null))
            {
                return;
            }

            // Do not continue if this operation has been aborted.
            if (object.ReferenceEquals(httpWebRequest, result.AsyncState) == false)
            {
                return;
            }

            // Fetch the HTTP response data.
            System.Net.HttpWebResponse httpWebResponse = null;
            System.IO.Stream           inputStream     = null;
            System.IO.Stream           outputStream    = null;
            try
            {
                // Fetch the HTTP response.
                try
                {
                    httpWebResponse = httpWebRequest.EndGetResponse(result) as System.Net.HttpWebResponse;
                }
                catch (System.Net.WebException ex)
                {
                    // Check if an exception was thrown because we've received an HTTP error response.
                    // This can happen if the response's status code is >= 400.
                    httpWebResponse = ex.Response as System.Net.HttpWebResponse;

                    // If we did not get a response, then assume its a network error and abort.
                    if (httpWebResponse == null)
                    {
                        throw ex;
                    }

#if WINDOWS_PHONE
                    // If the Internet connection is down, then we'll get a fake 404 response.
                    // If this is the case, then error out immediately. (The HTTP response is not real. So, don't provide it.)
                    if (Microsoft.Phone.Net.NetworkInformation.DeviceNetworkInformation.IsNetworkAvailable == false)
                    {
                        throw new Exception("Network connection error.");
                    }
#endif
                }

                // If the HTTP request had no content, then the OnAsyncGetRequestStream() never got called.
                // Notify the system that we've finished sending the HTTP request, which happened in EndGetResponse() above.
                if (httpWebRequest.ContentLength < 0)
                {
                    var asyncSentRequestEventHandler = this.AsyncSentRequest;
                    if (asyncSentRequestEventHandler != null)
                    {
                        asyncSentRequestEventHandler.Invoke(this, new HttpProgressEventArgs(0, 0));
                    }
                }

                // Do not continue if the handler for the above event has aborted this operation.
                if (object.ReferenceEquals(httpWebRequest, fHttpWebRequest) == false)
                {
                    return;
                }

                // Fetch the estimated number of bytes in the HTTP response's body.
                // If the value is -1 or 4294967295 (the unsigned version of -1), then the amount of bytes is unknown.
                inputStream = httpWebResponse.GetResponseStream();
                long responseContentLength = httpWebResponse.ContentLength;
                if ((responseContentLength < 0) || (responseContentLength == (long)UInt32.MaxValue))
                {
                    responseContentLength = -1;
                }

                // Open an output stream if set up to download to file.
                if (string.IsNullOrEmpty(settings.DownloadFilePath) == false)
                {
                    // First, create the file's sub-directories if applicable.
                    string directoryPath = System.IO.Path.GetDirectoryName(settings.DownloadFilePath);
                    System.IO.Directory.CreateDirectory(directoryPath);

                    // Attempt to create the file to write to.
                    outputStream = System.IO.File.Open(
                        settings.DownloadFilePath, System.IO.FileMode.Create, System.IO.FileAccess.Write);
                }

                // Fetch the response's HTTP headers.
                var headerCollection = new System.Collections.Generic.Dictionary <string, string>();
                foreach (var headerName in httpWebResponse.Headers.AllKeys)
                {
                    headerCollection.Add(headerName, httpWebResponse.Headers[headerName]);
                }
                var readOnlyHeaderCollection =
                    new System.Collections.ObjectModel.ReadOnlyDictionary <string, string>(headerCollection);

                // Notify the system that we've started to receive an HTTP response.
                var asynReceivingResponseEventHandler = this.AsyncReceivingResponse;
                if (asynReceivingResponseEventHandler != null)
                {
                    asynReceivingResponseEventHandler.Invoke(
                        this, new HttpResponseEventArgs((int)httpWebResponse.StatusCode, readOnlyHeaderCollection, null));
                }

                // Do not continue if the handler for the above event has aborted this operation.
                if (object.ReferenceEquals(httpWebRequest, fHttpWebRequest) == false)
                {
                    return;
                }

                // Download the HTTP response's content body.
                var httpBodyBytes = new System.Collections.Generic.List <byte>();
                if (httpWebResponse.ContentLength > 0)
                {
                    int bytesReceived = 0;
                    var byteBuffer    = new byte[2048];
                    while (true)
                    {
                        // Fetch the next batch of response content bytes, if any are left.
                        int bytesRead = inputStream.Read(byteBuffer, 0, byteBuffer.Length);
                        if (bytesRead == 0)
                        {
                            // No more bytes are available. The entire response has been received.
                            break;
                        }

                        // Do not continue if this operation has been aborted.
                        if (object.ReferenceEquals(httpWebRequest, fHttpWebRequest) == false)
                        {
                            return;
                        }

                        // Copy the HTTP response bytes to file or memory.
                        if (outputStream != null)
                        {
                            // Write the response bytes to file.
                            outputStream.Write(byteBuffer, 0, bytesRead);
                        }
                        else if (bytesRead == byteBuffer.Length)
                        {
                            // Write the response bytes to the memory buffer.
                            // Note: This is an optimization. Copying the entire array in one shot is faster.
                            httpBodyBytes.AddRange(byteBuffer);
                        }
                        else
                        {
                            // Write the last portion of response bytes to the memory buffer.
                            // Note: No more response bytes should be available after this.
                            for (int index = 0; index < bytesRead; index++)
                            {
                                httpBodyBytes.Add(byteBuffer[index]);
                            }
                        }

                        // Notify the system how many bytes have been downloaded so far.
                        bytesReceived += bytesRead;
                        if (bytesReceived > 0)
                        {
                            var asyncReceiveProgressChangedEventHandler = this.AsyncReceiveProgressChanged;
                            if (asyncReceiveProgressChangedEventHandler != null)
                            {
                                // Raise a progress event.
                                asyncReceiveProgressChangedEventHandler.Invoke(
                                    this, new HttpProgressEventArgs(bytesReceived, responseContentLength));

                                // Do not continue if the handler for the above event has aborted this operation.
                                if (object.ReferenceEquals(httpWebRequest, fHttpWebRequest) == false)
                                {
                                    return;
                                }
                            }
                        }
                    }
                }
                var immutableHttpBodyBytes = CoronaLabs.WinRT.ImmutableByteBuffer.From(httpBodyBytes);

                // If downloading to file, close its stream.
                if (outputStream != null)
                {
                    outputStream.Close();
                    outputStream.Dispose();
                    outputStream = null;
                }

                // Clear this operation's member variables.
                // This frees up this object to execute another HTTP request.
                fHttpWebRequest = null;
                fClonedSettings = null;

                // Notify the system that we've received the entire response and we're done.
                var asynReceivedResponseEventHandler = this.AsyncReceivedResponse;
                if (asynReceivedResponseEventHandler != null)
                {
                    var eventArgs = new HttpResponseEventArgs(
                        (int)httpWebResponse.StatusCode, readOnlyHeaderCollection, immutableHttpBodyBytes);
                    asynReceivedResponseEventHandler.Invoke(this, eventArgs);
                }
            }
            catch (Exception ex)
            {
                AbortWithError(ex.Message);
                return;
            }
            finally
            {
                // Close all open streams.
                if (inputStream != null)
                {
                    try { inputStream.Close(); }
                    catch (Exception) { }
                }
                if (outputStream != null)
                {
                    try { outputStream.Close(); }
                    catch (Exception) { }
                }
                if (httpWebResponse != null)
                {
                    try { httpWebResponse.Close(); }
                    catch (Exception) { }
                }
            }
        }