I have developed one project and successfully works on my local machine.on live site i create one folder dev in public_html and move same project from local machine,but its gives me following error.
Zend\ServiceManager\Exception\ServiceNotCreatedException
File: /home/projectname/public_html/dev/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:859
Message: An exception was raised while creating "Front/Model/Slider"; no instance returned
Zend\ServiceManager\Exception\ServiceNotCreatedException
File: /home/projectname/public_html/dev/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:859
Message: An exception was raised while creating "Zend\Db\Adapter\Adapter"; no instance returned
Zend\Db\Adapter\Exception\RuntimeException
File: /home/projectname/public_html/dev/vendor/zendframework/zendframework/library/Zend/Db/Adapter/Driver/Pdo/Pdo.php:218
Message: The PDO extension is required for this adapter but the extension is not loaded..
My Service Factory means model.config.php file is:
<?php
namespace Front;
/*use Zend\ModuleManager\ModuleManager;*/
class Module
{
public function getAutoloaderConfig()
{
return array('Zend\Loader\StandardAutoloader' =>
array('namespaces' =>
array(__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,),
),
);
}
/* public function init(ModuleManager $moduleManager)
{
$sharedEvents = $moduleManager->getEventManager()->getSharedManager();
$sharedEvents->attach(__NAMESPACE__, 'dispatch', function($e) {
// This event will only be fired when an ActionController under the MyModule namespace is dispatched.
$controller = $e->getTarget();
$controller->layout('layout/frontlayout');
}, 100);
}
*/
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
// Add this method:
public function getServiceConfig()
{
return array(
'factories' => array(
'Front\Model\Cms' => function($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$table = new \Front\Model\Cms($dbAdapter);
return $table;
},
'Front\Model\Slider' => function($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$table = new \Front\Model\Slider($dbAdapter);
return $table;
},
),
);
}
}
?>
Stack Trace is like this:
Zend\ServiceManager\Exception\ServiceNotCreatedException
File: /home/projectname/public_html/dev/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:859
Message: An exception was raised while creating "Front/Model/Slider"; no instance returned
#0 /home/projectname/public_html/dev/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php(984): Zend\ServiceManager\ServiceManager->createServiceViaCallback(Object(Closure), 'frontmodelslide...', 'Front/Model/Sli...')
#1 /home/projectname/public_html/dev/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php(597): Zend\ServiceManager\ServiceManager->createFromFactory('frontmodelslide...', 'Front/Model/Sli...')
#2 /home/projectname/public_html/dev/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php(556): Zend\ServiceManager\ServiceManager->doCreate('Front/Model/Sli...', 'frontmodelslide...')
#3 /home/projectname/public_html/dev/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php(480): Zend\ServiceManager\ServiceManager->create(Array)
#4 /home/projectname/public_html/dev/module/Front/src/Front/Controller/FrontController.php(65): Zend\ServiceManager\ServiceManager->get('Front/Model/Sli...')
#5 /home/projectname/public_html/dev/module/Front/src/Front/Controller/FrontController.php(53): Front\Controller\FrontController->getSlider()
#6 /home/projectname/public_html/dev/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/AbstractActionController.php(83): Front\Controller\FrontController->indexAction()
#7 [internal function]: Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent))
#8 /home/projectname/public_html/dev/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#9 /home/projectname/public_html/dev/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#10 /home/projectname/public_html/dev/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/AbstractController.php(117): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#11 /home/projectname/public_html/dev/vendor/zendframework/zendframework/library/Zend/Mvc/DispatchListener.php(114): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
#12 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#13 /home/projectname/public_html/dev/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#14 /home/projectname/public_html/dev/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#15 /home/projectname/public_html/dev/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php(309): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#16 /home/projectname/public_html/dev/public/index.php(17): Zend\Mvc\Application->run()
#17 {main}
The PDO extension is required for this adapter but the extension is not loaded
This gives you the answer: php has a module called php data objects, or pdo. This is a module available on modern php installations which enables database access for your php application.
I think there are three possible reasons:
You don't have the pdo module installed
You have pdo as a module installed, but not enabled
You have an old version of php. For Zend Framework 2, minimally php 5.3.3 is required
So you probably have to upgrade or configure your server to get this working.
Related
I am trying to perform a widget test, specifically navigation test. I am using bloc architecture, setting a stream on the bloc triggers a series of events inside the bloc, gets session info from the server call (which returns a future of session info object), on successful server call a login stream is set and the widget has a stream subscription to this stream and navigates to the next screen.
I am using mockito to mock the server call and stubbing the server call to return a future of success response. The problem is the when I am calling pumpAndSettle() it is getting timed out as it is not waiting for the future to complete and return the success response.
I apologize if I am not making it very clear, but here is the sample code:
login_bloc.dart
class LoginBloc {
LoginRepository _loginRepository;
final String searchKeyword = "special-keyword";
final _urlString = PublishSubject<String>();
final _isLoggedIn = BehaviorSubject<bool>(seedValue: false);
final _errorMessage = PublishSubject<String>();
Observable<bool> get isLoggedIn => _isLoggedIn.stream;
Observable<String> get isErrorState => _errorMessage.stream;
LoginBloc({LoginRepository loginRepository})
: _loginRepository = loginRepository ?? LoginRepository() {
// Listen on the _urlString stream to call the function which checks for the special keyword and if a match is found make a server call
_urlString.stream.listen((String url) {
_authorizationFullService(url);
});
}
// Search for special keyword and if a match is found call the server call function
void _authorizationFullService(String url) {
if (url.contains(searchKeyword)) {
int index = url.indexOf(searchKeyword);
String result = url.substring(index + searchKeyword.length);
result = result.trim();
String decodedUrl = Uri.decodeFull(result);
if (decodedUrl != null && decodedUrl.length > 0) {
_fullServiceServerCall(decodedUrl);
} else {
_isLoggedIn.sink.add(false);
}
}
}
// Call server call function from repository which returns a future of the Authorization object
void _fullServiceServerCall(String decodedUrl) {
_loginRepository
.getSession(decodedUrl)
.then(_handleSuccessAuthorization)
.catchError(_handleErrorState);
}
// Handle success response and set the login stream
void _handleSuccessAuthorization(Authorization authorization) {
if (authorization != null && authorization.idnumber != 0) {
_isLoggedIn.sink.add(true);
} else {
_isLoggedIn.sink.add(false);
}
}
// Handle error response and set the error stream
void _handleErrorState(dynamic error) {
_isLoggedIn.sink.add(false);
_errorMessage.sink.add(error.toString());
}
void dispose() {
_urlString.close();
_isLoggedIn.close();
_errorMessage.close();
}
}
widget_test.dart
group('Full Login Navigation test', () {
LoginRepository mockLoginRepository;
LoginBloc loginBloc;
NotificationBloc notificationBloc;
NavigatorObserver mockNavigatorObserver;
Authorization _auth;
String testUrl;
setUp(() {
mockLoginRepository = MockLoginRepository();
_auth = Authorization((auth) => auth
..param1 = "foo"
..param2 = "bar"
..param3 = "foobar"
..param4 = "barfoo");
loginBloc = LoginBloc(loginRepository: mockLoginRepository);
mockNavigatorObserver = MockNavigatorObserver();
testUrl = "http://test.test.com";
});
Future<Null> _buildFullLoginPage(LoginBloc loginBloc,
NotificationBloc notificationBloc, WidgetTester tester) async {
when(mockLoginRepository.getSession(testUrl))
.thenAnswer((_) => Future.value(_auth));
await tester.pumpWidget(LoginBlocProvider(
child: NotificationBlocProvider(
child: MaterialApp(
home: LoginFullService(),
onGenerateRoute: NavigationRoutes.routes,
navigatorObservers: [mockNavigatorObserver],
),
notificationBloc: notificationBloc,
),
loginBloc: loginBloc,
));
//TODO: Remove casting to dynamic after dart sdk bug fix: https://github.com/dart-lang/mockito/issues/163
verify(mockNavigatorObserver.didPush(any, any) as dynamic);
loginBloc.getAuthorization(
"http://testing.testing.com?search-keyword=http%3A%2F%2Ftest.test.com");
}
testWidgets('Navigate to landing page on correct login url',
(WidgetTester tester) async {
await _buildFullLoginPage(loginBloc, notificationBloc, tester);
await tester.pumpAndSettle();
expect(find.byKey(Key('webview_scaffold')), findsNothing);
//TODO: Remove casting to dynamic after dart sdk bug fix: https://github.com/dart-lang/mockito/issues/163
verify(mockNavigatorObserver.didPush(any, any) as dynamic);
});
});
On running the widget test the tester.pumpAndSettle() inside testWidgets times out before the future is completed. This is the error log:
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following assertion was thrown running a test:
pumpAndSettle timed out
When the exception was thrown, this was the stack:
#0 WidgetTester.pumpAndSettle.<anonymous closure> (package:flutter_test/src/widget_tester.dart:299:11)
<asynchronous suspension>
#3 TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:69:41)
#4 WidgetTester.pumpAndSettle (package:flutter_test/src/widget_tester.dart:295:27)
#5 main.<anonymous closure>.<anonymous closure> (file:///Users/ssiddh/Documents/projects/mobile-flutter/test/ui/pages/login/login_full_test.dart:114:20)
<asynchronous suspension>
#6 testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:72:23)
#7 TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:555:19)
<asynchronous suspension>
#10 TestWidgetsFlutterBinding._runTest (package:flutter_test/src/binding.dart:539:14)
#11 AutomatedTestWidgetsFlutterBinding.runTest.<anonymous closure> (package:flutter_test/src/binding.dart:883:24)
#17 AutomatedTestWidgetsFlutterBinding.runTest (package:flutter_test/src/binding.dart:880:15)
#18 testWidgets.<anonymous closure> (package:flutter_test/src/widget_tester.dart:71:22)
#19 Declarer.test.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:test/src/backend/declarer.dart:168:27)
<asynchronous suspension>
#20 Invoker.waitForOutstandingCallbacks.<anonymous closure> (package:test/src/backend/invoker.dart:249:15)
<asynchronous suspension>
#25 Invoker.waitForOutstandingCallbacks (package:test/src/backend/invoker.dart:246:5)
#26 Declarer.test.<anonymous closure>.<anonymous closure> (package:test/src/backend/declarer.dart:166:33)
#31 Declarer.test.<anonymous closure> (package:test/src/backend/declarer.dart:165:13)
<asynchronous suspension>
#32 Invoker._onRun.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:test/src/backend/invoker.dart:403:25)
<asynchronous suspension>
#46 _Timer._runTimers (dart:isolate/runtime/libtimer_impl.dart:382:19)
#47 _Timer._handleMessage (dart:isolate/runtime/libtimer_impl.dart:416:5)
#48 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:169:12)
(elided 30 frames from class _FakeAsync, package dart:async, and package stack_trace)
I would really appreciate any kind of help or feedback.
Try wrapping your test with
testWidgets('Navigate to landing page on correct login url',
(WidgetTester tester) async {
await tester.runAsync(() async {
// test code here
});
});
In Polymer you can create neon-animations like their already built 'fade-in-animation'. You would implement the Polymer.NeonAnimationBehavior like this
<script>
Polymer({
is: 'fade-in-animation',
behaviors: [
Polymer.NeonAnimationBehavior
],
configure: function(config) {
var node = config.node;
this._effect = new KeyframeEffect(node, [
{'opacity': '0'},
{'opacity': '1'}
], this.timingFromConfig(config));
return this._effect;
}
});
</script>
I could create something similar to that and just provide the configure function, which returns a KeyframeEffect. I tried reproducing this in Polymer Dart 1.0
#HtmlImport('diagonal-left.html')
library wellington.elements.animation.diagonal_left;
import 'dart:html';
import 'package:web_components/web_components.dart';
import 'package:polymer/polymer.dart';
import 'package:polymer_elements/neon_animation_behavior.dart';
#CustomElement('diagonal-left')
class DiagonalLeft extends PolymerElement with NeonAnimationBehavior {
KeyframeEffect _effect;
configure(config) {
var node = config.node;
if (config.transformOrigin) {
setPrefixedProperty(node, 'transformOrigin', config.transformOrigin);
} else {
setPrefixedProperty(node, 'transformOrigin', '0 75%');
}
_effect = new KeyframeEffect(node, [
{'transform': 'none'},
{'transform': 'translateX(-100%)'}
], timingFromConfig(config));
return _effect;
}
DiagonalLeft.created() : super.created();
}
with the HTMLImport importing this
<script type="application/dart" src="diagonal_left.dart"></script>
I try importing this, and putting this in the animationConfig
#property
Map get animationConfig => {
'entry': [
{
'name': 'fade-in-animation',
'node': this,
'timing': {'delay': 500, 'duration': 1000}
},
{
'name': 'scale-up-animation',
'node': this,
'timing': {'duration': 2000}
}],
'exit': [{
'name': 'fade-out-animation',
'node': this,
'timing': {'delay': 500, 'duration': 1000}
},
{
'name': 'slide-left-animation',
'node': this,
'timing': {'duration': 1000}
},
{
'name': 'diagonal-left',
'node': this
}]
};
and all I get is a message in the browser console saying
neon-animated-pages: diagonal-left not found!
What am I doing wrong? In other words, how can I create a custom animation for use in neon-animations in Polymer Dart 1.0?
UPDATE:
I've found the reason it was failing to find the custom animation I had created. Surprised no one noticed my mistake. I was using
#CustomElement('diagonal-left')
which is the old pre Polymer Dart 1.0 way of registering an element. It should be instead
#PolymerRegister('diagonal-left')
Now it's able to find my animation, but that only gave me another error in Dartium
VM4374:1 ORIGINAL EXCEPTION: V8 Exception(anonymous function) # VM4374:1
VM4374:1 ORIGINAL STACKTRACE:(anonymous function) # VM4374:1
VM4374:1 #0 JsFunction._apply (dart:js:1490)
#1 JsFunction.apply (dart:js:1488)
#2 BrowserDomAdapter.setProperty (package:angular2/src/platform/browser/browser_adapter.dart:140:20)
#3 DomRenderer.setElementProperty (package:angular2/src/platform/dom/dom_renderer.dart:190:9)
#4 DebugDomRenderer.setElementProperty (package:angular2/src/core/debug/debug_renderer.dart:127:10)
#5 AppView.notifyOnBinding (package:angular2/src/core/linker/view.dart:211:23)
#6 AbstractChangeDetector.notifyDispatcher (package:angular2/src/core/change_detection/abstract_change_detector.dart:280:21)
#7 _WaterfrontView_0.detectChangesInRecordsInternal (package:wellington/views/waterfront_view/waterfront_view.template.dart:66:20)
#8 AbstractChangeDetector.detectChangesInRecords (package:angular2/src/core/change_detection/abstract_change_detector.dart:151:12)
#9 AbstractChangeDetector.runDetectChanges (package:angular2/src/core/change_detection/abstract_change_detector.dart:125:10)
#10 AbstractChangeDetector._detectChangesInViewChildren (package:angular2/src/core/change_detection/abstract_change_detector.dart:244:12)
#11 AbstractChangeDetector.runDetectChanges (package:angular2/src/core/change_detection/abstract_change_detector.dart:128:10)
#12 AbstractChangeDetector._detectChangesInViewChildren (package:angular2/src/core/change_detection/abstract_change_detector.dart:244:12)
#13 AbstractChangeDetector.runDetectChanges (package:angular2/src/core/change_detection/abstract_change_detector.dart:128:10)
#14 AbstractChangeDetector.detectChanges (package:angular2/src/core/change_detection/abstract_change_detector.dart:111:10)
#15 ChangeDetectorRef_.detectChanges (package:angular2/src/core/change_detection/change_detector_ref.dart:209:14)
#16 ApplicationRef_.tick.<anonymous closure> (package:angular2/src/core/application_ref.dart:512:63)
#17 List.forEach (dart:core-patch/growable_array.dart:258)
#18 ApplicationRef_.tick (package:angular2/src/core/application_ref.dart:512:32)
#19 ApplicationRef_.ApplicationRef_.<anonymous closure>.<anonymous closure> (package:angular2/src/core/application_ref.dart:410:16)
#20 _rootRun (dart:async/zone.dart:1150)
#21 _ZoneDelegate.run (dart:async/zone.dart:693)
#22 NgZoneImpl._run (package:angular2/src/core/zone/ng_zone_impl.dart:150:21)
#23 _CustomZone.run (dart:async/zone.dart:1026)
#24 _CustomZone.runGuarded (dart:async/zone.dart:924)
#25 NgZoneImpl.runInner (package:angular2/src/core/zone/ng_zone_impl.dart:121:23)
#26 NgZone.run (package:angular2/src/core/zone/ng_zone.dart:219:27)
#27 ApplicationRef_.ApplicationRef_.<anonymous closure> (package:angular2/src/core/application_ref.dart:409:20)
#28 _RootZone.runUnaryGuarded (dart:async/zone.dart:1338)
#29 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:331)
#30 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:258)
#31 _SyncBroadcastStreamController._sendData (dart:async/broadcast_stream_controller.dart:386)
#32 _BroadcastStreamController.add (dart:async/broadcast_stream_controller.dart:261)
#33 EventEmitter.emit (package:angular2/src/facade/async.dart:95:17)
#34 NgZone._checkStable (package:angular2/src/core/zone/ng_zone.dart:146:34)
#35 NgZone.NgZone.<anonymous closure> (package:angular2/src/core/zone/ng_zone.dart:129:16)
#36 NgZoneImpl._run (package:angular2/src/core/zone/ng_zone_impl.dart:152:14)
#37 NgZoneImpl._runUnary (package:angular2/src/core/zone/ng_zone_impl.dart:157:7)
#38 _CustomZone.runUnary (dart:async/zone.dart:1037)
#39 _CustomZone.runUnaryGuarded (dart:async/zone.dart:932)
#40 _CustomZone.bindUnaryCallback.<anonymous closure> (dart:async/zone.dart:961)
#41 _Timer._Timer.<anonymous closure> (dart:html:49206)
and when run through pub serve I get the following in Chrome
EXCEPTION: NoSuchMethodError: method not found: 'configure' (animation.configure is not a function) in [selected in WaterfrontView#7:40] html_dart2js.dart:3351
EXCEPTION: NoSuchMethodError: method not found: 'configure' (animation.configure is not a function) in [selected in WaterfrontView#7:40]
ORIGINAL EXCEPTION: NoSuchMethodError: method not found: 'configure' (animation.configure is not a function)
ORIGINAL STACKTRACE:
TypeError: animation.configure is not a function
at HTMLElement._configureAnimationEffects (index.html?_ijt=j7c5fphk4jffr92eaclvnf00al:20326)
at HTMLElement.playAnimation (index.html?_ijt=j7c5fphk4jffr92eaclvnf00al:20362)
at HTMLElement._selectedChanged (index.html?_ijt=j7c5fphk4jffr92eaclvnf00al:20572)
at HTMLElement._complexObserverEffect (index.html?_ijt=j7c5fphk4jffr92eaclvnf00al:7749)
at HTMLElement._effectEffects (index.html?_ijt=j7c5fphk4jffr92eaclvnf00al:7496)
at HTMLElement._propertySetter (index.html?_ijt=j7c5fphk4jffr92eaclvnf00al:7473)
at HTMLElement.setter (index.html?_ijt=j7c5fphk4jffr92eaclvnf00al:7582)
at eval (eval at F (js_dart2js.dart:358), <anonymous>:1:39)
at h2.bt (js_dart2js.dart:387)
at h2.aC (js_dart2js.dart:392)
aE # html_dart2js.dart:3351
(anonymous function) # exception_handler.dart:80
dart.cI.$3 # exception_handler.dart:91
dart.yu.$1 # application_ref.dart:262
dart.xS.$0 # ng_zone_impl.dart:157
dart.nY # zone.dart:1150
dart.xN.fj # zone.dart:693
dart.xN.lB # ng_zone_impl.dart:157
(anonymous function) # VM202:2
bP # zone.dart:1037
bQ # zone.dart:932
W # stream_impl.dart:331
dart.ey.ay # stream_impl.dart:258
W # broadcast_stream_controller.dart:386
$1 # broadcast_stream_controller.dart:261
dart.xN.lz # ng_zone_impl.dart:190
(anonymous function) # VM198:2
aq # zone.dart:1005
ai # zone.dart:926
dart.ug.$1 # ng_zone_impl.dart:121
bQ # zone.dart:1338
W # stream_impl.dart:331
dart.ey.ay # stream_impl.dart:258
W # broadcast_stream_controller.dart:386
eH # broadcast_stream_controller.dart:261
$0 # ng_zone.dart:129
dart.xN.fj # ng_zone_impl.dart:152
dart.xN.lB # ng_zone_impl.dart:157
(anonymous function) # VM202:2
bP # zone.dart:1037
bQ # zone.dart:932
dart.Ar.$1 # zone.dart:961
dart.zF.$0 # isolate_helper.dart:1396
$0 # js_helper.dart:2408
bz # isolate_helper.dart:462
d9 # isolate_helper.dart:54
dart.HW # js_helper.dart:2408
(anonymous function) # js_helper.dart:2430
Which is telling me the dart method configure(config) is not being converted/wrapped into a JS function. Is there something I can do to fix this and get a custom dart animation to work in Polymer? And yes this is Polymer being run in a Angular 2 app, which means I am forced to use shadowroot.
UPDATE 2:
I encountered an error in the version of Chrome I was using, which relates to this bug https://github.com/Polymer/core-animation/pull/28. I found I needed to update to the latest polymer_elements 1.0.0-rc.9. Now I'm back to square one with the error being
neon-animated-pages: diagonal-left not found!
Oh well so much for progress.
I have yet again answered my own question. The only method I can get to work is to write the animation in JS, and then wrap it in a Polymer Dart wrapper. The easiest way is to use the custom_element_apigen. The problem is that's not working with the current Dart version, due to changes in pub. There is a pull request that answers that problem, but in the meantime you'll have to do it manually. I mimic the way custom_element_apigen does things.
JavaScript version in lib/src/test-animation/test-animation.html
<link rel="import" href="../../../../packages/polymer/polymer.html">
<link rel="import" href="../../../../packages/polymer_elements/src/neon-animation/neon-animation-behavior.html">
<link rel="import" href="../../../../packages/polymer_elements/src/neon-animation/web-animations.html">
<script>
Polymer({
is: 'test-animation',
behaviors: [
Polymer.NeonAnimationBehavior
],
configure: function(config) {
var node = config.node;
node.style.perspective = "600px";
node.style.backfaceVisibility = "hidden";
node.style.transformStyle = "preserve-3d";
node.style.transition = "transform 1s";
node.style.position = "absolute";
this._effect = new KeyframeEffect(node, [
{'transform': 'rotateY(-20deg)'},
{'transform': 'rotateY(-40deg)'},
{'transform': 'rotateY(-60deg)'},
{'transform': 'rotateY(-80deg)'},
{'transform': 'rotateY(-100deg)'},
{'transform': 'rotateY(-120deg)'},
{'transform': 'rotateY(-140deg)'},
{'transform': 'rotateY(-160deg)'},
{'transform': 'rotateY(-180deg)'},
{'transform': 'rotateY(0deg)'}
], this.timingFromConfig(config));
return this._effect;
}
});
</script>
Create a nodart html file lib/test_animation_nodart.html
<link rel="import" href="src/test-animation/test-animation.html">
<link rel="import" href="../../packages/polymer_elements/neon_animation_behavior_nodart.html">
Create the dart polymer html wrapper lib/test_animation.html. You actually don't need this file, but custom_element_apigen creates it, so I leave it in.
<link rel="import" href="test_animation_nodart.html">
<script type="application/dart" src="test_animation.dart"></script>
And then finally the dart wrapper lib test_animation.dart
#HtmlImport('test_animation_nodart.html')
library family_tree.lib.src.test_animation.test_animation;
import 'dart:html';
import 'package:web_components/web_components.dart';
import 'package:polymer_interop/polymer_interop.dart';
import 'package:polymer_elements/neon_animation_behavior.dart';
#CustomElementProxy('test-animation')
class TestAnimation extends HtmlElement with CustomElementProxyMixin, PolymerBase, NeonAnimationBehavior {
TestAnimation.created() : super.created();
}
You should now be able to include this in your neon animation element, in the animationConfig field. See this answer on how to do this.
This isn't the answer I was hoping for, but it works.
Am I possibly creating the stream and consequently the media instance incorrectly?
Modifying googleapis_examples/drive_upload_download_console, I'm attempting to convert already stored .docx, .xlsx, etc files to their corresponding Google Drive counterpart.
The following code
import 'dart:async';
import 'dart:io';
import 'package:http/http.dart' show Client;
import 'package:googleapis/common/common.dart' show Media, DownloadOptions;
import 'package:googleapis/drive/v2.dart' as drive;
import 'package:path/path.dart' as path;
Future convertFile(drive.DriveApi api,
Client client,
String objectId) {
var completer = new Completer();
api.files.get(objectId).then((drive.File file) {
var fileName = path.basenameWithoutExtension(file.title);
var parents = file.parents;
client.readBytes(file.downloadUrl).then((bytes) {
var driveFile = new drive.File()
..title = fileName
..mimeType = 'application/vnd.google-apps.document'
..parents = parents;
api.files.insert(driveFile)
.then((driveFile){
var byteList = bytes.toList();
var stream = new Stream.fromIterable(byteList);
var media = new Media(stream, byteList.length);
api.files.update(new drive.File(), driveFile.id, uploadMedia: media)
.then((drive.File f){
stream.close().whenComplete((){
api.files.delete(objectId)
.then((_){
completer.complete(true);
print("Converted ${f.id}");
});
});
});
});
});
});
return completer.future;
}
results in the following error.
Unhandled exception:
Uncaught Error: Class 'int' has no instance getter 'length'.
NoSuchMethodError: method not found: 'length'
Receiver: 80
Arguments: []
Stack Trace:
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:45)
#1 Base64Encoder.bind.onData (package:googleapis/src/common_internal.dart:325:42)
#2 _RootZone.runUnaryGuarded (dart:async/zone.dart:1093)
#3 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341)
#4 _IterablePendingEvents.handleNext (dart:async/stream_impl.dart:549)
#5 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:671)
#6 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:41)
#7 _asyncRunCallback (dart:async/schedule_microtask.dart:48)
#8 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:84)
#9 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:131)
#0 _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:886)
#1 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:41)
#2 _asyncRunCallback (dart:async/schedule_microtask.dart:48)
#3 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:84)
#4 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:131)
The Media constructor expects a Stream<List<int>>, and your code is providing a Stream<int>. To solve this, just replace this line:
var stream = new Stream.fromIterable(byteList);
by:
var stream = new Stream.fromIterable([byteList]);
I am getting this exception when I close the pool very soon after closing a query:
Uncaught Error: Bad state: Cannot write to socket, it is closed
Stack Trace:
#0 BufferedSocket.writeBufferPart (package:sqljocky/src/buffered_socket.dart:114:7)
#1 BufferedSocket.writeBuffer (package:sqljocky/src/buffered_socket.dart:108:27)
#2 _Connection._sendBufferPart (package:sqljocky/src/connection.dart:261:31)
#3 _Connection._sendBuffer (package:sqljocky/src/connection.dart:249:29)
#4 _Connection.processHandler (package:sqljocky/src/connection.dart:289:16)
#5 ConnectionPool._closeQuery.<anonymous closure> (package:sqljocky/src/connection_pool.dart:220:29)
#6 _rootRunUnary (dart:async/zone.dart:730)
#7 _RootZone.runUnary (dart:async/zone.dart:864)
#8 _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:488)
#9 _Future._propagateToListeners (dart:async/future_impl.dart:571)
#10 _Future._completeWithValue (dart:async/future_impl.dart:331)
#11 _Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:393)
#12 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:23)
#13 _asyncRunCallback (dart:async/schedule_microtask.dart:32)
#14 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:128)
Unhandled exception:
Bad state: Cannot write to socket, it is closed
#0 _rootHandleUncaughtError.<anonymous closure>.<anonymous closure> (dart:async/zone.dart:713)
#1 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:23)
#2 _asyncRunCallback (dart:async/schedule_microtask.dart:32)
#3 _asyncRunCallback (dart:async/schedule_microtask.dart:36)
#4 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:128)
the issue seems to be that the query close fires of a Future internally, so the close() function returns before the close is actually finished:
void _closeQuery(Query q, bool retain) {
_log.finest("Closing query: ${q.sql}");
for (var cnx in _pool) {
var preparedQuery = cnx.removePreparedQueryFromCache(q.sql);
if (preparedQuery != null) {
_waitUntilReady(cnx).then((_) {
_log.finest("Connection ready - closing query: ${q.sql}");
var handler = new _CloseStatementHandler(preparedQuery.statementHandlerId);
cnx.autoRelease = !retain;
cnx.processHandler(handler, noResponse: true);
});
}
}
}
The pool close happens immediately, it closes the socket right away. This means the query close (which is delayed till after the pool close due to the Future) fails, unable to send whatever information it needs to through the socket. I've opened a ticket to sqljocky at https://github.com/jamesots/sqljocky/issues/44 but I've received no replies, and I need a workaround if it's going to take a while to get a response.
This code has allowed me to replicate the issue 100% of the time:
Future _putMethod(RestRequest request) {
return new Future.sync(() {
mysql.ConnectionPool pool = getConnectionPool();
return pool.prepare("SELECT * FROM files").then((mysql.Query query) {
return query.execute().then((result) {
// Do something?
}).then((_) {
this._log.info("Closing");
query.close();
});
}).then((_) {
pool.close();
});
});
}
This is yet more a question than an answer but I can't put this code in a comment in a usable way.
You should ensure that you return the Future returned from every async invocation.
I don't know if the lines where I added the comment // added return are async invocations.
Can you please try and give feedback if this changes anything.
Future _putMethod(RestRequest request) {
return new Future.sync(() {
mysql.ConnectionPool pool = getConnectionPool();
return pool.prepare("SELECT * FROM files").then((mysql.Query query) {
return query.execute().then((result) {
// Do something? // also ensure that a Future of an async invocation is returned
}).then((_) {
this._log.info("Closing");
return query.close(); // added return
});
}).then((_) {
return pool.close(); // added return
});
});
}
I made a simple web server but it crashes every time I am refreshing page many times in a short time. I just enter 127.0.0.1:8080 in my browser and then spam with F5. Here is the code to reproduce this issue:
void main()
{
HttpServer server = new HttpServer();
server.addRequestHandler((req) => true, handleGET);
server.listen('127.0.0.1', 8080);
}
void handleGET(HttpRequest req, HttpResponse res)
{
var requestedFile = ".${req.path}";
if(req.path == "/")
{
requestedFile = requestedFile.concat("index.html");
}
File file = new File(requestedFile);
file.exists().then((bool found) {
if(found)
{
file.openInputStream().pipe(res.outputStream);
}
else
{
res.statusCode = HttpStatus.NOT_FOUND;
res.outputStream.close();
}
});
}
The error I get is following:
Unhandled exception:
StreamException: Stream closed
#0 _SocketOutputStream._write (dart:io:6017:30)
#1 _HttpResponse._writeHeader (dart:io:5981:18)
#2 _HttpRequestResponseBase._ensureHeadersSent (dart:io:2696:19)
#3 _HttpResponse._streamClose (dart:io:2921:23)
#4 _HttpOutputStream.close (dart:io:3078:36)
#5 _pipe.<anonymous closure> (dart:io:6271:28)
#6 _BaseDataInputStream._checkScheduleCallbacks.issueCloseCallback (dart:io:6231:59)
#7 _Timer._createTimerHandler._handleTimeout (dart:io:6804:28)
#8 _Timer._createTimerHandler._handleTimeout (dart:io:6812:7)
#9 _Timer._createTimerHandler.<anonymous closure> (dart:io:6820:23)
#10 _ReceivePortImpl._handleMessage (dart:isolate-patch:37:92)
Often before this mayor exception I receive a bunch of warnings like WSASend failed: 10053 but those don't crash the server. I work on Windows if this problem is related to some specific implementation.
Because you are hitting reload very quickly, your code ends up trying to write to a socket that has already been closed. Hence, you should probably catch StreamException and just ignore it. It could be argued that the io library should help you out a bit more. I just filed this bug:
http://code.google.com/p/dart/issues/detail?id=7334&thanks=7334&ts=1355280746