Beispiel #1
0
 /// <summary>
 /// Adds a <see cref="System.Uri"/> to a request.
 /// </summary>
 public Address(IScalar <System.Uri> uri) : base(() =>
                                                 new Joined(
                                                     new Scheme(uri.Value().Scheme),
                                                     new Conditional(() =>
                                                                     uri.Value().UserInfo != string.Empty,
                                                                     new User(uri.Value().UserInfo)
                                                                     ),
                                                     new Host(uri.Value().Host),
                                                     new Conditional(() =>
                                                                     uri.Value().Port != 0,
                                                                     new Port(uri.Value().Port)
                                                                     ),
                                                     new Conditional(() =>
                                                                     uri.Value().AbsolutePath != string.Empty,
                                                                     new Path(uri.Value().AbsolutePath)
                                                                     ),
                                                     new Conditional(() =>
                                                                     uri.Value().Query != string.Empty,
                                                                     new QueryParams(uri.Value().Query)
                                                                     ),
                                                     new Conditional(() =>
                                                                     uri.Value().Fragment != string.Empty,
                                                                     new Fragment(uri.Value().Fragment)
                                                                     )
                                                     )
                                                 )
 {
 }
 /// <summary> Patched XML.</summary>
 /// <param name="xml"> XML to patch </param>
 /// <param name="xambler"> Xambler to modify xml </param>
 public XMLPatched(IScalar <XNode> xml, Xambler xambler) : this(
         new ScalarOf <IXML>(() =>
                             new XMLCursor(xambler.Apply(xml.Value()))
                             )
         )
 {
 }
Beispiel #3
0
 public T Value()
 {
     lock (_lock)
     {
         return(_source.Value());
     }
 }
Beispiel #4
0
        /// <summary>
        /// Gets the value.
        /// </summary>
        /// <returns>New dictionary instance.</returns>
        public IReadOnlyDictionary <string, Type[]> Value()
        {
            var types = _source.Value()
                        .Select(item => (new SimpleName(item.Key).Name, item.Value))
                        .ToArray();

            var dictionary = new Dictionary <string, Type[]>();

            for (int i = 0; i < types.Length; i++)
            {
                (var key, var value) = types[i];
                if (dictionary.ContainsKey(key))
                {
                    Type[] type    = dictionary[key];
                    var    newitem = new Type[type.Length + 1];
                    for (int j = 0; j < type.Length; j++)
                    {
                        newitem[j] = type[j];
                    }
                    newitem[type.Length] = value;
                    dictionary[key]      = newitem;
                }
                else
                {
                    dictionary[key] = new Type[] { value };
                }
            }
            return(dictionary);
        }
Beispiel #5
0
        public BadCredentialViewModel(IScalar <Dictionary <string, string> > source, Reason reason)
        {
            var errors = source.Value();

            switch (reason)
            {
            case Reason.InvalidLogin:
                Message = errors["invalid_login"];
                break;

            case Reason.InvalidPassword:
                Message = errors["invalid_password"];
                break;

            case Reason.EmptyLogin:
                Message = errors["empty_login"];
                break;

            case Reason.EmptyPassword:
                Message = errors["empty_password"];
                break;

            default:
                break;
            }
        }
 /// <summary> Patched XML.</summary>
 /// <param name="xml"> XML to patch </param>
 /// <param name="xambler"> Patching Xambler </param>
 public XMLPatched(IScalar <string> xml, Xambler xambler) : this(
         new ScalarOf <XNode>(() =>
 {
     return(XDocument.Parse(xml.Value()));
 }
                              ),
         xambler
         )
 { }
Beispiel #7
0
 /// <summary>
 /// Gets the cached value.
 /// </summary>
 /// <returns>Cached value.</returns>
 public T Value()
 {
     if (!evaluated)
     {
         evaluated = true;
         value     = _scalar.Value();
     }
     return(value);
 }
Beispiel #8
0
        private IList <string> EncodedProps(string prop)
        {
            var values = new List <string>(memoryProps.Value().Values(prop));

            for (int i = 0; i < values.Count; i++)
            {
                values[i] = XmlConvert.EncodeLocalName(values[i]);
            }
            return(values);
        }
Beispiel #9
0
 /// <summary>
 /// An item which exists in memory.
 /// This cell has its internal memory stored in the itemMap. So: If you make two cells
 /// using this ctor, they will have the same memory.
 /// </summary>
 /// <param name="path">path to the item (key to the map)</param>
 /// <param name="itemMap">map with content for many items</param>
 internal RamCell(IScalar <string> name, IScalar <IMnemonic> mem)
 {
     lock (mem)
     {
         this.id   = Guid.NewGuid().ToString();
         this.name =
             new Solid <string>(
                 () => new StrictCellName(name.Value()).AsString()
                 );
         this.mem = mem;
     }
 }
Beispiel #10
0
 public T Value()
 {
     try
     {
         return(_value.Value());
     }
     catch (Exception e)
     {
         failed = true;
         _error = e;
         return(_fallback.Value());
     }
 }
Beispiel #11
0
        /// <summary>
        /// Returns an enumerator that iterates through the collection.
        /// </summary>
        /// <returns>An enumerator that can be used to iterate through the collection.</returns>
        public IEnumerator <Type> GetEnumerator()
        {
            Assembly assembly = _assembly.Value();
            var      types    = assembly.DefinedTypes
                                .Cast <Type>()
                                .Concat(assembly.ExportedTypes)
                                .Distinct();

            if (_omitAbstract)
            {
                types = types.Where(type => !type.Name.StartsWith("I"));
            }
            return(types.GetEnumerator());
        }
        private bool Available()
        {
            var isAvailable = true;

            foreach (var listener in IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners())
            {
                if (listener.Port == port.Value())
                {
                    isAvailable = false;
                    break;
                }
            }
            return(isAvailable);
        }
Beispiel #13
0
 /// <summary>
 /// A cell which exists in memory.
 /// Note: This memory cell lives only as long as this object lives.
 /// If you create two cells with the same path using this ctor,
 /// they will not have the same content.
 /// </summary>
 public RamCell(IScalar <string> path, MemoryStream content) : this(
         path,
         new Solid <IMnemonic>(() =>
 {
     var mem = new RamMnemonic();
     mem.Contents()
     .UpdateBytes(
         path.Value(),
         new BytesOf(
             new InputOf(content)
             ).AsBytes()
         );
     return(mem);
 })
         )
 { }
Beispiel #14
0
        /// <summary>
        /// "Main" equivalent.
        /// </summary>
        /// <returns>New <see cref="Task"/> object.</returns>
        private async Task Proceed()
        {
            if (!Validate(Login, Reason.EmptyLogin) ||
                !Validate(Password, Reason.EmptyPassword))
            {
                return;
            }

            //artificial delay
            await AsynchronousDelay();

            NavigateTo(new PleaseWaitViewModel(this));

            var login =
                new ErrorSafeAsyncScalar <IResult <bool> >(
                    () => _api.Value().LoginAsync(),
                    () => Result.Fail <bool>("an exception was thrown")
                    );

            var loginResult = await login.Value();

            if (loginResult.Succeeded)
            {
                var profileViewModel = new ProfileViewModel("The message", this);

                NavigateTo(profileViewModel);

                //no code is running below except an asynchronous operation, so use ConfigureAwait(false)
                await profileViewModel.FetchData().ConfigureAwait(false);
            }
            else
            {
                GoBack();
                if (login.HasErrors())
                {
                    NavigateTo("dock", new BadCredentialViewModel(login));
                }
                else
                {
                    NavigateTo("dock", new BadCredentialViewModel(loginResult.Info.Message));
                }
                Set(nameof(Login), ref _login, string.Empty);
                Set(nameof(Password), ref _password, string.Empty);
            }
        }
Beispiel #15
0
        /// <summary>
        /// Gets the string value.
        /// </summary>
        /// <returns>New name, with inferred namespace.</returns>
        public string String()
        {
            string result          = _source.String();
            string targetNamespace = null;

            if (!new IsNamespaced(result).Value())
            {
                IReadOnlyDictionary <string, Type[]> value = _typeCacheWithoutNamespace.Value();
                if (value.ContainsKey(result))
                {
                    return(value[result][_handleDuplicatesIndex].FullName);
                }

                if (new IsBlank(targetNamespace).Value())
                {
                    throw new InvalidOperationException($"Unable to infer the namespace for {result}");
                }
            }
            return(result);
        }
 internal XMLCursor(IScalar <XNode> node, IScalar <IXmlNamespaceResolver> context)
 {
     this.stringTransform = nd =>
     {
         StringBuilder     sb  = new StringBuilder();
         XmlWriterSettings xws = new XmlWriterSettings();
         xws.OmitXmlDeclaration = nd.NodeType != XmlNodeType.Document;
         xws.Indent             = false;
         using (XmlWriter xw = XmlWriter.Create(sb, xws))
         {
             nd.Document.WriteTo(xw);
         }
         return(sb.ToString());
     };
     this.xml = new ScalarOf <string>(
         () =>
     {
         return(this.stringTransform.Invoke(node.Value()));
     });
     this.cache   = new ScalarOf <XNode>(node);
     this.context = new ScalarOf <IXmlNamespaceResolver>(context);
 }
Beispiel #17
0
        public T Value()
        {
            T value = default(T);

            for (int i = 0; i < _attempts; i++)
            {
                try
                {
                    value = _source.Value();
                }
                catch (Exception e)
                {
                    _errors.Add(e);
                    if (i == _attempts - 1)
                    {
                        throw;
                    }
                }
            }

            return(value);
        }
Beispiel #18
0
 public byte Value()
 {
     return(byte.Parse(_source.Value(), CultureInfo.InvariantCulture));
 }
Beispiel #19
0
 public bool Value() => !_value.Value();
Beispiel #20
0
 /// <summary>
 /// Gets the bytes.
 /// </summary>
 /// <returns>The bytes.</returns>
 public byte[] Bytes()
 {
     return(BitConverter.GetBytes(_source.Value()));
 }
Beispiel #21
0
 public bool Value() => _left.Value() || _right.Value();
Beispiel #22
0
 /// <summary>
 /// Adds a query parameter to a request.
 /// </summary>
 public QueryParam(IScalar <string> key, IScalar <string> value) : this(
         () => key.Value(),
         () => value.Value()
         )
 {
 }
Beispiel #23
0
 /// <summary>
 /// A property which has a name and a value.
 /// </summary>
 public BxProp(string name, IScalar <string> value) : this(name, () => value.Value())
 {
 }
Beispiel #24
0
 public long Value()
 {
     return(long.Parse(_source.Value(), System.Globalization.CultureInfo.InvariantCulture));
 }
Beispiel #25
0
 /// <summary>
 /// Adds the scheme part of a <see cref="System.Uri"/> to a request.
 /// </summary>
 public Scheme(IScalar <string> scheme) : this(() => scheme.Value())
 {
 }
Beispiel #26
0
 /// <summary>
 /// Adds a <see cref="System.Uri"/> to a request.
 /// </summary>
 public Address(IScalar <string> uri) : this(new ScalarOf <System.Uri>(new System.Uri(uri.Value())))
 {
 }
 public XNode AsNode()
 {
     return(xml.Value().AsNode());
 }
Beispiel #28
0
 public string String()
 {
     return(_source.Value().ToString());
 }
Beispiel #29
0
 public float Value()
 {
     return(float.Parse(_source.Value(), CultureInfo.InvariantCulture));
 }
Beispiel #30
0
 public int Value()
 {
     return(int.Parse(_source.Value(), CultureInfo.InvariantCulture));
 }