Beispiel #1
0
        public void EvalBlock(RCRunner runner, RCClosure closure, RCCube right)
        {
            BlockWriter writer = new BlockWriter(right);
            RCBlock     result = writer.Write();

            runner.Yield(closure, result);
        }
        /// <inheritdoc />
        public override string ToLS(bool indent = true)
        {
            var writer = new BlockWriter(GetType(), indent, Disabled);

            writer
            .Label(Label)
            .Token("ELEMENTACTION")
            .Token(Locator)
            .Literal(ElementString);

            if (Recursive)
            {
                writer.Boolean(Recursive, "Recursive");
            }
            else if (ElementIndex != 0)
            {
                writer.Integer(ElementIndex, "ElementIndex");
            }

            writer
            .Indent()
            .Token(Action)
            .Literal(Input, "Input");

            if (!writer.CheckDefault(OutputVariable, "OutputVariable"))
            {
                writer
                .Arrow()
                .Token(IsCapture ? "CAP" : "VAR")
                .Literal(OutputVariable);
            }

            return(writer.ToString());
        }
        public override string ToLS(bool indent = true)
        {
            var writer = new BlockWriter(GetType(), indent, Disabled)
                         .Label(Label) // Write the label. If the label is the default one, nothing is written.
                         .Token(Name)  // Write the block name. This cannot be changed.
                         .Literal(awshost)
                         .Literal(awspath)
                         .Literal(awsregion)
                         .Literal(awscredential)
                         .Literal(awskey)
                         .Literal(awssecretkey)
                         .Literal(awssession)
                         .Literal(awshttpmethod)
                         .Literal(awsbodydata)
                         .Literal(awscustomheader);

            if (!writer.CheckDefault(VariableName, nameof(VariableName)))
            {
                writer
                .Arrow()                          // Write the -> arrow.
                .Token(IsCapture ? "CAP" : "VAR") // Write CAP or VAR depending on IsCapture.
                .Literal(VariableName);           // Write the Variable Name as a literal.
            }
            return(writer.ToString());
        }
Beispiel #4
0
        /// <inheritdoc />
        public override string ToLS(bool indent = true)
        {
            var writer = new BlockWriter(GetType(), indent, Disabled);

            writer
            .Label(Label)
            .Token("PARSE")
            .Literal(ParseTarget)
            .Token(Type);

            switch (Type)
            {
            case ParseType.LR:
                writer
                .Literal(LeftString)
                .Literal(RightString)
                .Boolean(Recursive, "Recursive")
                .Boolean(UseRegexLR, "UseRegexLR");
                break;

            case ParseType.CSS:
                writer
                .Literal(CssSelector)
                .Literal(AttributeName);
                if (Recursive)
                {
                    writer.Boolean(Recursive, "Recursive");
                }
                else
                {
                    writer.Integer(CssElementIndex, "CssElementIndex");
                }
                break;

            case ParseType.JSON:
                writer
                .Literal(JsonField)
                .Boolean(Recursive, "Recursive");
                break;

            case ParseType.REGEX:
                writer
                .Literal(RegexString)
                .Literal(RegexOutput)
                .Boolean(Recursive, "Recursive");
                break;
            }

            writer
            .Arrow()
            .Token(IsCapture ? "CAP" : "VAR")
            .Literal(VariableName);

            if (!writer.CheckDefault(Prefix, "Prefix") || !writer.CheckDefault(Suffix, "Suffix"))
            {
                writer.Literal(Prefix).Literal(Suffix);
            }

            return(writer.ToString());
        }
Beispiel #5
0
        /// <inheritdoc />
        public override string ToLS(bool indent = true)
        {
            var writer = new BlockWriter(GetType(), indent, Disabled);

            writer
            .Label(Label)
            .Token("TCP")
            .Token(TCPCommand);

            switch (TCPCommand)
            {
            case TCPCommand.Connect:
                writer
                .Literal(Host)
                .Literal(Port)
                .Boolean(UseSSL, "UseSSL");
                break;

            case TCPCommand.Send:
                writer
                .Literal(Message);
                break;
            }

            if (!writer.CheckDefault(VariableName, "VariableName"))
            {
                writer
                .Arrow()
                .Token(IsCapture ? "CAP" : "VAR")
                .Literal(VariableName);
            }

            return(writer.ToString());
        }
Beispiel #6
0
        private static Block GetLitTextureShaderBlock(Shader shader)
        {
            var w = new BlockWriter();

            w.WriteString(shader.Name);                                 // shader name
            w.WriteU32(1);                                              // Lit texture shader attributes: 1 = Lights enabled
            w.WriteF32(0f);                                             // Alpha Test Reference
            w.WriteU32(0x00000617);                                     // Alpha Test Function: ALWAYS
            w.WriteU32(0x00000605);                                     // Color Blend Function: FB_MULTIPLY
            w.WriteU32(1);                                              // Render pass enabled flags
            w.WriteU32(string.IsNullOrEmpty(shader.Texture) ? 0u : 1u); // Shader channels (active texture count)
            w.WriteU32(0);                                              // Alpha texture channels
            w.WriteString(shader.Material);                             // Material name
            // Texture information.
            if (!string.IsNullOrEmpty(shader.Texture))
            {
                w.WriteString(shader.Texture);                       // Texture name
                w.WriteF32(1f);                                      // Texture Intensity
                w.WriteU8(0);                                        // Blend function: 0 - Multiply
                w.WriteU8(1);                                        // Blend Source, 1 - blending constant
                w.WriteF32(1f);                                      // Blend Constant
                w.WriteU8(0x00);                                     // Texture Mod; 0x00: TM_NONE; shader should use texture coordinates of the model
                w.WriteArray(Matrix4.GetIdentityMatrix().ToArray()); // Texture Transform Matrix Element
                w.WriteArray(Matrix4.GetIdentityMatrix().ToArray()); // Texture Wrap Transform Matrix Element
                w.WriteU8(0x03);                                     // Texture Repeat
            }
            return(w.GetBlock(BlockType.LitTextureShader));
        }
Beispiel #7
0
        public void TestWrite()
        {
            IGZipBlockWriter blockWriter      = new BlockWriter();
            Stream           compressedStream = TestUtils.Compress(10);
            Block            block            = new Block
            {
                ExtraField       = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
                OriginalFileName = "test.txt",
                Comment          = "test",
                Flags            = GZipFlags.FEXTRA | GZipFlags.FNAME | GZipFlags.FCOMMENT
            };

            blockWriter.Write(
                compressedStream,
                block,
                BlockFlags.ExtraField | BlockFlags.OriginalFileName | BlockFlags.Comment | BlockFlags.Flags
                );

            IBlockReader blockReader = new BlockReader();
            Block        newBlock    = blockReader.Read(compressedStream, BlockFlags.All);

            Assert.AreEqual(block.Flags, newBlock.Flags);
            CollectionAssert.AreEqual(block.ExtraField, newBlock.ExtraField);
            Assert.AreEqual(block.Comment, newBlock.Comment);
            Assert.AreEqual(block.OriginalFileName, newBlock.OriginalFileName);
        }
Beispiel #8
0
        public void ReadWriteTest(int count)
        {
            var bw = new BlockWriter(_filepath);

            var r        = new Random();
            var testData = new byte[count];

            var testblock = new Datablock
            {
                Data  = testData,
                Count = testData.Length
            };

            bw.Write(testblock, 0);

            var testblock2 = new Datablock
            {
                Data = new byte[count]
            };
            var br = new BlockReader(_filepath);

            br.Read(testblock2, 0, testblock.Count);

            CollectionAssert.AreEqual(testblock.Data, testblock2.Data);
            Assert.AreEqual(testblock.Count, testblock.Count);
        }
Beispiel #9
0
        /*
         * This method basically does the opposite of the method above, so it converts a Block from a class to an actual
         * LoliScript statement. It's much easier to write since the BlockWriter was implemented with a fluent pattern.
         */
        public override string ToLS(bool indent = true)
        {
            /*
             * We initialize a new BlockWriter with the given Block type (in this case, GetType() will return BlockSum)
             * and indentation enabled by default when needed (you can type .Indent() anywhere to indent to the next line).
             * The Disabled parameter will tell the writer if the block has been disabled. In that case, it will put a '!'
             * in front of the statement to indicate that it shouldn't be executed by a debugger or runner.
             */
            var writer = new BlockWriter(GetType(), indent, Disabled)
                         .Label(Label)     // Write the label. If the label is the default one, nothing is written.
                         .Token(Name)      // Write the block name. This cannot be changed.
                         .Literal(First)   // Write the 'First' parameter as a literal (it will be double quoted).
                         .Literal(Second); // Write the 'Second' parameter as a literal.

            // Check if the VariableName is the default one. If it is, we don't need to write it to the string.
            if (!writer.CheckDefault(VariableName, nameof(VariableName)))
            {
                // Here we reutilize the writer to write more stuff.
                writer
                .Arrow()                          // Write the -> arrow.
                .Token(IsCapture ? "CAP" : "VAR") // Write CAP or VAR depending on IsCapture.
                .Literal(VariableName);           // Write the Variable Name as a literal.
            }

            // Finally we call the ToString() method of the writer to return the statement that will be written to the LoliScript code.
            return(writer.ToString());
        }
Beispiel #10
0
        public static void WriteRules(BlockWriter br, MetadataCli.Property entityTypeProperty, MetadataCli.Metadata metadataCli)
        {
            if (!entityTypeProperty.Nullable)
            {
                br.WriteLine("required: true,");
            }

            switch (entityTypeProperty.Type)
            {
            case "number":
                br.WriteLine("number: true,");
                break;

            case "string":
                br.WriteLine("maxLength: " + entityTypeProperty.MaxLength + ",");
                break;

            case "boolean":
                break;

            case "Date":
                br.WriteLine("date: true,");
                break;

            case "any":
            case "any[]":
                break;

            default:
                throw new ArgumentException("Unknown data type.");
            }
        }
Beispiel #11
0
        private void WriteBlocks(PipeWriter pipeWriter, IEnumerator <IMemoryItem> iterator, ref int counter)
        {
            using var blockWriter = new BlockWriter(iterator, _metaData.Filter);

            while (blockWriter.MoreToWrite)
            {
                var span = pipeWriter.GetSpan(FileConsts.PageSize);
                span = span[..FileConsts.PageSize];
Beispiel #12
0
 private void WriteVarOrCap(BlockWriter writer)
 {
     if (!writer.CheckDefault(VariableName, nameof(VariableName)))
     {
         writer.Arrow()
         .Token(IsCapture ? "CAP" : "VAR")
         .Literal(VariableName);
     }
 }
Beispiel #13
0
        private void Write(BlockWriter writer)
        {
            while (!_isCancelled && _writeBlockQueue.TryDequeue(out Block block))
            {
                writer.Write(block);
            }

            writer.Dispose();
        }
Beispiel #14
0
 /// <inheritdoc />
 public override string ToLS(bool indent = true)
 {
     var writer = new BlockWriter(GetType(), indent, Disabled);
     writer                
         .Label(Label)
         .Token("BROWSERACTION")
         .Token(Action)
         .Literal(Input, "Input");
     return writer.ToString();
 }
Beispiel #15
0
        /// <inheritdoc />
        public override string ToLS(bool indent = true)
        {
            var writer = new BlockWriter(GetType(), indent, Disabled);

            writer
            .Label(Label)
            .Token("EXECUTEJS")
            .Literal(JavascriptCode.Replace("\r\n", " ").Replace("\n", " "));
            return(writer.ToString());
        }
Beispiel #16
0
        private static Block GetGroupNodeBlock(Node node)
        {
            var w = new BlockWriter();

            w.WriteString(node.Name);                    // model node name
            w.WriteU32(1);                               // parent node count
            w.WriteString(node.Parent);                  // parent node name
            w.WriteArray(node.Transformation.ToArray()); // transformation
            return(w.GetBlock(BlockType.GroupNode));
        }
        private static BlockWriter initializeBlockWriter(string filePath, int blockSize)
        {
            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
            var fileBase    = new FileIOBasics(filePath, blockSize, true);
            var blockWriter = new BlockWriter(fileBase, new BlockSplitter(fileBase), true);

            return(blockWriter);
        }
Beispiel #18
0
        /// <inheritdoc />
        public override string ToLS(bool indent = true)
        {
            var writer = new BlockWriter(GetType(), indent, Disabled);

            writer
            .Label(Label)
            .Token("BYPASSCF")
            .Literal(Url)
            .Literal(UserAgent, "UserAgent");
            return(writer.ToString());
        }
Beispiel #19
0
        /// <inheritdoc />
        public override string ToLS(bool indent = true)
        {
            var writer = new BlockWriter(GetType(), indent, Disabled);

            writer
            .Label(Label)
            .Token("NAVIGATE")
            .Literal(Url)
            .Integer(Timeout, "Timeout");
            return(writer.ToString());
        }
Beispiel #20
0
        public override string ToLS(bool indent = true)
        {
            BlockWriter blockWriter = new BlockWriter(base.GetType(), indent, base.Disabled).Label(base.Label).Token(this.Name, "").Literal(this.Email, "").Literal(this.Password, "").Integer(this.MaxFilesCaptured, "");
            bool        flag        = !blockWriter.CheckDefault(this.VariableName, "VariableName");

            if (flag)
            {
                blockWriter.Arrow().Token(this.IsCapture ? "CAP" : "VAR", "").Literal(this.VariableName, "");
            }
            return(blockWriter.ToString());
        }
Beispiel #21
0
        private static Block GetShadingModifierBlock(string nodeName, string shaderName)
        {
            var w = new BlockWriter();

            w.WriteString(nodeName);   // shading modifier name
            w.WriteU32(1);             // chain index
            w.WriteU32(1);             // shading attributes
            w.WriteU32(1);             // shading list count
            w.WriteU32(1);             // shader count
            w.WriteString(shaderName); // shader name
            return(w.GetBlock(BlockType.ShadingModifier));
        }
Beispiel #22
0
        private static Block GetTextureResourceModifierChain(Texture texture)
        {
            var w = new BlockWriter();

            w.WriteString(texture.Name); // modifier chain name
            w.WriteU32(2);               // modifier chain type: 2 = texture resource modifier chain
            w.WriteU32(0);               // modifier chain attributes: 0 = neither bounding sphere nor
            w.WritePadding();            // modifier chain padding
            w.WriteU32(1);               // modifier count in this chain
            w.WriteBlock(GetTextureDeclarationBlock(texture));
            return(w.GetBlock(BlockType.ModifierChain));
        }
Beispiel #23
0
        private static Block GetModelNodeBlock(Node node)
        {
            var w = new BlockWriter();

            w.WriteString(node.Name);                    // model node name
            w.WriteU32(1);                               // parent node count
            w.WriteString(node.Parent);                  // parent node name
            w.WriteArray(node.Transformation.ToArray()); // transformation
            w.WriteString(node.Mesh);                    // model resource name
            w.WriteU32(3);                               // visibility 3 = front and back
            return(w.GetBlock(BlockType.ModelNode));
        }
Beispiel #24
0
        private static Block GetMeshContinuationBlock(Mesh mesh)
        {
            var w = new BlockWriter();

            w.WriteString(mesh.Name);                        // mesh name
            w.WriteU32(0);                                   // chain index
            // Base Mesh Description.
            w.WriteU32((uint)mesh.Triangles.Count);          // base face count
            w.WriteU32((uint)mesh.Positions.Count);          // base position count
            w.WriteU32((uint)mesh.Normals.Count);            // base normal count
            w.WriteU32(0);                                   // base diffuse color count
            w.WriteU32(0);                                   // base specular color count
            w.WriteU32((uint)mesh.TextureCoordinates.Count); // base texture coordinate count
            // Base Mesh Data.
            foreach (Vector3 position in mesh.Positions)
            {
                w.WriteF32(position.X);
                w.WriteF32(position.Y);
                w.WriteF32(position.Z);
            }
            foreach (Vector3 normal in mesh.Normals)
            {
                w.WriteF32(normal.X);
                w.WriteF32(normal.Y);
                w.WriteF32(normal.Z);
            }
            foreach (Vector2 textureCoordinate in mesh.TextureCoordinates)
            {
                w.WriteF32(textureCoordinate.X);
                w.WriteF32(textureCoordinate.Y);
                w.WriteF32(0);
                w.WriteF32(0);
            }
            // Base Face.
            foreach (Triangle triangle in mesh.Triangles)
            {
                w.WriteU32(0u); // shading id
                foreach (Corner corner in triangle)
                {
                    w.WriteU32((uint)corner.Position);
                    if (corner.Normal >= 0)
                    {
                        w.WriteU32((uint)corner.Normal);
                    }
                    if (corner.TextureCoordinate >= 0)
                    {
                        w.WriteU32((uint)corner.TextureCoordinate);
                    }
                }
            }
            return(w.GetBlock(BlockType.MeshContinuation));
        }
Beispiel #25
0
        private static Block GetGroupNodeModifierChain(Node node)
        {
            var w = new BlockWriter();

            w.WriteString(node.Name); // modifier chain name
            w.WriteU32(0);            // modifier chain type: 0 = node modifier chain
            w.WriteU32(0);            // modifier chain attributes: 0 = neither bounding sphere nor
            // Bounding box info present.
            w.WritePadding();
            w.WriteU32(1); // modifier count in this chain
            w.WriteBlock(GetGroupNodeBlock(node));
            return(w.GetBlock(BlockType.ModifierChain));
        }
 public static void WriteProperties(BlockWriter br, Dictionary <string, Property> etp)
 {
     foreach (var property in etp)
     {
         var nullable = property.Value.Nullable ? "?" : string.Empty;
         var type     = property.Value.Type;
         nullable = (new string[] { "string", "object", "byte[]" }).Contains(type) ? string.Empty : nullable;
         //var integers = new List<string>() { "int", "short", "sbyte", "ushort" };
         // Info credit: http://geekswithblogs.net/BlackRabbitCoder/archive/2011/01/27/c.net-little-pitfalls-the-dangers-of-casting-boxed-values.aspx
         br.WriteLine(string.Format("public {0}{1} {2} {{ get {{ return ({0}{1})this.entity.dto[\"{2}\"]; }} set {{ this.entity.dto[\"{2}\"] = value; }} }}", type, nullable, property.Key));
     }
     br.WriteLine();
 }
Beispiel #27
0
        private static Block GetModelResourceModifierChain(Mesh mesh)
        {
            var w = new BlockWriter();

            w.WriteString(mesh.Name); // modifier chain name, bonded to ModelNodeBlock.ModelResourceName
            w.WriteU32(1);            // modifier chain type: 1 = model resource modifier chain
            w.WriteU32(0);            // modifier chain attributes: 0 = neither bounding sphere nor
            // Bounding box info present. Padding.
            w.WritePadding();
            w.WriteU32(1); // modifier count in this chain
            w.WriteBlock(GetMeshDeclarationBlock(mesh));
            return(w.GetBlock(BlockType.ModifierChain));
        }
Beispiel #28
0
        /// <inheritdoc />
        public override string ToLS(bool indent = true)
        {
            var writer = new BlockWriter(GetType(), indent, Disabled);

            writer
            .Label(Label)
            .Token("BYPASSCF")
            .Literal(Url)
            .Literal(UserAgent, "UserAgent")
            .Boolean(PrintResponseInfo, "PrintResponseInfo")
            .Boolean(ErrorOn302, "ErrorOn302");
            return(writer.ToString());
        }
Beispiel #29
0
        private static Block GetTextureContinuationBlock(Texture texture)
        {
            var w = new BlockWriter();

            w.WriteString(texture.Name); // texture name
            w.WriteU32(0);               // continuation image index
            // Image data.
            foreach (byte b in texture.Image)
            {
                w.WriteU8(b);
            }
            return(w.GetBlock(BlockType.TextureContinuation));
        }
Beispiel #30
0
        /// <inheritdoc />
        public override string ToLS(bool indent = true)
        {
            var writer = new BlockWriter(GetType(), indent, Disabled);

            writer
            .Label(Label)
            .Token("KEYCHECK")
            .Boolean(BanOn4XX, "BanOn4XX")
            .Boolean(BanOnToCheck, "BanOnToCheck");

            foreach (var kc in KeyChains)
            {
                writer
                .Indent(1)
                .Token("KEYCHAIN")
                .Token(kc.Type);

                if (kc.Type == KeyChain.KeychainType.Custom)
                {
                    writer.Literal(kc.CustomType);
                }

                writer.Token(kc.Mode);

                foreach (var k in kc.Keys)
                {
                    if (k.LeftTerm == "<SOURCE>" && k.Condition == Condition.Contains)
                    {
                        writer
                        .Indent(2)
                        .Token("KEY")
                        .Literal(k.RightTerm);
                    }
                    else
                    {
                        writer
                        .Indent(2)
                        .Token("KEY")
                        .Literal(k.LeftTerm)
                        .Token(k.Condition);

                        if (k.Condition != Condition.Exists)
                        {
                            writer.Literal(k.RightTerm);
                        }
                    }
                }
            }

            return(writer.ToString());
        }
 public ChromDataCollectorSet(ChromSource chromSource, TimeSharing timeSharing,
     ChromatogramLoadingStatus.TransitionData allChromData, BlockWriter blockWriter)
 {
     ChromSource = chromSource;
     TypeOfScans = timeSharing;
     PrecursorCollectorMap = new List<Tuple<PrecursorTextId, ChromDataCollector>>();
     if (timeSharing == TimeSharing.shared)
     {
         SharedTimesCollector = new SortedBlockedList<float>();
         ScanIdsCollector = new BlockedList<int>();
     }
     _allChromData = allChromData;
     _blockWriter = blockWriter;
 }
        public override void SetRequestOrder(IList<IList<int>> chromatogramRequestOrder)
        {
            if (_isSrm)
                return;

            if (_chromGroups != null)
                _chromGroups.Dispose();

            _chromGroups = new ChromGroups(chromatogramRequestOrder, _collectors.ChromKeys, (float) (MaxRetentionTime ?? 30), _cachePath);
            _blockWriter = new BlockWriter(_chromGroups);

            if (!_collectors.IsRunningAsync)
                ExtractChromatograms();
            else
            {
                ActionUtil.RunAsync(() =>
                {
                    try
                    {
                        ExtractChromatograms();
                    }
                    catch (Exception ex)
                    {
                        if (_collectors == null)
                            throw;

                        _collectors.SetException(ex);
                    }
                }, "Chromatogram extractor"); // Not L10N
            }
        }