Neo4jclient where is this class - Neo4jDataRepository? - c#

I am trying to batch insert relationships into neo4j database using the Neo4jclient for c#. I found this code by user dcinzona. I am looking through the latest source code and can't find this class Neo4jDataRespository anywhere. Is this a custom class created by this user or am I missing something?
string merge1 = string.Format("c:{0} {{{1}:row.{2}}}", IDFieldLeft.Replace("Id", ""), IDFieldLeft, IDFieldLeft);
string merge2 = string.Format("a:{0} {{{1}:row.{2}}}", IDFieldRight.Replace("Id", ""), IDFieldRight, IDFieldRight);
string merge3 = string.Format("(c)-[r:{0} {{row}}]->(a)", entityName);
foreach (var list in Neo4jDataRepository.Batch(relationshipMatrix, 1000))
{
var query = client
.Cypher
.WithParam("coll", list.ToList())
.ForEach("(row in {coll})")//manually create json array of list objects
.Merge(merge1)
.Merge(merge2)
.Merge(merge3);
query.ExecuteWithoutResults();
}

This is a custom class created by that user, it's not part of Neo4jClient.
I'm not sure what they've done, and I've not seen it referenced anywhere else but by them I'm afraid :/

Related

Selenium C# Find Element with class and text

im very new to testing and have no training in automated tests so please bare with me if i say stupid things but ill try the best i can.
Bascially i am trying to assert that a specific employee in the employee list has the status of 'leaver'.
This is what i have tried (and other variations with the different classes)
Assert.Equal("image-tile__badge background-color--status-leaver ng-star-inserted", Driver.FindElement(By.XPath("//*[contains(#class,'image-tile__content-header') and contains(text(),'End Date, Contract') and contains(#class, 'image-tile__badge')]")).GetAttribute("Class"));
Assert.Equal("image-tile__badge background-color--status-leaver ng-star-inserted", Driver.FindElement(By.XPath("//*[contains(#class,'image-tile__content-header') and contains(text(),'End Date, Contract')]")).FindElement(By.XPath("//*[contains(#class, 'image-tile__badge')]")).GetAttribute("Class"));
The last one finds the element when the status is 'new', but when i change the employee status to 'leaver', it still returns as 'new' so possibly looking at another employee with a 'new' status.
Hopefully this is enough info, let me know if more is needed (this is my first ever post!)
HTML code in image below
[HTML code on Chrome]
[1]: https://i.stack.imgur.com/kUxkf.png
Summary: im trying to assert that the Employee "End Date, Contract" has the status of leaver (aka the leaver class "image-tile__badge background-color--status-leaver ng-star-inserted")
Thanks everyone for their help!
One of my devs managed to take #noldors example and modify it a bit so heres what ended up working for me:
var newElmList1 = Driver.FindElements(By.CssSelector("div.background-color--status-leaver")).ToList();
List<string> newNames1 = new List<string>();
foreach (var newElm in newElmList1)
{
var newName1 = newElm.FindElement(By.XPath(".."))
.FindElement(By.CssSelector("div.image-tile__content-header")).Text;
newNames.Add(newName1);
}
if (!newNames.Contains("End Date, Contract"))
{
throw new Exception("Exception Error on leaver Person");
}
As per your screenshot i fill it's better if you try using Xpath
var elmList = Driver.FindElements(By.Xpath("//div[contains(text(),'leaver')]")).ToList();
i hope it will help you
Thank You.
According to your screenshot, you can find all elements with 'Leaver' specific class with this;
var leaverElmList = Driver.FindElements(By.CssSelector("div.background-color--status-leaver")).ToList();
List<string> leaverNames = new List<string>();
foreach (var leaverElm in leaverElmList) {
var leaverName = leaverElm.FindElement(By.XPath(".."))
.FindElement(By.CssSelector("div.image-tile__content-header"));
.Text()
leaverNames.Add(leaverName);
}
Enddate, Contract which is not related to the div that contains Leaver. It's direct parent is the image-tile div

How do I delete an Index using NEST 7.4.1?

I am new to Elastic search and I have written code to index a list of City. I am using "elasticsearch head" add-on for chrome to check and manipulate the indexes and _doc.
While indexing and CRUD operation of doc is resulting correctly, I had to delete the index manually via elastic-search add-on.
I want to check for the index first, if an index is available, delete it, and create the index & index the list of City again. This is what I want to do. But getting an error in Delete() method saying
argument 1: cannot convert from string to Nest.IDeleteRequest
Following is my code to show you what I am doing:
public async Task<List<BulkResponseItemBase>> AddNewIndex(string index_name, List<City> model)
{
client = new ElasticClient(elstcstngs);
List<BulkResponseItemBase> elstcManyrespoStatusList = new List<BulkResponseItemBase>();
if (await CheckIndexExists(index_name))
{
//This is where I am getting error - Cannot Convert from string to Nest.IDeleteRequest
client.Delete(index_name);
}
elstcstngs.DefaultMappingFor<City>(m => m.IndexName(index_name));
BulkResponse elstcManyrespoStatus = await client.IndexManyAsync<City>(model, null);
if (elstcManyrespoStatus.Errors)
{
foreach (var itemWithError in elstcManyrespoStatus.ItemsWithErrors)
{
elstcManyrespoStatusList.Add(itemWithError);
System.Diagnostics.Debug.WriteLine("Failed to index document {0}: {1}", itemWithError.Id, itemWithError.Error);
}
}
return elstcManyrespoStatusList;
}
I have searched the Elastic search Documentation but could not find any API in NEST 7.4.1 documentation, which will delete the index itself.
Instead what I am getting is of NEST version 1.x.
Any link towards a documentation or any help regarding the code will very helpful.
Thank you.
As you can see from client.Delete method description
it exposes elasticsearch delete API which is responsible for deleting documents from elasticsearch.
If you want to remove index you can do this with
await client.Indices.DeleteAsync("index_name");
Hope that helps.

Finding changesets associated with the work item or having specific comment TFS Api

I'm trying to find all changesets associated with the work item using Microsoft.TeamFoundation.WorkItemTracking.Client. Using query I was able to get the information about the work items in question, however I cannot find any changeset information on the object I'm getting back. In addition to that there are some changesets that are not linked to specific work item but easy identifiable by the comment. Is there a quick way to find these using tfs api?
Edit: this is not a duplicate of How to get work items associated with a changeset id using tfs api? b/c in that question person has a changeset and would like to find associated work items. In my case I have a work items and I would like to find all changesets associated with the specific work items. In addition to that I need to find all changesets that have specific string in the comment.
After more googling on the subject and exploring tfs API here is what I ended up with:
If all you changesets are linked to the work items (not really my case but this is what I originally was asking about):
// based on https://etoptanci.wordpress.com/2011/05/04/seeing-all-code-changes-for-a-work-item/
private static void GetChangesForWorkItem()
{
var configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(new Uri(#"http://myserver:8080/tfs"));
var tpcService = configurationServer.GetService<ITeamProjectCollectionService>();
var collectionNodes = configurationServer.CatalogNode.QueryChildren(
new[] { CatalogResourceTypes.ProjectCollection },
false, CatalogQueryOptions.None);
var collectionNode = collectionNodes.First(x => x.Resource.DisplayName == "<collection name>");
// Use the InstanceId property to get the team project collection
Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]);
TfsTeamProjectCollection collection = configurationServer.GetTeamProjectCollection(collectionId);
var vcs = collection.GetService<VersionControlServer>();
var store = new WorkItemStore(collection);
var workItems = new List<WorkItem>()
{
store.GetWorkItem(1123),
store.GetWorkItem(1145),
};
var associatedChangesets = new List<Changeset>();
foreach (var workItem in workItems)
{
foreach (var link in workItem.Links)
{
if((link==null) || !(link is ExternalLink))
continue;
string externalLink = ((ExternalLink)link).LinkedArtifactUri;
var artifact =LinkingUtilities.DecodeUri(externalLink);
if (artifact.ArtifactType == "Changeset")
associatedChangesets.Add(vcs.ArtifactProvider.GetChangeset(new Uri(externalLink)));
}
}
Console.WriteLine(associatedChangesets.Select(x=>x.ChangesetId).OrderBy(x => x));
}
If you need to get by comment as well then you gate all changesets for the daterange and then filter out by Changeset.Comment which is a string.
Check the REST API:
GET https://{instance}/defaultcollection/_apis/tfvc/changesets/{id}?api-version={version}[&includedetails={boolean}&includeworkitems={boolean}&includesourcerenames={boolean}&maxchangecount={int}&maxcommentlength={int}]
You can also use RestAPI (as stated in the first answer)
https://www.visualstudio.com/en-us/docs/integrate/api/wit/work-items#with-links-and-attachments
You need to filter out "relations" array with rel == "ArtifactLink"

How do I retrieve simple products associated with configurable products

Hi i'm using magento soap api v2 with c#. Do far I have been calling
var groupedProducts = magentoService.catalogProductLinkList(sessionId, "grouped", id, "productId");
that does return grouped Products, but instead I would like to retrieve simple products such as green large t-shirt which is associated with configurable t-shirt.
How can this be achieved?
Unfortunatelly that's not possible with the magento SOAP api. You are not able to retrieve child products of a parent product via the api. Believe me, I have tackled this myself some time ago. I can suggest 2 fixes and 1 workaround.
Workaround - Try to retrieve child products by sku or name. This can work provided that all your child products use the parent's name or sku as the prefix. That's how I resolved it in the beginning and it worked well as long as the client did not introduce child product names that did not match the parent name. Here's some sample code:
//fetch configurable products
filters filter = new filters();
filter.filter = new associativeEntity[1];
filter.filter[0] = new associativeEntity();
filter.filter[0].key = "type_id";
filter.filter[0].value = "configurable";
//get all configurable products
var configurableProducts = service.catalogProductList(sessionID, filter, storeView);
foreach (var parent in configurableProducts)
{
filters filter = new filters();
filter.filter = new associativeEntity[1];
filter.filter[0] = new associativeEntity();
filter.filter[0].key = "type_id";
filter.filter[0].value = "configurable";
filter.complex_filter = new complexFilter[1];
filter.complex_filter[0] = new complexFilter();
filter.complex_filter[0].key = "sku";
filter.complex_filter[0].value = new associativeEntity() { key="LIKE", value=parent.sku + "%" };
var simpleProducts = service.catalogProductList(sessionID, filter, storeView);
//do whatever you need with the simple products
}
Fix #1 - Free - Write your own api extension. To retrieve child products you could use:
$childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $product);
You then send the results to the api caller and all should be well. I have not tried that myself, though, so I'm not sure if there are any other problems on the way.
Fix #2 - Paid - Get the (excellent, but pricey) CoreAPI extension from netzkollektiv. That's what I did when the workaround stopped working out for me and never regretted this decision.
I dont think what you are trying to do is possible with default magento SOAP api.
What you could do is create a custom api
eg.
How to setup custom api for Magento with SOAP V2?
http://www.magentocommerce.com/api/soap/create_your_own_api.html
Then create the logic to retrieve all the simple products associated with that configurable product.
$_product = Mage::getModel('catalog/product')->load($id);
// check if it's a configurable product
if($_product->isConfigurable()){
//load simple product ids
$ids = $_product->getTypeInstance()->getUsedProductIds();
OR
$ids = Mage::getResourceModel('catalog/product_type_configurable')->load($_product);
}
Please be aware that it should be
... new associativeEntity() { key="like", ...
and not
... new associativeEntity() { key="LIKE", ....
Upper case LIKE does not work.
I found a Magento Extension on Github, which includes this functionallity.
Get configurable's subproducts informations in the same response.
https://github.com/Yameveo/Yameveo_ProductInfo

How to save selections from a multi-select listbox using Entity Framework

I'm new to Entify Framework so this is probably a very basic question. In a WinForms application I have a data entry page that works fine until I add a listbox and try to update the database with the selections that have been made.
On the form the user selects a file to upload and specifies one or more departments that can access the file. Here's how I thought it would work:
using (var ctx = new FCEntities())
{
var batch = new Batch() { Description = txtDescription.Text, Filename = filename, Departments = (System.Data.Objects.DataClasses.EntityCollection<Department>)lstDepartments.SelectedItems };
ctx.AddToBatches(batch);
ctx.SaveChanges();
}
But when this didn't work I did some research and learned that I can't cast the SelectedItems to EntityCollection so I decided to copy the items from the original collection into a new collection and then use the new collection as follows:
using (var ctx = new FCEntities())
{
var departments = new System.Data.Objects.DataClasses.EntityCollection<Department>();
foreach (var department in lstDepartments.SelectedItems)
{
departments.Add((Department)department);
}
var batch = new Batch() {Description = txtDescription.Text, Filename = filename, Departments=departments };
ctx.AddToBatches(batch);
ctx.SaveChanges();
}
This didn't work either and gave this error on the departments.Add line:
"An object that is attached to an ObjectContext cannot be added to an
EntityCollection or EntityReference that is not associated with a
source object."
I don't understand because it doesn't appear to me that the department object is attached to the ObjectContext? I'm obviously missing something fundamental, so any advice and/or links to examples of how others do this would be appreciated.
I wanted to leave an answer to this in case someone else runs into this someday. The comments left by Wiktor were helpful in getting me in the right direction. I decided I had a lack of fundamental understanding so I did some reading on MSDN and was able to resolve my issue.
The datamodel behind this existed of three tables: Batches, Departments, and Batches_Departments which allowed for a many to many relationship between Batches and Departments.
The problem with my original code/logic, in a nutshell, was that the Department objects in the ListBox were associated with a different context than the one I was using in my Save method. EF didn't like this for obvious reasons (at least now they are obvious), so in the save method I used the ID from the selected Departments to get a reference to the same Department in the current context. I could then add this Department to the newly created batch.
Here's what the code now looks like:
using (var ctx = new FCEntities())
{
var batch = new Batch() { Description = txtDescription.Text, Filename = filename};
foreach (var department in lstDepartments.CheckedItems)
{
var dept = (from d in ctx.Departments where d.DepartmentID == ((Department)department).DepartmentID select d).First();
batch.Departments.Add(dept);
}
ctx.Batches.AddObject(batch);
ctx.SaveChanges();
}
Hopefully this helps someone else who is dealing with the same issue.

Categories

Resources