Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nesned class exposing #189

Open
HakanKaraoglu opened this issue Sep 16, 2020 · 2 comments
Open

Nesned class exposing #189

HakanKaraoglu opened this issue Sep 16, 2020 · 2 comments
Labels

Comments

@HakanKaraoglu
Copy link

HakanKaraoglu commented Sep 16, 2020

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.?

@paulbartrum
Copy link
Owner

Can you clarify what you are looking to do?

@HakanKaraoglu
Copy link
Author

HakanKaraoglu commented Sep 18, 2020

@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;
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants