Ejemplo n.º 1
0
        public static Dictionary <object, object> DeserializeYaml(string source)
        {
            Dictionary <object, object> result = new Dictionary <object, object>();

            using (StringReader sr = new StringReader(source))
            {
                result = YamlHelpers.Deserialize <Dictionary <object, object> >(sr);
            }
            return(result);
        }
Ejemplo n.º 2
0
        public static T GetCryptoValues <T>(T c, ref XmlDocument source, bool isEncryptMode = true) where T : class, ICrypto
        {
            T result = null;

            if (c.HasCrypto)
            {
                c.Crypto.LoadRsaKeys();
                c.Crypto.IsEncryptMode = isEncryptMode;

                List <string> errors = new List <string>();

                foreach (string element in c.Crypto.Elements)
                {
                    try
                    {
                        XmlNode src = source.SelectSingleNode(element);
                        if (src != null)
                        {
                            if (src.NodeType == XmlNodeType.Element)
                            {
                                if (src.SelectNodes("*").Count > 0)
                                {
                                    src.InnerXml = c.Crypto.SafeHandleCrypto(src.InnerXml);
                                }
                                else
                                {
                                    src.InnerText = c.Crypto.SafeHandleCrypto(src.InnerText);
                                }
                            }
                            else
                            {
                                src.Value = c.Crypto.SafeHandleCrypto(src.Value);
                            }
                        }
                        else
                        {
                            errors.Add($"Element: [{element}] failed with error: [SelectSingleNode returned null].");
                        }
                    }
                    catch (Exception ex)
                    {
                        errors.Add($"Element: [{element}] failed with error: [{ex.Message.Trim()}].");
                    }
                }

                string p = YamlHelpers.Serialize(c);
                result = YamlHelpers.Deserialize <T>(p);

                if (errors.Count == 0)
                {
                    result.Crypto.Errors = null;
                }
                else
                {
                    foreach (string error in errors)
                    {
                        result.Crypto.Errors.Add(error);
                    }
                }
            }

            return(result);
        }