(function(){"use strict";u8.Base.Processes=function(e){$.extend(this,e);this.bind(e);this._running={}};$.extend(u8.Base.Processes.prototype,{get:function(e){return this._running[e]},create:function(e){var t=new u8.Base.Process(e);t.bind("Dispose",this._onProcessDispose.bind(this));this._running[t.id]=t;this.raise("Update",{reason:"Processes",added:[e.id]});return t},getStep:function(e,t){$assert(e,"Missing or empty argument 'stepName' in a call to 'Processes.getStep(...)'.");var s;if(typeof e=="object"){s=e}else{s={name:e}}var i=this;u8.request("ProcessChannel.GetStep",s,function(e,s){return t&&t(i,s.error&&s||{step:s.response&&s.response.step})})},getProcess:function(e,t){var s=this;u8.request("ProcessChannel.GetProcess",{name:e},function(e,i){return t&&t(s,i.error&&i||{process:i.response&&i.response.process})})},_onProcessDispose:function(e,t){var s=e.id;delete this._running[s];this.raise("Update",{reason:"Processes",removed:[s]})}});u8.Base.Processes.makeClass({name:"Processes",events:["Update"]});u8.services.add("processes","Processes");u8.Base.Processes.DataProvider=function(e){$.extend(this,e);this.onValueChange=new u8.Base.Event(e.onValueChange);this._createModel()};$.extend(u8.Base.Processes.DataProvider.prototype,{load:function(e){var t=this;if(!this.action){if(e){e(t,{})}return}if(this.isLoaded()&&this.isValid()){if(e){e(t,{})}return}if(e){this._callbacks.push(e)}if(this._isPending){return}this._isPending=true;var s=this.value&&this.value["DataProvider.load"];if(typeof s=="function"){s.call(this.value,i);return}u8.services.actions.execute(this.action,{arguments:{parent:this.parent,dataProvider:this,dataProviders:this.parent}},i);function i(e,s){s=s||{};t._isValid=true;t._isPending=false;if("output"in s){t.setValue(s.output)}var i=s&&s.error||{};while(t._callbacks.length){t._callbacks.shift()(t,i)}}},depends:function(e){var t=this.action;var s=t&&typeof t=="object"&&t.arguments;e=e||[];if(s){for(var i,n=0;n<s.length;n++){i=s[n];if(!i.dataProvider){continue}if(e.indexOf(i.dataProvider)>=0){continue}e.push(i.dataProvider);var r=this.parent.getDataProvider(i.dataProvider);if(r){r.depends(e).each(function(t){e.include(t)})}}}return e},hasCircularDependencies:function(){return this.depends().indexOf(this.name)>=0},isLoaded:function(){return"value"in this},isValid:function(){return this._isValid},invalidate:function(){if(this.action){this._isValid=false}},setValue:function(e){if(this.value===e){return}this.value=e;this.raise("ValueChange")},getValue:function(e){var t=this.value;if(!e||!t){return t}if(u8.tools.isArray(e)){t={};e.forEach(function(e){t[e]=this.getValue(e)},this);return t}var s="get"+e.toPascalCase();if(typeof t[s]=="function"){return t[s]()}if(e in t){return t[e]}if(typeof t.get=="function"){return t.get(e)}},_createModel:function(){this._callbacks=[];this._isValid=!this.action;this._isPending=false;if(this.action){this.action=new u8.Base.Action(this.action)}}});u8.Base.Processes.DataProvider.makeClass({name:"Processes_DataProvider",mixins:[u8.Base.EventSource]});u8.Base.Processes.Metric=function(e){$.extend(this,e);this.onValueChange=new u8.Base.Event(e.onValueChange);this._createModel()};$.extend(u8.Base.Processes.Metric.prototype,{getValue:function(){return this.value},setValue:function(e){if(e===this.value){return}this.value=e;this.raise("ValueChange")},update:function(e){var t=this;var s=t;if(this.dataProvider){this.process.getDataProvider(this.dataProvider).invalidate()}this.process.getExpressionValue(s,"Metric",function(s,i){t.setValue(i.value);return e&&e(t,{})})},_createModel:function(){if(this.view&&typeof this.view=="string"){try{this.view=evalValue(this.view)}catch(e){u8.log.exception("process","Process metrics is ignoring invalid view '"+this.view+"'.",e);this.view=null}}}});u8.tools.mixin(u8.Base.Processes.Metric,u8.Base.EventSource)})();