jurassic icon indicating copy to clipboard operation
jurassic copied to clipboard

Nesned class exposing

Open HakanKaraoglu opened this issue 4 years ago • 2 comments

Hi, I have two different class nested class

public class FeedKeywordProxy
    {
        private int workspaceId;
        private KeywordProxy keyword;        
    }

and

public class ScriptableKeywords 
    {        
        public FeedKeywordProxy[] keywords {get;set;}
        
        public bool jsFunction_hasText(string keyword)
        {
            if (this.keywords == null || this.keywords.Length == 0)
            {
                return false;
            }
            bool retval = false;
            foreach (FeedKeywordProxy kw in this.keywords)
            {
                //  TODO equals case insensitive?
                if ((kw.getKeyword() != null) && ((kw.getKeyword().getText() != null) && kw.getKeyword().getText().Equals(keyword)))
                {
                    retval = true;
                    break;
                }
            }

            return retval;
        }

        
        public bool jsFunction_hasId(int keywordId)
        {
            if (this.keywords == null || this.keywords.Length == 0)
            {
                return false;
            }
            bool retval = false;
            foreach (FeedKeywordProxy kw in this.keywords)
            {
                if ((kw.getKeyword().getId() == keywordId))
                {
                    retval = true;
                    break;
                }
            }
            return retval;
        }
 }

How can I expose this nested class.?

HakanKaraoglu avatar Sep 16 '20 19:09 HakanKaraoglu

Can you clarify what you are looking to do?

paulbartrum avatar Sep 18 '20 03:09 paulbartrum

@paulbartrum of course. Now, I have three classes (ScriptableFeed, ScriptableFeeder and ScriptableKeywords). My goal is to fill the classes with parameters and convert them into a js class, then run the rule expressions created on the screen. And then i run the following step. I hope I was able to explain my problem :)

string ruleExpression = "keywords.hasId(33159) && keywords.hasId(33158)";
var engine = new Jurassic.ScriptEngine();
engine.SetGlobalValue("feed",new ScriptableFeed(engine));
engine.SetGlobalValue("feeder",new ScriptableFeeder(engine));
engine.SetGlobalValue("keywords", new ScriptableKeywords(engine));

ScriptableFeeder feederScope =new ScriptableFeeder(engine);
feederScope.setUsername("Test");
feederScope.setName("Test");
feederScope.setKlout(1);
feederScope.setFollowercount(100);

ScriptableFeed feedScope = new ScriptableFeed(engine);
feedScope.setText("lorem ipsum dolar sit amet");
feedScope.setLang("en");
feedScope.setFeedType("Reply");
feedScope.setSentiment(1);
feedScope.setAuthor("Test Data");

feedScope.setFeeder(feederScope);
feedScope.setSource(1);

var kwList = new List<FeedKeywordProxy>();
var kw = new FeedKeywordProxy();
kw.setKeyword(new KeywordProxy(33158, "sit"));
kw.setWorkspaceId(66);

var kw1 = new FeedKeywordProxy();
kw1.setKeyword(new KeywordProxy(33159, "amet"));
kw1.setWorkspaceId(66);

kwList.Add(kw1);

ScriptableKeywords keywordsScope = new ScriptableKeywords(engine);
keywordsScope.setKeywords(kwList.ToArray());

engine.Evaluate("String.prototype.contains = function(str) { return this.indexOf(str) !== -1; };");

var state=engine.Evaluate<bool>(ruleExpression);
public class ScriptableFeed : ObjectInstance
    {

        public ScriptableFeed(ScriptEngine engine):base(engine)
        {

        }

        private string text;
        private string lang;
        private int klout;
        private int sentiment;
        private string author;
        private int source;
        private string feedType;
        private ScriptableFeeder feeder;
        private string instagramLocation;
        private string instagramTags;

        
        public void setText(string text)
        {
            this.text = text;
        }

        public void setLang(string lang)
        {
            this.lang = lang;
        }

        public void setAuthor(string author)
        {
            this.author = author;
        }

        public void setSentiment(int sentiment)
        {
            this.sentiment = sentiment;
        }

        public void setKlout(int klout)
        {
            this.klout = klout;
        }

        public void setSource(int source)
        {
            this.source = source;
        }

        [JSFunction(Name = "text")]
        public string jsGet_text()
        {
            return this.text;
        }

        [JSFunction(Name = "lang")]
        public string jsGet_lang()
        {
            return this.lang;
        }

        [JSFunction(Name = "sentiment")]
        public int jsGet_sentiment()
        {
            return this.sentiment;
        }

        [JSFunction(Name = "klout")]
        public int jsGet_klout()
        {
            return this.klout;
        }

        [JSFunction(Name = "source")]
        public int jsGet_source()
        {
            return this.source;
        }

        [JSFunction(Name = "author")]
        public string jsGet_author()
        {
            return this.author;
        }

        [JSFunction(Name = "feeder")]
        public ScriptableFeeder jsGet_feeder()
        {
            return feeder;
        }

        public void setFeeder(ScriptableFeeder feeder)
        {
            this.feeder = feeder;
        }

        public void setFeedType(string feedType)
        {
            this.feedType = feedType;
        }

        [JSFunction(Name = "feedType")]
        public string jsGet_feedType()
        {
            return this.feedType;
        }

        [JSFunction(Name = "instagramLocation")]
        public string jsGet_instagramLocation()
        {
            return this.instagramLocation;
        }

        public void setInstagramLocation(string instagramLocation)
        {
            this.instagramLocation = instagramLocation;
        }

        [JSFunction(Name = "instagramTags")]
        public string jsGet_instagramTags()
        {
            return this.instagramTags;
        }

        public void setInstagramTags(string instagramTags)
        {
            this.instagramTags = instagramTags;
        }

    }
public ScriptableFeeder(ScriptEngine engine) : base(engine)
		{

		}

		private string name;
		private string username;
		private int klout;
		private int followercount;

		[JSFunction(Name = "name")]
		public string jsGet_name()
		{
			return name;
		}

		public void setName(string name)
		{
			this.name = name;
		}

		[JSFunction(Name = "username")]
		public string jsGet_username()
		{
			return username;
		}

		public void setUsername(string username)
		{
			this.username = username;
		}

		[JSFunction(Name = "klout")]
		public int jsGet_klout()
		{
			return klout;
		}

		public void setKlout(int klout)
		{
			this.klout = klout;
		}

		[JSFunction(Name = "followercount")]
		public int jsGet_followercount()
		{
			return followercount;
		}

		public void setFollowercount(int followercount)
		{
			this.followercount = followercount;
		}
	}
public class ScriptableKeywords : ObjectInstance
    {

        public ScriptableKeywords(ScriptEngine engine) : base(engine)
        {
            this.PopulateFields();
            this.PopulateFunctions();
        }


        private FeedKeywordProxy[] keywords;

        public void setKeywords(FeedKeywordProxy[] keywords)
        {
            this.keywords = keywords;
        }

        [JSFunction(Name = "hasText")]
        public bool jsFunction_hasText(string keyword)
        {
            if (this.keywords == null || this.keywords.Length == 0)
            {
                return false;
            }
            bool retval = false;
            foreach (FeedKeywordProxy kw in this.keywords)
            {
                if ((kw.getKeyword() != null) && ((kw.getKeyword().getText() != null)
                            && kw.getKeyword().getText().Equals(keyword)))
                {
                    retval = true;
                    break;
                }

            }

            return retval;
        }

        [JSFunction(Name = "hasId")]
        public bool jsFunction_hasId(int keywordId)
        {
            if (this.keywords == null || this.keywords.Length == 0)
            {
                return false;
            }
            bool retval = false;
            foreach (FeedKeywordProxy kw in this.keywords)
            {
                if ((kw.getKeyword().getId() == keywordId))
                {
                    retval = true;
                    break;
                }

            }

            return retval;
        }

    }
public class FeedKeywordProxy
    {

        private int workspaceId;
        private KeywordProxy keyword;

        public KeywordProxy getKeyword()
        {
            return keyword;
        }
        public void setKeyword(KeywordProxy keyword)
        {
            this.keyword = keyword;
        }

        public int getWorkspaceId()
        {
            return workspaceId;
        }
        public void setWorkspaceId(int workspaceId)
        {
            this.workspaceId = workspaceId;
        }
    }

HakanKaraoglu avatar Sep 18 '20 13:09 HakanKaraoglu