예제 #1
0
        /// <summary>
        /// Given a trace id or a previous link return the previous link.
        /// </summary>
        /// <typeparam name="TLinkData"></typeparam>
        /// <param name="input">       .traceId the id of the trace </param>
        /// <returns>The <see cref="Task{TraceLink{TLinkData}}"/></returns>
        public async Task <TraceLink <TLinkData> > GetHeadLinkAsync <TLinkData>(ParentLink <TLinkData> input)
        {
            TraceLink <TLinkData> headLink = input.PrevLink;

            // if prevLink was not provided
            if (headLink == null && input.TraceId != null)
            {
                Dictionary <String, object> variables = new Dictionary <String, object>
                {
                    { "traceId", input.TraceId }
                };
                string query = GraphQL.QUERY_GETHEADLINK;
                // execute graphql query
                GraphQLResponse <dynamic> jsonResponse = await this.client.GraphqlAsync(query, variables, null, null);

                var trace = jsonResponse.Data.trace;

                string raw = trace.head.raw.ToString();

                TLinkData data = JsonHelper.ObjectToObject <TLinkData>(trace.head.data);

                // convert the raw response to a link object
                headLink = new TraceLink <TLinkData>(Stratumn.Chainscript.Link.FromObject(raw), data);
            }
            if (headLink != null)
            {
                return(headLink);
            }
            else
            {
                throw new TraceSdkException("Previous link or trace Id must be provided");
            }
        }
예제 #2
0
        private void OnContextMenuItemClick(object sender, EventArgs e)
        {
            ToolStripMenuItem item = (ToolStripMenuItem)sender;

            if (item.Tag is ToExchange)
            {
                ToExchange exchange = (ToExchange)item.Tag;

                CodeBinaryOperatorExpression expression = ParentLink.GetParent(exchange.original);

                if (ParentLink.GetSide(exchange.original) == ParentSide.Left)
                {
                    expression.Left = exchange.newExpression;
                }
                else
                {
                    expression.Right = exchange.newExpression;
                }

                this.DisableButtons(exchange.original);

                this.highlightedAreas.Clear();
                this.Refresh();

                this.CheckEvaluateButtonEnable();
            }
        }
예제 #3
0
        private void OnSetValueClick(object sender, EventArgs e)
        {
            ToolStripMenuItem item = (ToolStripMenuItem)sender;

            ToExchange exchange = (ToExchange)item.Tag;

            ToolStripTextBox textBox = exchange.valueBox;

            object primitiveObject = null;

            try
            {
                primitiveObject = Convert.ChangeType(textBox.Text, EvaluatorGenerator.GetType(exchange.original, true));
            }
            catch (FormatException)
            {
                MessageBox.Show(string.Format("Could not convert '{0}' to object of type '{1}'.  Please enter a value into the textbox in the context menu.", textBox.Text, EvaluatorGenerator.GetType(exchange.original, false)));
                return;
            }

            CodePrimitiveExpression replacement = new CodePrimitiveExpression(primitiveObject);

            replacement.UserData.Add(typeof(ButtonAndMenuData), exchange.original.UserData[typeof(ButtonAndMenuData)]);
            EvaluatorGenerator.SetType(replacement, EvaluatorGenerator.GetType(exchange.original, true));
            EvaluatorGenerator.SetParameterIndex(replacement, EvaluatorGenerator.GetParameterIndex(exchange.original, true));

            CodeBinaryOperatorExpression expression = ParentLink.GetParent(exchange.original);

            if (ParentLink.GetSide(exchange.original) == ParentSide.Left)
            {
                expression.Left = replacement;
            }
            else
            {
                expression.Right = replacement;
            }

            ToolStripMenuItem menuItem = new ToolStripMenuItem(textBox.Text);

            menuItem.Tag    = new ToExchange(exchange.original, replacement);
            menuItem.Click += OnContextMenuItemClick;
            List <ToolStripItem> menuItems = ButtonAndMenuData.GetMenuItems(exchange.original);

            menuItems.Insert(1, menuItem);

            if (menuItems.Count > 3 + 1 + 5)
            {
                menuItems.RemoveAt(6);
            }

            textBox.Clear();

            this.highlightedAreas.Clear();
            this.Refresh();
            this.CheckEvaluateButtonEnable();
        }
예제 #4
0
        public void Feeder_AddToDownloadQueue()
        {
            BlockingCollection <ParentLink>     _newLinks        = new BlockingCollection <ParentLink>(new ConcurrentQueue <ParentLink>(), 1000);
            BlockingCollection <ParentLink>     _downloadQueue   = new BlockingCollection <ParentLink>(new ConcurrentQueue <ParentLink>(), 1000);
            BlockingCollection <DownloadResult> _downloadResults = new BlockingCollection <DownloadResult>(new ConcurrentQueue <DownloadResult>(), 10);
            var seedParentLink = new ParentLink(Const.SEED, null);

            var feeder = new Feeder(_newLinks, _downloadQueue, 1, 1, new MockProgess());

            feeder.Start();
            _newLinks.Add(seedParentLink);

            Thread.Sleep(40);
            Assert.IsTrue(_newLinks.Count == 0);
            Assert.AreEqual(_downloadQueue.First(), seedParentLink);
            _downloadQueue.Take();
            feeder.Stop();
            Thread.Sleep(1000);
        }
예제 #5
0
        public void FeederTest_NoDuplicateLinks()
        {
            Assert.Empty(Crawler.NewLinks);
            Assert.Empty(Crawler.DownloadQueue);
            Assert.Empty(Crawler.DownloadResults);

            const string mockSeed        = "https://seed.co.za/";
            const string link2           = "https://seed.co.za/link2/";
            const string link3           = "https://seed.co.za/link3/";
            var          seedParentLink  = new ParentLink(mockSeed, null);
            var          link2ParentLink = new ParentLink(link2, 1);
            var          link3ParentLink = new ParentLink(link3, 1);
            var          mockProgrss     = new MockProgess();

            var feeder = new Feeder(1, 1, mockProgrss);

            feeder.Start();
            Crawler.NewLinks.Add(seedParentLink);
            Crawler.NewLinks.Add(link2ParentLink);
            Crawler.NewLinks.Add(link3ParentLink);
            Crawler.NewLinks.Add(link2ParentLink);
            Crawler.NewLinks.Add(link3ParentLink);
            Crawler.NewLinks.Add(link3ParentLink);
            Crawler.NewLinks.Add(link2ParentLink);
            Crawler.NewLinks.Add(link3ParentLink);
            Crawler.NewLinks.Add(link2ParentLink);

            Thread.Sleep(100);
            Assert.Empty(Crawler.NewLinks);
            //should only have 2 items, the duplicate shouldn't come through.
            Assert.Equal(3, Crawler.DownloadQueue.Count);

            //the links should come in the order they were added.
            Assert.Equal(mockSeed, Crawler.DownloadQueue.Take().Link);
            Assert.Equal(link2, Crawler.DownloadQueue.Take().Link);
            Assert.Equal(link3, Crawler.DownloadQueue.Take().Link);

            feeder.Stop();
            Thread.Sleep(1000);

            Assert.Empty(Crawler.NewLinks);
            Assert.Empty(Crawler.DownloadQueue);
        }
        /// <summary>
        /// The following properties are picked up in BtsBaseComponent:
        ///
        /// BaseNode attributes:
        /// OID
        /// ParentLink
        /// Type
        /// Signal
        ///
        /// BaseNode child elements:
        /// ReportToAnalyst
        /// AnalystComments
        /// Name
        ///
        /// </summary>
        internal void GetCommonOrchProperties()
        {
#if DOM
            _oid    = new Guid(this._baseNode.Attributes["OID"].Value);
            _typeId = this._baseNode.Attributes["Type"].Value;
            _report = this.GetNamedItemValueAsBool("om:Property[@Name='ReportToAnalyst']", String.Empty);

            XmlAttribute attr;

            //returns empty string if null, which can happen also if AnalystComments doesn't exist?
            this._desc = this.GetNamedItemValue("om:Property[@Name='AnalystComments']");

            //shape name
            this._name = this.GetNamedItemValue("om:Property[@Name='Name']");

            this._signal = this.GetNamedItemValueAsBool("om:Property[@Name='Signal']");

            //parent link
            try
            {
                attr = this._baseNode.Attributes["ParentLink"];
                if (null == attr)
                {
                    _parentLinkRef = "(none)";
                    _parentLink    = ParentLink.None;
                }
                else
                {
                    _parentLinkRef = attr.Value;
                    _parentLink    = this.DetermineParentLink(_parentLinkRef);
                }
            }
            catch (Exception ee)
            {
                ///TODO: standardized exception handling here
#if DEBUG
                Debugger.Break();
#endif
            }
#endif //dom
        }
예제 #7
0
        private string GetLocalizedAssetsFolderName(string name)
        {
            ISiteDefinitionRepository definitionRepository = this.GetSiteDefinitionRepository();
            LocalizationService       localizationService  = this.GetLocalizationService();

            if (definitionRepository != null && localizationService != null)
            {
                foreach (SiteDefinition siteDefinition in definitionRepository.List())
                {
                    if (ParentLink.CompareToIgnoreWorkID(siteDefinition.GlobalAssetsRoot))
                    {
                        return(localizationService.GetString("/episerver/cms/widget/hierachicallist/roots/globalroot/label", name));
                    }

                    if (ParentLink.CompareToIgnoreWorkID(siteDefinition.SiteAssetsRoot))
                    {
                        return(localizationService.GetString("/episerver/cms/widget/hierachicallist/roots/siteroot/label", name));
                    }
                }
            }

            return(name);
        }
        internal BtsBaseComponent(XmlReader reader)
        {
            try
            {
                //we only want to do this if we haven't initialized yet
                if (reader.HasAttributes && reader.AttributeCount < 1)
                {
                    reader.Read();
                }

                _oid        = new Guid(reader.GetAttribute("OID"));
                _parentLink = GetParentLink(reader.GetAttribute("ParentLink"));
                _typeId     = reader.GetAttribute("Type");
            }
            catch (Exception e)
            {
#if DEBUG
                Debug.WriteLine("[BtsBaseComponent.ctor] An exception of type " + e.GetType().ToString() +
                                " has occured: " + e.Message);
                Debugger.Break();
#endif
            }
        }
예제 #9
0
        public void FeederTest_NoDuplicateLinks()
        {
            BlockingCollection <ParentLink> _newLinks      = new BlockingCollection <ParentLink>(new ConcurrentQueue <ParentLink>(), 1000);
            BlockingCollection <ParentLink> _downloadQueue = new BlockingCollection <ParentLink>(new ConcurrentQueue <ParentLink>(), 1000);

            var seedParentLink  = new ParentLink(Const.SEED, null);
            var link2ParentLink = new ParentLink(Const.LINK1, 1);
            var link3ParentLink = new ParentLink(Const.LINK2, 1);
            var mockProgrss     = new MockProgess();

            var feeder = new Feeder(_newLinks, _downloadQueue, 1, 1, mockProgrss);

            feeder.Start();
            _newLinks.Add(seedParentLink);
            _newLinks.Add(link2ParentLink);
            _newLinks.Add(link3ParentLink);
            _newLinks.Add(link2ParentLink);
            _newLinks.Add(link3ParentLink);
            _newLinks.Add(link3ParentLink);
            _newLinks.Add(link2ParentLink);
            _newLinks.Add(link3ParentLink);
            _newLinks.Add(link2ParentLink);

            Thread.Sleep(100);
            Assert.IsTrue(_newLinks.Count == 0);
            //should only have 2 items, the duplicate shouldn't come through.
            Assert.AreEqual(3, _downloadQueue.Count);

            //the links should come in the order they were added.
            Assert.AreEqual(Const.SEED, _downloadQueue.Take().Link);
            Assert.AreEqual(Const.LINK1, _downloadQueue.Take().Link);
            Assert.AreEqual(Const.LINK2, _downloadQueue.Take().Link);

            feeder.Stop();
            Thread.Sleep(1000);
        }
예제 #10
0
        public void Feeder_AddToDownloadQueue()
        {
            Assert.Empty(Crawler.NewLinks);
            Assert.Empty(Crawler.DownloadQueue);

            const string mockSeed       = "https://seed.co.za/";
            var          seedParentLink = new ParentLink(mockSeed, null);

            var feeder = new Feeder(1, 1, new MockProgess());

            feeder.Start();
            Crawler.NewLinks.Add(seedParentLink);

            Thread.Sleep(40);
            Assert.Empty(Crawler.NewLinks);
            Assert.Single(Crawler.DownloadQueue, seedParentLink);
            Crawler.DownloadQueue.Take();
            feeder.Stop();
            Thread.Sleep(1000);

            Assert.Empty(Crawler.NewLinks);
            Assert.Empty(Crawler.DownloadQueue);
            Assert.Empty(Crawler.DownloadResults);
        }