问:
How do I position a window in WPF in an exact location?
I'm trying to display a window that aligns with an existing component. In this example I want to align it to a button. When i click the button I would like the window to position itself so that it's bottom is just above the button, and it's width is the same as the button. The left of the window should be the same as the left of the button.

To achieve this I use the following xaml:

```<code><Window x:Class="WindowPositioningTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:WindowPositioningTest"
    mc:Ignorable="d"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <Button Name="MyButton" Content="Click me to see window!" Width="300" Height="50" Click="Button_Click"/>
</Grid>
</code>```

The onclick function looks like this:

```<code>private void Button_Click(object sender, RoutedEventArgs e)
    {
        var window = new Window();

        var myButtonLocation = MyButton.PointToScreen(new Point(0, 0));

        window.Width = MyButton.ActualWidth;
        window.Height = 300;
        window.Left = myButtonLocation.X;
        window.Top = myButtonLocation.Y - window.Height;

        window.Show();
    }
</code>```

When I click the button a window is displayed like in the picture below.

My question is: why is the window not as wide as the button and why is it not in the right position? It's almost as if there's an invisible frame around the window.

答:
Try this:

```<code>private void Button_Click(object sender, RoutedEventArgs e)
{
    var window = new Window();

    var myButtonLocation = MyButton.PointToScreen(new Point(0, 0));

    window.Width = MyButton.ActualWidth + 16;
    window.Height = 300;
    window.Left = myButtonLocation.X - 8;
    window.Top = myButtonLocation.Y - window.Height;

    window.Show();
}
</code>```

It happens beacuse of window border. As you know, window is a composite element. I think when you set Width, you set a width of the working space, not the width of the whole window.

Body:
I'm trying to display a window that aligns with an existing component. In this example I want to align it to a button. When i click the button I would like the window to position itself so that it's bottom is just above the button, and it's width is the same as the button. The left of the window should be the same as the left of the button.

To achieve this I use the following xaml:

<Window x:Class="WindowPositioningTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:WindowPositioningTest"
    mc:Ignorable="d"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <Button Name="MyButton" Content="Click me to see window!" Width="300" Height="50" Click="Button_Click"/>
</Grid>

The onclick function looks like this:

private void Button_Click(object sender, RoutedEventArgs e)
    {
        var window = new Window();

        var myButtonLocation = MyButton.PointToScreen(new Point(0, 0));

        window.Width = MyButton.ActualWidth;
        window.Height = 300;
        window.Left = myButtonLocation.X;
        window.Top = myButtonLocation.Y - window.Height;

        window.Show();
    }

When I click the button a window is displayed like in the picture below.

My question is: why is the window not as wide as the button and why is it not in the right position? It's almost as if there's an invisible frame around the window.

Body:
Try this:

private void Button_Click(object sender, RoutedEventArgs e)
{
    var window = new Window();

    var myButtonLocation = MyButton.PointToScreen(new Point(0, 0));

    window.Width = MyButton.ActualWidth + 16;
    window.Height = 300;
    window.Left = myButtonLocation.X - 8;
    window.Top = myButtonLocation.Y - window.Height;

    window.Show();
}

It happens beacuse of window border. As you know, window is a composite element. I think when you set Width, you set a width of the working space, not the width of the whole window.


来源: stackexchange

问:
c# dllimport of MsiGetShortcutTarget(msi.dll) failed with error 1603 under Windows 7
I want to resolve an advertised MSI shortcut in c# as described here:
How to parse "special" .lnk files, aka. MSI shortcuts aka. Windows Installer advertised shortcuts using C#

```<code>[DllImport("msi.dll", CharSet = CharSet.Auto)]
private static extern UInt32 MsiGetShortcutTarget(
    string szShortcutTarget,
    [Out] StringBuilder szProductCode,
    [Out] StringBuilder szFeatureId,
    [Out] StringBuilder szComponentCode);

public static string ParseShortcut(string file)
{
    StringBuilder product = new StringBuilder(MaxGuidLength + 1);
    StringBuilder feature = new StringBuilder(MaxFeatureLength + 1);
    StringBuilder component = new StringBuilder(MaxGuidLength + 1);

    UInt32 res = MsiGetShortcutTarget(file, product, feature, component);
    ...
}
</code>```

I use VS 2010 and tried with different settings for "Platform target" and/or "Target framework". MsiGetShortcutTarget always returns 1603 (A fatal error occurred during installation) under Windows 7.

I tried to do the same with c++ and I can resolve the Shortcut and everything is fine. I also tested with a msi.dll, that I copied from a Windows XP and this dll can resolve the Shortcut with the C# code. I have no idea why the c# code won't work with the msi.dll under Windows 7.

I testet MsiGetComponentPath with a known product GUID and component GUID to resolve the target path in c# with the dll, that returns 1603 for MsiGetShortcutTarget and it works perfectly. So only MsiGetComponentPath fails under Windows 7 and I don't know why it went wrong.

答:
I highly suggest taking a look at WiX's Deployment Tools Foundation.  It  has a really nice interop library developed by a MSFT employee that makes calling MSI easy.

For example, the Microsoft.Deployment.WindowsInstaller namespace has an Installer class that exposes a static method ShortcutTarget GetShortcutTarget( string shortcut ).   The ShortcutTarget class then has get accessors for ComponentCode, Feature and ProductCode.

Additionalyl this is an open source project so if you really, really want to know how the P/Invoke stuff works you can look at the code.

ContentLicense: CC BY-SA 2.5

Body:
I want to resolve an advertised MSI shortcut in c# as described here:
How to parse "special" .lnk files, aka. MSI shortcuts aka. Windows Installer advertised shortcuts using C#

[DllImport("msi.dll", CharSet = CharSet.Auto)]
private static extern UInt32 MsiGetShortcutTarget(
    string szShortcutTarget,
    [Out] StringBuilder szProductCode,
    [Out] StringBuilder szFeatureId,
    [Out] StringBuilder szComponentCode);

public static string ParseShortcut(string file)
{
    StringBuilder product = new StringBuilder(MaxGuidLength + 1);
    StringBuilder feature = new StringBuilder(MaxFeatureLength + 1);
    StringBuilder component = new StringBuilder(MaxGuidLength + 1);

    UInt32 res = MsiGetShortcutTarget(file, product, feature, component);
    ...
}

I use VS 2010 and tried with different settings for "Platform target" and/or "Target framework". MsiGetShortcutTarget always returns 1603 (A fatal error occurred during installation) under Windows 7.

I tried to do the same with c++ and I can resolve the Shortcut and everything is fine. I also tested with a msi.dll, that I copied from a Windows XP and this dll can resolve the Shortcut with the C# code. I have no idea why the c# code won't work with the msi.dll under Windows 7.

I testet MsiGetComponentPath with a known product GUID and component GUID to resolve the target path in c# with the dll, that returns 1603 for MsiGetShortcutTarget and it works perfectly. So only MsiGetComponentPath fails under Windows 7 and I don't know why it went wrong.


问:
Get button click from reusable cell in collection view (xib file)
I have created reusable cell with include a button in a XIB for a collection.

I can change the text of labels and buttons in the collection view but i can't get on click event.

I have tried below options:

a.   This in UICollectionViewCell :  Not working

```<code>class cellVC: UICollectionViewCell {
    @IBOutlet weak var sampleLabel: UILabel!
    @IBOutlet weak var buttonClicked: UIButton!

    @IBAction func buttonTest(_ sender: Any) {
        print("dsfsdf   111111")
    }
}
</code>```

b. I have also tried : Not working

```<code>func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{

    let cell : cellVC = collectionView.dequeueReusableCell(withReuseIdentifier: "cellVC", for: indexPath) as! cellVC
    cell.sampleLabel. = "sample text"
    cell.buttonClicked.tag = indexPath.row
    cell.buttonClicked.addTarget(self, action: #selector(masterAction(sender:)), for: .touchUpInside)

    cell.buttonClicked.backgroundColor = UIColor.cyan
    return cell
}

func masterAction(_ sender: UIButton) {
    print ("button click")
}
</code>```

As both solutions are not working, how do i achieve this.

Thanks

答:
You can go with:

    class cellVC: UICollectionViewCell {
        @IBOutlet weak var sampleLabel: UILabel!
        @IBOutlet weak var buttonClicked: UIButton!

        var buttonTapAction: ((cellVC) -> ())?

        @IBAction func buttonTest(_ sender: Any) {
            buttonTapAction?(self)
        }
    }

    //////////

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{

    let cell : cellVC = collectionView.dequeueReusableCell(withReuseIdentifier: "cellVC", for: indexPath) as! cellVC
    cell.sampleLabel. = "sample text"
    cell.buttonClicked.tag = indexPath.row

    cell.buttonTapAction = { cell in

    //Tap handling logic

    }

    cell.buttonClicked.backgroundColor = UIColor.cyan
    return cell
}```

ContentLicense: CC BY-SA 3.0

Body:
I have created reusable cell with include a button in a XIB for a collection.

I can change the text of labels and buttons in the collection view but i can't get on click event.

I have tried below options:

a.   This in UICollectionViewCell :  Not working

class cellVC: UICollectionViewCell {
    @IBOutlet weak var sampleLabel: UILabel!
    @IBOutlet weak var buttonClicked: UIButton!

    @IBAction func buttonTest(_ sender: Any) {
        print("dsfsdf   111111")
    }
}

b. I have also tried : Not working

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{

    let cell : cellVC = collectionView.dequeueReusableCell(withReuseIdentifier: "cellVC", for: indexPath) as! cellVC
    cell.sampleLabel. = "sample text"
    cell.buttonClicked.tag = indexPath.row
    cell.buttonClicked.addTarget(self, action: #selector(masterAction(sender:)), for: .touchUpInside)

    cell.buttonClicked.backgroundColor = UIColor.cyan
    return cell
}

func masterAction(_ sender: UIButton) {
    print ("button click")
}

As both solutions are not working, how do i achieve this.

Thanks


问:
R Data Merge without Copying
In data.table, it is possible to work directly on the current data table (say DT) without creating a copy of it. For example, this can be done when creating a new column.

```<code>DT[,new_col:=1]
</code>```

I would like to know how this can be done for merging, in particular left join. For example, the data table way of left join is

```<code>DT_right[DT_left,on="id"]
</code>```

However, this does not modify the original DT_left table, requiring me to reassign. i.e.

```<code>DT_left = DT_right[DT_left,on="id"]
</code>```

Is there a way for me to do this without reassigning? i.e. working on DT_left directly.

答:
Lets say you have DT_right as

```<code>     id right_value
  1:  1           2
  2:  2           4
  3:  3           6
  4:  4           8
</code>```

and DT_left as

```<code>    id left_value
 1:  1          3
 2:  2          6
 3:  3          9
 4:  4         12
</code>```

if you want to perform left-join of DT_left on DT_right then i.value will be i.left_value i.e. the column name of the column you want to join from DT_left to DT_right.

```<code>DT_right[DT_left, joined_from_left := i.left_value, on = "id"]
DT_right[]
   id right_value joined_from_left
1:  1           2                3
2:  2           4                6
3:  3           6                9
4:  4           8               12
</code>```

Title: R Data Merge without Copying

Body:
In data.table, it is possible to work directly on the current data table (say DT) without creating a copy of it. For example, this can be done when creating a new column.

DT[,new_col:=1]

I would like to know how this can be done for merging, in particular left join. For example, the data table way of left join is

DT_right[DT_left,on="id"]

However, this does not modify the original DT_left table, requiring me to reassign. i.e.

DT_left = DT_right[DT_left,on="id"]

Is there a way for me to do this without reassigning? i.e. working on DT_left directly.

Body:
Lets say you have DT_right as

     id right_value
  1:  1           2
  2:  2           4
  3:  3           6
  4:  4           8

and DT_left as

    id left_value
 1:  1          3
 2:  2          6
 3:  3          9
 4:  4         12

if you want to perform left-join of DT_left on DT_right then i.value will be i.left_value i.e. the column name of the column you want to join from DT_left to DT_right.

DT_right[DT_left, joined_from_left := i.left_value, on = "id"]
DT_right[]
   id right_value joined_from_left
1:  1           2                3
2:  2           4                6
3:  3           6                9
4:  4           8               12


问:
Are infinite lists useful for any real world applications?
I've been using haskell for quite a while now, and I've read most of Real World Haskell and Learn You a Haskell. What I want to know is whether there is a point to a language using lazy evaluation, in particular the "advantage" of having infinite lists, is there a task which infinite lists make very easy, or even a task that is only possible with infinite lists?</p>

答:
Basically, lazy lists allow you to delay computation until you need it. This can prove useful when you don't know in advance when to stop, and what to precompute.

A standard example is u_n a sequence of numerical computations converging to some limit. You can ask for the first term such that |u_n - u_{n-1}| < epsilon, the right number of terms is computed for you.

Now, you have two such sequences u_n and v_n, and you want to know the sum of the limits to epsilon accuracy. The algorithm is:

compute u_n until epsilon/2 accuracy

compute v_n until epsilon/2 accuracy

return u_n + v_n

All is done lazily, only the necessary u_n and v_n are computed. You may want less simple examples, eg. computing f(u_n) where you know (ie. know how to compute) f's modulus of continuity.


问:
Send post value using javascript
I have this curl that works ok and I can send the values using Post this is the curl code

```<code>$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://192.168.1.9/apply.cgi");
url_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "submit_button=Wireless_Basic&action=Apply&change_action=gozila_cgi&submit_type=add_vifs&wl0_nctrlsb=&wl1_nctrlsb=&iface=ath0&ath0_mode=wet&ath0_relayd_gw_auto=0&ath0_relayd_gw_ipaddr=4&ath0_relayd_gw_ipaddr_0=192&ath0_relayd_gw_ipaddr_1=168&ath0_relayd_gw_ipaddr_2=1&ath0_relayd_gw_ipaddr_3=1&ath0_net_mode=g-only&ath0_channelbw=20&ath0_ssid=TP-LINK&ath0_regdomain=SPAIN&ath0_txpwrdbm=20&ath0_antgain=0&ath0_protmode=None&ath0_rts=0&ath0_rtsvalue=2190&ath0_preamble=0&ath0_txantenna=7&ath0_rxantenna=7&ath0_ap_isolate=0&ath0_scanlist=default&ath0_distance=2000&ath0_mtikie=0&ath0_bridged=1&ath0_multicast=0&ath0_nat=1&ath0_ipaddr=4&ath0_ipaddr_0=0&ath0_ipaddr_1=0&ath0_ipaddr_2=0&ath0_ipaddr_3=0&ath0_netmask=4&ath0_netmask_0=0&ath0_netmask_1=0&ath0_netmask_2=0&ath0_netmask_3=0");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0";
$headers[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
$headers[] = "Accept-Language: es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3";
$headers[] = "Content-Type: application/x-www-form-urlencoded";
$headers[] = "Referer: http://192.168.1.90/Wireless_Basic.asp";
$headers[] = "Authorization: Basic YWRtaW46Q3JlYXRpdmUx";
$headers[] = "Connection: keep-alive";
$headers[] = "Upgrade-Insecure-Requests: 1";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
}
</code>```

I am trying to do the same as curl but using javascript, I try with this code but It doesn´t works

var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://192.168.1.90/apply.cgi', true);
xhr.setRequestHeader('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0');
xhr.setRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
xhr.setRequestHeader('Accept-Language', 'es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3');
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Authorization", "Basic YWRtaW46Q3JlYXRpdmUx");
xhr.setRequestHeader("Upgrade-Insecure-Requests", "1");

xhr.onload = function () {
    // do something to response
    console.log(this.responseText);
};
xhr.send('submit_button=Wireless_Basic&action=Apply&change_action=gozila_cgi&submit_type=add_vifs&wl0_nctrlsb=&wl1_nctrlsb=&iface=ath0&ath0_mode=wet&ath0_relayd_gw_auto=0&ath0_relayd_gw_ipaddr=4&ath0_relayd_gw_ipaddr_0=192&ath0_relayd_gw_ipaddr_1=168&ath0_relayd_gw_ipaddr_2=1&ath0_relayd_gw_ipaddr_3=1&ath0_net_mode=g-only&ath0_channelbw=20&ath0_ssid=TP-LINK&ath0_regdomain=SPAIN&ath0_txpwrdbm=20&ath0_antgain=0&ath0_protmode=None&ath0_rts=0&ath0_rtsvalue=2190&ath0_preamble=0&ath0_txantenna=7&ath0_rxantenna=7&ath0_ap_isolate=0&ath0_scanlist=default&ath0_distance=2000&ath0_mtikie=0&ath0_bridged=1&ath0_multicast=0&ath0_nat=1&ath0_ipaddr=4&ath0_ipaddr_0=0&ath0_ipaddr_1=0&ath0_ipaddr_2=0&ath0_ipaddr_3=0&ath0_netmask=4&ath0_netmask_0=0&ath0_netmask_1=0&ath0_netmask_2=0&ath0_netmask_3=0');

   ```

答:
With This Library</p>

```<code>var api = axios.create({
  baseURL: 'http://192.168.1.90',
  timeout: 1000,
  headers: {'Authorization': 'Basic YWRtaW46Q3JlYXRpdmUx',...}
});
api.post('/apply.cgi', {
...
}).then(function(response) {});
</code>```

Title: Send post value using javascript

Body:
I have this curl that works ok and I can send the values using Post this is the curl code

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://192.168.1.9/apply.cgi");
url_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "submit_button=Wireless_Basic&action=Apply&change_action=gozila_cgi&submit_type=add_vifs&wl0_nctrlsb=&wl1_nctrlsb=&iface=ath0&ath0_mode=wet&ath0_relayd_gw_auto=0&ath0_relayd_gw_ipaddr=4&ath0_relayd_gw_ipaddr_0=192&ath0_relayd_gw_ipaddr_1=168&ath0_relayd_gw_ipaddr_2=1&ath0_relayd_gw_ipaddr_3=1&ath0_net_mode=g-only&ath0_channelbw=20&ath0_ssid=TP-LINK&ath0_regdomain=SPAIN&ath0_txpwrdbm=20&ath0_antgain=0&ath0_protmode=None&ath0_rts=0&ath0_rtsvalue=2190&ath0_preamble=0&ath0_txantenna=7&ath0_rxantenna=7&ath0_ap_isolate=0&ath0_scanlist=default&ath0_distance=2000&ath0_mtikie=0&ath0_bridged=1&ath0_multicast=0&ath0_nat=1&ath0_ipaddr=4&ath0_ipaddr_0=0&ath0_ipaddr_1=0&ath0_ipaddr_2=0&ath0_ipaddr_3=0&ath0_netmask=4&ath0_netmask_0=0&ath0_netmask_1=0&ath0_netmask_2=0&ath0_netmask_3=0");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0";
$headers[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
$headers[] = "Accept-Language: es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3";
$headers[] = "Content-Type: application/x-www-form-urlencoded";
$headers[] = "Referer: http://192.168.1.90/Wireless_Basic.asp";
$headers[] = "Authorization: Basic YWRtaW46Q3JlYXRpdmUx";
$headers[] = "Connection: keep-alive";
$headers[] = "Upgrade-Insecure-Requests: 1";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
}

I am trying to do the same as curl but using javascript, I try with this code but It doesn´t works

var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://192.168.1.90/apply.cgi', true);
xhr.setRequestHeader('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0');
xhr.setRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
xhr.setRequestHeader('Accept-Language', 'es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3');
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Authorization", "Basic YWRtaW46Q3JlYXRpdmUx");
xhr.setRequestHeader("Upgrade-Insecure-Requests", "1");

xhr.onload = function () {
    // do something to response
    console.log(this.responseText);
};
xhr.send('submit_button=Wireless_Basic&action=Apply&change_action=gozila_cgi&submit_type=add_vifs&wl0_nctrlsb=&wl1_nctrlsb=&iface=ath0&ath0_mode=wet&ath0_relayd_gw_auto=0&ath0_relayd_gw_ipaddr=4&ath0_relayd_gw_ipaddr_0=192&ath0_relayd_gw_ipaddr_1=168&ath0_relayd_gw_ipaddr_2=1&ath0_relayd_gw_ipaddr_3=1&ath0_net_mode=g-only&ath0_channelbw=20&ath0_ssid=TP-LINK&ath0_regdomain=SPAIN&ath0_txpwrdbm=20&ath0_antgain=0&ath0_protmode=None&ath0_rts=0&ath0_rtsvalue=2190&ath0_preamble=0&ath0_txantenna=7&ath0_rxantenna=7&ath0_ap_isolate=0&ath0_scanlist=default&ath0_distance=2000&ath0_mtikie=0&ath0_bridged=1&ath0_multicast=0&ath0_nat=1&ath0_ipaddr=4&ath0_ipaddr_0=0&ath0_ipaddr_1=0&ath0_ipaddr_2=0&ath0_ipaddr_3=0&ath0_netmask=4&ath0_netmask_0=0&ath0_netmask_1=0&ath0_netmask_2=0&ath0_netmask_3=0');

Body:
With This Library

var api = axios.create({
  baseURL: 'http://192.168.1.90',
  timeout: 1000,
  headers: {'Authorization': 'Basic YWRtaW46Q3JlYXRpdmUx',...}
});
api.post('/apply.cgi', {
...
}).then(function(response) {});


问:
cannot find -lopencv_imgcodecs and -lopencv_videoio when installing caffe
I got the problem when installing Caffe with opencv3.0+ and CUDA on Ubuntu 16.04

I also added opencv_imgcodescs and opencv_videoio to my Makefile, but that's not solving the issue.

I have checked several answers on the Caffe user group, but no answers solve my problem.

My error message:

```<code>nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so.1.0.0-rc3
/usr/bin/ld: cannot find -lopencv_imgcodecs
/usr/bin/ld: cannot find -lopencv_videoio
collect2: error: ld returned 1 exit status
Makefile:566: recipe for target '.build_release/lib/libcaffe.so.1.0.0-rc3' failed
make: *** [.build_release/lib/libcaffe.so.1.0.0-rc3] Error 1
</code>```

My setting in Makefile

```<code>LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5 opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs opencv_videoio
</code>```

My imgcodecs and videoio is under ~/miniconda2/envs/frcnn/include/opencv2/

```<code>(fastrcnn) pohsuan@pohsuan-Predator-G9-592:~/miniconda2/envs/fastrcnn/include/opencv2$ ls
aruco            dnn.hpp         imgcodecs            photo          structured_light      videostab
aruco.hpp        dpm.hpp         imgcodecs.hpp        photo.hpp      structured_light.hpp  videostab.hpp
bgsegm.hpp       face            imgproc              plot.hpp       superres              xfeatures2d
bioinspired      face.hpp        imgproc.hpp          reg            superres.hpp          xfeatures2d.hpp
bioinspired.hpp  features2d      line_descriptor      rgbd           surface_matching      ximgproc
calib3d          features2d.hpp  line_descriptor.hpp  rgbd.hpp       surface_matching.hpp  ximgproc.hpp
calib3d.hpp      flann           ml                   saliency       text                  xobjdetect.hpp
ccalib           flann.hpp       ml.hpp               saliency.hpp   text.hpp              xphoto
ccalib.hpp       fuzzy           objdetect            shape          tracking              xphoto.hpp
core             fuzzy.hpp       objdetect.hpp        shape.hpp      tracking.hpp
core.hpp         hdf             opencv.hpp           stereo         video
cvconfig.h       hdf.hpp         opencv_modules.hpp   stereo.hpp     video.hpp
datasets         highgui         optflow              stitching      videoio
dnn              highgui.hpp     optflow.hpp          stitching.hpp  videoio.hpp
</code>```

Where I modified my Makfile.config regarding my Miniconda virtual environment :

```<code> ANACONDA_HOME := $(HOME)/miniconda2
 PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
             $(ANACONDA_HOME)/include/python2.7 \
             $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial /home/pohsuan/miniconda2/envs/fastrcnn/include

LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial /home/pohsuan/miniconda2/fastrcnn/lib
</code>```

答:
Maybe uncomment

```<code> OPENCV_VERSION := 3
</code>```

on line 21, if you haven't already.
Worse case, uninstall OpenCV, and install a version less than 3.

I struggled a lot with this, finally decided to use OpenCV 2.4.9.1, and it worked.

Body:
I got the problem when installing Caffe with opencv3.0+ and CUDA on Ubuntu 16.04

I also added opencv_imgcodescs and opencv_videoio to my Makefile, but that's not solving the issue.

I have checked several answers on the Caffe user group, but no answers solve my problem.

My error message:

nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so.1.0.0-rc3
/usr/bin/ld: cannot find -lopencv_imgcodecs
/usr/bin/ld: cannot find -lopencv_videoio
collect2: error: ld returned 1 exit status
Makefile:566: recipe for target '.build_release/lib/libcaffe.so.1.0.0-rc3' failed
make: *** [.build_release/lib/libcaffe.so.1.0.0-rc3] Error 1

My setting in Makefile

LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5 opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs opencv_videoio

My imgcodecs and videoio is under ~/miniconda2/envs/frcnn/include/opencv2/

(fastrcnn) pohsuan@pohsuan-Predator-G9-592:~/miniconda2/envs/fastrcnn/include/opencv2$ ls
aruco            dnn.hpp         imgcodecs            photo          structured_light      videostab
aruco.hpp        dpm.hpp         imgcodecs.hpp        photo.hpp      structured_light.hpp  videostab.hpp
bgsegm.hpp       face            imgproc              plot.hpp       superres              xfeatures2d
bioinspired      face.hpp        imgproc.hpp          reg            superres.hpp          xfeatures2d.hpp
bioinspired.hpp  features2d      line_descriptor      rgbd           surface_matching      ximgproc
calib3d          features2d.hpp  line_descriptor.hpp  rgbd.hpp       surface_matching.hpp  ximgproc.hpp
calib3d.hpp      flann           ml                   saliency       text                  xobjdetect.hpp
ccalib           flann.hpp       ml.hpp               saliency.hpp   text.hpp              xphoto
ccalib.hpp       fuzzy           objdetect            shape          tracking              xphoto.hpp
core             fuzzy.hpp       objdetect.hpp        shape.hpp      tracking.hpp
core.hpp         hdf             opencv.hpp           stereo         video
cvconfig.h       hdf.hpp         opencv_modules.hpp   stereo.hpp     video.hpp
datasets         highgui         optflow              stitching      videoio
dnn              highgui.hpp     optflow.hpp          stitching.hpp  videoio.hpp

Where I modified my Makfile.config regarding my Miniconda virtual environment :

 ANACONDA_HOME := $(HOME)/miniconda2
 PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
             $(ANACONDA_HOME)/include/python2.7 \
             $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial /home/pohsuan/miniconda2/envs/fastrcnn/include

LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial /home/pohsuan/miniconda2/fastrcnn/lib

Body:
Maybe uncomment

 OPENCV_VERSION := 3

on line 21, if you haven't already.
Worse case, uninstall OpenCV, and install a version less than 3.

I struggled a lot with this, finally decided to use OpenCV 2.4.9.1, and it worked.


问:
manage code versioning with Bitbucket from existing project in VS2012
I've developed a VS2012 project in C# and I would like to use Bitbucket for versioning.

I have two versions of the software (1.0 and 1.1). Further modifications and new functionalities will be made to create the 1.2 version.

I would like to store, in a BitBucket repository, both the freezed versions 1.0 and 1.1 and, when it will be ready, to commit the new 1.2 version.
Can I create the 1.0 and 1.1 in the same repository or it is better to have a repo for 1.0 and one for 1.1?

Obviously, I suppose that the 1.2 will be in the same repo of the 1.1

答:
I'm not sure if I got what you mean by versioning. Are you talking about source control versioning? In that case, I'd propose to use branching or tags.

If you plan on supporting and making changes to 1.0 and 1.1, make a branch. Otherwise, just tag the commit with appropriate version.

If you already have 1.0 and 1.1, you can commit 1.0, then copy over the files of 1.1, commit the changes as 1.1 and start developing 1.2 from what you have. Does it make sense?


问:
Where does Maven store junit jar files
I changed the version of junit from 3.8.1 to 4.11 in my pom file, when I ran maven it downloaded junit 4.11.  I got the message

"Downloaded: https://repo.maven.apache.org/maven2/junit/junit/4.11/junit-4.11.jar (245 kB at 825 kB/s)"

My tests ran fine after the install but I cannot find the jar file anywhere.  Can someone tell me where it is stored?

答:
The default repo location could be changed. To show the actual repo location you can use this command:</p>

```<code>$ mvn help:evaluate -Dexpression=settings.localRepository | grep repository
/home/<username>/.m2/repository
</code>```

Title: Where does Maven store junit jar files

Body:
The default repo location could be changed. To show the actual repo location you can use this command:

$ mvn help:evaluate -Dexpression=settings.localRepository | grep repository
/home/<username>/.m2/repository


问:
Angular html5 mode and Spring routing
I'm having an issue using angular html5 mode for routing with a spring boot backend. The application works fine when I use ui router's $state.go() to navigate to different url's, but when I attempt to enter a different state's url and go directly to it, it fails to load properly.

We used a solution similar to what is detailed here (https://spring.io/guides/tutorials/spring-security-and-angular-js/), essentially using a spring controller to forward certain pages to the base url, "/". The difference with ours is that we use a base url, 'step', to put before every page but the home page. When we do navigate directly to a different page in our site, however, every resource that is loaded is turned into our index.html file (js, css, etc.). When we look at the network requests, it's appended the 'step' url in front of every request for some reason (so instead of css/style.css, it would be step/css/style.css).

Here's an example of our spring controller:

```<code>@Controller
public class ViewController {
    @RequestMapping(value="/step/**")
    public String forward() {
        return "forward:/";
    }
}
</code>```

Any help would be appreciated, but keep in mind we have looked into various solutions already such as the link mentioned and several others which have similar solutions.

答:
In combination with thread and this source we finally got it working. In our case there aren't any subpages. Maybe it helps someone:

```<code>@RequestMapping(value = "/**/{id:[^\\.]*}")
public String html5Forwarding() {
    return "forward:/index.html";
}
</code>```

The /**/ in the beginning helps to map nested resources to this method.

Title: Angular html5 mode and Spring routing

Body:
I'm having an issue using angular html5 mode for routing with a spring boot backend. The application works fine when I use ui router's $state.go() to navigate to different url's, but when I attempt to enter a different state's url and go directly to it, it fails to load properly.

We used a solution similar to what is detailed here (https://spring.io/guides/tutorials/spring-security-and-angular-js/), essentially using a spring controller to forward certain pages to the base url, "/". The difference with ours is that we use a base url, 'step', to put before every page but the home page. When we do navigate directly to a different page in our site, however, every resource that is loaded is turned into our index.html file (js, css, etc.). When we look at the network requests, it's appended the 'step' url in front of every request for some reason (so instead of css/style.css, it would be step/css/style.css).

Here's an example of our spring controller:

@Controller
public class ViewController {
    @RequestMapping(value="/step/**")
    public String forward() {
        return "forward:/";
    }
}

Any help would be appreciated, but keep in mind we have looked into various solutions already such as the link mentioned and several others which have similar solutions.

Body:
In combination with thread and this source we finally got it working. In our case there aren't any subpages. Maybe it helps someone:

@RequestMapping(value = "/**/{id:[^\\.]*}")
public String html5Forwarding() {
    return "forward:/index.html";
}

The /**/ in the beginning helps to map nested resources to this method.


问:
how transform xml document with xslt to duplicate output lines according to the child node
I worked on extracting information of Icecat xml files with SSIS package.

```<code><?xml version="1.0" encoding="UTF-8"?>
<ICECAT-interface>
<Response Date="Tue Jun 27 16:00:01 2017" ID="0" Request_ID="1498572001"
Status="1">
<SuppliersList>
  <Supplier ID="1" LogoPic="http://images.icecat.biz/img/brand/thumb/1_91e0e5b25690437cb026012c624a00ad.jpg" LogoPicHeight="75" LogoPicWidth="75" LogoPicSize="10201" LogoLowPic="http://images.icecat.biz/img/brand/low/1_577ba75b274e4917bf27f4ff5fc609be.jpg" LogoLowPicHeight="200" LogoLowPicWidth="200" LogoLowSize="31058" LogoMediumPic="" LogoMediumPicHeight="0" LogoMediumPicWidth="0" LogoMediumPicSize="0" LogoHighPic="http://images.icecat.biz/img/brand/high/1_43ebe562b309447dbbf377fd5adf41e3.jpg" LogoHighPicHeight="200" LogoHighPicWidth="200" LogoHighPicSize="31058" LogoOriginal="http://images.icecat.biz/img/brand/original/1_9a451c84f85c44d78ae79a1712706fe9.jpg" LogoOriginalSize="31133" Name="HP" Sponsor="1">
    <Names>
      <Name langid="12" Name="惠普" />
    </Names>
  </Supplier>
  <Supplier ID="2" LogoPic="http://images.icecat.biz/img/brand/thumb/2_b4222cd1f4ef41a79d452c7d47d9b8a8.jpg" LogoPicHeight="75" LogoPicWidth="75" LogoPicSize="3668" LogoLowPic="http://images.icecat.biz/img/brand/low/2_7a45daa4e872400c8037f0e4231a7cb4.jpg" LogoLowPicHeight="53" LogoLowPicWidth="200" LogoLowSize="13241" LogoMediumPic="" LogoMediumPicHeight="0" LogoMediumPicWidth="0" LogoMediumPicSize="0" LogoHighPic="http://images.icecat.biz/img/brand/high/2_286ef5dd29ca4941be0b9de27f041b4b.jpg" LogoHighPicHeight="53" LogoHighPicWidth="200" LogoHighPicSize="13241" LogoOriginal="http://images.icecat.biz/img/brand/original/2_093830b1b15a4eb8b38425d64ba80e9d.jpg" LogoOriginalSize="37929" Name="Toshiba" Sponsor="1" />
  <Supplier ID="3" LogoPic="http://images.icecat.biz/img/brand/thumb/3_d2375bf6ef1d47269cd01fa902a13788.jpg" LogoPicHeight="75" LogoPicWidth="75" LogoPicSize="3382" LogoLowPic="http://images.icecat.biz/img/brand/low/3_d05e0e4693d34b85ad56c94404338662.jpg" LogoLowPicHeight="76" LogoLowPicWidth="200" LogoLowSize="9156" LogoMediumPic="" LogoMediumPicHeight="0" LogoMediumPicWidth="0" LogoMediumPicSize="0" LogoHighPic="http://images.icecat.biz/img/brand/high/3_a4caad745868496ea1ee4e6c0df57585.jpg" LogoHighPicHeight="76" LogoHighPicWidth="200" LogoHighPicSize="9156" LogoOriginal="http://images.icecat.biz/img/brand/original/3_b5bc53009d974136ba7048b8e2d9e8b4.jpg" LogoOriginalSize="37257" Name="IBM" Sponsor="1" />
  <Supplier ID="5" LogoPic="http://images.icecat.biz/img/brand/thumb/5_1cf5d422c33b47159d29120556249309.jpg" LogoPicHeight="75" LogoPicWidth="75" LogoPicSize="1916" LogoLowPic="http://images.icecat.biz/img/brand/low/5_a028484b02804360a3b2a3d6f1635439.jpg" LogoLowPicHeight="43" LogoLowPicWidth="200" LogoLowSize="6322" LogoMediumPic="" LogoMediumPicHeight="0" LogoMediumPicWidth="0" LogoMediumPicSize="0" LogoHighPic="http://images.icecat.biz/img/brand/high/5_5666d3e455e34cdea7572e6ab5a4e38e.jpg" LogoHighPicHeight="43" LogoHighPicWidth="200" LogoHighPicSize="6322" LogoOriginal="http://images.icecat.biz/img/brand/original/5_b1c151c0bacf4360b4eb9161b71ea8a4.jpg" LogoOriginalSize="6510" Name="Sony" Sponsor="1" />
  <Supplier ID="6" LogoPic="http://images.icecat.biz/img/brand/thumb/6_bed73021a8fc496a8386b3c9276f0216.jpg" LogoPicHeight="75" LogoPicWidth="75" LogoPicSize="3111" LogoLowPic="http://images.icecat.biz/img/brand/low/6_8dae0e5b024145aa82c5c229048240e8.jpg" LogoLowPicHeight="117" LogoLowPicWidth="200" LogoLowSize="11196" LogoMediumPic="" LogoMediumPicHeight="0" LogoMediumPicWidth="0" LogoMediumPicSize="0" LogoHighPic="http://images.icecat.biz/img/brand/high/6_53e052f2b7594a4e9f3950081dfe143d.jpg" LogoHighPicHeight="117" LogoHighPicWidth="200" LogoHighPicSize="11196" LogoOriginal="http://images.icecat.biz/img/brand/original/6_f4b347ab7d2e4ab88f84d8e04ccfe966.jpg" LogoOriginalSize="24384" Name="3com" />
  <Supplier ID="7" LogoPic="http://images.icecat.biz/img/brand/thumb/7_2e1091176d2d450eae2dce7506f1952f.jpg" LogoPicHeight="75" LogoPicWidth="75" LogoPicSize="3583" LogoLowPic="http://images.icecat.biz/img/brand/low/7_5760a89b29ab45aeae95ae639c247b3a.jpg" LogoLowPicHeight="89" LogoLowPicWidth="200" LogoLowSize="11942" LogoMediumPic="http://images.icecat.biz/img/brand/medium/7_ce2e94986d1847568b47a2d488d374fd.jpg" LogoMediumPicHeight="222" LogoMediumPicWidth="500" LogoMediumPicSize="31489" LogoHighPic="http://images.icecat.biz/img/brand/high/7_faa735acc8b7487093b094c1440cc91d.jpg" LogoHighPicHeight="1336" LogoHighPicWidth="2999" LogoHighPicSize="241523" LogoOriginal="http://images.icecat.biz/img/brand/original/7_6a89e510401c47d894ad4bb6188cc65a.jpg" LogoOriginalSize="442120" Name="Acer" Sponsor="1">
    <Names>
      <Name langid="12" Name="宏碁" />
    </Names>
  </Supplier>
  <Supplier ID="8" LogoPic="http://images.icecat.biz/img/brand/thumb/8_d489e504070b40e886b6456a0a7beb99.jpg" LogoPicHeight="75" LogoPicWidth="75" LogoPicSize="6122" LogoLowPic="http://images.icecat.biz/img/brand/low/8_d5179e6b3bb14bf889d5bf56e2ed42e3.jpg" LogoLowPicHeight="200" LogoLowPicWidth="158" LogoLowSize="20437" LogoMediumPic="" LogoMediumPicHeight="0" LogoMediumPicWidth="0" LogoMediumPicSize="0" LogoHighPic="http://images.icecat.biz/img/brand/high/8_e7673fd830a04b2fa8f655bb58dad630.jpg" LogoHighPicHeight="252" LogoHighPicWidth="200" LogoHighPicSize="25045" LogoOriginal="http://images.icecat.biz/img/brand/original/8_a711999f9d3a4c8fb35fec28f22d4dbf.jpg" LogoOriginalSize="46934" Name="Adobe" />
  <Supplier ID="9" LogoPic="" LogoPicHeight="0" LogoPicWidth="0" LogoPicSize="0" LogoLowPic="" LogoLowPicHeight="0" LogoLowPicWidth="0" LogoLowSize="0" LogoMediumPic="" LogoMediumPicHeight="0" LogoMediumPicWidth="0" LogoMediumPicSize="0" LogoHighPic="" LogoHighPicHeight="0" LogoHighPicWidth="0" LogoHighPicSize="0" LogoOriginal="" LogoOriginalSize="0" Name="Apple">
    <Names>
      <Name langid="12" Name="苹果" />
    </Names>
  </Supplier>
 ....
</code>```

Like u see some times I've Name of supplier like attibutes (it's the internationnal name of supplier langid=1=english) but sometimes I've child nodes "Names" for name in special language like chinese...

I want create a new xml file with on line Name and LangId attibutes duplicating lines when I've child node likes this:

```<code>  <Supplier ID="1" LogoLowPic="http://images.icecat.biz/img/brand/low/1_577ba75b274e4917bf27f4ff5fc609be.jpg" Name="HP" langid="1"></Supplier>
    <Supplier ID="1" LogoLowPic="http://images.icecat.biz/img/brand/low/1_577ba75b274e4917bf27f4ff5fc609be.jpg" Name="惠普" langid="12"></Supplier>
    <Supplier ID="2"  LogoLowPic="http://images.icecat.biz/img/brand/low/2_7a45daa4e872400c8037f0e4231a7cb4.jpg"  Name="Toshiba" langid="1"></Supplier>
</code>```

Here my try, but It's not the good result.

```<code><?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output  method="xml" encoding="UTF-8" indent="yes"/>

<xsl:template match="/ICECAT-interface">
    <xsl:apply-templates select="Response"/>
</xsl:template>

<xsl:template match="Response">
    <xsl:apply-templates select="SuppliersList"/>
</xsl:template>

<xsl:template match="SuppliersList">
    <xsl:apply-templates select="Supplier"/>
</xsl:template>

<xsl:template match="Supplier">
    <xsl:element name="Supplier">
        <xsl:attribute name="ID">
            <xsl:value-of select="@ID"/>
        </xsl:attribute>
        <xsl:attribute name="LogoLowPic">
            <xsl:value-of select="@LogoLowPic"/>
        </xsl:attribute>
        <xsl:attribute name="Name">
            <xsl:value-of select="@Name"/>
        </xsl:attribute>
        <xsl:attribute name="langid">
            <xsl:value-of select="1"/>
        </xsl:attribute>
        <xsl:apply-templates select="Names"/>
    </xsl:element>
</xsl:template>
 <xsl:template match="Names">
    <xsl:element name="Name">
        <xsl:attribute name="Name">
            <xsl:value-of select="@Name"/>
        </xsl:attribute>
        <xsl:attribute name="langid">
            <xsl:value-of select="@langid"/>
        </xsl:attribute>
    </xsl:element>
 </xsl:template>
</xsl:stylesheet>
</code>```

Thanks for your help.

答:
One thing you need to do is move the <xsl:apply-templates select="Names"/> to be after copying of the Supplier element, rather than in it, so you create a sibling, rather than a child.

It would also be easier if you selected Names/Name rather than just Name.

Try this XSLT...

```<code><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output  method="xml" encoding="UTF-8" indent="yes"/>

<xsl:template match="/ICECAT-interface">
    <xsl:apply-templates select="Response"/>
</xsl:template>

<xsl:template match="Response">
    <xsl:apply-templates select="SuppliersList"/>
</xsl:template>

<xsl:template match="SuppliersList">
  <xsl:copy>
    <xsl:apply-templates select="Supplier"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="Supplier">
    <Supplier>
      <xsl:copy-of select="@ID|@LogoLowPic|@Name"/>
      <xsl:attribute name="langid">
          <xsl:value-of select="1"/>
      </xsl:attribute>
  </Supplier>
  <xsl:apply-templates select="Names/Name"/>
</xsl:template>

<xsl:template match="Name">
  <Supplier>
    <xsl:copy-of select="../../@ID|../../@LogoLowPic" />
    <xsl:copy-of select="@Name|@langid" />
  </Supplier>
 </xsl:template>
</xsl:stylesheet>
</code>```

Note how I have used xsl:copy-of to simplify the copying of attributes. Alternatively, you can make use of Attribute Value Templates here. For example, the Name template can be written like this.

```<code><xsl:template match="Name">
  <Supplier ID="{../../@ID}">
    <xsl:copy-of select="@Name|@langid" />
  </Supplier>
 </xsl:template>
</code>```

Body:
I worked on extracting information of Icecat xml files with SSIS package.

<?xml version="1.0" encoding="UTF-8"?>
<ICECAT-interface>
<Response Date="Tue Jun 27 16:00:01 2017" ID="0" Request_ID="1498572001"
Status="1">
<SuppliersList>
  <Supplier ID="1" LogoPic="http://images.icecat.biz/img/brand/thumb/1_91e0e5b25690437cb026012c624a00ad.jpg" LogoPicHeight="75" LogoPicWidth="75" LogoPicSize="10201" LogoLowPic="http://images.icecat.biz/img/brand/low/1_577ba75b274e4917bf27f4ff5fc609be.jpg" LogoLowPicHeight="200" LogoLowPicWidth="200" LogoLowSize="31058" LogoMediumPic="" LogoMediumPicHeight="0" LogoMediumPicWidth="0" LogoMediumPicSize="0" LogoHighPic="http://images.icecat.biz/img/brand/high/1_43ebe562b309447dbbf377fd5adf41e3.jpg" LogoHighPicHeight="200" LogoHighPicWidth="200" LogoHighPicSize="31058" LogoOriginal="http://images.icecat.biz/img/brand/original/1_9a451c84f85c44d78ae79a1712706fe9.jpg" LogoOriginalSize="31133" Name="HP" Sponsor="1">
    <Names>
      <Name langid="12" Name="惠普" />
    </Names>
  </Supplier>
  <Supplier ID="2" LogoPic="http://images.icecat.biz/img/brand/thumb/2_b4222cd1f4ef41a79d452c7d47d9b8a8.jpg" LogoPicHeight="75" LogoPicWidth="75" LogoPicSize="3668" LogoLowPic="http://images.icecat.biz/img/brand/low/2_7a45daa4e872400c8037f0e4231a7cb4.jpg" LogoLowPicHeight="53" LogoLowPicWidth="200" LogoLowSize="13241" LogoMediumPic="" LogoMediumPicHeight="0" LogoMediumPicWidth="0" LogoMediumPicSize="0" LogoHighPic="http://images.icecat.biz/img/brand/high/2_286ef5dd29ca4941be0b9de27f041b4b.jpg" LogoHighPicHeight="53" LogoHighPicWidth="200" LogoHighPicSize="13241" LogoOriginal="http://images.icecat.biz/img/brand/original/2_093830b1b15a4eb8b38425d64ba80e9d.jpg" LogoOriginalSize="37929" Name="Toshiba" Sponsor="1" />
  <Supplier ID="3" LogoPic="http://images.icecat.biz/img/brand/thumb/3_d2375bf6ef1d47269cd01fa902a13788.jpg" LogoPicHeight="75" LogoPicWidth="75" LogoPicSize="3382" LogoLowPic="http://images.icecat.biz/img/brand/low/3_d05e0e4693d34b85ad56c94404338662.jpg" LogoLowPicHeight="76" LogoLowPicWidth="200" LogoLowSize="9156" LogoMediumPic="" LogoMediumPicHeight="0" LogoMediumPicWidth="0" LogoMediumPicSize="0" LogoHighPic="http://images.icecat.biz/img/brand/high/3_a4caad745868496ea1ee4e6c0df57585.jpg" LogoHighPicHeight="76" LogoHighPicWidth="200" LogoHighPicSize="9156" LogoOriginal="http://images.icecat.biz/img/brand/original/3_b5bc53009d974136ba7048b8e2d9e8b4.jpg" LogoOriginalSize="37257" Name="IBM" Sponsor="1" />
  <Supplier ID="5" LogoPic="http://images.icecat.biz/img/brand/thumb/5_1cf5d422c33b47159d29120556249309.jpg" LogoPicHeight="75" LogoPicWidth="75" LogoPicSize="1916" LogoLowPic="http://images.icecat.biz/img/brand/low/5_a028484b02804360a3b2a3d6f1635439.jpg" LogoLowPicHeight="43" LogoLowPicWidth="200" LogoLowSize="6322" LogoMediumPic="" LogoMediumPicHeight="0" LogoMediumPicWidth="0" LogoMediumPicSize="0" LogoHighPic="http://images.icecat.biz/img/brand/high/5_5666d3e455e34cdea7572e6ab5a4e38e.jpg" LogoHighPicHeight="43" LogoHighPicWidth="200" LogoHighPicSize="6322" LogoOriginal="http://images.icecat.biz/img/brand/original/5_b1c151c0bacf4360b4eb9161b71ea8a4.jpg" LogoOriginalSize="6510" Name="Sony" Sponsor="1" />
  <Supplier ID="6" LogoPic="http://images.icecat.biz/img/brand/thumb/6_bed73021a8fc496a8386b3c9276f0216.jpg" LogoPicHeight="75" LogoPicWidth="75" LogoPicSize="3111" LogoLowPic="http://images.icecat.biz/img/brand/low/6_8dae0e5b024145aa82c5c229048240e8.jpg" LogoLowPicHeight="117" LogoLowPicWidth="200" LogoLowSize="11196" LogoMediumPic="" LogoMediumPicHeight="0" LogoMediumPicWidth="0" LogoMediumPicSize="0" LogoHighPic="http://images.icecat.biz/img/brand/high/6_53e052f2b7594a4e9f3950081dfe143d.jpg" LogoHighPicHeight="117" LogoHighPicWidth="200" LogoHighPicSize="11196" LogoOriginal="http://images.icecat.biz/img/brand/original/6_f4b347ab7d2e4ab88f84d8e04ccfe966.jpg" LogoOriginalSize="24384" Name="3com" />
  <Supplier ID="7" LogoPic="http://images.icecat.biz/img/brand/thumb/7_2e1091176d2d450eae2dce7506f1952f.jpg" LogoPicHeight="75" LogoPicWidth="75" LogoPicSize="3583" LogoLowPic="http://images.icecat.biz/img/brand/low/7_5760a89b29ab45aeae95ae639c247b3a.jpg" LogoLowPicHeight="89" LogoLowPicWidth="200" LogoLowSize="11942" LogoMediumPic="http://images.icecat.biz/img/brand/medium/7_ce2e94986d1847568b47a2d488d374fd.jpg" LogoMediumPicHeight="222" LogoMediumPicWidth="500" LogoMediumPicSize="31489" LogoHighPic="http://images.icecat.biz/img/brand/high/7_faa735acc8b7487093b094c1440cc91d.jpg" LogoHighPicHeight="1336" LogoHighPicWidth="2999" LogoHighPicSize="241523" LogoOriginal="http://images.icecat.biz/img/brand/original/7_6a89e510401c47d894ad4bb6188cc65a.jpg" LogoOriginalSize="442120" Name="Acer" Sponsor="1">
    <Names>
      <Name langid="12" Name="宏碁" />
    </Names>
  </Supplier>
  <Supplier ID="8" LogoPic="http://images.icecat.biz/img/brand/thumb/8_d489e504070b40e886b6456a0a7beb99.jpg" LogoPicHeight="75" LogoPicWidth="75" LogoPicSize="6122" LogoLowPic="http://images.icecat.biz/img/brand/low/8_d5179e6b3bb14bf889d5bf56e2ed42e3.jpg" LogoLowPicHeight="200" LogoLowPicWidth="158" LogoLowSize="20437" LogoMediumPic="" LogoMediumPicHeight="0" LogoMediumPicWidth="0" LogoMediumPicSize="0" LogoHighPic="http://images.icecat.biz/img/brand/high/8_e7673fd830a04b2fa8f655bb58dad630.jpg" LogoHighPicHeight="252" LogoHighPicWidth="200" LogoHighPicSize="25045" LogoOriginal="http://images.icecat.biz/img/brand/original/8_a711999f9d3a4c8fb35fec28f22d4dbf.jpg" LogoOriginalSize="46934" Name="Adobe" />
  <Supplier ID="9" LogoPic="" LogoPicHeight="0" LogoPicWidth="0" LogoPicSize="0" LogoLowPic="" LogoLowPicHeight="0" LogoLowPicWidth="0" LogoLowSize="0" LogoMediumPic="" LogoMediumPicHeight="0" LogoMediumPicWidth="0" LogoMediumPicSize="0" LogoHighPic="" LogoHighPicHeight="0" LogoHighPicWidth="0" LogoHighPicSize="0" LogoOriginal="" LogoOriginalSize="0" Name="Apple">
    <Names>
      <Name langid="12" Name="苹果" />
    </Names>
  </Supplier>
 ....

Like u see some times I've Name of supplier like attibutes (it's the internationnal name of supplier langid=1=english) but sometimes I've child nodes "Names" for name in special language like chinese...

I want create a new xml file with on line Name and LangId attibutes duplicating lines when I've child node likes this:

  <Supplier ID="1" LogoLowPic="http://images.icecat.biz/img/brand/low/1_577ba75b274e4917bf27f4ff5fc609be.jpg" Name="HP" langid="1"></Supplier>
    <Supplier ID="1" LogoLowPic="http://images.icecat.biz/img/brand/low/1_577ba75b274e4917bf27f4ff5fc609be.jpg" Name="惠普" langid="12"></Supplier>
    <Supplier ID="2"  LogoLowPic="http://images.icecat.biz/img/brand/low/2_7a45daa4e872400c8037f0e4231a7cb4.jpg"  Name="Toshiba" langid="1"></Supplier>

Here my try, but It's not the good result.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output  method="xml" encoding="UTF-8" indent="yes"/>

<xsl:template match="/ICECAT-interface">
    <xsl:apply-templates select="Response"/>
</xsl:template>

<xsl:template match="Response">
    <xsl:apply-templates select="SuppliersList"/>
</xsl:template>

<xsl:template match="SuppliersList">
    <xsl:apply-templates select="Supplier"/>
</xsl:template>

<xsl:template match="Supplier">
    <xsl:element name="Supplier">
        <xsl:attribute name="ID">
            <xsl:value-of select="@ID"/>
        </xsl:attribute>
        <xsl:attribute name="LogoLowPic">
            <xsl:value-of select="@LogoLowPic"/>
        </xsl:attribute>
        <xsl:attribute name="Name">
            <xsl:value-of select="@Name"/>
        </xsl:attribute>
        <xsl:attribute name="langid">
            <xsl:value-of select="1"/>
        </xsl:attribute>
        <xsl:apply-templates select="Names"/>
    </xsl:element>
</xsl:template>
 <xsl:template match="Names">
    <xsl:element name="Name">
        <xsl:attribute name="Name">
            <xsl:value-of select="@Name"/>
        </xsl:attribute>
        <xsl:attribute name="langid">
            <xsl:value-of select="@langid"/>
        </xsl:attribute>
    </xsl:element>
 </xsl:template>
</xsl:stylesheet>

Thanks for your help.

Body:
One thing you need to do is move the <xsl:apply-templates select="Names"/> to be after copying of the Supplier element, rather than in it, so you create a sibling, rather than a child.

It would also be easier if you selected Names/Name rather than just Name.

Try this XSLT...

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output  method="xml" encoding="UTF-8" indent="yes"/>

<xsl:template match="/ICECAT-interface">
    <xsl:apply-templates select="Response"/>
</xsl:template>

<xsl:template match="Response">
    <xsl:apply-templates select="SuppliersList"/>
</xsl:template>

<xsl:template match="SuppliersList">
  <xsl:copy>
    <xsl:apply-templates select="Supplier"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="Supplier">
    <Supplier>
      <xsl:copy-of select="@ID|@LogoLowPic|@Name"/>
      <xsl:attribute name="langid">
          <xsl:value-of select="1"/>
      </xsl:attribute>
  </Supplier>
  <xsl:apply-templates select="Names/Name"/>
</xsl:template>

<xsl:template match="Name">
  <Supplier>
    <xsl:copy-of select="../../@ID|../../@LogoLowPic" />
    <xsl:copy-of select="@Name|@langid" />
  </Supplier>
 </xsl:template>
</xsl:stylesheet>

Note how I have used xsl:copy-of to simplify the copying of attributes. Alternatively, you can make use of Attribute Value Templates here. For example, the Name template can be written like this.

<xsl:template match="Name">
  <Supplier ID="{../../@ID}">
    <xsl:copy-of select="@Name|@langid" />
  </Supplier>
 </xsl:template>


问:
Why can't I find System.Text.RegularExpressions when using Mono in Linux?
I'm attempting to use Mono and Monodevelop (the IDE) to code a C# project in Ubuntu.

Everything is working apart from the fact that the System.Text.RegularExpressions (Package?) is not found.  The only relevant thing I have found on the interwebs is here

There appears to be a solution of sorts posted, but I don't understand.  Please help :)

答:
In MonoDevelop, right click on References and add a reference to the System assembly.

You could use gmcs -r System *.cs to compile from command line.

LastEditorDisplayName: Simucal

OwnerDisplayName: Mehrdad Afshari


问:
can client connect from 10.20.0.2 to wcf host on 192.168.0.2?
It's possible to mobile client on 10.20.0.2 network connect to wcf service host on other network ? They are connected by usb cord by now and I want test that they can connect...</p>

答: If you have a network route, I don't see why not, provided that WCF itself can do networking.</p>


问:
Installing additional Wordpress instances into a Bitnami multi-tier WP stack?
I have installed the Bitnami Mutli-tier Wordpress stack (on Azure).

I want to install a number of additional instances of WP onto that stack. Because it is the multi-tier version of the stack, the normal instructions for installing additional WP instances do not work. This is because the MySQL server is on a separate VM, and the Bitnami Wordpress installed is not set up for handling that.

So, instructions such as those posted here, don't work. The official instructions, which those are a replica of, are here.

So, what I am wanting to hear from people, is the recommended way to add additional WP instances to this stack. For instance, can I just go ahead and install wordpress the normal way (set up a new directory with the WP source files in it), and then make some manual changes to the Apache and/or vhost conf files so that the new instance is registered on the server? If so, what changes do I need to make to the conf files (etc.) for that?

Please note, I am not referring to the Bitnami Wordpress Multisite stack. It is the Multi-tier stack, on which the MySQL server is on a separate VM. Also, I am not interested in using the multisite feature of Wordpress, for various reasons.

答:
[Bitnami Developer here] As you mentioned, you can't follow the official workflow to install several WordPress on top of the same stack when using the Multi-Tier solution.

Bitnami has not developed yet a similar way to install several WP on a Multi-Tier solution. However, I can describe step-by-step what you need to do in order to get your purpose.

Connect to your Server via SSH as described here.

Duplicate the WordPress Folder. You can use the commands below:

```<code>sudo cp -rf /opt/bitnami/wordpress /opt/bitnami/second-wordpress
sudo cp -rf /bitnami/wordpress/ /bitnami/second-wordpress/
sudo rm /opt/bitnami/second-wordpress/wp-config.php
sudo rm /opt/bitnami/second-wordpress/wp-content
sudo ln -s /bitnami/second-wordpress/wp-config.php /opt/bitnami/second-wordpress/wp-config.php
sudo ln -s /bitnami/second-wordpress/wp-content /opt/bitnami/second-wordpress/wp-content
sudo chown -R root:daemon /opt/bitnami/second-wordpress/
sudo chown -R root:daemon /bitnami/second-wordpress/
</code>```

Configure Apache. This step depends on the Apache Configuration you desire. I supposed you want to have two WP one at: http://YOUR-SERVER-IP/first-wordpress and the second one at http://YOUR-SERVER-IP/second-wordpres.

Fist, prepare Apache to use a "Prefix Configuration".

```<code>sudo mkdir /opt/bitnami/apache/conf/prefix
sudo mv /opt/bitnami/apache/conf/vhosts/htaccess /opt/bitnami/apache/conf/prefix/htaccess
sudo cp /opt/bitnami/apache/conf/prefix/htaccess/wordpress-htaccess.conf /opt/bitnami/apache/conf/prefix/htaccess/second-wordpress-htaccess.conf
sudo rm /opt/bitnami/apache/conf/vhosts/wordpress-vhost.conf
sudo rm /opt/bitnami/apache/conf/vhosts/wordpress-vhost.conf
</code>```

Create the file /opt/bitnami/apache/conf/prefix/wordpress-prefix.conf        with the content below:

```<code>Alias /first-wordpress/ "/opt/bitnami/wordpress/"
Alias /first-wordpress "/opt/bitnami/wordpress"
<Directory "/opt/bitnami/wordpress">
  Options -Indexes +FollowSymLinks -MultiViews
  AllowOverride None
  Require all granted
  DirectoryIndex index.html index.php

  RewriteEngine On
  RewriteBase /
  RewriteRule ^index.php$ - [S=1]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . index.php [L]

</Directory>
Include /opt/bitnami/apache/conf/prefix/htaccess/wordpress-htaccess.conf
</code>```

Create the file /opt/bitnami/apache/conf/prefix/second-wordpress-prefix.conf        with the content below:

```<code>Alias /second-wordpress/ "/opt/bitnami/second-wordpress/"
Alias /second-wordpress "/opt/bitnami/second-wordpress"
<Directory "/opt/bitnami/second-wordpress">
  Options -Indexes +FollowSymLinks -MultiViews
  AllowOverride None
  Require all granted
  DirectoryIndex index.html index.php

  RewriteEngine On
  RewriteBase /
  RewriteRule ^index.php$ - [S=1]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . index.php [L]

</Directory>
Include /opt/bitnami/apache/conf/prefix/htaccess/second-wordpress-htaccess.conf
</code>```

Edit the line below in the file /opt/bitnami/apache/conf/prefix/htaccess/second-wordpress-htaccess.conf:

```<code><Directory "/opt/bitnami/wordpress/wp-content/plugins/akismet">
</code>```

with the value:

```<code><Directory "/opt/bitnami/second-wordpress/wp-content/plugins/akismet">
</code>```

Add the lines below in the file /opt/bitnami/apache/conf/bitnami/bitnami.conf (both Vhosts behind the line ErrorDocument 503 /503.html):

```<code>Include "/opt/bitnami/apache/conf/prefix/wordpress-prefix.conf"
Include "/opt/bitnami/apache/conf/prefix/second-wordpress-prefix.conf"
</code>```

Connect to the Database

```<code>sudo /opt/bitnami/mysql/bin/mysql -u root -h mariadb -p
</code>```

Create a Database for the new WP and grant permissions to bn_wordpress user.

```<code>CREATE DATABASE bitnami_second_wordpress;
GRANT ALL PRIVILEGES ON `bitnami_second_wordpress`.* TO 'bn_wordpress'@'%'
</code>```

Edit the lines below at /opt/bitnami/wordpress/wp-config.php:

```<code>define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/');
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/');
</code>```

with the value:

```<code>sudo mkdir /opt/bitnami/apache/conf/prefix
sudo mv /opt/bitnami/apache/conf/vhosts/htaccess /opt/bitnami/apache/conf/prefix/htaccess
sudo cp /opt/bitnami/apache/conf/prefix/htaccess/wordpress-htaccess.conf /opt/bitnami/apache/conf/prefix/htaccess/second-wordpress-htaccess.conf
sudo rm /opt/bitnami/apache/conf/vhosts/wordpress-vhost.conf
sudo rm /opt/bitnami/apache/conf/vhosts/wordpress-vhost.conf
</code>```0

Edit the lines below at /opt/bitnami/second-wordpress/wp-config.php:

```<code>sudo mkdir /opt/bitnami/apache/conf/prefix
sudo mv /opt/bitnami/apache/conf/vhosts/htaccess /opt/bitnami/apache/conf/prefix/htaccess
sudo cp /opt/bitnami/apache/conf/prefix/htaccess/wordpress-htaccess.conf /opt/bitnami/apache/conf/prefix/htaccess/second-wordpress-htaccess.conf
sudo rm /opt/bitnami/apache/conf/vhosts/wordpress-vhost.conf
sudo rm /opt/bitnami/apache/conf/vhosts/wordpress-vhost.conf
</code>```1

with the value:

```<code>sudo mkdir /opt/bitnami/apache/conf/prefix
sudo mv /opt/bitnami/apache/conf/vhosts/htaccess /opt/bitnami/apache/conf/prefix/htaccess
sudo cp /opt/bitnami/apache/conf/prefix/htaccess/wordpress-htaccess.conf /opt/bitnami/apache/conf/prefix/htaccess/second-wordpress-htaccess.conf
sudo rm /opt/bitnami/apache/conf/vhosts/wordpress-vhost.conf
sudo rm /opt/bitnami/apache/conf/vhosts/wordpress-vhost.conf
</code>```2

Finally Restart Apache;

```<code>sudo nami restart apache
</code>```

Body:
[Bitnami Developer here] As you mentioned, you can't follow the official workflow to install several WordPress on top of the same stack when using the Multi-Tier solution.

Bitnami has not developed yet a similar way to install several WP on a Multi-Tier solution. However, I can describe step-by-step what you need to do in order to get your purpose.

Connect to your Server via SSH as described here.

Duplicate the WordPress Folder. You can use the commands below:

sudo cp -rf /opt/bitnami/wordpress /opt/bitnami/second-wordpress
sudo cp -rf /bitnami/wordpress/ /bitnami/second-wordpress/
sudo rm /opt/bitnami/second-wordpress/wp-config.php
sudo rm /opt/bitnami/second-wordpress/wp-content
sudo ln -s /bitnami/second-wordpress/wp-config.php /opt/bitnami/second-wordpress/wp-config.php
sudo ln -s /bitnami/second-wordpress/wp-content /opt/bitnami/second-wordpress/wp-content
sudo chown -R root:daemon /opt/bitnami/second-wordpress/
sudo chown -R root:daemon /bitnami/second-wordpress/

Configure Apache. This step depends on the Apache Configuration you desire. I supposed you want to have two WP one at: http://YOUR-SERVER-IP/first-wordpress and the second one at http://YOUR-SERVER-IP/second-wordpres.

Fist, prepare Apache to use a "Prefix Configuration".

sudo mkdir /opt/bitnami/apache/conf/prefix
sudo mv /opt/bitnami/apache/conf/vhosts/htaccess /opt/bitnami/apache/conf/prefix/htaccess
sudo cp /opt/bitnami/apache/conf/prefix/htaccess/wordpress-htaccess.conf /opt/bitnami/apache/conf/prefix/htaccess/second-wordpress-htaccess.conf
sudo rm /opt/bitnami/apache/conf/vhosts/wordpress-vhost.conf
sudo rm /opt/bitnami/apache/conf/vhosts/wordpress-vhost.conf

Create the file /opt/bitnami/apache/conf/prefix/wordpress-prefix.conf        with the content below:

Alias /first-wordpress/ "/opt/bitnami/wordpress/"
Alias /first-wordpress "/opt/bitnami/wordpress"
<Directory "/opt/bitnami/wordpress">
  Options -Indexes +FollowSymLinks -MultiViews
  AllowOverride None
  Require all granted
  DirectoryIndex index.html index.php

  RewriteEngine On
  RewriteBase /
  RewriteRule ^index.php$ - [S=1]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . index.php [L]

</Directory>
Include /opt/bitnami/apache/conf/prefix/htaccess/wordpress-htaccess.conf

Create the file /opt/bitnami/apache/conf/prefix/second-wordpress-prefix.conf        with the content below:

Alias /second-wordpress/ "/opt/bitnami/second-wordpress/"
Alias /second-wordpress "/opt/bitnami/second-wordpress"
<Directory "/opt/bitnami/second-wordpress">
  Options -Indexes +FollowSymLinks -MultiViews
  AllowOverride None
  Require all granted
  DirectoryIndex index.html index.php

  RewriteEngine On
  RewriteBase /
  RewriteRule ^index.php$ - [S=1]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . index.php [L]

</Directory>
Include /opt/bitnami/apache/conf/prefix/htaccess/second-wordpress-htaccess.conf

Edit the line below in the file /opt/bitnami/apache/conf/prefix/htaccess/second-wordpress-htaccess.conf:

<Directory "/opt/bitnami/wordpress/wp-content/plugins/akismet">

with the value:

<Directory "/opt/bitnami/second-wordpress/wp-content/plugins/akismet">

Add the lines below in the file /opt/bitnami/apache/conf/bitnami/bitnami.conf (both Vhosts behind the line ErrorDocument 503 /503.html):

Include "/opt/bitnami/apache/conf/prefix/wordpress-prefix.conf"
Include "/opt/bitnami/apache/conf/prefix/second-wordpress-prefix.conf"

Connect to the Database

sudo /opt/bitnami/mysql/bin/mysql -u root -h mariadb -p

Create a Database for the new WP and grant permissions to bn_wordpress user.

CREATE DATABASE bitnami_second_wordpress;
GRANT ALL PRIVILEGES ON `bitnami_second_wordpress`.* TO 'bn_wordpress'@'%'

Edit the lines below at /opt/bitnami/wordpress/wp-config.php:

define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/');
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/');

with the value:

define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/first-wordpress');
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/first-wordpress');

Edit the lines below at /opt/bitnami/second-wordpress/wp-config.php:

define('DB_NAME', 'bitnami_wordpress');
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/');
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/');

with the value:

define('DB_NAME', 'bitnami_second_wordpress');
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/second-wordpress');
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/second-wordpress');

Finally Restart Apache;

sudo nami restart apache


问:
Error extending Shape class
Im getting an error in my C# code and I cant figure out why

```<code>namespace Memory
{
    class Meme : Shape
    {
        public int used { get; set; }
        public string name { get; set; }

        protected override Geometry DefiningGeometry => throw new NotImplementedException();
    }
}
</code>```

The error im getting is:

System.NotImplementedException: 'The method or operation is not implemented.'

code creating the instance:

```<code>options.Add(new Meme()
    {
     name  =  option,
            used = 0,
            Width = 50,
            Height = 50,
            Fill = Brushes.Red
        });
</code>```

答:
Looking at just the piece of code that you shown:

1) When you are 'extending' a class, given that the DefiningGeometry was an abstract property, you would need to explicitly provide an implementation for it. C# would automatically implement it using 'NotImplementedException' so that at least it could compile.

2) I've tried the code that creates the instance, and based on the above, it shouldn't call the 'DefiningGeometry' property. As such, it shouldn't actually throw the 'NotImplementedException'. There may be something else in your code that might trigger that exception.

--> Try mm8 suggestion of giving an actual implementation to verify if your code does call the DefiningGeometry method or not. Without changing this, your code should compile -- but if now it doesn't resulted in an exception, your other code may call this property.

--> I was guessing that in this code, the name = option, option here is a variable declared somewhere else (and that it doesn't have a 'get' implementation that calls a different method) -- as that probably another possible explanation.

Title: Error extending Shape class

Body:
Im getting an error in my C# code and I cant figure out why

namespace Memory
{
    class Meme : Shape
    {
        public int used { get; set; }
        public string name { get; set; }

        protected override Geometry DefiningGeometry => throw new NotImplementedException();
    }
}

The error im getting is:

System.NotImplementedException: 'The method or operation is not implemented.'

code creating the instance:

options.Add(new Meme()
    {
     name  =  option,
            used = 0,
            Width = 50,
            Height = 50,
            Fill = Brushes.Red
        });


问:
loading only some images in HTML and angularJS
In this images shows what happen
HTML code is here- In this some of my images showing in webpage and some of is not..how should i fix it</p>

```<code><img src="img/uploadFiles/{{room.imageLocation.split('//')[6]}}/{{room.imageLocation.split('-')[1]}}" alt="Image Loading Failed"/>
</code>```

答:
Use ng-src instead of src when you are binding images

```<code><img  ng-src="img/uploadFiles/{{room.imageLocation.split('//')[6]}}/{{room.imageLocation.split('-')[1]}}" alt="Image Loading Failed"/>
</code>```

Body:
Use ng-src instead of src when you are binding images

<img  ng-src="img/uploadFiles/{{room.imageLocation.split('//')[6]}}/{{room.imageLocation.split('-')[1]}}" alt="Image Loading Failed"/>


问:
Twilio chat synchronization on re-connection
Lets say that a twilio chat client(TC1) on an Android/iOS device has already received M messages from another chat client(TC2).

Due to network issues, TC1 stays disconnected for D mins, during which TC2 sends 3 messages.

When TC1 comes back online, will it receive these 3 messages automatically in quick succession ?

If yes, what if D is in hours or days ?

In which cases can the app rely on the twilio sdk to auto synchronize on disconnections and which are the cases when the app needs to explicitly synchronize the channel or fetch latest messages manually and merge it with what it has so far ?

答: I contacted twilio and here is what they replied:


问:
Convert from 4 digit Military time to Standard time
I am using SQL Server 2016 and I'm trying to convert military time to standard time. The military time is a 4 digit integer and I'm trying to get the standard time format (00:00 am/pm).

I ran a simple CASE statement that made it standard but without ':' and 'am/pm'.

```<code>CASE
  WHEN  SA_BEGTIME between 0 and 1259 then SA_BEGTIME
  WHEN SA_BEGTIME between 1300 and 2400 then  SA_BEGTIME - 1200

  ELSE ''

END as Time
</code>```

Results

How do I convert it so that it is in the right format: '00:00 am/pm'

Thank you!

答:
I'm using the solution that @BaconBits provided but I had to make a tweak because 2400 was a valid representation but it failed with that code. Here's the tweaked solution:

```<code>declare @x int = 2400
select TIMEFROMPARTS((@x / 100) % 24,@x % 100, 0, 0, 0)
</code>```

Body:
I am using SQL Server 2016 and I'm trying to convert military time to standard time. The military time is a 4 digit integer and I'm trying to get the standard time format (00:00 am/pm).

I ran a simple CASE statement that made it standard but without ':' and 'am/pm'.

CASE
  WHEN  SA_BEGTIME between 0 and 1259 then SA_BEGTIME
  WHEN SA_BEGTIME between 1300 and 2400 then  SA_BEGTIME - 1200

  ELSE ''

END as Time

Results

How do I convert it so that it is in the right format: '00:00 am/pm'

Thank you!

Body:
I'm using the solution that @BaconBits provided but I had to make a tweak because 2400 was a valid representation but it failed with that code. Here's the tweaked solution:

declare @x int = 2400
select TIMEFROMPARTS((@x / 100) % 24,@x % 100, 0, 0, 0)


问:
Minus positive with negative value in a table using subquery
I have the data below:

```<code>| Amount | Type | Employee |
| -----  | ---- | -------- |
| 500   |  A   |  001     |
| 200   |  B   |  001     |
| 300   |  A   |  002     |
| 200   |  A   |  002     |
| 100   |  B   |  002     |
</code>```

In the scenario above, all Type A columns are positive values, and Type B are negative values.

I need to calculate the amount of each employee with positive minus negative as the end result, which means Type A minus Type B.

So Employee 001 should have the result 500 - 200 = 300, and Employee 002 is 300 + 200 - 100 = 400.

I have following incomplete query:

```<code>SELECT
 (SELECT SUM(Amount) FROM A WHERE Type = 'A') -
 (SELECT SUM(Amount) FROM A WHERE Type = 'B') As Payable, Employee
FROM Payroll A
WHERE Company = @Company AND Month = @Month AND Year = @Year
GROUP BY Employee
</code>```

In the query above, the statement SELECT SUM(Amount) FROM A WHERE Type = 'A' is trying to get the positive Amount of the Payroll table which is already filtered by Company, Month and Year column. It didn't work because A is not recognize as a valid object.

So what should I do to get the data from the filtered Payroll table rather than I have to put in the WHERE condition again into both subquery?

EDIT:

Thanks Kannan and Thomas for the suggestion, but I still have problem achieving the desire result. Right now, this is my modified query with CASE

```<code>SELECT
 SUM(CASE WHEN Type = 'B' THEN -Amount ELSE Amount END) As Payable, Employee
FROM Payroll A
WHERE Company = @Company AND Month = @Month AND Year = @Year
GROUP BY Employee
</code>```

And this is the result of the query:

```<code>| Payable | Employee |
| -----   | -------- |
| 500     |  001     |
| -200    |  001     |
| 500     |  002     |
| -100    |  002     |
</code>```

Instead of sum up the value, both positive and negative is displayed as different rows.

Any help please?

答:
you can query as below:</p>

```<code>Select Employee, Sum(Case when type = 'B' then -Amount else Amount End) as Sm
   From Payroll
   WHERE Company = @Company AND Month = @Month AND Year = @Year
   GROUP BY Employee
</code>```

Body:
I have the data below:

| Amount | Type | Employee |
| -----  | ---- | -------- |
| 500   |  A   |  001     |
| 200   |  B   |  001     |
| 300   |  A   |  002     |
| 200   |  A   |  002     |
| 100   |  B   |  002     |

In the scenario above, all Type A columns are positive values, and Type B are negative values.

I need to calculate the amount of each employee with positive minus negative as the end result, which means Type A minus Type B.

So Employee 001 should have the result 500 - 200 = 300, and Employee 002 is 300 + 200 - 100 = 400.

I have following incomplete query:

SELECT
 (SELECT SUM(Amount) FROM A WHERE Type = 'A') -
 (SELECT SUM(Amount) FROM A WHERE Type = 'B') As Payable, Employee
FROM Payroll A
WHERE Company = @Company AND Month = @Month AND Year = @Year
GROUP BY Employee

In the query above, the statement SELECT SUM(Amount) FROM A WHERE Type = 'A' is trying to get the positive Amount of the Payroll table which is already filtered by Company, Month and Year column. It didn't work because A is not recognize as a valid object.

So what should I do to get the data from the filtered Payroll table rather than I have to put in the WHERE condition again into both subquery?

EDIT:

Thanks Kannan and Thomas for the suggestion, but I still have problem achieving the desire result. Right now, this is my modified query with CASE

SELECT
 SUM(CASE WHEN Type = 'B' THEN -Amount ELSE Amount END) As Payable, Employee
FROM Payroll A
WHERE Company = @Company AND Month = @Month AND Year = @Year
GROUP BY Employee

And this is the result of the query:

| Payable | Employee |
| -----   | -------- |
| 500     |  001     |
| -200    |  001     |
| 500     |  002     |
| -100    |  002     |

Instead of sum up the value, both positive and negative is displayed as different rows.

Any help please?

Body:
you can query as below:

Select Employee, Sum(Case when type = 'B' then -Amount else Amount End) as Sm
   From Payroll
   WHERE Company = @Company AND Month = @Month AND Year = @Year
   GROUP BY Employee


问:
Java FileDialog selecting directories: Mac OSX only?
I read that via

```<code>System.setProperty("apple.awt.fileDialogForDirectories", "true");
</code>```

users can select directories via a FileDialog, now the FileDialog evoces the native file chooser, so that is exactly what i want but in the line above it reads: apple.awt..., does this mean this option will only work on Mac OSX?

```<code>if(no) {
    great
} else {
    what can i do to implement this on other operating systems than?
}
</code>```

Thanks for any help!

PS: I know a lot of people suggest the use of a JFileChooser, but in this case i'd very much prefer the FileDialog, except if that's impossible

答:
To my knowledge, FileDialog does not support (in-code) using a directory dialog on all platforms.

You're already mentioned Swing's JFileChooser, but you may want to consider SWT for your widgets instead.

SWT is Eclipse (originally IBM)'s project to create an updated Java GUI Toolkit that still uses native widgets when they are available.

The major downside of SWT is that it is not part of the standard Java distribution... and each platform has its own SWT jar file.

Incidentally, SWT has a DirectoryDialog widget.

Body:
I read that via

System.setProperty("apple.awt.fileDialogForDirectories", "true");

users can select directories via a FileDialog, now the FileDialog evoces the native file chooser, so that is exactly what i want but in the line above it reads: apple.awt..., does this mean this option will only work on Mac OSX?

if(no) {
    great
} else {
    what can i do to implement this on other operating systems than?
}

Thanks for any help!

PS: I know a lot of people suggest the use of a JFileChooser, but in this case i'd very much prefer the FileDialog, except if that's impossible


问:
Pass parameter from cloudformation into a jenkins instance as a variable
I'm trying to pass a parameter, which has been received by the user at the time of stack creation of a cloudformation template e.g. below

```<code>Parameters:
  EnvironmentName:
    Type: String
    Description: The name of the environment
    AllowedPattern: "[a-z0-9-]+"
</code>```

I'd like to pass that parameter into jenkins (which is being created as part of this stack), to be used as a global variable, probably using the Global Variable String Parameter Plugin.

Is there a way of doing this purely using cloudformation? I've been told I will probably need something like Ansible or Terraform, but I would prefer to use only cloudformation if that is possible.

答:
If you want to use it in another CF script, there is an export option for the Outputs section that will export a variable. </p>

```<code>Outputs:
  EnvironmentName:
    Type: String
    Description: The name of the environment
    Export: !Sub EnvironmentName
    Value: EnvironmentName
</code>```

<p>Then you can interrogate from Jenkings or a sh script using list-stack-resources function. </p>

Body:
I'm trying to pass a parameter, which has been received by the user at the time of stack creation of a cloudformation template e.g. below

Parameters:
  EnvironmentName:
    Type: String
    Description: The name of the environment
    AllowedPattern: "[a-z0-9-]+"

I'd like to pass that parameter into jenkins (which is being created as part of this stack), to be used as a global variable, probably using the Global Variable String Parameter Plugin.

Is there a way of doing this purely using cloudformation? I've been told I will probably need something like Ansible or Terraform, but I would prefer to use only cloudformation if that is possible.

Body:
If you want to use it in another CF script, there is an export option for the Outputs section that will export a variable.

Outputs:
  EnvironmentName:
    Type: String
    Description: The name of the environment
    Export: !Sub EnvironmentName
    Value: EnvironmentName

Then you can interrogate from Jenkings or a sh script using list-stack-resources function.


问:
Change scrollbar color on hover CSS
I'm trying to change the scrollbar color on hover in my application and for some reason, when i hover over it, it becomes red. Here's my code:

```<code>    .scroller {
position: absolute;
top: 120px;
bottom: 0;
left: 0;
right: 0;
padding: 0;
margin-bottom: 10px;
overflow: auto;
</code>```

}

```<code>    .scrooler:hover{
      color: blue;
    }
</code>```

With this code, all it does is as soon as I hover over my table, all the text becomes blue. i'm having a hard time getting only the scrollbar since I think it is directly within the table. Is there any way of targeting the scrollbar only?

答:
The scrollbar is part of the table and color will be the text color (as always), but in css there is a special property for scrollbars:

```<code>scrollbar-base-color:YOURCOLOR;
</code>```

just put this in your existing class

Title: Change scrollbar color on hover CSS

Body:
I'm trying to change the scrollbar color on hover in my application and for some reason, when i hover over it, it becomes red. Here's my code:

    .scroller {
position: absolute;
top: 120px;
bottom: 0;
left: 0;
right: 0;
padding: 0;
margin-bottom: 10px;
overflow: auto;

}

    .scrooler:hover{
      color: blue;
    }

With this code, all it does is as soon as I hover over my table, all the text becomes blue. i'm having a hard time getting only the scrollbar since I think it is directly within the table. Is there any way of targeting the scrollbar only?

Body:
The scrollbar is part of the table and color will be the text color (as always), but in css there is a special property for scrollbars:

scrollbar-base-color:YOURCOLOR;

just put this in your existing class


问:
steam priceoverview SyntaxError
What's wrong?

```<code><script>
var url="http://steamcommunity.com/market/priceoverview/?appid=730&currency=3&market_hash_name=StatTrak%E2%84%A2 M4A1-S | Hyper Beast (Minimal Wear)";
var s = document.createElement("script");
s.src = url;
document.body.appendChild(s);
</script>
</code>```

Error: SyntaxError: missing ; before statement - priceoverview:1:10

答: That returns a plain json, rather than a jsonp. Unfortunately, Steam has cross origin stuff so ajax requests won't work, and they don't support jsonp. That means you won't be able to make the requests from the client--you have to get it server side.</p>

Title: steam priceoverview SyntaxError

Body:
What's wrong?

Error: SyntaxError: missing ; before statement - priceoverview:1:10


问:
Cancelling RowInserting Event resets fields in row
In my acumatica application, I created a custom page where the user needs to insert data in the grid section. In order to validate the provided data, I implemented the RowInserting and RowUpdating Events.

The problem is that in the rowinserting event I first throw an error using the following code:

```<code>cache.RaiseExceptionHandling<DZField.size>(fieldLine, fieldLine.Size,
    new PXSetPropertyException(string.Format(ValidationMessages.FIELD_NOT_VALID_FORMAT,
        "Size"), PXErrorLevel.RowError));
</code>```

Then I set the e.Cancel property to true. But when the user changes the incorrect value and re-triggers the event, the row will have missing values which were not manipulated in the event.

I also tried to not set the e.Cancel property and instead throw a PXException, but even in this case other values in the row were reset.

答:
In your RowInserting event, you are not throwing an error, you are raising it.

From documentation, the RowInserting event handler is used to:

Evaluate the data record that is being inserted.

Cancel the insert operation by throwing an exception.

Assign the default values to the fields of the data record that is being inserted.

If you use the throw syntax in a row inserting event, a popup window will appear with your error message and the record will not be visible in the grid. You shouldn't use e.Cancel for validations in RowInserting.

Example of cancelling insertion:

```<code>protected virtual void DACName_RowInserting(PXCache sender,
                                            PXRowInsertingEventArgs e)
{
    throw new PXException(ErrorMessages.FieldIsEmpty,
                          typeof(PaymentMethodAccount.paymentMethodID).Name);
}
</code>```

Source: RowInserting Event

Regarding row updating, using e.Cancel for validations will cancel updating of all fields which are marked as dirty for that row. Sometimes that's what you want but based on your question I think that's something you want to avoid.

When validating individual fields you can use the field updating event which will not affect other fields or raise field exceptions. Throwing an error in a row event or setting e.Cancel in a row event will affect the whole row.

Body:
In my acumatica application, I created a custom page where the user needs to insert data in the grid section. In order to validate the provided data, I implemented the RowInserting and RowUpdating Events.

The problem is that in the rowinserting event I first throw an error using the following code:

cache.RaiseExceptionHandling<DZField.size>(fieldLine, fieldLine.Size,
    new PXSetPropertyException(string.Format(ValidationMessages.FIELD_NOT_VALID_FORMAT,
        "Size"), PXErrorLevel.RowError));

Then I set the e.Cancel property to true. But when the user changes the incorrect value and re-triggers the event, the row will have missing values which were not manipulated in the event.

I also tried to not set the e.Cancel property and instead throw a PXException, but even in this case other values in the row were reset.

Body:
In your RowInserting event, you are not throwing an error, you are raising it.

From documentation, the RowInserting event handler is used to:

Evaluate the data record that is being inserted.

Cancel the insert operation by throwing an exception.

Assign the default values to the fields of the data record that is being inserted.

If you use the throw syntax in a row inserting event, a popup window will appear with your error message and the record will not be visible in the grid. You shouldn't use e.Cancel for validations in RowInserting.

Example of cancelling insertion:

protected virtual void DACName_RowInserting(PXCache sender,
                                            PXRowInsertingEventArgs e)
{
    throw new PXException(ErrorMessages.FieldIsEmpty,
                          typeof(PaymentMethodAccount.paymentMethodID).Name);
}

Source: RowInserting Event

Regarding row updating, using e.Cancel for validations will cancel updating of all fields which are marked as dirty for that row. Sometimes that's what you want but based on your question I think that's something you want to avoid.

When validating individual fields you can use the field updating event which will not affect other fields or raise field exceptions. Throwing an error in a row event or setting e.Cancel in a row event will affect the whole row.


问:
Java, Lucene : Get document by saved Id and then update one of it's field
We are creating a Spring-MVC application in which we are using Lucene for text indexing and searching. I am saving the Object's ID along with it for retrieving the associated Java Object later. How do I get the Document with saved ID and update a field which is being set manually. I know how to search for given text, but nothing specific for a single document. Thank you.

Save code :

```<code>// retrieve from the ID below
            doc.add(new StringField("id", String.valueOf(objectId), Field.Store.YES));
// Update the Integer count below
 LegacyIntField intField = new LegacyIntField("score",0,Field.Store.YES);
                    intField.setIntValue(1);
                    doc.add(intField);
</code>```

Current update code :

```<code> Path path = Paths.get(OUR_PATH);
                    Directory index_dir = FSDirectory.open(path);

                    IndexWriter writer = new IndexWriter(index_dir, new IndexWriterConfig(new StandardAnalyzer()));
                    IndexReader reader = DirectoryReader.open(writer);
</code>```

Thank you.

答:
First of all lucene does not support updating a single field and thus there's no benefit in trying to isolate and optimize the update process of a single field.

Basically what you are looking for is a way to:

load the original document that was previously indexed (this is not provided out of the box with lucene)

and a method to update an existing document (this is IndexWriter.updateDocument)

If the lucene index is not the primary datastore you should use your primary datastore to fetch the document set the new vaue and then reindex the whole document, in pseudo code:

```<code>public void updateField(String docId, int newFieldvalue) {
    MyDataObject data = primaryDataStore.fetch(docId);
    data.setFieldValue(newFieldValue);
    primaryDataStore.save(data);
    updateIndex(data);
}

public void updateIndex(MyDataObject object) {
    // convertToLucene is more or less the code in the
    // first snippet of your question
    Document d = convertToLucene(object);
    // IndexWriter should be created once
    // IndexWriter.updateDocument will internally delete and index
    // the document
    this.writer.updateDocument(new Term("id", object.getId()), d);
    // potentially call writer.commit()
}
</code>```

If lucene is your primary datastore it's more complex and I strongly suggest (if not too late) to use solr or elasticsearch which provides a nice REST API that makes lucene more like a document store.
You have to consider that lucene is not "out of the box" a document datastore. If you want to use lucene as a primary datastore what you could do is store the document in a stored field using a format of your choice (JSON, binary serialization,...).

To fetch the document you'll have to perform a search query on the field "id" you created with a TermQuery, use a collector or TodDocs and then call document(int luceneDocId) on IndexReader or IndexSearcher to fetch stored fields, in pseudo code (methods to replace primaryDataStore.fetch(docId) used in the previous snippet):

```<code>public MyDataObject fetchFromLucene(String docId) {
     IndexSearcher searcher = getSearcher();
     TopDocs docs = searcher.search(new TermQuery(new Term("id", docId)), 1);
     if (docs.totalHits > 0) {
         Document d = searcher.document(docs.scoreDocs[0].doc);
         // "document_data" is a binary field you'll have to add
         // on every lucene docs where you put a serialized version
         // of your domain object.
         return deserialize( d.getBinaryValue("document_data") );
     }
     return null;
}

public MyDataObject deserialize(ByteRef data) {
    // a method to deserialize binary data into MyDataObject
    return deserializedData;
}
</code>```

In short you'll end up writing a lot of boiler plate code if you want to deal with lucene directly as a primary datastore.
Note that you'll have to manage yourself a lot of lowlevel lucene aspects such as refreshing your IndexReaders in a way that is efficient.

Body:
We are creating a Spring-MVC application in which we are using Lucene for text indexing and searching. I am saving the Object's ID along with it for retrieving the associated Java Object later. How do I get the Document with saved ID and update a field which is being set manually. I know how to search for given text, but nothing specific for a single document. Thank you.

Save code :

// retrieve from the ID below
            doc.add(new StringField("id", String.valueOf(objectId), Field.Store.YES));
// Update the Integer count below
 LegacyIntField intField = new LegacyIntField("score",0,Field.Store.YES);
                    intField.setIntValue(1);
                    doc.add(intField);

Current update code :

 Path path = Paths.get(OUR_PATH);
                    Directory index_dir = FSDirectory.open(path);

                    IndexWriter writer = new IndexWriter(index_dir, new IndexWriterConfig(new StandardAnalyzer()));
                    IndexReader reader = DirectoryReader.open(writer);

Thank you.

Body:
First of all lucene does not support updating a single field and thus there's no benefit in trying to isolate and optimize the update process of a single field.

Basically what you are looking for is a way to:

load the original document that was previously indexed (this is not provided out of the box with lucene)

and a method to update an existing document (this is IndexWriter.updateDocument)

If the lucene index is not the primary datastore you should use your primary datastore to fetch the document set the new vaue and then reindex the whole document, in pseudo code:

public void updateField(String docId, int newFieldvalue) {
    MyDataObject data = primaryDataStore.fetch(docId);
    data.setFieldValue(newFieldValue);
    primaryDataStore.save(data);
    updateIndex(data);
}

public void updateIndex(MyDataObject object) {
    // convertToLucene is more or less the code in the
    // first snippet of your question
    Document d = convertToLucene(object);
    // IndexWriter should be created once
    // IndexWriter.updateDocument will internally delete and index
    // the document
    this.writer.updateDocument(new Term("id", object.getId()), d);
    // potentially call writer.commit()
}

If lucene is your primary datastore it's more complex and I strongly suggest (if not too late) to use solr or elasticsearch which provides a nice REST API that makes lucene more like a document store.
You have to consider that lucene is not "out of the box" a document datastore. If you want to use lucene as a primary datastore what you could do is store the document in a stored field using a format of your choice (JSON, binary serialization,...).

To fetch the document you'll have to perform a search query on the field "id" you created with a TermQuery, use a collector or TodDocs and then call document(int luceneDocId) on IndexReader or IndexSearcher to fetch stored fields, in pseudo code (methods to replace primaryDataStore.fetch(docId) used in the previous snippet):

public MyDataObject fetchFromLucene(String docId) {
     IndexSearcher searcher = getSearcher();
     TopDocs docs = searcher.search(new TermQuery(new Term("id", docId)), 1);
     if (docs.totalHits > 0) {
         Document d = searcher.document(docs.scoreDocs[0].doc);
         // "document_data" is a binary field you'll have to add
         // on every lucene docs where you put a serialized version
         // of your domain object.
         return deserialize( d.getBinaryValue("document_data") );
     }
     return null;
}

public MyDataObject deserialize(ByteRef data) {
    // a method to deserialize binary data into MyDataObject
    return deserializedData;
}

In short you'll end up writing a lot of boiler plate code if you want to deal with lucene directly as a primary datastore.
Note that you'll have to manage yourself a lot of lowlevel lucene aspects such as refreshing your IndexReaders in a way that is efficient.


问:
Python: for loops: using an index from a list and another index from another list
I would like to loop as something like:

```<code>for j in range(1,4) and for k in ['one', 'two', 'three']:
               print(str(j) + ' is written ' + k)
</code>```

I tried with and but it didn't work. How does someone get this effect?

And what would happen in the case that the two lists have different lengths? How could I still iterate through both of them?

答:
You should zip 'em all!

```<code>for j, k in zip(range(1,4), ("one", "two", "three")):
    # use j and k
</code>```

Body:
I would like to loop as something like:

for j in range(1,4) and for k in ['one', 'two', 'three']:
               print(str(j) + ' is written ' + k)

I tried with and but it didn't work. How does someone get this effect?

And what would happen in the case that the two lists have different lengths? How could I still iterate through both of them?

Body:
You should zip 'em all!

for j, k in zip(range(1,4), ("one", "two", "three")):
    # use j and k