Example #1
0
		public void GetValueTest()
		{
			IDictionary<String, String> d = new Dictionary<String, String>();
			d["Test1"] = "Test";
			Assert.AreEqual("Test", d.GetValue("Test1"));
			Assert.AreEqual(null, d.GetValue("Test2"));
		}
Example #2
0
    protected SVGGradientElement(SVGParser xmlImp, Dictionary<string, string> attrList)
    {
        _attrList = attrList;
        _xmlImp = xmlImp;
        _stopList = new List<SVGStopElement>();
        _id = _attrList.GetValue("id");
        _gradientUnits = SVGGradientUnit.ObjectBoundingBox;
        if (_attrList.GetValue("gradiantUnits") == "userSpaceOnUse")
        {
            _gradientUnits = SVGGradientUnit.UserSpaceOnUse;
        }

        //------
        // TODO: It's probably a bug that the value is not innoculated for CaSe
        // VaRiAtIoN in GetValue, below:
        _spreadMethod = SVGSpreadMethod.Pad;
        if (_attrList.GetValue("spreadMethod") == "reflect")
        {
            _spreadMethod = SVGSpreadMethod.Reflect;
        }
        else if (_attrList.GetValue("spreadMethod") == "repeat")
        {
            _spreadMethod = SVGSpreadMethod.Repeat;
        }

        GetElementList();
    }
		public void GetValueTest()
		{
			var d = new Dictionary<int?, string> { { 1, "a" } };

			AssertSome(d.GetValue(1), "a");
			AssertNothing(d.GetValue(2));
			AssertNothing(d.GetValue(null));
		}
Example #4
0
        public void ReturnsNullableValue()
        {
            var dict = new Dictionary<Type, string>() {{typeof(int), "1"}, {typeof(double), "2.0"}};

            Assert.Equal("1", dict.GetValue(typeof(int)));
            Assert.Equal(null, dict.GetValue(typeof(string)));

        }
Example #5
0
    public SVGCircleElement(Dictionary<string, string> attrList,
		SVGTransformList inheritTransformList,
		SVGPaintable inheritPaintable,
		SVGGraphics render)
        : base(attrList, inheritTransformList, inheritPaintable, render)
    {
        _cx = new SVGLength(attrList.GetValue("cx"));
        _cy = new SVGLength(attrList.GetValue("cy"));
        _r = new SVGLength(attrList.GetValue("r"));
    }
 public void SetValue()
 {
     IDictionary<string, int> Test = new Dictionary<string, int>();
     Test.Add("Q", 4);
     Test.Add("Z", 2);
     Test.Add("C", 3);
     Test.Add("A", 1);
     Assert.Equal(4, Test.GetValue("Q"));
     Test.SetValue("Q", 40);
     Assert.Equal(40, Test.GetValue("Q"));
 }
Example #7
0
 public SVGStopElement(Dictionary<string, string> attrList)
 {
     _stopColor = new SVGColor(attrList.GetValue("stop-color"));
     string temp = attrList.GetValue("offset").Trim();
     if(temp != "") {
       if(temp.EndsWith("%"))
     _offset = float.Parse(temp.TrimEnd(new[] { '%' }), System.Globalization.CultureInfo.InvariantCulture);
       else
     _offset = float.Parse(temp, System.Globalization.CultureInfo.InvariantCulture) * 100;
     }
 }
 public void GetValue()
 {
     IDictionary<string, int> Test = new Dictionary<string, int>();
     Test.Add("Q", 4);
     Test.Add("Z", 2);
     Test.Add("C", 3);
     Test.Add("A", 1);
     Assert.Equal(4, Test.GetValue("Q"));
     Assert.Equal(0, Test.GetValue("V"));
     Assert.Equal(123, Test.GetValue("B", 123));
 }
Example #9
0
 public SVGEllipseElement(Dictionary<string, string> attrList,
                        SVGTransformList inheritTransformList,
                        SVGPaintable inheritPaintable,
                        SVGGraphics render)
     : base(attrList, inheritTransformList, inheritPaintable, render)
 {
     _cx = new SVGLength(attrList.GetValue("cx"));
     _cy = new SVGLength(attrList.GetValue("cy"));
     _rx = new SVGLength(attrList.GetValue("rx"));
     _ry = new SVGLength(attrList.GetValue("ry"));
     currentTransformList = new SVGTransformList(attrList.GetValue("transform"));
 }
        public void GetValue()
        {
            var d = new Dictionary<int, int>
                {
                    {1, 2}
                };
            Assert.AreEqual(2, d.GetValue(1, 0));
            Assert.AreEqual(0, d.GetValue(2, 0));

            Assert.AreEqual(Maybe<int>.Empty, d.GetValue(10));
            Assert.AreEqual(2, d.GetValue(1).Value);
        }
Example #11
0
 public SVGLineElement(Dictionary<string, string> attrList,
                     SVGTransformList inheritTransformList,
                     SVGPaintable inheritPaintable,
                     SVGGraphics render)
     : base(inheritTransformList)
 {
     _paintable = new SVGPaintable(inheritPaintable, attrList);
     _render = render;
     _x1 = new SVGLength(attrList.GetValue("x1"));
     _y1 = new SVGLength(attrList.GetValue("y1"));
     _x2 = new SVGLength(attrList.GetValue("x2"));
     _y2 = new SVGLength(attrList.GetValue("y2"));
 }
Example #12
0
 internal Cookie(RemoteSession session, Dictionary dict) {
     _session = session;
     try {
         _name = dict.GetValue("name", string.Empty);
         _value = dict.GetValue("value", string.Empty);
         _path = dict.GetValue("path", string.Empty);
         _domain = dict.GetValue("domain", string.Empty);
         _secure = Convert.ToBoolean(dict.Get("secure", false));
         _expiry = Convert.ToDouble(dict.Get("expiry", 0));
     } catch (Errors.KeyNotFoundError ex) {
         throw new DeserializeException(typeof(Cookie), ex);
     } catch (Exception ex) {
         throw new SeleniumException(ex);
     }
 }
        public static ArchiveProperties PropertiesFromMap(Dictionary<string, string> properties)
        {
            Contract.Requires(properties != null);

            var result = new ArchiveProperties { Name = properties.GetValue("Path") };
            if (string.IsNullOrEmpty(result.Name)) {
                throw new ArgumentException("Archive properties do not contain path.", nameof(properties));
            }

            result.Type = Archive.StringToType(properties.GetValue("Type"));
            result.Size = SevenZipTools.LongFromString(properties.GetValue("Size"));
            result.PhysicalSize = SevenZipTools.LongFromString(properties.GetValue("Physical Size"));
            result.TotalPhysicalSize = SevenZipTools.LongFromString(properties.GetValue("Total Physical Size"));
            return result;
        }
Example #14
0
 public VarietyPairSurrogate(VarietyPair vp)
 {
     Variety1 = vp.Variety1.Name;
     Variety2 = vp.Variety2.Name;
     var wordPairSurrogates = new Dictionary<WordPair, WordPairSurrogate>();
     _wordPairs = vp.WordPairs.Select(wp => wordPairSurrogates.GetValue(wp, () => new WordPairSurrogate(wp))).ToList();
     PhoneticSimilarityScore = vp.PhoneticSimilarityScore;
     LexicalSimilarityScore = vp.LexicalSimilarityScore;
     DefaultSoundCorrespondenceProbability = vp.DefaultSoundCorrespondenceProbability;
     _cognateSoundCorrespondenceFrequencyDistribution = new Dictionary<SoundContextSurrogate, Tuple<string[], int>[]>();
     foreach (SoundContext lhs in vp.CognateSoundCorrespondenceFrequencyDistribution.Conditions)
     {
         FrequencyDistribution<Ngram<Segment>> freqDist = vp.CognateSoundCorrespondenceFrequencyDistribution[lhs];
         _cognateSoundCorrespondenceFrequencyDistribution[new SoundContextSurrogate(lhs)] = freqDist.ObservedSamples.Select(ngram => Tuple.Create(ngram.Select(seg => seg.StrRep).ToArray(), freqDist[ngram])).ToArray();
     }
     _cognateSoundCorrespondenceByPosition = new Dictionary<string, List<SoundCorrespondenceSurrogate>>();
     foreach (KeyValuePair<FeatureSymbol, SoundCorrespondenceCollection> kvp in vp.CognateSoundCorrespondencesByPosition)
     {
         string pos;
         if (kvp.Key == CogFeatureSystem.Onset)
             pos = "onset";
         else if (kvp.Key == CogFeatureSystem.Nucleus)
             pos = "nucleus";
         else
             pos = "coda";
         _cognateSoundCorrespondenceByPosition[pos] = kvp.Value.Select(corr => new SoundCorrespondenceSurrogate(wordPairSurrogates, corr)).ToList();
     }
 }
        public void GetValue_Absent_Empty()
        {
            var dictiionary = new Dictionary<string, int> { { "A", 1 } };
            Option<int> item = dictiionary.GetValue("B");

            Assert.False(item.HasValue);
        }
		/// <summary>
		/// 认证
		/// </summary>
		/// <param name="strUserID"></param>
		/// <param name="strPassword"></param>
		/// <param name="context">一些额外的参数</param>
		/// <returns></returns>
		public ISignInUserInfo Authenticate(string strUserID, string strPassword, Dictionary<string, object> context)
		{
			LogOnIdentity loi = new LogOnIdentity(strUserID, strPassword);

			DefaultSignInUserInfo signInUserInfo = new DefaultSignInUserInfo();

			string authCode = context.GetValue("AuthenticationCode", string.Empty);

			//是否使用验证码认证
			if (authCode.IsNotEmpty())
			{
				AuthenticationCodeAdapter.Instance.CheckAuthenticationCode(authCode, strPassword);
			}
			else
			{
				if (AuthenticateUser(loi) == false)
				{
					IEnumerable<string> alternativeUserIDs = context.GetValue("AlternativeUserIDs", (IEnumerable<string>)null);

					if (AuthenticateAlternativeUserIDs(alternativeUserIDs, strPassword, context) == false)
						AuthenticateException.ThrowAuthenticateException(loi.LogOnNameWithoutDomain);
				}
			}

			signInUserInfo.UserID = loi.LogOnNameWithoutDomain;
			signInUserInfo.Domain = loi.Domain;

			return signInUserInfo;
		}
Example #17
0
    public SVGPolylineElement(Dictionary<string,string> attrList,
		SVGTransformList inheritTransformList,
		SVGPaintable inheritPaintable,
		SVGGraphics render)
        : base(attrList, inheritTransformList, inheritPaintable, render)
    {
        _listPoints = ExtractPoints(attrList.GetValue("points"));
    }
        public void GetValue_Exists_Value()
        {
            var dictiionary = new Dictionary<string, int> { { "A", 1 } };
            Option<int> item = dictiionary.GetValue("A");

            Assert.True(item.HasValue);
            Assert.Equal(1, item.Value);
        }
    public SVGRadialGradientElement(SVGParser xmlImp, Dictionary<string, string> attrList)
        : base(xmlImp, attrList)
    {
        string temp = attrList.GetValue("cx");
        _cx = new SVGLength((temp == "") ? "50%" : temp);

        temp = attrList.GetValue("cy");
        _cy = new SVGLength((temp == "") ? "50%" : temp);

        temp = attrList.GetValue("r");
        _r = new SVGLength((temp == "") ? "50%" : temp);

        temp = attrList.GetValue("fx");
        _fx = new SVGLength((temp == "") ? "50%" : temp);

        temp = attrList.GetValue("fy");
        _fy = new SVGLength((temp == "") ? "50%" : temp);
    }
Example #20
0
		PositionedNode MatchNode(PositionedNode oldNode, Dictionary<int, PositionedNode> newNodeMap)
		{
			PositionedNode newNodeFound = newNodeMap.GetValue(oldNode.ObjectNode.HashCode);
			if ((newNodeFound != null) && IsSameAddress(oldNode, newNodeFound))	{
				return newNodeFound;
			} else {
				return null;
			}
		}
    public SVGRadialGradientElement(SVGParser xmlImp, Dictionary<string, string> attrList)
        : base(xmlImp, attrList)
    {
        // TODO: Override GetValue to return `null` and use `||`.
        string temp = attrList.GetValue("cx");
        _cx = new SVGLength((temp == "") ? "50%" : temp);

        temp = attrList.GetValue("cy");
        _cy = new SVGLength((temp == "") ? "50%" : temp);

        temp = attrList.GetValue("r");
        _r = new SVGLength((temp == "") ? "50%" : temp);

        temp = attrList.GetValue("fx");
        _fx = new SVGLength((temp == "") ? "50%" : temp);

        temp = attrList.GetValue("fy");
        _fy = new SVGLength((temp == "") ? "50%" : temp);
    }
Example #22
0
 /// <summary>
 /// Stores the message with the given headers and body data, delaying it until the specified <paramref name="approximateDueTime"/>
 /// </summary>
 public async Task Defer(DateTimeOffset approximateDueTime, Dictionary<string, string> headers, byte[] body)
 {
     lock (_deferredMessages)
     {
         _deferredMessages
             .AddOrUpdate(headers.GetValue(Headers.MessageId),
                 id => new DeferredMessage(approximateDueTime, headers, body),
                 (id, existing) => existing);
     }
 }
Example #23
0
        public override void ExecuteCommand(WebSocket session, WebSocketCommandInfo commandInfo)
        {
            var dict = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);

            commandInfo.Text.ParseMimeHeader(dict);

            string websocketVersion = dict.GetValue(m_WebSocketVersion, string.Empty);

            if (!session.NotSpecifiedVersion)
            {
                if (string.IsNullOrEmpty(websocketVersion))
                    session.FireError(new Exception("the server doesn't support the websocket protocol version your client was using"));
                else
                    session.FireError(new Exception(string.Format("the server(version: {0}) doesn't support the websocket protocol version your client was using", websocketVersion)));
                session.CloseWithoutHandshake();
                return;
            }

            if (string.IsNullOrEmpty(websocketVersion))
            {
                session.FireError(new Exception("unknown server protocol version"));
                session.CloseWithoutHandshake();
                return;
            }

            var versions = websocketVersion.Split(',');

            versions = versions.Where((x) => x.Trim().Length > 0).ToArray();

            var versionValues = new int[versions.Length];

            for (var i = 0; i < versions.Length; i++)
            {
                try
                {
                    int value = int.Parse(versions[i]);
                    versionValues[i] = value;
                }
                catch (FormatException)
                {
                    session.FireError(new Exception("invalid websocket version"));
                    session.CloseWithoutHandshake();
                    return;
                }
            }

            if (!session.GetAvailableProcessor(versionValues))
            {
                session.FireError(new Exception("unknown server protocol version"));
                session.CloseWithoutHandshake();
                return;
            }

            session.ProtocolProcessor.SendHandshake(session);
        }
Example #24
0
        public async Task Defer(DateTimeOffset approximateDueTime, Dictionary<string, string> headers, byte[] body)
        {
            var newTimeout = new Timeout(headers, body, approximateDueTime.UtcDateTime);
            _log.Debug("Deferring message with ID {0} until {1} (doc ID {2})", headers.GetValue(Headers.MessageId), approximateDueTime, newTimeout.Id);

            using (var session = _documentStore.OpenAsyncSession())
            {
                await session.StoreAsync(newTimeout);
                await session.SaveChangesAsync();
            }
        }
Example #25
0
        public override void ExecuteCommand(WebSocket session, WebSocketCommandInfo commandInfo)
        {
            var dict = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
            var verbLine = string.Empty;

            commandInfo.Text.ParseMimeHeader(dict, out verbLine);

            string websocketVersion = dict.GetValue(m_WebSocketVersion, string.Empty);

            if (!session.NotSpecifiedVersion)
            {
                if (string.IsNullOrEmpty(websocketVersion))
                    session.FireError(new Exception("the server doesn't support the websocket protocol version your client was using"));
                else
                    session.FireError(new Exception(string.Format("the server(version: {0}) doesn't support the websocket protocol version your client was using", websocketVersion)));
                session.CloseWithoutHandshake();
                return;
            }

            if (string.IsNullOrEmpty(websocketVersion))
            {
                session.FireError(new Exception("unknown server protocol version"));
                session.CloseWithoutHandshake();
                return;
            }

            var versions = websocketVersion.Split(m_ValueSeparator, StringSplitOptions.RemoveEmptyEntries);

            var versionValues = new int[versions.Length];

            for (var i = 0; i < versions.Length; i++)
            {
                int value;

                if (!int.TryParse(versions[i], out value))
                {
                    session.FireError(new Exception("invalid websocket version"));
                    session.CloseWithoutHandshake();
                    return;
                }

                versionValues[i] = value;
            }

            if (!session.GetAvailableProcessor(versionValues))
            {
                session.FireError(new Exception("unknown server protocol version"));
                session.CloseWithoutHandshake();
                return;
            }

            session.ProtocolProcessor.SendHandshake(session);
        }
Example #26
0
    public SVGSVGElement(SVGParser xmlImp,
                       SVGTransformList inheritTransformList,
                       SVGPaintable inheritPaintable,
                       SVGGraphics r)
        : base(inheritTransformList)
    {
        _render = r;
        _attrList = xmlImp.Node.Attributes;
        var paintable = new SVGPaintable(inheritPaintable, _attrList);
        _width = new SVGLength(_attrList.GetValue("width"));
        _height = new SVGLength(_attrList.GetValue("height"));

        SetViewBox();

        ViewBoxTransform();

        SVGTransform temp = new SVGTransform(_cachedViewBoxTransform);
        SVGTransformList t_currentTransformList = new SVGTransformList();
        t_currentTransformList.AppendItem(temp);
        currentTransformList = t_currentTransformList; // use setter only once, since it also updates other lists

        xmlImp.GetElementList(_elementList, paintable, _render, summaryTransformList);
    }
        public void GetValueShouldStoreNewValuesAfterCallingTheValueInitializerOnce()
        {
            var dictionary = new Dictionary<string, string>
            {
                { "foo", "bar" }
            };

            var dictionaryLock = new object();

            // Arrange
            dictionary.GetValue("bar", dictionaryLock, () => "qak");

            // Act
            dictionary.GetValue(
                "bar",
                dictionaryLock,
                () =>
                {
                    // Assert
                    Assert.Fail("Value initializer should not have been called a second time.");
                    return null;
                });
        }
        public void GetValueShouldReturnExistingValueWithoutUsingTheLock()
        {
            var dictionary = new Dictionary<string, string>
            {
                { "foo", "bar" }
            };

            // Act
            // null can't be used as a lock and will throw an exception if attempted
            var value = dictionary.GetValue("foo", null, null);

            // Assert
            Assert.AreEqual("bar", value);
        }
        protected override string GenerateContent(IDataContext context, string outputFolder)
        {
            const string caTopicId = "CA_Chunks";
              var caLibrary = XmlHelpers.CreateHmTopic(caTopicId);
              var tablesByLanguage = new Dictionary<string, XElement>();
              var sortedActions = context.GetComponent<IContextActionTable>().AllActions.OrderBy(ca => ca.Name);
              var caPath = GeneralHelpers.GetCaPath(context);

              caLibrary.Root.Add(
            new XComment("Total context actions in ReSharper " +
                     GeneralHelpers.GetCurrentVersion() + ": " +
                     sortedActions.Count()));
              foreach (var ca in sortedActions)
              {
            var lang = ca.Group ?? "Unknown";

            if (!tablesByLanguage.ContainsKey(lang))
              tablesByLanguage.Add(lang,
            XmlHelpers.CreateTwoColumnTable("Name",
              "Description", "40%"));

            var exampleTable = ExtractExamples(ca, caPath, lang);

            tablesByLanguage.GetValue(lang).Add(new XElement("tr",
              new XElement("td", new XElement("b", ca.Name)),
              new XElement("td",
            ca.Description ?? "", exampleTable,
            XmlHelpers.CreateInclude("CA_Static_Chunks",
              ca.MergeKey.NormalizeStringForAttribute()))));
              }

              foreach (var table in tablesByLanguage)
              {
            var languageChunk =
              XmlHelpers.CreateChunk("ca_" +
                                 table.Key
                                   .NormalizeStringForAttribute());
            string langText = table.Key == "Common"
              ? "common use"
              : table.Key;
            languageChunk.Add(new XElement("p",
              "ReSharper provides the following context actions for " +
              langText + ":"));
            languageChunk.Add(table.Value);
            caLibrary.Root.Add(languageChunk);
              }

              caLibrary.Save(Path.Combine(outputFolder, caTopicId + ".xml"));
              return "Context actions";
        }
Example #30
0
        public ListSegmentMappings(Segmenter segmenter, IEnumerable<UnorderedTuple<string, string>> mappings, bool implicitComplexSegments)
        {
            _segmenter = segmenter;
            _mappings = mappings.ToList();
            _implicitComplexSegments = implicitComplexSegments;

            _mappingLookup = new Dictionary<string, Dictionary<string, List<Tuple<Environment, Environment>>>>();
            foreach (UnorderedTuple<string, string> mapping in _mappings)
            {
                FeatureSymbol leftEnv1, rightEnv1, leftEnv2, rightEnv2;
                string str1, str2;
                if (Normalize(_segmenter, mapping.Item1, out str1, out leftEnv1, out rightEnv1) && Normalize(_segmenter, mapping.Item2, out str2, out leftEnv2, out rightEnv2))
                {
                    var env1 = new Environment(leftEnv1, rightEnv1);
                    var env2 = new Environment(leftEnv2, rightEnv2);
                    Dictionary<string, List<Tuple<Environment, Environment>>> segments = _mappingLookup.GetValue(str1, () => new Dictionary<string, List<Tuple<Environment, Environment>>>());
                    List<Tuple<Environment, Environment>> contexts = segments.GetValue(str2, () => new List<Tuple<Environment, Environment>>());
                    contexts.Add(Tuple.Create(env1, env2));
                    segments = _mappingLookup.GetValue(str2, () => new Dictionary<string, List<Tuple<Environment, Environment>>>());
                    contexts = segments.GetValue(str1, () => new List<Tuple<Environment, Environment>>());
                    contexts.Add(Tuple.Create(env2, env1));
                }
            }
        }