示例#1
0
        /// <summary>
        /// Props which are read into memory from internal xml document props.cat in the given comb.
        /// Props are read from memory.
        /// Props are updated into the comb.
        /// </summary>
        public SandboxProps(IMnemonic mem, string scope, string id)
        {
            this.id          = id;
            this.scope       = scope;
            this.mem         = mem;
            this.memoryProps = new Solid <IProps>(() =>
            {
                var stringProps =
                    new TextOf(
                        new BytesOf(
                            this.mem
                            .Contents()
                            .Bytes(
                                new Normalized($"{scope}/{id}/props.cat").AsString(),
                                () => new byte[0]
                                )
                            ),
                        Encoding.UTF8
                        ).AsString();

                var cachedProps = new RamProps();
                Parallel.ForEach(stringProps.Split(new char[] { '\r' }, StringSplitOptions.RemoveEmptyEntries), (stringProp) =>
                {
                    var parts = stringProp.Split(':');
                    if (parts.Length != 2)
                    {
                        throw new ApplicationException($"A property of {scope}/{id} has an invalid format: {stringProp}");
                    }
                    var name   = XmlConvert.DecodeName(parts[0].Trim());
                    var values = parts[1].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < values.Length; i++)
                    {
                        values[i] = XmlConvert.DecodeName(values[i]);
                    }
                    cachedProps.Refined(name, values);
                });
                return(cachedProps);
            });
        }