Libtorrent 1.1.0 issues - libtorrent

I'm using this method here to have the session available globally but the latest updates changed how things are working.
using boost::shared_ptr;
using boost::weak_ptr;
using libtorrent::aux::session_impl;
using namespace libtorrent;
libtorrent::session* session;
libtorrent::settings_pack* pack;
bool start ( )
{
pack->set_str ( user_agent, std::string ( "Test " ) + TEST_VERSION_STRING );
/////
return true
}
I'm getting user_agent is undefined and after a search of the source I cant see it defined anywhere, libtorrent/settings_pack.hpp is included.

Related

Laravel Mix - Is Chaining Required to Ensure Execution Order?

TLDR;
Do you have to chain Laravel Mix methods to maintain the execution order? Are any methods async that would prevent one from using the following non-chaining pattern, mix.scripts(); mix.js(); mix.sass();?
The few tests I've run suggest I do not need to chain.
An Example
Due to how our Laravel app is setup, we need to have more that one Laravel Mix setup. Instead of copy-n-pasting a webpack.mix.js file and modifying a few lines here and there in each file, we're looking at creating a config object that is passed to a singular webpack.mix.js file. In this file, we would check if various things have been configured, and if so, run the appropriate Mix method. Below is a pseudo-code example.
if ( config.js ) {
mix.js( config.js.src, config.js.dist );
}
if ( config.sass ) {
mix.sass( config.sass.src, config.sass.dist );
}
if ( config.concat ) {
if ( config.concat.styles ) {
// Could be more than one set of files that need to be combined, so array.
config.concat.styles.map( ( files ) => {
mix.styles( files.src, files.dist );
}
}
if ( config.concat.scripts ) {
// Could be more than one set of files that need to be combined, so array.
config.concat.scripts.map( ( files ) => {
mix.scripts( files.src, files.dist );
}
}
}
Currently, our code is more like most examples you see on the web.
mix
.options()
.webpackConfig()
.styles()
.styles()
.scripts()
.js()
.sass();
laravel-mix abstracts configuration of webpack and dynamically generates the webpack config.
The organization of its API implementation is done using Builder pattern with a fluent or chainable interface.
This makes it such that to produce a particular configuration only steps that are necessary to be performed have to be called.
You need to ensure that code in your webpack.mix.js module can be properly imported.
You need to be careful about the ordering of custom tasks such as copy, copyDirectory, combine, version. In v5.0.0, custom tasks are run without any bearing on their asynchronous nature. However there is coming changes to see to it that they are run sequentially.
Other API methods can be called in any order.
The few tests I've run suggest I do not need to chain.
You're absolutly correct!
Laravel Mix is written in JavaScript and makes use of Method Chaining.
You can visualize code execution with OnlinePythonTutor.
If you look at the code below, you'll find that you don't necessarily need to chain methods to maintain execution order.
class Person {
setName(name) {
this.name = name
return this
}
setAge(age) {
this.age = age
return this
}
}
var p = new Person()
p.setName("Alice").setAge(42) // Set name before age
p.setName("Bob") // Set name
p.setAge(42) // Set age
You can visualize this code here

LINQ Extensions not available inside CSharpCodeProvider

I have a .NET application that can take a script written in C# and executes it internally. The scripts are parsed by the class listed below and then compiled. I find that whenever I try and use System.Xml.Linq in the C# script that is compiled I get a compile error and I am not sure why.
public static void CreateFunction(string scriptCode, BO.ObjectBO obj)
{
CSharpCodeProvider provider = new CSharpCodeProvider();
CompilerParameters options = new CompilerParameters();
options.ReferencedAssemblies.Add("System.Data.dll");
options.ReferencedAssemblies.Add("System.dll");
options.ReferencedAssemblies.Add("System.Xml.dll");
options.ReferencedAssemblies.Add("System.Linq.dll");
options.ReferencedAssemblies.Add("System.Xml.Linq.dll");
options.GenerateExecutable = false;
options.GenerateInMemory = true;
CompilerResults results = provider.CompileAssemblyFromSource(options, scriptCode);
_errors = results.Errors;
if (results.Errors.HasErrors)
{
DataTable errorTable = BO.DataTableBO.ErrorTable();
foreach(CompilerError err in results.Errors)
{
DataRow dr = errorTable.NewRow();
dr["ErrorMessage"] = "Line "+ err.ErrorNumber.ToString() + " " + err.ErrorText;
errorTable.Rows.Add(dr);
}
return;
}
Type binaryFunction = results.CompiledAssembly.GetType("UserFunctions.BinaryFunction");
_methodInfo = binaryFunction.GetMethod("Function");
}
Here is the error message I get when I try and run a script that makes use of LINQ extensions inside the compiler.
'System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement>' does not contain a definition for 'Select' and no extension method 'Select' accepting a first argument of type 'System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement>' could be found (are you missing a using directive or an assembly reference?)
Does anyone see what I may be doing wrong? I am attempting to include System.Linq and System.Xml.Linq yet the compiler does not seem to be able to locate them.
Here is an example C# script I am trying to compile that makes use of LINQ extensions.
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Xml.Linq;
namespace CompilerTest
{
public class BinaryFunction
{
public static void Function()
{
string xmlData = #"<data>
<clients>
<client>
<clientId>1</clientId>
<clientName>Dell</clientName>
</client>
<client>
<clientId>2</clientId>
<clientName>Apple</clientName>
</client>
</clients>
</data>";
XDocument xDoc = XDocument.Parse(xmlData);
List<string> results = xDoc.Descendants("data")
.Descendants("client")
.Select(x => x.Element("clientName").Value)
.ToList<string>();
}
}
}
UPDATE: I confirmed that the following assemblies were in the GAC. System.Xml and System.Xml.Linq. I also added the compiler version to the constructor and I still get the same error.
CSharpCodeProvider(new Dictionary<String, String> { { "CompilerVersion", "v4.6.1" } })
After searching for related errors I found the solution. I needed to add System.Core as a referenced assembly.
options.ReferencedAssemblies.Add("System.Core.dll");
Once I did this then the LINQ assemblies were used and I was able to use LINQ extensions. So to be clear my new code is
CSharpCodeProvider provider = new CSharpCodeProvider();
CompilerParameters options = new CompilerParameters();
options.ReferencedAssemblies.Add("System.Data.dll");
options.ReferencedAssemblies.Add("System.dll");
options.ReferencedAssemblies.Add("System.Xml.dll");
options.ReferencedAssemblies.Add("System.Linq.dll");
options.ReferencedAssemblies.Add("System.Xml.Linq.dll");
options.ReferencedAssemblies.Add("System.Core.dll");
I am not sure why the reference to System.Core.dll is needed to be added as I would assume that it was referenced by default when creating a compiler instance but I guess not.

How to use SQLITE async extensions within a transaction in a Xamarin Forms PCL?

I'm trying to figure out how, in a transaction, to use SQLITE async extension methods such as InsertOrReplaceWithChildrenAsync (NuGet from TwinCoders).
On startup in my Xamarin.Forms PCL, I have:
using Xamarin.Forms;
using SQLite.Net;
using SQLite.Net.Async;
using SQLiteNetExtensions;
using SQLiteNetExtensionsAsync.Extensions;
...
...
static SQLiteAsyncConnection db;
db = DependencyService.Get<ISQLite> ().GetAsyncConnection ();
As a side note, I could additionally do the following, but I don't, having read that it is unwise to mix sync and async database operations:
dbSync = DependencyService.Get<ISQLite> ().GetSyncConnection ();
My first idea was:
await db.RunInTransactionAsync (
( SQLite.Net.Async.SQLiteAsyncConnection tran ) =>
{ tran.InsertAll WithChildren ( ...); ... }
but this gets the following warning at build time:
... RunInTransactionAsync(Action<SQLiteAsyncConnection> ... will
cause a deadlock if ....
Use RunInTransactionAsync(Action<SQLiteConnection>) instead.
If I use synchronous methods within the transaction, the following does work:
await db.RunInTransactionAsync ( ( SQLite.Net.SQLiteConnection tran ) =>
{
var x = new X();
tran.Insert (x);
var y = new Y();
tran.Insert (y);
});
However, tran has only the regular synchronous methods, and does not offer any of the extension methods such as InsertOrReplaceWithChildren.
My searches have not turned up any information on how to access extension methods within the transaction.
If I obtain dbSync as above, dbSync does not offer the extension methods. Maybe that has something to do with the problem. In my companion IOS project I have:
using Xamarin.Forms;
using SQLite.Net;
using SQLite.Net.Async;
using SQLite.Net.Platform.XamarinIOS;
...
...
public class Conn : Xyz.ISQLite
{
...
public SQLite.Net.SQLiteConnection GetSyncConnection () { ... }
public SQLiteAsyncConnection GetAsyncConnection() { ... }
...
}
It would appear that adding the async packages somehow blocks the synchronous extensions. However adding a PCL helper class library that has only the synchronous SQLite.Net and synchronous extensions, and fetching the sync connection from there, did not help.
Guillermo GutiƩrrez Doral resolved this as follows:
"Due to the nature of SQLite.Net async, only synchronous operations are supported inside a transaction. Otherwise, any failed operation between the begin and the end of the transaction may make the transaction to rollback even when the operation was not inside the transaction block.
This is not a SQLite-Net Extensions limitation, but a SQLite.Net one. You can still access to all SQLite-Net Extensions synchronous operations, like InsertOrReplaceWithChildren."
https://bitbucket.org/twincoders/sqlite-net-extensions/issue/61/async-extension-methods-within-a

Spy, Stub or Mock? Or None of the Above?

I'm using Mocha to test a Node.js API. I need to test a route that checks whether an update is available. The route accepts a version number of what's currently installed and compares it with an available version retrieved via an HTTP request.
To get the latest version available, a model method is called. Client.availableVersion() makes the HTTP request, does some simple manipulation and passes the available version to a callback function. Fairly straightforward stuff, but now I want to test my update() route and I need to be able to control what is returned by Client.availableVersion().
Having read the Mocha docs and the Sinon docs I was referred to...I'm stuck. It sounds like Sinon will handle what I need, but the implementation has me a little confused.
Here's a snippet from my routes method:
update: function( req, res, next ) {
var installedVersion = req.params.version;
client.availableVersion( function( err, availableVersion ) {
if( !err ) {
if( parseInt( installedVersion, 10 ) < parseInt( availableVersion, 10 ) ) {
// SEND UPDATE AVAILABLE RESPONSE
}
// SEND NO UPDATE AVAILABLE RESPONSE
}
else {
res.send( 500, err );
}
})
}
Any nudge in the right direction would be appreciated.
I would definitely go with stubs. http://sinonjs.org/docs/#stubs
I would use the stub.yields(...)
var next = sinon.spy()
var err = ... //Whatever object you want to pass as error or undefined
var availbleVersion = ... // A fake of the response the method is supposed to give
client.availableVersion = sinon.stub().yields(err, availableVersion);
myRoute.update(fakeReq, fakeRes, next);
//All you expectations

Joomla Plugin not running (is installed)

I have "written" a plugin for Joomla! I say "written" because it is actually someone else's, but it was for Joomla 1.5, and I'm trying to upgrade it to run in Joomla 1.7. However, it's installed and it doesn't want to run. I have tried making it generate an error out of nothing, but it wouldn't give me anything.
I'm not even sure if it is Joomla 1.7 code or not, but I'm hoping you could help with that too.
<?php
// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );
jimport('joomla.plugin.plugin');
class plgContentRegisteredTags extends JPlugin
{
function plgContentRegisteredTags (&$subject, $params)
{
parent::__construct($subject,$params);
}
function onPrepareContent ( $context, &$article, &$params, $page=0 )
{
global $mainframe;
//if ( !$published ) return true;
// define the regular expression for the bot
$regex1 = "#{reg}(.*?){/reg}#s";
$regex2 = "#{noreg}(.*?){/noreg}#s";
// perform the replacement
$article->text = preg_replace_callback(
$regex1,
create_function(
'$matches',
'global $my;
if($my->id) return $matches[1];
return "";'
),
$article->text
);
$article->text = preg_replace_callback(
$regex2,
create_function(
'$matches',
'global $my;
if(!$my->id) return $matches[1];
return "";'
),
$article->text
);
return true;
}
}
Note: it just doesn't want to run at all (no error, no code execution), even though it is enabled and installed.
Any help would be appreciated.
Plugin-ins in Joomla! are stored in plugins/plugin-type/plugin_name/ relative to the site root. Components are stored in the components/ directory.
eg. the pagebreak content plugin is found at 'plugins/content/pagebreak/' and contains the files:
plugins/content/pagebreak/pagebreak.php
plugins/content/pagebreak/pagebreak.xml
plugins/content/pagebreak/index.html // not an active file
You can read about creating a content plugin here.

Resources