How do you restore a "versioned node" in a jackrabbit 2.1 repository? - jackrabbit

Once a node has been deleted, how do you locate it so that you can restore it using jackrabbit or the jcr APIs?

I'm not an expert in Jackrabbit versioning, but as far as I know there is no easy way to locate such a node unless you know some of it's data. If you do know, then you can use a query and navigate to the next parent that is an instance of javax.jcr.version.Version, and restore it. If you don't know, then you need to iterate over the version storage and print all the data. You could filter out nodes that are not deleted, but otherwise it's a manual job because the path of a node is not stored in the version storage (unless you add a property that contains the path). Here is an example on how to list all nodes in the version storage. It will restore the last javax.jcr.version.Version it finds:
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.version.Version;
import javax.jcr.version.VersionManager;
import org.apache.jackrabbit.core.TransientRepository;
public class TestRestoreDeleted {
public static void main(String... args) throws Exception {
TransientRepository rep = new TransientRepository();
Session s = rep.login(
new SimpleCredentials("", new char[0]));
try {
// clear the repository first
if (s.getRootNode().hasNode("test")) {
s.getRootNode().getNode("test").remove();
s.save();
}
// add test/t1 and check in the change
Node test = s.getRootNode().addNode("test");
Node t1 = test.addNode("t1");
t1.addMixin("mix:versionable");
s.save();
VersionManager vm = s.getWorkspace().
getVersionManager();
for(int i=0; i<3; i++) {
vm.checkout("/test/t1");
t1.setProperty("data", "Hello" + i);
s.save();
vm.checkin("/test/t1");
}
// remove the node
t1.remove();
s.save();
// list all versions of all nodes in the repository
Node vs = s.getRootNode().
getNode("jcr:system").
getNode("jcr:versionStorage");
Version v = traverseVersionStorage(vs, 0);
// restore a version
vm.restore("/test/t1", v, false);
// get the node and print the data
t1 = s.getRootNode().
getNode("test").getNode("t1");
System.out.println("Restored: " +
t1.getProperty("data").getString());
} finally {
s.logout();
}
}
private static Version traverseVersionStorage(
Node n, int level) throws Exception {
Version v = null;
for (NodeIterator it = n.getNodes(); it.hasNext();) {
Node n2 = it.nextNode();
if (n2 instanceof Version
&& !n2.getName().startsWith("jcr:")) {
v = (Version) n2;
System.out.println("version " + n2.getName() +
" of node " + n2.getParent().getName() + ":");
Node n3 = n2.getNode("jcr:frozenNode");
for (PropertyIterator pt =
n3.getProperties(); pt.hasNext();) {
Property p = pt.nextProperty();
if (!p.getName().startsWith("jcr:")) {
System.out.println(" " + p.getName() + "="
+ (p.isMultiple() ? p.getValues().toString()
: p.getValue().getString()));
}
}
System.out.println();
}
Version v2 = traverseVersionStorage(n2, level + 1);
v = v == null ? v2 : v;
}
return v;
}
}

Related

Waiting time shown nothing in cloudsim why?

/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation
* of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009, The University of Melbourne, Australia
*/
//package org.cloudbus.cloudsim.examples;
//package cloudIntro;
import java.text.DecimalFormat;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
import org.cloudbus.cloudsim.Datacenter;
import org.cloudbus.cloudsim.DatacenterBroker;
import org.cloudbus.cloudsim.DatacenterCharacteristics;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.Storage;
import org.cloudbus.cloudsim.UtilizationModel;
import org.cloudbus.cloudsim.UtilizationModelFull;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.VmSchedulerTimeShared;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
/**
* A simple example showing how to create
* a datacenter with two hosts and run two
* cloudlets on it. The cloudlets run in
* VMs with different MIPS requirements.
* The cloudlets will take different time
* to complete the execution depending on
* the requested VM performance.
*/
public class Simulation
{
/**
* Creates main() to run this example
*/
public static void main(String[] args)
{
Log.printLine("Starting CloudSimExample3...");
try
{
int noOfTypes = 6;
// First step: Initialize the CloudSim package. It should be called
// before creating any entities.
int num_user = 1; // number of cloud users
Calendar calendar = Calendar.getInstance();
boolean trace_flag = false; // mean trace events
// Initialize the CloudSim library
CloudSim.init(num_user, calendar, trace_flag);
// Second step: Create Datacenters
//Datacenters are the resource providers in CloudSim. We need at list one of them to run a CloudSim simulation
#SuppressWarnings("unused")
Datacenter datacenter0 = createDatacenter("Datacenter_0");
//Third step: Create Broker
//Fourth step: Create one virtual machine
//VM description
int vmid = 0;
int mips = 250;
long size = 10000; //image size (MB)
int ram = 512; //vm memory (MB)
long bw = 1000;
int pesNumber = 1; //number of cpus
String vmm = "Xen"; //VMM name
//Fifth step: Create two Cloudlets
//Cloudlet properties
int id = 0;
long length = 40000;
long fileSize = 300;
long outputSize = 300;
UtilizationModel utilizationModel = new UtilizationModelFull();
int vmNumberArray[] = {1,1,1,1,1,1};
int cloudletNumberArray[] = {500,500,500,500,500,500};
ArrayList<DatacenterBroker> brokerList = new ArrayList<>();
for(int i=0;i<noOfTypes;i++) // create 6 types of vm
{
List<Cloudlet> cloudletList = new ArrayList<>();
List<Vm> vmlist = new ArrayList<>();
DatacenterBroker broker = createBroker();
brokerList.add(broker);
int brokerId = broker.getId();
//int randomNumber1 = ThreadLocalRandom.current().nextInt(1,15);
int randomNumber1 = vmNumberArray[i];
for(int j=0;j<randomNumber1;j++)
{
Vm vm = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
vmid++;
vmlist.add(vm);
}
//int randomNumber2 = ThreadLocalRandom.current().nextInt(20,30);
int randomNumber2 = cloudletNumberArray[i];
for(int j=0;j<randomNumber2;j++)
{
Cloudlet cloudlet = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
id++;
cloudlet.setUserId(brokerId);
cloudletList.add(cloudlet);
}
broker.submitVmList(vmlist);
broker.submitCloudletList(cloudletList);
}
long start = System.nanoTime();
CloudSim.startSimulation();
for(int i=0;i<noOfTypes;i++)
{
List<Cloudlet> cloudletList = brokerList.get(i).getCloudletReceivedList();
printCloudletList(cloudletList);
}
CloudSim.stopSimulation();
long end = System.nanoTime();
Log.printLine("CloudSim finished");
System.out.println("total time required = "+(end-start));
}
catch (Exception e) {
e.printStackTrace();
Log.printLine("The simulation has been terminated due to an unexpected error");
}
}
private static Datacenter createDatacenter(String name)
{
// Here are the steps needed to create a PowerDatacenter:
// 1. We need to create a list to store
// our machine
List<Host> hostList = new ArrayList<Host>();
// 2. A Machine contains one or more PEs or CPUs/Cores.
// In this example, it will have only one core.
List<Pe> peList = new ArrayList<Pe>();
int mips = 60000;
// 3. Create PEs and add these into a list.
peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating
//4. Create Hosts with its id and list of PEs and add them to the list of machines
int hostId=0;
int ram = 307230720; //host memory (MB)
long storage = 1000000; //host storage
int bw = 10000000;
hostList.add(
new Host(
hostId,
new RamProvisionerSimple(ram),
new BwProvisionerSimple(bw),
storage,
peList,
new VmSchedulerTimeShared(peList)
)
); // This is our first machine
//create another machine in the Data center
/*List<Pe> peList2 = new ArrayList<Pe>();
peList2.add(new Pe(0, new PeProvisionerSimple(mips)));
hostId++;
hostList.add(
new Host(
hostId,
new RamProvisionerSimple(ram),
new BwProvisionerSimple(bw),
storage,
peList2,
new VmSchedulerTimeShared(peList2)
)
);*/ // This is our second machine
// 5. Create a DatacenterCharacteristics object that stores the
// properties of a data center: architecture, OS, list of
// Machines, allocation policy: time- or space-shared, time zone
// and its price (G$/Pe time unit).
String arch = "x86"; // system architecture
String os = "Linux"; // operating system
String vmm = "Xen";
double time_zone = 10.0; // time zone this resource located
double cost = 3.0; // the cost of using processing in this resource
double costPerMem = 0.05; // the cost of using memory in this resource
double costPerStorage = 0.001; // the cost of using storage in this resource
double costPerBw = 0.0; // the cost of using bw in this resource
LinkedList<Storage> storageList = new LinkedList<Storage>(); //we are not adding SAN devices by now
DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
arch, os, vmm, hostList, time_zone, cost, costPerMem, costPerStorage, costPerBw);
// 6. Finally, we need to create a PowerDatacenter object.
Datacenter datacenter = null;
try {
datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0);
} catch (Exception e) {
e.printStackTrace();
}
return datacenter;
}
//We strongly encourage users to develop their own broker policies, to submit vms and cloudlets according
//to the specific rules of the simulated scenario
private static DatacenterBroker createBroker()
{
DatacenterBroker broker = null;
try
{
broker = new DatacenterBroker("Broker");
} catch (Exception e) {
e.printStackTrace();
return null;
}
return broker;
}
/**
* Prints the Cloudlet objects
* #param list list of Cloudlets
*/
private static void printCloudletList(List<Cloudlet> list)
{
int size = list.size();
Cloudlet cloudlet;
String indent = " ";
Log.printLine();
Log.printLine("========== OUTPUT ==========");
Log.printLine("Cloudlet ID" + indent + "STATUS" + indent +
"Data center ID" + indent + "VM ID" + indent + "Time" + indent + "Start Time" + indent + "Finish Time" + indent + "waiting Time");
DecimalFormat dft = new DecimalFormat("###.##");
for (int i = 0; i < size; i++)
{
cloudlet = list.get(i);
Log.print(indent + cloudlet.getCloudletId() + indent + indent);
if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS)
{
Log.print("SUCCESS");
Log.printLine( indent + indent + cloudlet.getResourceId() + indent + indent + indent + cloudlet.getVmId() +
indent + indent + dft.format(cloudlet.getActualCPUTime()) + indent + indent + dft.format(cloudlet.getExecStartTime())+
indent + indent + dft.format(cloudlet.getFinishTime()) + dft.format(cloudlet.getWaitingTime()));
}
}
}
}
This code is modified from cloudsim example 3 code https://github.com/Cloudslab/cloudsim/blob/master/modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/CloudSimExample3.java.
Here, I create one datacenter with one host and 6 datacenter broker. Each brocker has one VM and 500 cloudlet.
output file https://paste.ubuntu.com/p/ZmmK2nFmyS/
The output shows that within a brocker each cloudlet start at a time and the waiting time shows nothing that means zero(0). How 500 tasks start at a time in a VM where there is one cpu in the VM and no waiting time?
That is because you used the CloudletSchedulerTimeShared
instead of other implementations such as the CloudletSchedulerSpaceShared.
In real operating systems, even a time-shared scheduler will make some applications to wait if the number of CPUs is lower than the number of apps (which is usually the case).
CloudSim provides an over-simplified time-shared scheduler.
There is an answer that explains how such a scheduler is implemented here.

Adding or Removing a level to a TreeNode

I was wondering if it was possible with a TreeView in a windows form to add or remove a level?
For example:
my treeview is like this to begin with:
ParentNode
| Child1
| Child2
if user clicks on a button to add a level to Child2 it becomes:
ParentNode
| Child1
| | Child1.1
There is a a Node.Level function but only usable to get the level and not to set it.
EDIT:
The nodes are built automatically, the level is assigned depending on the style of an excel cell. The problem is, it happens that the created node is not at it's correct place because the excel file is not well made. So I see 2 options o resolve this problem:
1- the user modifies the excel file directly
2- I create a Move Left Move Right button on a selection of nodes.
I'd like to offer the 2nd possibility.
Here's the code I used to build the nodes:
public static void AddNodes(Excel.Application app,
TreeView treeView)
{
Excel.Range selection = app.Selection;
ArrayList style = new ArrayList();
TreeNode parentNode = treeView.SelectedNode;
//Selected Node => Last used node
for (int i = 1; i <= selection.Rows.Count; i++)
{
TreeNode tn;
int fontSize = Convert.ToInt32(selection.Cells[i].Font.Size);
if (!style.Contains(fontSize))
{
style.Add(fontSize);
}
else if (style[style.Count - 1].Equals(fontSize))
{
try
{
treeView.SelectedNode = treeView.SelectedNode.Parent;
}
catch (Exception x)
{
ErrorBox(x);
}
}
else
{
int indexPreviousCellofSameColor = style.IndexOf(fontSize);
//Select TN parent
for (int j = 1; j <= (style.Count - indexPreviousCellofSameFont); j++)
{ treeView.SelectedNode = treeView.SelectedNode.Parent; }
style.RemoveRange(indexPreviousCellofSameFont + 1, style.Count - indexPreviousCellofSameFont - 1);
}
if (selection.Cells[i].Value2 == null)
{
//if empty cell, do something ... or nothing
treeView.SelectedNode = treeView.SelectedNode.LastNode;
}
else
{
//Add new TN to parent - TN object corresponds to excel cell
tn = new TreeNode()
{
Text = selection.Cells[i].Value2,
Tag = selection.Cells[i],
};
treeView.SelectedNode.Nodes.Add(tn);
tn.ToolTipText = tn.Level.ToString();
//selected TN => created TN
treeView.SelectedNode = tn;
}
}
}
I had to change my answer completely to the changed question.
This seems to do the job in my tests. It moves the selected node to a new level, under the one that was just above it.
It needs more checks offcourse to make sure your not moving nodes to oblivion...
private void button1_Click(object sender, EventArgs e)
{
TreeNode selected = treeViewFilter.SelectedNode;
TreeNode parent = selected.Parent;
// find the node just above the selected node
TreeNode prior = parent.Nodes[selected.Index - 1];
if (parent != prior)
{
treeViewFilter.Nodes.Remove(selected);
prior.Nodes.Add(selected);
}
}

GAE, Local datastore does not create

I have no idea in what extend GAE is not easy to understand :(
My servlet manipulate a json string and then I'm trying to store it in datastore.
When I run the application I'm getting this output:
Jan 27, 2014 6:59:04 PM com.google.appengine.api.datastore.dev.LocalDatastoreService load
INFO: The backing store, D:\Android\IntelliJ IDEA\workspace\EyeBall\AppEngine\out\artifacts\AppEngine_war_exploded\WEB-INF\appengine-generated\local_db.bin, does not exist. It will be created.
1
2
3
4
5
7
***
***
***
***
***
8
9
Although it's mentioned that local_db.bin will be created but when I navigate to that directory the file is not there. Also, when I open http://localhost:8080/_ah/admin/datastore in browser nothing displays in Entity Kind drop down list.
So wtf happene to local_db.bin? Why it doesn't generates?
any suggestion would be appreciated. thanks.
==================
UPDATE:
I added my code based on request.
private static final String NO_DEVICE_ID = "FFFF0000";
private static final String SAMPLE_JSON = "{\"history\":[{\"date\":null,\"info\":null,\"title\":\"Maybank2u.com\",\"url\":\"https://www.maybank2u.com.my/mbb/Mobile/info.do\",\"visits\":14},{\"date\":null,\"info\":null,\"title\":\"Maybank2u.com\",\"url\":\"https://www.maybank2u.com.my/mbb/Mobile/adaptInfo.do\",\"visits\":4},{\"date\":null,\"info\":null,\"title\":\"Maybank2u.com\",\"url\":\"http://www.maybank2u.com.my/mbb_info/m2u/public/personalBanking.do\",\"visits\":16},{\"date\":null,\"info\":null,\"title\":\"Maybank2u.com Online Financial Services\",\"url\":\"https://www.maybank2u.com.my/mbb/m2u/common/M2ULogin.do?action=Login\",\"visits\":52},{\"date\":null,\"info\":null,\"title\":\"‭BBC\",\"url\":\"http://www.bbc.co.uk/persian/\",\"visits\":16}]}";
private static final String QUERY_HISTORY_DEVICE = "SELECT m FROM HistoryDeviceJPA m WHERE m.userUUID = :keyword ORDER BY m.domain ASC";
private static final String QUERY_HISTORY = "SELECT m FROM HistoryJPA m WHERE m.pageAddress = :keyword";
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// displayError(response, "The page doesn't support httpGet");
String deviceId = NO_DEVICE_ID;
String content = SAMPLE_JSON;
System.out.println("1");
HistoryBrowser historyBrowser = parseJson(content);
if(historyBrowser == null)
return;
System.out.println("2");
List<HistoryBrowser.BrowserInfo> historyList = historyBrowser.getHistory();
if(historyList == null)
return;
System.out.println("3");
List<HistoryDeviceJPA> historyDeviceJPAList = new ArrayList<HistoryDeviceJPA>(historyList.size());
for(int i=0; i<historyList.size(); i++) {
try {
HistoryBrowser.BrowserInfo browser = historyList.get(i);
HistoryDeviceJPA historyDeviceJPA = new HistoryDeviceJPA();
historyDeviceJPA.setUserUUID(deviceId);
historyDeviceJPA.setDomain(getDomainName(browser.getUrl()));
historyDeviceJPA.setPageAddress(browser.getUrl());
historyDeviceJPA.setPageTitle(browser.getTitle());
historyDeviceJPA.setPageVisits(browser.getVisits());
historyDeviceJPAList.add(historyDeviceJPA);
} catch (URISyntaxException e) {
System.out.println(e.getMessage());
}
}
System.out.println("4");
// get history of device from data store
EntityManager em = EMF.get().createEntityManager();
Query q = em.createQuery(QUERY_HISTORY_DEVICE).setParameter("keyword", deviceId);
#SuppressWarnings("unchecked")
List<HistoryDeviceJPA> dbList = (List<HistoryDeviceJPA>) q.getResultList();
System.out.println("5");
// If there is no result (shows there is no record for that device)
if(dbList == null)
addHistoryDeviceJPAToDs(historyDeviceJPAList);
else {
System.out.println("7");
// find each item in datastore and replace them if needed
// if current page visit is less ot equal than previous visit don't do anything (remove item form historyDeviceJPAList)
outerLoop:
for(int i=0; i<historyDeviceJPAList.size(); i++) {
HistoryDeviceJPA deviceItem = historyDeviceJPAList.get(i);
System.out.println("***");
for(int j=0; j<dbList.size(); j++) {
HistoryDeviceJPA dbItem = dbList.get(j);
if(deviceItem.getPageAddress().equalsIgnoreCase(dbItem.getPageAddress())) {
if(deviceItem.getPageVisits() > dbItem.getPageVisits()) {
long diff = deviceItem.getPageVisits() - dbItem.getPageVisits();
dbItem.setPageVisits(deviceItem.getPageVisits());
HistoryJPA historyJPA = findHistoryJPA(dbItem.getPageAddress());
historyJPA.setPageVisits(historyJPA.getPageVisits() + diff);
// update datastore
addHistoryDeviceJPAToDs(dbItem);
addHistoryJPAToDs(historyJPA);
// don't check other items of j list
break outerLoop;
}
}
}
}
System.out.println("8");
}
System.out.println("9");
// http://www.sohailaziz.com/2012/06/scheduling-activities-services-and.html
// https://dev.twitter.com/docs/api/1.1
// https://developers.google.com/appengine/docs/java/datastore/jdo/creatinggettinganddeletingdata?csw=1#Updating_an_Object
// http://en.wikibooks.org/wiki/Java_Persistence/Inheritance
}
and 6 is here:
private void addHistoryDeviceJPAToDs(List<HistoryDeviceJPA> list) {
System.out.println("6");
EntityManager em = EMF.get().createEntityManager();
try {
for (int i=0; i<list.size(); i++) {
System.out.println("=> " + i + " - " + list.get(i).toString());
em.getTransaction().begin();
em.persist(list.get(i));
em.getTransaction().commit();
}
} finally {
em.close();
}
}
after debug I found the problem is in this line:
List<HistoryDeviceJPA> dbList = (List<HistoryDeviceJPA>) q.getResultList();
if(dbList == null)
addHistoryDeviceJPAToDs(historyDeviceJPAList);
'dbList' is never null and it's size is 0 if there is nothing in datastore. That's why addHistoryDeviceJPAToDs method never invoked. By changing the code to following problem solved and local db created.
List<HistoryDeviceJPA> dbList = (List<HistoryDeviceJPA>) q.getResultList();
if(dbList == null)
return;
System.out.println("5");
// If there is no result (shows there is no record for that device)
if(dbList.size() == 0)
addHistoryDeviceJPAToDs(historyDeviceJPAList);
For other people who come across the same issue --
GAE will not create local_db.bin until you put data in the datastore. So if the file is not there, there is likely a bug in the application code.

problems with old c code with new ncurses version (ldat struct)

I have a problem with some code using curses after upgrading to a new server and thus also new software like libs, headers and such.
The problem is the use of the ldat struct fields "firstchar", "lastchar" and "text" which in the the newer versions of curses.h is hidden in the curses.priv.h and therefore they are not resolved.
I could really use some pointers as to how I might be able to resolve these issues.
The code below indicates the use of the struct fields, but it just a part of the complete code as it several thousand lines...
If there is need for additional code I can add this.
I might also add that I have not made this program myself, I'm just responsible for making it work with our new server...
int
update_window(changed, dw, sw, win_shared)
bool *changed;
WINDOW *dw; /* Destination window */
window_t *sw; /* Source window */
bool win_shared;
{
int y, x;
int yind, nx, first, last;
chtype *pd, *ps; /* pd = pointer destination, ps = pointer source */
int nscrolls; /* Number of scrolls to make */
if(! sw->changed) {
*changed = FALSE;
return(0);
}
/****************************************
* Determine number of times window is
* scrolled since last update
****************************************/
nscrolls = sw->scrollcount; if(nscrolls >= sw->ny)
nscrolls = 0;
sw->scrollcount = 0L;
dw->_flags = _HASMOVED;
dw->_cury = sw->cury;
dw->_curx = sw->curx;
if(nscrolls > 0) {
/* Don't copy lines that is scolled away */
for(y = nscrolls; y < sw->ny; y++) {
yind = GETYIND(y - nscrolls, sw->toprow, sw->ny);
if(sw->lastch[yind] != _NOCHANGE) {
first = dw->_line[y].firstchar = sw->firstch[yind];
last = dw->_line[y].lastchar = sw->lastch[yind];
ps = &sw->screen[yind][first];
pd = (chtype *)&dw->_line[y].text[first];
nx = last - first + 1;
LOOPDN(x, nx)
d++ = *ps++;
if(! win_shared) {
sw->firstch[yind] = sw->nx;
sw->lastch[yind] = _NOCHANGE;
}
}
}
} else {
LOOPUP(y, sw->ny) {
yind = GETYIND(y, sw->toprow, sw->ny);
if(sw->lastch[yind] != _NOCHANGE) {
first = dw->_line[y].firstchar = sw->firstch[yind];
last = dw->_line[y].lastchar = sw->lastch[yind];
ps = &sw->screen[yind][first];
pd = (chtype *)&dw->_line[y].text[first];
nx = last - first + 1;
LOOPDN(x, nx)
*pd++ = *ps++;
if(! win_shared) {
sw->firstch[yind] = sw->nx;
sw->lastch[yind] = _NOCHANGE;
}
}
}
if(! win_shared)
sw->changed = FALSE;
}
*changed = TRUE;
return(nscrolls);
}
I appreciate all the help I can get!
The members of struct ldat were made private in June 2001. Reading the function and its mention of scrolls hints that it is writing a portion of some window used to imitate scrolling (by writing a set of lines to the real window), and attempting to bypass the ncurses logic which checks for changed lines.
For a function like that, the only solution is to determine what the developer was trying to do, and write a new function which does this — using the library functions provided.

string comparion with the innertext of a childnode

In the following code, I am trying to do a text parsing by using a streamreader. This is to get the email address from the text file. If i have no email address, combobox is left blank (index = -1). If i have a email that is found in my xml file, then i will select it. Else, i will add a node to my xml file with the new email address.
code:
private void Textparsing()
{
using (StreamReader sr = new StreamReader(Masterbuildpropertiespath))
{
while (sr.Peek() >= 0)
if (line.StartsWith("Builder_Email:"))
{
string[] fields = line.Split('\t');
string builderemail = fields[3];
XmlDocument emailparse = new XmlDocument();
emailparse.LoadXml(#"C:\GUI\buildermanageremail.xml");
XmlNodeList emailnode = emailparse.GetElementsByTagName("value");
if (string.IsNullOrEmpty(builderemail))
comboBox1.SelectedIndex = -1;
else
foreach (XmlNode node in emailnode)
{
if (builderemail == node.InnerText)
{
int count = emailparse.SelectNodes("email/builderemail/builder").Count;
count--;
comboBox1.SelectedIndex = count;
}
else
{
//create main node
XmlNode abc = emailparse.CreateNode(XmlNodeType.Element, "builder", null);
//create the first child node
XmlNode value = emailparse.CreateElement("value");
//set the value
value.InnerText = builderemail;
// add childes to father
//node.AppendChild(id);
abc.AppendChild(value);
// find the node we want to add the new node to
XmlNodeList l = emailparse.GetElementsByTagName("builderemail");
// append the new node
l[0].AppendChild(abc);
// save the file
emailparse.Save(#"C:\GUI\buildermanageremail.xml");
//then we populate the new updated xml file into the drop down list:
PopulateDDLFromXMLFile();
int count = emailparse.SelectNodes("email/builderemail/builder").Count;
count--;
comboBox1.SelectedIndex = count;
}
}
}
However, I get an XmlException (Data at the root level is invalid. Line 1, position 1.) at this line:
emailparse.LoadXml(#"C:\GUI\buildermanageremail.xml");
Why is that so?
my xmlfile:
<?xml version="1.0" encoding="utf-8"?>
<email>
<builderemail>
<builder>
<value>abc#123.com</value>
</builder>
<builder>
<value>Others</value>
</builder>
</builderemail>
<manageremail>
<manager>
<value>abc#456.com</value>
</manager>
<manager>
<value>Others</value>
</manager>
</manageremail>
</email>
You should use the
emailparse.Load(#"C:\GUI\buildermanageremail.xml");
method instead of
emailparse.LoadXml(#"C:\GUI\buildermanageremail.xml");
since LoadXml can load xml string, not the file.

Resources