Ejemplo n.º 1
0
        public static IMaybe <(Block, int)> GetBlock(string source, int index, bool advanceTabs, InclusionType inclusion = InclusionType.Classes,
                                                     bool compileAll = false)
        {
            if (advanceTabs)
            {
                AdvanceTabs();
            }

            var whenUnlessParser = new WhenUnlessParser();
            var statementParser  = new StatementParser {
                Inclusions = inclusion
            };
            var block      = new Block();
            var continuing = true;

            while (continuing && index < source.Length)
            {
                continuing = false;
                foreach (var parserResult in statementParser.Parsers
                         .Where(parser => parser.Scan(source, index))
                         .Select(parser => parser.Result))
                {
                    whenUnlessParser.OtherVerb = parserResult.Verb;
                    if (whenUnlessParser.Scan(source, parserResult.Position))
                    {
                        block.Add(whenUnlessParser.Verb);
                        index = whenUnlessParser.Position;
                    }
                    else
                    {
                        block.Add(parserResult.Verb);
                        index = parserResult.Position;
                    }

                    continuing = true;
                    break;
                }

                if (continuing && index < source.Length)
                {
                    var endParser = new EndParser();
                    if (endParser.Scan(source, index))
                    {
                        index = endParser.Position;
                    }
                }
            }

            if (compileAll)
            {
                index.Must().BeGreaterThanOrEqual(source.Length).OrThrow("Compilation", () => $"Didn't understand {source.Drop(index)}");
            }

            if (advanceTabs)
            {
                RegressTabs();
            }

            return(maybe(block.Count > 0, () => (block, index)));
        }
Ejemplo n.º 2
0
        protected IMaybe <int> getTerm(Block block, int index)
        {
            if (valueParser.Scan(source, index) && isNotWordOperator(valueParser.Value))
            {
                block.Add(valueParser.Verb);
                index = valueParser.Position;
                addPossibleParameter(valueParser.Value);
            }
            else
            {
                var name     = MangledName($"{FillInVariableParser.Index++}");
                var variable = new Variable(name);
                var push     = new Push(variable);
                block.Add(push);
                addPossibleParameter(variable);
            }

            while (sendMessageParser.Scan(source, index))
            {
                block.Add(sendMessageParser.Verb);
                index = sendMessageParser.Position;
            }

            return(index.Some());
        }
Ejemplo n.º 3
0
        internal Block CreateLockedBlock(Expression monitor, Block body)
        {
            ReferenceExpression monitorReference = CreateMonitorReference(monitor.LexicalInfo);

            Block block = new Block(body.LexicalInfo);

            // __monitorN__ = <expression>
            block.Add(new BinaryExpression(BinaryOperatorType.Assign,
                                           monitorReference,
                                           monitor));

            // System.Threading.Monitor.Enter(__monitorN__)
            block.Add(AstUtil.CreateMethodInvocationExpression(Monitor_Enter, monitorReference));

            // try:
            //      <the rest>
            // ensure:
            //		Monitor.Leave
            TryStatement stmt = new TryStatement();

            stmt.ProtectedBlock = body;
            stmt.EnsureBlock    = new Block();
            stmt.EnsureBlock.Add(
                AstUtil.CreateMethodInvocationExpression(Monitor_Exit, monitorReference));

            block.Add(stmt);

            return(block);
        }
Ejemplo n.º 4
0
 private void MakeBlock(int horLeft, int horRight, int verDown, int verUp, double distX, double distY)
 {   // läuft asynchron
     backgroundBlock = Block.Construct();
     for (int i = -horLeft; i <= horRight; ++i)
     {
         if (i != 0) // i=0 ist das Original, soll nicht verdoppelt werden!
         {
             GeoObjectList li = new GeoObjectList();
             // für jede Kopie ein Clone machen
             li = originals.CloneObjects();
             // AbstandX * Kopienwinkel:
             GeoVector vect = (i * distX) * dirV;
             ModOp     m    = ModOp.Translate(vect);
             li.Modify(m);
             backgroundBlock.Add(li);
         }
         for (int j = -verDown; j <= verUp; ++j)
         {
             if (j != 0) // J=0 ist das Original, soll nicht verdoppelt werden!
             {
                 GeoObjectList liV = new GeoObjectList();
                 // für jede Kopie ein Clone machen
                 liV = originals.CloneObjects();
                 // der senkrechte Winkel auf Kopienwinkel dirV
                 GeoVector dirV_Vert = base.ActiveDrawingPlane.Normal ^ dirV;
                 GeoVector vectV     = (i * distX) * dirV + (j * distY) * dirV_Vert;
                 ModOp     m         = ModOp.Translate(vectV);
                 liV.Modify(m);
                 backgroundBlock.Add(liV);
             }
         }
     }
 }
Ejemplo n.º 5
0
        public static void UnpackArray(BooCodeBuilder codeBuilder, Method method, Block block, Expression expression, DeclarationCollection declarations)
        {
            ILocalEntity local = expression.Entity as ILocalEntity;

            if (null == local)
            {
                local = codeBuilder.DeclareTempLocal(method,
                                                     expression.ExpressionType);
                block.Add(
                    codeBuilder.CreateAssignment(
                        codeBuilder.CreateReference(local),
                        expression));
            }
            for (int i = 0; i < declarations.Count; ++i)
            {
                Declaration declaration = declarations[i];
                block.Add(
                    codeBuilder.CreateAssignment(
                        codeBuilder.CreateReference(
                            declaration.Entity),
                        codeBuilder.CreateSlicing(
                            codeBuilder.CreateReference(local),
                            i)));
            }
        }
Ejemplo n.º 6
0
        private void Registration(Block block)
        {
            if (status != Status.Connected)
            {
                blocksToSend.Add(new Block(BlockCode.Disconnect,
                                           (int)DisconnectType.Error));
                //SendAndDisconnect(BlockType.Disconnect, BlockRez.Error, "Connection Error");
                return;
            }
            string[] logins = block.mes[0].Split(new char[] { '\t' },
                                                 StringSplitOptions.RemoveEmptyEntries);
            Block regBlock = new Block(BlockCode.Registration);

            using (OleDbConnection dbConnect = new OleDbConnection(db))
            {
                dbConnect.Open();
                string command = "SELECT * FROM users WHERE login='******'";
                OleDbCommand    cmd    = new OleDbCommand(command, dbConnect);
                OleDbDataReader reader = cmd.ExecuteReader();
                if (reader.Read())
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    string answer = "User " + reader[1] + " was created early.";
                    Console.WriteLine(answer);
                    Console.ResetColor();
                    regBlock.Add((int)RegistrationType.AccExists);
                    blocksToSend.Add(regBlock);
                    dbConnect.Close();
                    return;
                }
                else
                {
                    command = "INSERT INTO users (login,pswd,ban) VALUES ('" + logins[0] + "', '" +
                              logins[1] + "', false);";
                    cmd = new OleDbCommand(command, dbConnect);
                    int i = cmd.ExecuteNonQuery();
                    if (i == 1)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        string answer = "Accaunt " + logins[0] + " successfully created.";
                        Console.WriteLine(answer);
                        Console.ResetColor();
                        regBlock.Add((int)RegistrationType.CreateNewAcc);
                        blocksToSend.Add(regBlock);
                    }
                    else
                    {
                        string answer = "Error add new account";
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(answer);
                        Console.ResetColor();
                        regBlock.Add((int)RegistrationType.Unknown);
                        blocksToSend.Add(regBlock);
                    }
                    dbConnect.Close();
                }
            }
        }
Ejemplo n.º 7
0
 public void Argument(Block argumentBlock)
 {
     prefixArguments();
     foreach (var verb in argumentBlock.AsAdded)
     {
         argumentsBlock.Add(verb);
     }
 }
Ejemplo n.º 8
0
        public override Verb CreateVerb(string[] tokens)
        {
            Color(position, tokens[1].Length, Whitespaces);
            Color(tokens[2].Length, KeyWords);
            Color(tokens[3].Length, KeyWords);
            Color(tokens[4].Length, KeyWords);

            var staticWord     = tokens[2].Trim();
            var visibility     = tokens[3].Trim();
            var visibilityType = ParseVisibility(visibility);
            var variableName   = tokens[5];

            Color(variableName.Length, Variables);

            var index = position + length;
            var verb  = new Define(variableName, visibilityType, true);
            var verbs = new List <Verb>();

            if (Parse(source, index).If(out var i, out var variableNames))
            {
                verbs.AddRange(variableNames.Select(v => new Define(v, visibilityType, true)));
                index = i;
            }

            if (staticWord == "static")
            {
                var block = new Block {
                    verb
                };
                foreach (var aVerb in verbs)
                {
                    block.Add(aVerb);
                }

                if (OneLineStatement(source, index).If(out var b, out var j))
                {
                    foreach (var bVerb in b.AsAdded)
                    {
                        block.Add(bVerb);
                    }

                    AddStaticBlock(block);
                    overridePosition = j;
                }

                return(new End());
            }

            overridePosition = index;
            if (verbs.Count > 0)
            {
                result.Verbs = verbs;
                return(new NullOp());
            }

            return(verb);
        }
Ejemplo n.º 9
0
        private Block SwitchBlock(Statement body, int ordinal, InternalLabel endpoint)
        {
            var result = new Block();

            result.Add(_F.CreateLabel(result, CompilerContext.Current.GetUniqueName("L" + ordinal), _tryDepth).LabelStatement);
            result.Add(body);
            result.Add(_F.CreateGoto(endpoint, _tryDepth));
            return(result);
        }
Ejemplo n.º 10
0
        public override Statement Expand(MacroStatement macro)
        {
            if (macro.Arguments.Count == 0)
            {
                throw new MonoRailException("Section must be called with a name");
            }

            var component = GetParentComponent(macro);

            componentContextName  = ComponentNaming.GetComponentContextName(component);
            componentVariableName = ComponentNaming.GetComponentNameFor(component);


            var sectionName = macro.Arguments[0].ToString();
            var block       = new Block();
            //if (!Component.SupportsSection(section.Name))
            //   throw new ViewComponentException( String.Format("The section '{0}' is not supported by the ViewComponent '{1}'", section.Name, ComponentName));
            var supportsSection = new MethodInvocationExpression(
                AstUtil.CreateReferenceExpression(componentVariableName + ".SupportsSection"),
                new StringLiteralExpression(sectionName));
            //create the new exception
            var raiseSectionNotSupportted = new RaiseStatement(
                new MethodInvocationExpression(
                    AstUtil.CreateReferenceExpression(typeof(ViewComponentException).FullName),
                    new StringLiteralExpression(
                        String.Format("The section '{0}' is not supported by the ViewComponent '{1}'", sectionName,
                                      component.Arguments[0])
                        )
                    ));

            var trueBlock = new Block();

            trueBlock.Add(raiseSectionNotSupportted);
            var ifSectionNotSupported =
                new IfStatement(new UnaryExpression(UnaryOperatorType.LogicalNot, supportsSection),
                                trueBlock, null);

            block.Add(ifSectionNotSupported);
            //componentContext.RegisterSection(sectionName);
            var mie = new MethodInvocationExpression(
                new MemberReferenceExpression(new ReferenceExpression(componentContextName), "RegisterSection"),
                new StringLiteralExpression(sectionName),
                CodeBuilderHelper.CreateCallableFromMacroBody(CodeBuilder, macro));

            block.Add(mie);

            var sections = (IDictionary)component["sections"];

            if (sections == null)
            {
                component["sections"] = sections = new Hashtable();
            }
            sections.Add(sectionName, block);
            return(null);
        }
Ejemplo n.º 11
0
        public Statement Expand(IEnumerable <Node> generator)
        {
            Block resultingBlock = new Block();

            foreach (Node node in generator)
            {
                //'yield' (ie. implicit 'yield null') means 'yield `macro`.Body'
                Node generatedNode = node ?? _node.Body;
                if (null == generatedNode)
                {
                    continue;
                }

                TypeMember member = generatedNode as TypeMember;
                if (null != member)
                {
                    ExpandTypeMember(member, resultingBlock);
                    continue;
                }

                Block block = generatedNode as Block;
                if (null != block)
                {
                    resultingBlock.Add(block);
                    continue;
                }

                Statement statement = generatedNode as Statement;
                if (null != statement)
                {
                    resultingBlock.Add(statement);
                    continue;
                }

                Expression expression = generatedNode as Expression;
                if (null != expression)
                {
                    resultingBlock.Add(expression);
                    continue;
                }

                Import import = generatedNode as Import;
                if (null != import)
                {
                    ExpandImport(import);
                    continue;
                }

                throw new CompilerError(_node, "Unsupported expansion: " + generatedNode.ToCodeString());
            }

            return(resultingBlock.IsEmpty
                                        ? null
                                        : resultingBlock.Simplify());
        }
Ejemplo n.º 12
0
        override public void LeaveYieldStatement(YieldStatement node)
        {
            Block block = new Block();

            block.Add(
                new ReturnStatement(
                    node.LexicalInfo,
                    CreateYieldInvocation(node.Expression),
                    null));
            block.Add(CreateLabel(node));
            ReplaceCurrentNode(block);
        }
        public Block PrepareEvaluationContextInitialization(IType evaluationContextType)
        {
            this._evaluationContextLocal = this.CodeBuilder.DeclareTempLocal(this.CurrentMethodNode, evaluationContextType);
            Block block = new Block();

            block.Add(this.CodeBuilder.CreateAssignment(this.CreateEvaluationContextReference(), this.CodeBuilder.CreateConstructorInvocation(UtilitiesModule.ConstructorTakingNArgumentsFor(evaluationContextType, 1), this.EvaluationDomainProviderReference())));
            foreach (ParameterDeclaration declaration in this.CurrentMethodNode.Parameters)
            {
                block.Add(this.CodeBuilder.CreateAssignment(this.CreateEvaluationContextFieldReference(this.GetEvaluationContextField(declaration)), this.CodeBuilder.CreateReference(declaration)));
            }
            return(block);
        }
Ejemplo n.º 14
0
        IMethod CreateDisposeMethod()
        {
            BooMethodBuilder mn = _enumerator.AddVirtualMethod("Dispose", TypeSystemServices.VoidType);

            mn.Method.LexicalInfo = this.LexicalInfo;

            LabelStatement noEnsure = CodeBuilder.CreateLabel(_generator.Method, "noEnsure").LabelStatement;

            mn.Body.Add(noEnsure);
            mn.Body.Add(SetStateTo(_finishedStateNumber));
            mn.Body.Add(new ReturnStatement());

            // Create a section calling all ensure methods for each converted try block
            LabelStatement[] disposeLabels = new LabelStatement[_labels.Count];
            for (int i = 0; i < _convertedTryStatements.Count; i++)
            {
                TryStatementInfo info = _convertedTryStatements[i];
                disposeLabels[info._stateNumber] = CodeBuilder.CreateLabel(_generator.Method, "$ensure_" + info._stateNumber).LabelStatement;
                mn.Body.Add(disposeLabels[info._stateNumber]);
                mn.Body.Add(SetStateTo(_finishedStateNumber));
                Block block = mn.Body;
                while (info._parent != null)
                {
                    TryStatement ts = new TryStatement();
                    block.Add(ts);
                    ts.ProtectedBlock.Add(CallMethodOnSelf(info._ensureMethod));
                    block = ts.EnsureBlock = new Block();
                    info  = info._parent;
                }
                block.Add(CallMethodOnSelf(info._ensureMethod));
                mn.Body.Add(new ReturnStatement());
            }

            // now map the labels of the suspended states to the labels we just created
            for (int i = 0; i < _labels.Count; i++)
            {
                if (_tryStatementInfoForLabels[i] == null)
                {
                    disposeLabels[i] = noEnsure;
                }
                else
                {
                    disposeLabels[i] = disposeLabels[_tryStatementInfoForLabels[i]._stateNumber];
                }
            }

            mn.Body.Insert(0, CodeBuilder.CreateSwitch(
                               this.LexicalInfo,
                               CodeBuilder.CreateMemberReference(_state),
                               disposeLabels));
            return(mn.Entity);
        }
Ejemplo n.º 15
0
        private void TransformPreprocessor(List <Element> elements)
        {
            var blocks        = new Stack <Block>();
            var current_block = new Block();

            foreach (var element in elements)
            {
                var start_block = false;
                var end_block   = false;

                var code = element.ActualCode;
                if (code.StartsWith("#if") || code.StartsWith("#load-if") || code.StartsWith("#for ") || code.StartsWith("#while ") || code.StartsWith("#foreach "))
                {
                    start_block = true;
                }
                else if (code.StartsWith("#end-if") || code.StartsWith("#end-for") || code.StartsWith("#end-while") || code.StartsWith("#end-foreach"))
                {
                    end_block = true;
                }

                if (start_block)
                {
                    var new_current_block = new Block();
                    current_block.Add(new_current_block);

                    blocks.Push(current_block);
                    current_block = new_current_block;

                    current_block.Add(element);
                }
                else if (end_block)
                {
                    current_block.Add(element);
                    current_block = blocks.Pop();
                }
                else
                {
                    current_block.Add(element);
                }
            }

            Debug.Assert(blocks.Count == 0, "Preprocessor block not closed-"); // stack should be empty again

            TransformBlock(current_block);

            elements.Clear();
            elements.AddRange(current_block.GetElements());
        }
        // CREATE NEW BLOCK COMMAND FUNCTIONS
        private void CreateNewBlockAction(object obj)
        {
            var checkedOrders = Order.Where(o => o.IsChecked).ToList();

            if (checkedOrders.Count == 0)
            {
                MessageBox.Show("Please select an order !");
                return;
            }

            // Validate
            bool isValid = CheckValidation(checkedOrders);

            if (!isValid)
            {
                MessageBox.Show("Type or Side doesn't match");
            }
            else
            {
                Block newBlock = CreateBlock(checkedOrders);

                db.Entry(newBlock).State = System.Data.Entity.EntityState.Added;
                db.SaveChanges();

                // Update Orders with new block id
                UpdateOrders(checkedOrders, newBlock.BlockID);

                //Update Order blotter


                // Add to Block blotter
                Block.Add(BlockToCheckedBlockMapper.ToCheckedBlock(db.Blocks.First(o => o.BlockID == newBlock.BlockID)));
                MessageBox.Show("Block Successfully Created!");
            }
        }
Ejemplo n.º 17
0
        public override Verb CreateVerb(string[] tokens)
        {
            Color(position, tokens[1].Length, KeyWords);

            AdvanceTabs();

            var statementParser = new StatementParser();
            var block           = new Block();

            var index = NextPosition;

            while (index < source.Length)
            {
                if (statementParser.Scan(source, index))
                {
                    index = statementParser.Position;
                    var verb = statementParser.Verb;
                    if (verb != null && !(verb is NullOp))
                    {
                        block.Add(verb);
                    }
                }
                else
                {
                    break;
                }
            }

            RegressTabs();

            overridePosition = index;
            Block            = block;
            return(block.PushedVerb);
        }
Ejemplo n.º 18
0
        public void TestSetBlockHash()
        {
            //Arrange
            var txn1 = new ClaimSettlement("ABC123", 1000.00m, DateTime.Now, "QWE123", 10000, ClaimType.TotalLoss);
            var txn2 = new ClaimSettlement("ABC123", 1000.00m, DateTime.Now, "QWE123", 10000, ClaimType.TotalLoss);
            IBlock <ClaimSettlement>      block      = new Block(0, 3);
            IBlockChain <ClaimSettlement> blockChain = new BlockChain <ClaimSettlement>();

            //Act
            block.Add(txn1);
            block.Add(txn2);
            blockChain.Add(block);

            //Assert
            Assert.AreEqual(32, block.BlockHash.Length);
        }
Ejemplo n.º 19
0
        public void FinishElementSelection()
        {
            switch (ShowDialogType)
            {
            case ShowDialogType.AddElements:
                if (SelectedElementIds != null)
                {
                    Block.Add(Blocking, SelectedElementIds);
                }
                ShowDialogType = ShowDialogType.Idle;
                break;

            case ShowDialogType.DeleleElements:
                if (SelectedElementIds != null)
                {
                    Block.Delete(Blocking, SelectedElementIds);
                }
                using (var transaction = new Transaction(m_Doc, "EarthworkBlocking." + nameof(FinishElementSelection)))
                {
                    transaction.Start();
                    m_UIDoc.ActiveView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate);    //解除隔离显示
                    transaction.Commit();
                }
                ShowDialogType = ShowDialogType.Idle;
                break;

            default:
                break;
            }
            ValueChanged(null, null);
            //ShowMessage("添加节点结束", $"节点:{Block.Name}现有:{Block.ElementIds.Count()}个元素");
        }
Ejemplo n.º 20
0
 public Respondent(int blocksCount, int attemptCount) : this()
 {
     for (int i = 0; i < blocksCount; ++i)
     {
         Block.Add(new Block(attemptCount));
     }
 }
Ejemplo n.º 21
0
            public virtual void ReadChildData(BinaryReader reader)
            {
                int x = 0;

                for (x = 0; (x < _block.Count); x = (x + 1))
                {
                    Block.Add(new EmptyStructureBlock());
                    Block[x].Read(reader);
                }
                for (x = 0; (x < _block.Count); x = (x + 1))
                {
                    Block[x].ReadChildData(reader);
                }
                _data.ReadBinary(reader);
                _tagReference.ReadString(reader);
                for (x = 0; (x < _fiveEntryBlock.Count); x = (x + 1))
                {
                    FiveEntryBlock.Add(new FiveEntryStructureBlock());
                    FiveEntryBlock[x].Read(reader);
                }
                for (x = 0; (x < _fiveEntryBlock.Count); x = (x + 1))
                {
                    FiveEntryBlock[x].ReadChildData(reader);
                }
            }
Ejemplo n.º 22
0
        private void AugmentEnsureBlock(Block block, Expression reference)
        {
            // if __disposable = <reference> as System.IDisposable:
            IfStatement stmt = new IfStatement();

            stmt.Condition = new BinaryExpression(
                BinaryOperatorType.Assign,
                new ReferenceExpression(DisposableLocalName),
                new TryCastExpression(reference, new SimpleTypeReference("System.IDisposable"))
                );

            stmt.TrueBlock = new Block();

            // __disposable.Dispose()
            stmt.TrueBlock.Add(
                new MethodInvocationExpression(
                    new MemberReferenceExpression(
                        new ReferenceExpression(DisposableLocalName),
                        "Dispose")
                    )
                );

            // __disposable = null
            stmt.TrueBlock.Add(
                new BinaryExpression(
                    BinaryOperatorType.Assign,
                    new ReferenceExpression(DisposableLocalName),
                    new NullLiteralExpression()
                    )
                );

            block.Add(stmt);
        }
Ejemplo n.º 23
0
        [DebuggerNonUserCode] public BlockExpander(Block source, ExpansionContext ctx)
        {
            Source = source;
            Ctx    = ctx;

            Stmts     = new Block();
            ctx.Scope = Stmts;
            var cloned_locals = source.Locals.Select(l => l.DeepClone());

            cloned_locals.ForEach(local => ctx.Scope.Locals.Add(local));

            var is_root = Ctx.Parent == null || (Ctx.Parent.Stack.Count() != Ctx.Stack.Count());

            if (is_root)
            {
                RetLabel = new Label();
            }
            else
            {
                RetLabel.AssertNotNull();
            }

            source.ForEach(Expand);
            if (is_root && Stmts.LastOrDefault() is Goto)
            {
                Stmts.RemoveLast();
            }
            var gotos = Stmts.Family().OfType <Goto>().Where(@goto => @goto.LabelId == RetLabel.Id).ToReadOnly();

            if (is_root && gotos.IsNotEmpty())
            {
                Stmts.Add(RetLabel);
            }
        }
        static void Main(string[] args)
        {
            Block b   = new Block();
            Block key = new Block();

            for (int i = 1; i <= 10; i++)
            {
                b.Add((byte)(i + 0x2F));
            }
            for (int i = 0; i < 10; i++)
            {
                key.Add((byte)i);
            }
            FileIO fio = new FileIO(@"D:\input.txt", @"D:\output.txt", 10);

            new OFB(fio, key).StartEncrypt();
            fio.Close();
            fio = new FileIO(@"D:\output.txt", @"D:\decrypt_output.txt", 10);
            new OFB(fio, key).StartDecrypt();
            fio.Close();
            //Console.WriteLine("Plainteks  : " + b);
            //b = Kripsi.Encrypt(b, key);
            //Console.WriteLine("Cipherteks : " + b);
            //b = Kripsi.Decrypt(b, key);
            //Console.WriteLine("Plainteks  : " + b);
            Console.ReadKey();
        }
Ejemplo n.º 25
0
        public Block CreateGenesis(string[] args)
        {
            var argsList = args.ToList();

            argsList.RemoveAt(0);


            var blockAddr    = IXIUtils.GenerateRandomString(81);
            var genesisBlock = new Block(0, blockAddr, Settings.CoinName);

            var poolAddr     = IXIUtils.GetTransactionPoolAddress(0, Settings.CoinName);
            var genesisTrans = new Transaction("me", -1, poolAddr)
                               .SetGenesisInformation(new ChainSettings(argsList.ToArray()))
                               .Final(_ixiSettings)
                               .Upload();

            genesisBlock.Add(genesisTrans)
            .Final(_ixiSettings)
            .GenerateProofOfWork(_ixiCore)
            .Upload();

            Console.WriteLine("Genesis Block at: {0} \nwith Hash {1}", genesisBlock.SendTo, genesisBlock.Hash);

            return(genesisBlock);
        }
Ejemplo n.º 26
0
        private bool Recalc()
        {
            if (theBaseCurve == null)
            {
                return(false);
            }
            Plane pln;

            if (theBaseCurve.GetPlanarState() == PlanarState.Planar)
            {
                pln = theBaseCurve.GetPlane();
            }
            else
            {
                pln = base.ActiveDrawingPlane;
            }
            ICurve2D c2d = theBaseCurve.GetProjectedCurve(pln);
            ICurve2D app = c2d.Approximate(false, Frame.GetDoubleSetting("Approximate.Precision", 0.01));
            Border   bdr = new Border(app);

            Border[] res = bdr.GetParallel(theDistance, true, 0.0, theMinAngle);
            Block    blk = Block.Construct();

            for (int i = 0; i < res.Length; ++i)
            {
                IGeoObject go = res[i].AsPath().MakeGeoObject(pln);
                go.CopyAttributes(theBaseCurve as IGeoObject);
                (go as IColorDef).ColorDef = (theBaseCurve as IColorDef).ColorDef;
                blk.Add(go);
            }
            base.ActiveObject = blk;
            return(true);
        }
Ejemplo n.º 27
0
        void Map()
        {
            IType         type   = (IType)_sharedLocalsClass.Entity;
            InternalLocal locals = CodeBuilder.DeclareLocal(_currentMethod, "___locals", type);

            foreach (ReferenceExpression reference in _references)
            {
                IField mapped = (IField)_mappings[reference.Entity];
                if (null != mapped)
                {
                    reference.ParentNode.Replace(
                        reference,
                        CodeBuilder.CreateMemberReference(
                            CodeBuilder.CreateReference(locals),
                            mapped));
                }
            }

            Block initializationBlock = new Block();

            initializationBlock.Add(CodeBuilder.CreateAssignment(
                                        CodeBuilder.CreateReference(locals),
                                        CodeBuilder.CreateConstructorInvocation(type.GetConstructors()[0])));
            InitializeSharedParameters(initializationBlock, locals);
            _currentMethod.Body.Statements.Insert(0, initializationBlock);

            foreach (IEntity entity in _mappings.Keys)
            {
                _currentMethod.Locals.RemoveByEntity(entity);
            }
        }
Ejemplo n.º 28
0
 private bool showCirc()
 {
     block = Block.Construct();
     for (int i = 1; i < copCount; ++i)
     {
         GeoObjectList li = new GeoObjectList();
         // für jede Kopie ein Clone machen
         li = originals.CloneObjects();
         ModOp m = ModOp.Rotate(rotationPoint, base.ActiveDrawingPlane.Normal, i * copAngle);
         if (!objRot) // Objekte drehen mit: einfach modifizieren
         {
             li.Modify(m);
         }
         else
         {   // Objekte drehen nicht mit: Translation des gedrehten centerpoints
             ModOp mt = ModOp.Translate(new GeoVector(centerPoint, m * centerPoint));
             li.Modify(mt);
         }
         block.Add(li);
     }
     if (block.Count > 0)
     {
         base.ActiveObject = block;
         return(true);
     }
     else
     {
         base.ActiveObject = null;
         return(false);
     }
 }
        override public void OnDestructor(Destructor node)
        {
            Method finalizer = CodeBuilder.CreateMethod(
                "Finalize",
                TypeSystemServices.VoidType,
                TypeMemberModifiers.Protected | TypeMemberModifiers.Override);

            finalizer.LexicalInfo = node.LexicalInfo;

            MethodInvocationExpression mie = new MethodInvocationExpression(new SuperLiteralExpression());

            Block bodyNew     = new Block();
            Block ensureBlock = new Block();

            ensureBlock.Add(mie);

            TryStatement tryStatement = new TryStatement();

            tryStatement.EnsureBlock    = ensureBlock;
            tryStatement.ProtectedBlock = node.Body;

            bodyNew.Add(tryStatement);
            finalizer.Body = bodyNew;

            node.ParentNode.Replace(node, finalizer);
        }
Ejemplo n.º 30
0
        //Second Level messages (code ChooseHero)
        private Block CreateHero(Block block)
        {
            Block nHero = new Block(BlockCode.ChooseHero);

            using (OleDbConnection dbConnect = new OleDbConnection(db))
            {
                dbConnect.Open();
                string          command = "SELECT name FROM players WHERE name='" + block.mes[0] + "';";
                OleDbCommand    cmd     = new OleDbCommand(command, dbConnect);
                OleDbDataReader reader  = cmd.ExecuteReader();
                if (reader.Read())
                {
                    nHero.Add((int)ChooseHeroType.HeroExists);
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("ID: {0}. Code: {1}. Type: {2}", loginId, nHero.Code, nHero.Type);
                    Console.ResetColor();
                    dbConnect.Close();
                    return(nHero);
                }
                else
                {
                    command = string.Format("INSERT INTO players([loginId], [name], [str], [agi], " +
                                            "[vit], [int], [dex], [luk]) VALUES ({0}, \'{1}\', {2}, {3}, {4}, {5}, {6}, {7});",
                                            loginId, block.mes[0], block.mes[1], block.mes[2], block.mes[3], block.mes[4],
                                            block.mes[5], block.mes[6]);
                    cmd = new OleDbCommand(command, dbConnect);
                    if (cmd.ExecuteNonQuery() == 1)
                    {
                        nHero.Add((int)ChooseHeroType.CreateHero);
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("ID: {0} Code: {1} Type: {2}", loginId, nHero.Code, nHero.Type);
                        Console.ResetColor();
                        dbConnect.Close();
                        return(nHero);
                    }
                    else
                    {
                        nHero.Add((int)ChooseHeroType.Unknown);
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Error add new hero");
                        Console.ResetColor();
                        dbConnect.Close();
                        return(nHero);
                    }
                }
            }
        }
Ejemplo n.º 31
0
        private static Block<int> GetFilledBlock(int size)
        {
            var block = new Block<int>(ElementsInBlockCount);
            for (int i = 0; i < size; i++)
            {
                block.Add(i);
            }

            return block;
        }
Ejemplo n.º 32
0
        private static ArrayMap<int> CteareTestStructure()
        {
            //Prepare block collection
            var blockCollection = new BlockCollection<int>();

            for (int i = 0; i < CountOfBlocks; i++)
            {
                var block = new Block<int>(BlockSize);
                for (int element = 0; element < BlockSize; element++)
                {
                    block.Add(element);
                }
                blockCollection.Add(block);
            }

            //Create block structure
            return new ArrayMap<int>(new FixedBalancer(),  blockCollection);
        }