The nodes have existed.
I tried to add edges by unwind,but my function importBuyConnectionIntoNeo4j didn't work,
Is there any one can help me?
the data structure:
class Connection
{
private string type;
public string Type
{
get { return type; }
set { type = value; }
}
private string source;
public string Source
{
get { return source; }
set { source = value; }
}
private string target;
public string Target
{
get { return target; }
set { target = value; }
}
}
class BuyConnection:Connection
{
}
myFunction:
public void importBuyConnectionIntoNeo4j(List<BuyConnection> connectionList)
{
GraphClient client = createConnectionToNeo4j();
client.Cypher
.Unwind(connectionList, "connection")
.Match("(source:Person),(target:Vegetable)")
.Where("source.Name=connection.Source AND target.Type=connection.Target")
.Create("(source)-[:Buy]->(target)")
.ExecuteWithoutResults();
}
I think the issue is with your .where text:
.Where("source.Name=connection.Source AND target.Type=connection.Target")
is the Source and Target the right way around?
Related
I have a custom class that gets some data from the web.
When I get this data I want to set it to the value of a property but when I do this unity crashes. The commented line generates the crash without this line everything works fine. See my code below:
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
public class GetDB
{
private readonly Main m;
private readonly string Url;
public string DBData {
get
{
if(DBData == null)
return null;
else
return DBData;
}
private set
{
DBData = value;
}
}
public GetDB(Main m, string url)
{
this.m = m;
this.Url = url;
}
public void GetServerData(){
m.StartCoroutine(GetText(Url, (result) =>{
this.DBData = result; //THIS LINE CRASHES UNITY
Debug.Log(result);
}));
}
IEnumerator GetText(string url, Action<string> result) {
UnityWebRequest www = UnityWebRequest.Get(url);
yield return www.SendWebRequest();
if(www.isNetworkError || www.isHttpError) {
Debug.Log(www.error);
}
else {
if (result != null)
result(www.downloadHandler.text);
}
}
}
How would I go about fixing this, and what exactly is happening here?
If anything is unclear let me know so I can clarify.
You have to use a backing field for the property:
string _dbData;
public string DBData
{
get
{
if(_dbData == null)
return null;
else
return _dbData;
}
private set
{
_dbData= value;
}
}
A property is just syntactic sugar for a getter and setter methods. So you can rewrite your property like:
public string GetDBData()
{
if(_dbData == null)
return null;
else
return _dbData;
}
public void SetDBData(string value)
{
_dbData = value;
}
The way you have implemented the property:
public void SetDBData(string value)
{
// you will never get out of here
SetDBData(value);
}
Properties act as accessors for variables. What is happening in your case is basically an endless loop - whenever somebody tries to get the value of your property, it keeps returning the property itself. Instead, you want a backing field _dbData:
private string _dbData;
public string DBData
{
get
{
return _dbData;
}
private set
{
_dbData = value;
}
}
Now your property controls the accesss to this field.
Your accessor can be really simplified.
Doing :
get
{
if(DBData == null)
return null;
else
return DBData;
}
Will provide exactly the same result than doing :
get
{
return DBData; //if DBData is null, it will return null
}
So, you can write your accessor that way :
public string DBData
{
get;
private set;
}
I've been working on this app about trees and have found myself stuck. What I have is a Tree class with some attributes to it, like ID, type and others. I need to be able to make a List or some other structure of a user-entered number of trees and have each tree be separately modified (in terms of its attributes). Now a problem I ran into is the fact that I need to have separate attributes for each tree each year (2017, 2018 and so on) since the installation of the app. I seem to not be able to think of a viable solution for this to work. How would I set separate attributes for each year? Hell, how would I even check when a new year is and update the list accordingly? I need the yearly attributes because I need to label a tree that hasn't had problems the past five years as "strong".
Here's the code for my simple Tree class:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Tree : MonoBehaviour {
public string leafType { get { return leafType; } set { } }
public string leafGender { get { return leafGender; } set { } }
public string fruitType { get { return fruitType; } set { } }
public string fruitProblems { get { return fruitProblems; } set { } }
public string bloomingStart { get { return bloomingStart; } set { } }
public string bloomingEnd { get { return bloomingEnd; } set { } }
public string kgHazelnutPerYear { get { return kgHazelnutPerYear; } set { } }
public string problemsInLeaf { get { return problemsInLeaf; } set { } }
public string pests { get { return pests; } set { } }
public string usedPesticides { get { return usedPesticides; } set { } }
public string altitude { get { return altitude; } set { } }
public string region { get { return region; } set { } }
}
Thanks in advance!
you can use Dictionary to manipulate it like bellow
void addYear(string year, Dictionary<string, List<YourTreeClass>> data)
{
if (!data.ContainsKey(year)) data.Add(year, new List<YourTreeClass>());
}
void addTree(string year,YourTreeClass tree, Dictionary<string, List<YourTreeClass>> data)
{
data[year].Add(tree);
}
Dictionary<string, List<YourTreeClass>> data = new Dictionary<string, List<YourTreeClass>>();
addYear("2017", data);
addTree("2017", tree1, data);
addTree("2017", tree2, data);
addYear("2018", data);
addTree("2018", tree3, data);
I have a class that is used for storing user data to a file. It works well, but can't really be placed into a PCL library easily. Outside of the PCL, it's all fine.
The class looks like this
public static class UserData
{
public static object GetPropertyValue(this object data, string propertyName)
{
return data.GetType().GetProperties().Single(pi => pi.Name == propertyName).GetValue(data, null);
}
public static object SetPropertyValue<T>(this object data, string propertyName, T value)
{
data.GetType().GetProperties().Single(pi => pi.Name == propertyName).SetValue(data, value);
return new object();
}
private static string pUserSettingsFile;
private static UserSettings userSetting;
public static bool AccountEnabled
{
get
{
return UserSettings.account_enabled;
}
set
{
UserSettings settings = UserSettings;
settings.account_enabled = value;
UserSettings = settings;
}
}
public static UserSettings UserSettings
{
get
{
if (userSetting == null)
{
if (File.Exists(UserSettingsFile))
{
userSetting = Serializer.XmlDeserializeObject<UserSettings>(UserSettingsFile);
}
else
{
userSetting = new UserSettings();
Serializer.XmlSerializeObject(userSetting, UserSettingsFile);
}
}
return userSetting;
}
set
{
if (value == null)
{
throw new ArgumentNullException("value is null!");
}
userSetting = value;
if (File.Exists(UserSettingsFile))
{
File.Delete(UserSettingsFile);
}
Serializer.XmlSerializeObject(userSetting, UserSettingsFile);
}
}
public static string UserSettingsFile
{
get
{
if (string.IsNullOrEmpty(pUserSettingsFile))
{
pUserSettingsFile = Path.Combine(GroupShootDroid.Singleton.ContentDirectory, "UserSettings.xml");
}
return pUserSettingsFile;
}
}
#endregion
}
public class UserSettings
{
public bool account_enabled { get; set; }
public string address { get; set; }
public string country { get; set; }
}
It's not rocket science, but does what I need it to do.
What I'm trying to do is use the Get/SetPropertyValue methods to return or set any of the properties within the class.
Currently, to access the Get/SetPropertyValue methods I'm using this
public string GetStringValue(string valToGet)
{
string rv = (string)UserData.GetPropertyValue(valToGet);
return rv;
}
public void SetStringValue(string name, string val)
{
UserData.SetPropertyValue(name, val);
}
On compiling though, the GetPropertyValue method is giving an error that No overload for method GetPropertyValue takes 1 argument with the SetPropertyValue complaining that there isn't an overload that takes 2
I'm not sure that the code I'm using will do what I need it to do (from what I've read on here it should be), but I'm more perplexed as to why the errors are showing.
Is there a better way to do what I'm trying to do? The application is a Xam.Forms app, so the PCL accesses the class through an interface using injection.
You are defining extension method, you need an instance of the class to call them:
var o = new Object();
string rv = (string)o.GetPropertyValue(valToGet);
// or, but no sure
string rv = (string)UserData.GetPropertyValue(o, valToGet);
or more probably in your case:
public string GetStringValue(string valToGet)
{
string rv = (string)this.GetPropertyValue(this, valToGet);
//or
//string rv = (string)UserData.GetPropertyValue(this, valToGet);
return rv;
}
I think you're getting confused between the UserData class and the object class. Your extension methods extend object.
I'm using JavascriptSerializer to convert the list into string, but its not working and its throwing an error as Recursion Limit Exceeded. I have searched a lot but i didn't found any solutions to overcome this issue.
My conversion is like below
List<CustomType> _customValues= serializer.ConvertToType<List<CustomType>>(dictionary["CustomValues"]);
string CustomString = new JavaScriptSerializer().Serialize(_customValues);
EDIT
My custom type is below
public class CustomType
{
private string _name;
public string Name
{
get
{ return _name; }
set
{
if (this._name != value)
{
this._name= value;
}
}
}
private double _mark;
public double Mark
{
get
{ return _mark; }
set
{
if (this._mark!= value)
{
this._mark= value;
}
}
}
private int _id;
public int Id
{
get
{ return _id; }
set
{
if (this._id!= value)
{
this._id= value;
}
}
}
}
How can i convert that list into string?.
How can i overcome this issue?.
Thanks,
Karthik
Use a JSON Serializer that ignores circular references. System.Web.Script.Serialization.JavaScriptSerializer can't ignore circular references and will easily get stuck in recursion and reach recursion limit.
I have generic class that should be a tree and I want to inherit the class like this:
public class Tree<T> {
private HashSet<Tree<T>> leaves;
private T data;
public Tree() {
leaves = new HashSet<Tree<T>>();
}
public Tree(T data) : this() {
this.data = data;
}
public T Data {
get {
return this.data;
}
set {
data = value;
}
}
public virtual Tree<T> findInLeaves(T data) {
foreach(Tree<T> leaf in leaves) {
if(leaf.Data.Equals(data)) {
return leaf;
}
}
return null;
}
}
public class ComboTree : Tree<IComboAction> {
private ComboMovement movement;
public ComboTree() : base() {
Movement = null;
}
public ComboTree(IComboAction action) : base(action) {
Movement = null;
}
public ComboMovement Movement {
get {
return this.movement;
}
set {
movement = value;
}
}
}
Putting data works well, but when I try to use method findInLeaves I always get null. I understand there is a problem with type casting, but why if ComboTree inherits Tree?
void readMove(IComboAction action) {
ComboTree leaf = (ComboTree)currentLeaf.findInLeaves(action);
}
Question is why and how to fix it?
Edit: I created console program, run it and it works. So this must be my engine problem!
public ComboTree(IComboAction action)
: base(action)
{
Movement = null; // <---- You are nulling Movement in the second constructor
}