Exemplo n.º 1
0
        private DCRF.Contract.Connector.EndPoint GetEndPoint(IBlockWeb context)
        {
            DCRF.Contract.Connector.EndPoint result = new Connector.EndPoint(context);

            if (value != null)
            {
                result.Value = value;
            }
            else if (serviceName != null)
            {
                result.BlockId = blockId;
                result.ServiceName = serviceName;
            }
            else
            {
                result.BlockId = blockId;
                result.ConnectorKey = connectorKey;
            }

            foreach (EndPointDescriptor ep in this.FixedArgs)
            {
                result.AddFixedArg(ep.GetEndPoint(context));
            }

            return result;
        }
Exemplo n.º 2
0
        public static bool FireSysEvent(IBlockWeb blockWeb, string timing, string eventCode, string blockIdOrConnectorKey, object eventArgs)
        {
            bool madeACall = false;

            if (blockWeb[CoordinatorBlockID] != null && blockIdOrConnectorKey != CoordinatorBlockID)
            {
                if (blockIdOrConnectorKey != null)
                {
                    string eventKey = SysEventCode.Join(timing, eventCode, blockIdOrConnectorKey);

                    if (blockWeb[CoordinatorBlockID][eventKey] != null)
                    {
                        blockWeb[CoordinatorBlockID][eventKey].ProcessRequest(eventArgs);
                        madeACall = true;
                    }
                }

                string eventKey2 = SysEventCode.Join(timing, eventCode);

                if (blockWeb[CoordinatorBlockID][eventKey2] != null)
                {
                    blockWeb[CoordinatorBlockID][eventKey2].ProcessRequest(eventArgs);
                    madeACall = true;
                }
            }

            return madeACall;
        }
Exemplo n.º 3
0
 public EndPointNode(IBlockWeb web, string id, string key, string ep)
 {
     myWeb = web;
     myId = id;
     myConnectorKey = key;
     this.ep = ep;
 }
Exemplo n.º 4
0
        public static void ProcessProcessRequest(XmlElement actionElement, IBlockWeb containerWeb, string blockId)
        {
            string targetBlockId = actionElement.GetAttribute("blockId");

            if (actionElement.HasAttribute("blockId") == false)
            {
                targetBlockId = blockId;
            }

            string service = actionElement.GetAttribute("service");
            List<object> args = new List<object>();

            XmlNode fixedArgsNode = actionElement.SelectSingleNode("fixedArgs");

            if (fixedArgsNode != null)
            {
                List<Connector.EndPoint> endPoints = EndPointExtractor.ExtractArguments(fixedArgsNode as XmlElement, containerWeb);

                foreach (Connector.EndPoint endPoint in endPoints)
                {
                    endPoint.ProcessRequest(args, new object[] { }, new ConnectorSysEventArgs(null, null));
                }
            }

            containerWeb[targetBlockId].ProcessRequest(service, args.ToArray());
        }
Exemplo n.º 5
0
        public static void ProcessSetProperty(XmlElement actionElement, IBlockWeb containerWeb, string blockId)
        {
            string connectorKey = actionElement.GetAttribute("connectorKey");
            object value = ObjectReader.ReadObject(actionElement);
            bool createConnector = false;

            if (actionElement.HasAttribute("create") && actionElement.GetAttribute("create") == "true")
            {
                createConnector = true;
            }

            if (actionElement.HasAttribute("blockId"))
            {
                string aBlockId = actionElement.GetAttribute("blockId");

                if (createConnector)
                {
                    containerWeb[aBlockId].ProcessRequest("ProcessMetaService", BlockMetaServiceType.CreateConnector, connectorKey, null);
                }

                containerWeb[aBlockId][connectorKey].AttachEndPoint(value);
            }
            else
            {
                if (createConnector)
                {
                    containerWeb[blockId].ProcessRequest("ProcessMetaService", BlockMetaServiceType.CreateConnector, connectorKey, null);
                }

                containerWeb[blockId][connectorKey].AttachEndPoint(value);
            }
        }
Exemplo n.º 6
0
 public BlockWebPeerSysEventArgs(IBlockWeb web, string id, string host, int port, bool isConnect)
 {
     BlockWeb = web;
     PeerHost = host;
     PeerPort = port;
     IsConnectEvent = isConnect;
     PeerId = id;
 }
Exemplo n.º 7
0
        public void OpenForm(string xmlFile)
        {
            IBlockWeb bw = XMLLoader.LoadBlockWeb(xmlFile, "a", blockWeb.Broker);

            string formId = bw.GetConnector("FormId").GetValue <string>();
            Form   frm    = bw[formId].ProcessRequest("GetUIElement") as Form;

            frm.ShowDialog();
        }
Exemplo n.º 8
0
        private void button1_Click(object sender, EventArgs e)
        {
            RuntimeBlockBroker broker = initBroker();

            IBlockWeb bw     = XMLLoader.LoadBlockWeb("blockWeb-copy.xml", "a", broker, null);
            string    formId = bw.GetConnector("FormId").GetValue <string>();

            System.Windows.Forms.Form frm = bw[formId].ProcessRequest("GetUIElement") as System.Windows.Forms.Form;
            frm.ShowDialog();
        }
Exemplo n.º 9
0
        public static void ProcessAttachEndPoint(IBlockWeb containerWeb, IConnector connector, XmlElement endpointElement, string blockId)
        {
            string endpointKey = null;

            if (endpointElement.Name == "valueEndPoint")
            {
                if (!TemplateProcessor.ProcessTemplateFile(endpointElement, containerWeb, blockId, connector))
                {
                    object value = ObjectReader.ReadObject(endpointElement);
                    endpointKey = connector.AttachEndPoint(value);
                }
            }
            else if (endpointElement.Name == "serviceEndPoint")
            {
                if (!TemplateProcessor.ProcessTemplateFile(endpointElement, containerWeb, blockId, connector))
                {
                    string endpointBlockId = endpointElement.GetAttribute("blockId");
                    string endpointService = endpointElement.GetAttribute("service");

                    if (!endpointElement.HasAttribute("blockId")) endpointBlockId = blockId;

                    endpointKey = connector.AttachEndPoint(endpointBlockId, endpointService);
                }
            }
            else if (endpointElement.Name == "connectorEndPoint")
            {
                if (!TemplateProcessor.ProcessTemplateFile(endpointElement, containerWeb, blockId, connector))
                {
                    string endpointBlockId = endpointElement.GetAttribute("blockId");
                    string endPointConnectorKey = endpointElement.GetAttribute("connectorKey");

                    if (!endpointElement.HasAttribute("blockId")) endpointBlockId = blockId;

                    endpointKey = connector.AttachConnectorEndPoint(endpointBlockId, endPointConnectorKey);
                }
            }
            else
            {
                throw new InvalidOperationException();
            }

            //now process fixed args
            XmlElement fixedArgsElement = endpointElement.SelectSingleNode("fixedArgs") as XmlElement;

            if (fixedArgsElement != null && endpointKey != null)
            {
                List<Connector.EndPoint> fixedArgs = EndPointExtractor.ExtractArguments(fixedArgsElement, containerWeb);

                foreach (Connector.EndPoint endPoint in fixedArgs)
                {
                    connector.AddFixedArg(endpointKey, endPoint);
                }
            }
        }
Exemplo n.º 10
0
        public static List<Connector.EndPoint> ExtractArguments(XmlElement fixedArgsElement, IBlockWeb containerWeb)
        {
            //TemplateProcessor.ProcessTemplateFile(fixedArgsElement, containerWeb, null);

            List<Connector.EndPoint> result = new List<Connector.EndPoint>();

            foreach (XmlElement argEndPoint in fixedArgsElement.ChildNodes)
            {
                result.Add(extractArgument(argEndPoint, containerWeb));
            }

            return result;
        }
Exemplo n.º 11
0
        private void button2_Click_1(object sender, EventArgs e)
        {
            SimpleBlockBroker broker = new SimpleBlockBroker();
            RepositoryOptions ro     = new RepositoryOptions();

            ro.Folder = txtBlocksFolder.Text;

            broker.SetupBroker(ro);

            IBlockWeb bw     = XMLLoader.LoadBlockWeb(txtFormFile.Text, txtBWID.Text, broker, null);
            string    formId = bw.GetConnector("FormId").GetValue <string>();

            System.Windows.Forms.Form frm = bw[formId].ProcessRequest("GetUIElement") as System.Windows.Forms.Form;
            frm.ShowDialog();
        }
Exemplo n.º 12
0
        public void Attach(IConnector connector, IBlockWeb context)
        {
            string epKey = null;

            if (value != null)
            {
                epKey = connector.AttachEndPoint(value);
            }
            else if (serviceName != null)
            {
                epKey = connector.AttachEndPoint(blockId, serviceName);
            }
            else
            {
                epKey = connector.AttachConnectorEndPoint(blockId, connectorKey);
            }

            foreach (EndPointDescriptor ep in FixedArgs)
            {
                connector.AddFixedArg(epKey, ep.GetEndPoint(context));
            }
        }
Exemplo n.º 13
0
        public static void ProcessSetVariable(XmlElement actionElement, IBlockWeb containerWeb, string blockId)
        {
            string name = actionElement.GetAttribute("name");

            if (actionElement.ChildNodes.Count == 0)
            {
                //in this case the actionElement itself has the required data
                object value = ObjectReader.ReadObject(actionElement);
                NodeProcessor.SetVar(name, value);
            }
            else
            {
                //read first childr as endpoint because variable can only have one value
                List<Connector.EndPoint> endpoints = EndPointExtractor.ExtractArguments(actionElement, containerWeb);
                Connector.EndPoint endpoint = endpoints[0];

                List<object> result = new List<object>();
                endpoint.ProcessRequest(result, null, new ConnectorSysEventArgs(null, null));

                //now save result of endpoint process
                NodeProcessor.SetVar(name, result[0]);
            }
        }
Exemplo n.º 14
0
        private void button2_Click(object sender, EventArgs e)
        {
            myBroker = new SimpleBlockBroker();
            RepositoryOptions opt = new RepositoryOptions();
            opt.Folder = txtBlocksFolder.Text;
            myBroker.SetupBroker(opt);

            innerWeb = new BlockWeb(txtWebId.Text, myBroker);

            //innerWeb.AddBlock(BlockHandle.New("DummyBlock"));
            //string logger = innerWeb.AddBlock(BlockHandle.New("Logger"));
            //string formBuilder = innerWeb.AddBlock(BlockHandle.New("FormBuilder"));

            //innerWeb[formBuilder].ProcessRequest("BuildForm", "frmLog");
            //innerWeb[logger]["ContainerControl"].AttachEndPoint(formBuilder, "GetForm", new object[] { "frmLog" });
            //innerWeb[formBuilder].ProcessRequest("ShowForm", "frmLog");
            //innerWeb[EventCode.LogWebEvent].AttachEndPoint(logger, "Log");

            txtBlocksFolder.Enabled = false;
            txtWebId.Enabled = false;
            button1.Enabled = false;
            button2.Enabled = false;

            lblWebAddress.Text= innerWeb.Address;

            cmdRefresh.Enabled = true;
            cmdShutdown.Enabled = true;
            button2.Enabled = false;

            startTime = DateTime.Now;
            timer1.Enabled = true;

            MessageBox.Show("BlockWeb is Started!");

            //innerWeb[logger].ProcessRequest("Log", LogType.General, "BlockWeb is Started!");
        }
Exemplo n.º 15
0
        public override void ExecuteCommand(string cmdKey, TreeNode myNode)
        {
            if (cmdKey == "REF")
            {
                refresh(myNode);
            }
            else if (cmdKey == "ADD")
            {
                //pass to first child
                if (requiresRefresh(myNode)) refresh(myNode, true);

                foreach (TreeNode tn in myNode.Nodes)
                {
                    if (tn.Tag is BlocksNode)
                    {
                        (tn.Tag as BlocksNode).ExecuteCommand("ADD", myNode.Nodes[0]);
                        break;
                    }
                }
            }
            else if (cmdKey == "UNLOAD")
            {
                //maybe unload is called more than once
                if (myWeb == null) return;

                //when web is disposed, it disposes all of its blocks and they dispose their
                //related innerweb so this command will be propagated
                myWeb.Dispose();
                myWeb = null;

                if (myNodes.Count > 0)
                {
                    TreeView tv = myNodes[0].TreeView;

                    tv.Invoke(new MethodInvoker(delegate()
                        {
                            foreach (TreeNode node in myNodes)
                            {
                                //maybe parent treeview is disposed
                                if (node != null && node.TreeView != null && !node.TreeView.IsDisposed && node.TreeView.Nodes != null)
                                {
                                    //this will remove all my children too
                                    node.Remove();
                                }
                            }
                        }));
                }

                myNodes.Clear();
                children.Clear();
            }
            else if (cmdKey == "CODE")
            {
                frmCode frm = new frmCode();

                Control container = myNode.TreeView.Parent;

                while (container.Parent != null)
                {
                    container = container.Parent;
                }

                frm.globalState = (container as frmMain).globalCodeState;
                frm.argWeb = myWeb;
                frm.Text = "Script Window - " + myWeb.Id + " @ " + myWeb.Address;

                frm.Show();
            }
            else if (cmdKey == "RELOAD")
            {
                if (MessageBox.Show("Are you sure you want to re-load all Blocks in this BlockWeb?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    myWeb.ReloadBlocks();
                    myNode.Collapse();
                    myNode.Nodes.Clear();
                    refresh(myNode, true);
                }
            }
            else if (cmdKey == "RELOADWEB")
            {
                myNode.Collapse();

                myWeb.Dispose();
                myWeb = null;
                children.Clear();

                foreach (TreeNode node in myNodes)
                {
                    //maybe parent treeview is disposed
                    if (node != null && node.TreeView != null && !node.TreeView.IsDisposed && node.TreeView.Nodes != null)
                    {
                        //this will remove all my children too
                        node.Nodes.Clear();
                        node.Collapse();
                    }
                }

                Control container = myNode.TreeView.Parent;

                while (!(container is ctlWebTree))
                {
                    container = container.Parent;
                }

                ctlWebTree parentCtl = container as ctlWebTree;
                parentCtl.loadBlockWeb(id, host, port, myNodes);
            }
        }
Exemplo n.º 16
0
 public bool Connect(IBlockWeb web, string peerId)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 17
0
        private bool doShutdown()
        {
            if (MessageBox.Show("Are you sure you want to shutdown BlockWeb Host?", "Confirm", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
            {
                if (innerWeb == null) return true;

                innerWeb.Dispose();

                //wait a little so all blocks and their info are disposed
                Thread.Sleep(2000);

                innerWeb = null;

                return true;
            }

            return false;
        }
Exemplo n.º 18
0
 public ConnectorNode(IBlockWeb web, string id, string key)
 {
     myWeb = web;
     myId = id;
     myConnectorKey = key;
 }
Exemplo n.º 19
0
        public static void ProcessAttachEndPointsAction(XmlElement actionElement, IBlockWeb containerWeb, string blockId)
        {
            string connectorKey = actionElement.GetAttribute("connectorKey");
            IConnector connector = null;

            bool hasTargetBlockId = actionElement.HasAttribute("blockId");
            string targetBlockId = actionElement.GetAttribute("blockId");
            bool createConnector = false;

            if (actionElement.HasAttribute("create") && actionElement.GetAttribute("create") == "true")
            {
                createConnector = true;
            }

            if (hasTargetBlockId)
            {
                if (createConnector)
                {
                    containerWeb[targetBlockId].ProcessRequest("ProcessMetaService", BlockMetaServiceType.CreateConnector,
                        connectorKey, null);
                }

                connector = containerWeb[targetBlockId][connectorKey];
            }
            else
            {
                if (createConnector)
                {
                    containerWeb[blockId].ProcessRequest("ProcessMetaService", BlockMetaServiceType.CreateConnector,
                        connectorKey, null);
                }

                connector = containerWeb[blockId][connectorKey];
            }

            foreach (XmlElement endpointElement in actionElement.ChildNodes)
            {
                EndPointExtractor.ProcessAttachEndPoint(containerWeb, connector, endpointElement, blockId);
            }
        }
Exemplo n.º 20
0
        public void innerExecute(IBlockWeb result)
        {
            import.DoImport(result);

            commandBlock.Execute();
        }
Exemplo n.º 21
0
        public BlockWebNode(IBlockWeb web)
        {
            myWeb = web;

            //TODO: fix web.PeerDisconnected += new NetSockets.Peer.PeerConnectDelegate(web_Disconnected);
        }
Exemplo n.º 22
0
        //public IBlockWeb this[string blockWebId]
        //{
        //    get
        //    {
        //        if (blockWebs.ContainsKey(blockWebId))
        //        {
        //            return blockWebs[blockWebId];
        //        }
        //        if (parent != null)
        //        {
        //            return parent[blockWebId];
        //        }
        //        return null;
        //    }
        //}
        public void RegisterBlockWeb(IBlockWeb web, bool isInnerWeb)
        {
            //add it to the parent too
            //so outer caller code will be able to see generated blockWebs
            if (!isInnerWeb && parent != null)
            {
                parent.RegisterBlockWeb(web, false);
            }

            blockWebs[web.Id] = web;
            currentBlockWebId = web.Id;
        }
Exemplo n.º 23
0
 public static void ProcessNodeChildren(XmlElement element, IBlockWeb blockWeb, string blockId, IConnector connector)
 {
     foreach (XmlNode actionNode in element.ChildNodes)
     {
         if (actionNode is XmlElement)
         {
             NodeProcessor.ProcessNode(actionNode as XmlElement, blockWeb, blockId, connector);
         }
     }
 }
Exemplo n.º 24
0
        private static void addFixedArgsToEndPoint(IBlockWeb containerWeb, XmlElement argEndPoint, Connector.EndPoint ep)
        {
            if (argEndPoint.SelectSingleNode("fixedArgs") != null)
            {
                List<Connector.EndPoint> subFixedArgs = ExtractArguments(argEndPoint.SelectSingleNode("fixedArgs") as XmlElement, containerWeb);

                foreach (Connector.EndPoint subFixedArg in subFixedArgs)
                {
                    ep.AddFixedArg(subFixedArg);
                }
            }
        }
Exemplo n.º 25
0
 public ServicesNode(IBlockWeb web, string id)
 {
     myWeb = web;
     myId = id;
 }
Exemplo n.º 26
0
 public BlocksNode(IBlockWeb web)
 {
     myWeb = web;
 }
Exemplo n.º 27
0
        public void DoImport(IBlockWeb baseBlockWeb)
        {
            if (importList == null) return;

            foreach (Identifier import in importList)
            {
                BlockWebCmd bwCmd = ExecutionContext.Current.LookupBlockWebDefinition(import.ValueText);

                if (bwCmd == null)
                {
                    throw new Exception("Cannot find reference block-web: " + import.ValueText);
                }

                bwCmd.innerExecute(baseBlockWeb);
            }
        }
Exemplo n.º 28
0
 public PeerNode(IBlockWeb web, string peerId, string peerAddress)
 {
     myWeb = web;
     this.peerId = peerId;
     this.peerAddress = peerAddress;
 }
Exemplo n.º 29
0
        private static Connector.EndPoint extractArgument(XmlElement argEndPoint, IBlockWeb containerWeb)
        {
            if (argEndPoint.GetAttribute("isMissing") == "true")
            {
                return null;
            }
            else if (argEndPoint.Name == "serviceEndPoint" || argEndPoint.Name == "serviceArg")
            {
                string endpointBlockId = argEndPoint.GetAttribute("blockId");
                string endpointService = argEndPoint.GetAttribute("service");

                Connector.EndPoint ep = new Connector.EndPoint(containerWeb);
                ep.BlockId = endpointBlockId;
                ep.ServiceName = endpointService;

                if (argEndPoint.HasAttribute("targetType"))
                {
                    ep.TargetType = Type.GetType(argEndPoint.GetAttribute("targetType"));
                }

                addFixedArgsToEndPoint(containerWeb, argEndPoint, ep);

                return ep;
            }
            else if (argEndPoint.Name == "connectorEndPoint" || argEndPoint.Name == "connectorArg")
            {
                string endpointBlockId = argEndPoint.GetAttribute("blockId");
                string endPointConnectorKey = argEndPoint.GetAttribute("connectorKey");

                Connector.EndPoint ep = new Connector.EndPoint(containerWeb);
                ep.BlockId = endpointBlockId;
                ep.ConnectorKey = endPointConnectorKey;

                if (argEndPoint.HasAttribute("targetType"))
                {
                    ep.TargetType = Type.GetType(argEndPoint.GetAttribute("targetType"));
                }

                addFixedArgsToEndPoint(containerWeb, argEndPoint, ep);

                return ep;
            }
            else if (argEndPoint.Name == "valueEndPoint" || argEndPoint.Name == "valueArg")
            {
                object value = ObjectReader.ReadObject(argEndPoint);
                Connector.EndPoint ep = new Connector.EndPoint(containerWeb);
                ep.Value = value;

                return ep;
            }

            throw new InvalidDataException();
        }
Exemplo n.º 30
0
 public void SetInnerWeb(IBlockWeb web)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 31
0
 public ConnectorsNode(IBlockWeb web, string id)
 {
     myWeb = web;
     myId = id;
 }
Exemplo n.º 32
0
        public static object ProcessNode(XmlElement element, IBlockWeb blockWeb, string blockId, IConnector connector)
        {
            switch (element.Name)
            {
                case "blockWeb":
                    {
                        string id = null;
                        if (element.HasAttribute("id"))
                        {
                            id = element.GetAttribute("id");
                        }

                        BlockWeb newWeb = null;

                        if ( blockId != null )
                        {
                            newWeb = (BlockWeb) blockWeb[blockId].ProcessRequest("ProcessMetaService", BlockMetaServiceType.GetInnerWeb,
                                null, null);
                        }
                        else
                        {
                            newWeb = new BlockWeb(id, DefaultBroker);
                        }

                        TemplateProcessor.ProcessTemplateFile(element, newWeb, blockId, connector);
                        ProcessNodeChildren(element, newWeb, blockId, connector);

                        return newWeb;
                    }
                case "actions":
                    {
                        TemplateProcessor.ProcessTemplateFile(element, blockWeb, blockId, connector);

                        ProcessNodeChildren(element, blockWeb, blockId, connector);

                        break;
                    }
                case "blocks":
                    {
                        TemplateProcessor.ProcessTemplateFile(element, blockWeb, blockId, connector);

                        ProcessNodeChildren(element, blockWeb, blockId, connector);

                        break;
                    }
                case "block":
                    {
                        BlockHandle cid = ObjectReader.ReadBlockHandle(element);
                        string id = null;

                        if (element.HasAttribute("id"))
                        {
                            id = element.GetAttribute("id");
                        }
                        else
                        {
                            id = "ctl_" + (Guid.NewGuid().ToString());
                        }

                        blockWeb.AddBlock(cid, id);

                        TemplateProcessor.ProcessTemplateFile(element, blockWeb, id, connector);

                        ProcessNodeChildren(element, blockWeb, id, connector);

                        //(blockWeb[id] as IContainedBlock).OnAfterLoad();

                        break;
                    }
                case "attachEndPoint":
                    {
                        EndPointExtractor.ProcessAttachEndPointsAction(element, blockWeb, blockId);

                        break;
                    }
                case "processRequest":
                    {
                        ActionProcessor.ProcessProcessRequest(element, blockWeb, blockId);

                        break;
                    }
                case "setProperty":
                    {
                        ActionProcessor.ProcessSetProperty(element, blockWeb, blockId);

                        break;
                    }
                case "setVariable":
                    {
                        ActionProcessor.ProcessSetVariable(element, blockWeb, blockId);

                        break;
                    }
                case "serviceEndPoint":
                case "valueEndPoint":
                case "connectorEndPoint":
                    {
                        EndPointExtractor.ProcessAttachEndPoint(blockWeb, connector, element, blockId);

                        break;
                    }
            }

            return null;
        }
Exemplo n.º 33
0
        public bool Connect(IBlockWeb web, string peerId)
        {
            if (web.Id != peerId) return false;

            peers.Add(peerId, web);

            //also inform other peer
            web.Connect(this, Id);

            return true;
        }