Ejemplo n.º 1
0
            public BundleAction AddReference()
            {
                m_ReferenceCount++;

                MDebug.LogVerbose(LOG_TAG, $"Bundle Add Reference:{ms_AssetManager.m_BundleInfos[m_BundleIndex].BundleName}, Reference Count: {m_ReferenceCount}");

                switch (m_BundleState)
                {
                case BundleState.NotLoad:
                    m_BundleState = BundleState.NeedLoad;
                    return(BundleAction.Load);

                case BundleState.Loaded:
                case BundleState.Loading:
                case BundleState.NeedLoad:
                    return(BundleAction.Null);

                case BundleState.NeedUnload:
                    m_BundleState = BundleState.Loaded;
                    return(BundleAction.Null);

                default:
                    MDebug.Assert(false, LOG_TAG, "Not support BundleState: " + m_BundleState);
                    return(BundleAction.Null);
                }
            }
Ejemplo n.º 2
0
        public virtual void Stop()
        {
            try
            {
                _state = BundleState.Stopping;
                EventManager.OnBundleChanged(new BundleEventArgs(BundleTransition.Stopping, this));

                foreach (IBundleActivator activator in Acitvators)
                {
                    if (activator == null)
                    {
                        throw new Exception("No activator for: " + Location);
                    }

                    activator.Stop(this.Context);
                }
                _activators = null;
                _framework.UnloadDomain(_domain);
            }
            catch (Exception ex)
            {
                FileLogUtility.Error(string.Format("{0}:{1}", ex.Message, "Bundle. Stop()"));
                throw new BundleException(ex.Message, ex);
            }

            _state = BundleState.Installed;
            EventManager.OnBundleChanged(new BundleEventArgs(BundleTransition.Stopped, this));
        }
Ejemplo n.º 3
0
        private BundleState CreateBundleState(IReadOnlyCollection <ISource> sources)
        {
            var items      = new HashSet <ISourceItem>(SourceItemEqualityComparer.Default);
            var watchPaths = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase);

            foreach (var containerSource in sources)
            {
                if (!containerSource.AddItems(Context, items, watchPaths))
                {
                    return(null);
                }
            }

            var transformResults = items.Select(TransformItem).ToArray();

            if (transformResults.Any(x => x == null || x.Errors.Count > 0))
            {
                return(null);
            }

            // Join watch paths
            watchPaths.UnionWith(transformResults.SelectMany(x => x.WatchPaths));

            var responseContent = _bundleRenderer.Concat(transformResults.Select(x => x.Content));
            var fileRespones    = transformResults
                                  .Select(x => new BundleFileResponse(x.VirtualFile, _bundleRenderer.ContentType, GetContentHash(x.Content), x.Content, DateTime.UtcNow))
                                  .ToDictionary(x => x.VirtualFile, x => (IBundleContentResponse)x, StringComparer.InvariantCultureIgnoreCase);

            var bundleResponse = new BundleResponse(_bundleRenderer.ContentType, GetContentHash(responseContent), DateTime.UtcNow, responseContent, fileRespones, new Dictionary <string, string>(0));

            var bundleState = new BundleState(sources.ToArray(), watchPaths.ToArray(), bundleResponse);

            return(bundleState);
        }
Ejemplo n.º 4
0
        internal void RegisterAlive(ImageBundle bundle)
        {
            Debug.Assert(bundle.liveIndex == -1);

            if (bundle.textures.Length == 0)
            {
                return; // <- skip bundles without textures, as they can never be reclaimed, and would just waste space in the live list
            }
            byte bucketFlags = 0;

            for (int i = 0; i < bundle.textures.Length; i++)
            {
                int classification = ClassifyTexture(bundle.textures[i].Width, bundle.textures[i].Height);
                bucketFlags |= (byte)(1u << classification);
            }

            LiveListEnsureCapacity();
            liveListState[liveCount] = new BundleState {
                timeOut = 0, bucketFlags = bucketFlags
            };
            liveListBundles[liveCount] = bundle;
            bundle.liveIndex           = liveCount;

            liveCount++;
        }
Ejemplo n.º 5
0
            public BundleAction RemoveReference()
            {
                MDebug.LogVerbose(LOG_TAG, $"Bundle Remove Reference:{ms_AssetManager.m_BundleInfos[m_BundleIndex].BundleName}, Reference Count: {m_ReferenceCount}");
                MDebug.Assert(m_ReferenceCount > 0, LOG_TAG, "m_ReferenceCount = 0, Cant Remove!");
                m_ReferenceCount--;
                switch (m_BundleState)
                {
                case BundleState.NotLoad:
                case BundleState.NeedLoad:
                    MDebug.Assert(false, LOG_TAG, "BundleState.NotLoad");
                    return(BundleAction.Null);

                case BundleState.Loaded:
                    if (m_ReferenceCount == 0)
                    {
                        m_BundleState = BundleState.NeedUnload;
                        return(BundleAction.Unload);
                    }
                    else
                    {
                        return(BundleAction.Null);
                    }

                case BundleState.Loading:
                    MDebug.Assert(m_ReferenceCount > 0, LOG_TAG, "m_ReferenceCount > 0");
                    return(BundleAction.Null);

                default:
                    MDebug.Assert(false, LOG_TAG, "Not support BundleState: " + m_BundleState);
                    return(BundleAction.Null);
                }
            }
Ejemplo n.º 6
0
        public Bundle(IBundleContext bundleContext, IBundleRenderer bundleRenderer, IBundleContentTransformer[] contentTransformers)
        {
            _bundleRenderer           = bundleRenderer;
            Context                   = bundleContext;
            BundleContentTransformers = contentTransformers?.ToArray() ?? new IBundleContentTransformer[0];

            _bundleState = BundleState.CreateEmpty(_bundleRenderer.ContentType);
        }
Ejemplo n.º 7
0
            public BundleHandler()
            {
                m_Bundle = null;

                m_BundleState    = BundleState.NotLoad;
                m_ReferenceCount = 0;

                m_OnBundleLoaded = default;
            }
Ejemplo n.º 8
0
 /// <summary>
 /// 将当前设置为已解析状态
 /// </summary>
 internal void Resolve()
 {
     if (state == BundleState.Installed)
     {
         state = BundleState.Resolved;
         // Do not publish RESOLVED event here.  This is done by caller
         // to Resolve if appropriate.
     }
 }
Ejemplo n.º 9
0
 public void OnRelease()
 {
     m_BundleIndex = -1;
     UnloadBundleForce();
     m_Bundle         = null;
     m_BundleState    = BundleState.NotLoad;
     m_ReferenceCount = 0;
     m_OnBundleLoaded = default;
 }
Ejemplo n.º 10
0
 //////////////////////////////////////////////////////////////////////////
 public CBundle(long id, string location, CManifest manifest, DateTime lastModified, CSystemBundle systemBundle)
 {
     m_id = id;
     m_location = location;
     m_manifest = manifest;
     m_lastModified = lastModified;
     m_systemBundle = systemBundle;
     m_state = BundleState.INSTALLED;
 }
Ejemplo n.º 11
0
 protected AbstractBundle(IBundleData bundledata, Framework framework)
 {
     resolveState    = ResolveState.Unresolved;
     state           = BundleState.Installed;
     this.bundledata = (BaseData)bundledata;
     this.bundledata.SetBundle(this);
     this.framework  = framework;
     statechangeLock = new AutoResetEvent(true);
 }
Ejemplo n.º 12
0
        private object GetBundleVersionInfo(BundleVersion bundleVersion)
        {
            BundleState bundleState = this.taskRunner.GetBundleState(bundleVersion.Id);

            double elapsedSecs = 0;
            double totalSecs   = 0;

            if (bundleState == BundleState.Deploying)
            {
                Publication publication = this.Entities.Publication.Where(p => p.State == PublicationState.InProgress && p.Package.BundleVersionId == bundleVersion.Id).OrderByDescending(p => p.CreatedDate).FirstOrDefault();

                if (publication != null)
                {
                    Environment environment = this.Entities.Environment.Include("PreviousEnvironment").FirstOrDefault(e => e.Id == publication.EnvironmentId);

                    elapsedSecs = (DateTime.UtcNow - publication.CreatedDate).TotalSeconds;
                    totalSecs   = bundleVersion.GetDoubleProperty("LastDeploymentDuration-e" + publication.EnvironmentId);

                    if (Math.Abs(totalSecs) < 1 && environment != null && environment.PreviousEnvironment.Count > 0)
                    {
                        totalSecs = bundleVersion.GetDoubleProperty("LastDeploymentDuration-e" + environment.PreviousEnvironment.First().Id);
                    }
                }
            }

            if (bundleState == BundleState.Packaging)
            {
                Package thisPackage     = this.Entities.Package.Where(p => p.BundleVersionId == bundleVersion.Id && p.PackageDate == null).OrderByDescending(p => p.CreatedDate).FirstOrDefault();
                Package previousPackage = this.Entities.Package.Where(p => p.BundleVersionId == bundleVersion.Id && p.PackageDate != null).OrderByDescending(p => p.CreatedDate).FirstOrDefault();

                if (thisPackage != null && previousPackage != null && previousPackage.PackageDate.HasValue)
                {
                    elapsedSecs = (DateTime.UtcNow - thisPackage.CreatedDate).TotalSeconds;
                    totalSecs   = (previousPackage.PackageDate.Value - previousPackage.CreatedDate).TotalSeconds;
                }
            }

            if (bundleState == BundleState.Building)
            {
                totalSecs = bundleVersion.GetDoubleProperty("LastBuildDuration");

                if (totalSecs > 0)
                {
                    elapsedSecs = (DateTime.UtcNow - bundleVersion.GetDateTimeProperty("LastBuildStartDate", DateTime.UtcNow)).TotalSeconds;
                }
            }

            return(new
            {
                id = bundleVersion.Id,
                elapsedSecs = (int)elapsedSecs,
                totalSecs = (int)totalSecs,
                state = bundleState.ToString(),
                projects = bundleVersion.ProjectVersions.Select(this.GetProjectVersionInfo).ToList()
            });
        }
Ejemplo n.º 13
0
        //////////////////////////////////////////////////////////////////////////

        protected void setState(BundleState state)
        {
            Debug.Assert(m_state != BundleState.INSTALLED || state == BundleState.RESOLVED);
            Debug.Assert(m_state != BundleState.RESOLVED || state == BundleState.STARTING);
            Debug.Assert(m_state != BundleState.STARTING || state == BundleState.ACTIVE || state == BundleState.STOPPING);
            Debug.Assert(m_state != BundleState.ACTIVE || state == BundleState.STOPPING);
            Debug.Assert(m_state != BundleState.STOPPING || state == BundleState.RESOLVED);

            m_state = state;
        }
Ejemplo n.º 14
0
 internal Bundle(BundleData bundleData, Framework framework)
 {
     id               = bundleData.Id;
     _storage         = new DirectoryInfo(bundleData.Location);
     this._framework  = framework;
     this._bundleData = bundleData;
     _location        = bundleData.Location;
     _symbolicName    = Path.GetFileNameWithoutExtension(bundleData.Location);
     _state           = BundleState.Installed;
     SetDynamicInfo();
 }
Ejemplo n.º 15
0
        private void ConcatBundle(BundleState bundle)
        {
            if (bundle == null)
            {
                throw new System.ArgumentNullException("bundle");
            }

            var outputFileInfo   = bundle.BundleOutputFile;
            var outputFile       = outputFileInfo.FullName;
            var includeFileInfos = bundle.Includes.Select(include => include.OutputFile).ToList();

            try
            {
                // clear the output file
                File.WriteAllText(outputFile, "");

                // concat all the output of the includes together
                foreach (var includeFileInfo in includeFileInfos)
                {
                    var file = includeFileInfo.FullName;
                    try
                    {
                        if (FileExtension.IsCss(file) ||
                            FileExtension.IsLess(file))
                        {
                            var css = Css.CssParser.GetCss(file, true, import =>
                            {
                                LogWarning("An import file could not be found. File: {0}, RelativeTo: {1}, Import: {2}, Statement: {3}", file, import.File, import.ImportFile, import.Statement);
                            });

                            // fix the relative paths
                            css = Css.CssParser.UpdateRelativePaths(css, includeFileInfo.DirectoryName, outputFileInfo.DirectoryName);

                            // append the css to the file
                            File.AppendAllText(outputFile, css);
                        }
                        else
                        {
                            File.AppendAllText(outputFile, File.ReadAllText(file));
                        }

                        OnFileBundled(outputFile, file);
                    }
                    catch (Exception ex)
                    {
                        throw new ApplicationException(string.Format("Failed to append include to bundle output. An error occurred trying to append the include to the bundle output.  File: {0}", file), ex);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException(string.Format("Failed to create bundle output. An error occurred trying to create the bundle output. OutputFile: {0}, Files: {1}", outputFile, string.Join(", ", includeFileInfos.Where(s => s != null).Select(s => string.Format("\"{0}\"", s)))), ex);
            }
        }
Ejemplo n.º 16
0
 internal Bundle(BundleData bundleData, Framework framework)
 {
     this.id = bundleData.Id;
     this.storage = new DirectoryInfo(bundleData.Location);
     this.framework = framework;
     this.bundleData = bundleData;
     this.location = bundleData.Location;
     this.symbolicName = Path.GetFileNameWithoutExtension(bundleData.Location);
     this.state = BundleState.Installed;
     SetDynamicInfo();
 }
Ejemplo n.º 17
0
            private void OnLoadedBundle(AsyncOperation obj)
            {
                MDebug.Assert(m_Bundle == null && m_BundleState == BundleState.Loading, LOG_TAG, "m_Bundle == null && m_BundleState == BundleState.Loading");
                m_Bundle      = (obj as AssetBundleCreateRequest).assetBundle;
                m_BundleState = BundleState.Loaded;

                MDebug.Log(LOG_TAG, $"Loaded Bundle {ms_AssetManager.m_BundleInfos[m_BundleIndex].BundleName}");

                m_OnBundleLoaded?.Invoke(ms_AssetManager.m_BundleInfos[m_BundleIndex].BundleName);
                m_OnBundleLoaded = null;
            }
Ejemplo n.º 18
0
        public Bundle(IBundleArchive ba)
        {
            this.id       = ba.Id;
            this.location = ba.Location;
            this.archive  = ba;
            this.theState = BundleState.Installed;

//            doExportImport();
//            FileTree dataRoot = fw.getDataStorage();
//            if (dataRoot != null)
//            {
//                bundleDir = new FileTree(dataRoot, Long.toString(id));
//            }
//            ProtectionDomain pd = null;
//            if (fw.bPermissions)
//            {
//                try
//                {
//                    URL bundleUrl = new URL(BundleURLStreamHandler.PROTOCOL, Long.toString(id), "");
//                    PermissionCollection pc = fw.permissions.getPermissionCollection(this);
//                    pd = new ProtectionDomain(new CodeSource(bundleUrl,
//                        (java.security.cert.Certificate[])null),
//                        pc);
//                }
//                catch (MalformedURLException never) { }
//            }
//            protectionDomain = pd;
//
//            int oldStartLevel = archive.getStartLevel();
//
//            try
//            {
//                if(framework.startLevelService == null)
//                {
//                    archive.setStartLevel(0);
//                }
//                else
//                {
//                    if(oldStartLevel == -1)
//                    {
//                        archive.setStartLevel(framework.startLevelService.getInitialBundleStartLevel());
//                    }
//                    else
//                    {
//                    }
//                }
//            }
//            catch (Exception e)
//            {
//                Debug.println("Failed to set start level on #" + getBundleId() + ": " + e);
//            }
        }
        private void ReadBundleState(XmlReader reader, bool withEndElement)
        {
            _bundleId = reader.GetAttribute("id");
            string bundleStateValue = reader.GetAttribute("value");

            reader.ReadStartElement(XmlExpression.BundleStateExpTag);
            if (withEndElement)
            {
                reader.ReadEndElement();
            }

            _BundleState = ParseBundleState(bundleStateValue);
        }
Ejemplo n.º 20
0
            private bool TryLoadBundle()
            {
                MDebug.Log(LOG_TAG, $"Start Load Bundle {ms_AssetManager.m_BundleInfos[m_BundleIndex].BundleName}");

                if (m_BundleState != BundleState.NeedLoad)
                {
                    return(false);
                }

                MDebug.Assert(m_Bundle == null, LOG_TAG, "m_Bundle == null");
                AssetBundle.LoadFromFileAsync(ms_AssetManager.GetBundlePath(m_BundleIndex)).completed += OnLoadedBundle;
                m_BundleState = BundleState.Loading;

                return(true);
            }
Ejemplo n.º 21
0
        internal Bundle(Int32 id, string location)
        {
            try
            {
                // Build the assembly full path
                string full = Path.GetFullPath(location);
                assembly = Assembly.LoadFrom(full);
            }
            catch (Exception e)
            {
                TracesProvider.TracesOutput.OutputTrace(e.Message);
                throw new BundleException(e.Message, e);
            }

            this.id    = id;
            this.state = BundleState.Installed;
        }
Ejemplo n.º 22
0
        internal Bundle(Int32 id, string location)
        {
            try
            {
                // Build the assembly full path
                string full = Path.GetFullPath(location);
                assembly = Assembly.LoadFrom(full);
            }
            catch (Exception e)
            {
                TracesProvider.TracesOutput.OutputTrace(e.Message);
                throw new BundleException(e.Message, e);
            }

            this.id = id;
            this.state = BundleState.Installed;
        }
Ejemplo n.º 23
0
        public void SetState(BundleState bundleState, double damagedSD)
        {
            state = bundleState;
            switch (bundleState)
            {
            case BundleState.On:
                stateMatrix = DenseMatrix.Create(SendLayer.UnitCount, ReceiveLayer.UnitCount, 1);
                break;

            case BundleState.Off:
                stateMatrix = DenseMatrix.Create(SendLayer.UnitCount, ReceiveLayer.UnitCount, 0);
                break;

            case BundleState.Damaged:
                stateMatrix = RandomizeGaussianMatrixMaker(damagedSD);
                break;
            }
        }
Ejemplo n.º 24
0
        public void Stop()
        {
            try
            {
                this.state = BundleState.Stopping;
                IBundleActivator activator = this.Activator;
                if (activator == null)
                {
                    throw new Exception("No activator for: " + this.Location);
                }

                activator.Stop(this.Context);
            }
            catch (Exception e)
            {
                TracesProvider.TracesOutput.OutputTrace(e.Message);
                throw new BundleException(e.Message, e);
            }

            this.state = BundleState.Installed;
        }
Ejemplo n.º 25
0
    public void Init(string path, string abName, LoadedCallback refCallback, bool async = true, BundleLoader parent = null, bool manifest = false)
    {
        base.Init(path, null, async);           //null不使用父类回调
        Util.Log(string.Format("Init BundleLoader path:{0}, name:{1}", path, abName));

        m_abName = abName;
        AddHandleCallBack(refCallback);
        AddParent(parent);

        BundleLoaderCtrl.Instance.AddBundleLoader(abName, this);

        if (manifest)
        {
            StartLoad();
        }
        else
        {
            string[] dependencies = LoadModule.Instance.GetDependencies(abName);
            for (int i = 0; i < dependencies.Length; ++i)
            {
                m_childs.Add(dependencies[i]);

                if (i == dependencies.Length - 1)
                {
                    allChildsPassed = true;
                }

                BundleState state = LoadModule.Instance.LoadAssetBundle(dependencies[i], null, async, this);
                if (state == BundleState.NotExist || state == BundleState.Loaded)
                {
                    m_childs.Remove(dependencies[i]);
                }
            }

            if (m_childs.Count == 0 && m_state != LoaderState.FINISHED) //无依赖直接加载自己
            {
                StartLoad();
            }
        }
    }
Ejemplo n.º 26
0
        /// <summary>
        /// Start Bundle
        /// </summary>
        /// <exception cref="Syncfusion.Addin.BundleException">No activator for:  +Location</exception>
        public virtual void Start()
        {
            try
            {
                _state = BundleState.Starting;

                EventManager.OnBundleChanged(new BundleEventArgs(BundleTransition.Starting, this));

                _domain = _framework.CreateDomain(this.Context);
                Debug.Assert(_domain != null, "Bundle AppDomain can't be set to null.");

                AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(AssemblyResolve);

                _assembly = Assembly.LoadFrom(FileHelper.FileCopyToDynamicDirectory(_location));

                Debug.Assert(_assembly != null, "Bundle Assembly can's be set to null.");

                foreach (IBundleActivator activator in Acitvators)
                {
                    if (activator == null)
                    {
                        throw new BundleException("No activator for: " + Location);
                    }

                    activator.Start(this.Context);
                }
                if (_activators == null)
                {
                    FileLogUtility.Error(string.Format("{0}:{1}:{2}", DateTime.Now, this.GetType().FullName, "Start().Method()   Not find Acitvators! 未找到插件启动入口!"));
                }
                _state = BundleState.Active;

                EventManager.OnBundleChanged(new BundleEventArgs(BundleTransition.Started, this));
            }
            catch (Exception ex)
            {
                _state = BundleState.Installed;
                FileLogUtility.Error(string.Format("{0}:{1}", ex.Message, "Bundle.Start()"));
            }
        }
Ejemplo n.º 27
0
        public void Stop()
        {
            try
            {
                this.state = BundleState.Stopping;
                IBundleActivator activator = this.Activator;
                if (activator == null)
                {
                    throw new Exception("No activator for: " + this.Location);
                }

                activator.Stop(this.Context);
            }
            catch (Exception e)
            {
                TracesProvider.TracesOutput.OutputTrace(e.Message);
                throw new BundleException(e.Message, e);
            }

            this.state = BundleState.Installed;
            EventManager.OnBundleChanged(new BundleEventArgs(BundleTransition.Stopped, this));
        }
Ejemplo n.º 28
0
        private void ConfigurateBundleStateUpdate(BundleState oldBundleState, BundleState newBundleState)
        {
            foreach (var bundleStateWatch in oldBundleState.Watches)
            {
                if (newBundleState.Watches.Contains(bundleStateWatch, StringComparer.InvariantCultureIgnoreCase))
                {
                    continue;
                }

                Context.Watcher.Unwatch(bundleStateWatch, ChangeHandler);
            }

            foreach (var bundleStateWatch in newBundleState.Watches)
            {
                if (oldBundleState.Watches.Contains(bundleStateWatch, StringComparer.InvariantCultureIgnoreCase))
                {
                    continue;
                }

                Context.Watcher.Watch(bundleStateWatch, ChangeHandler);
            }
        }
Ejemplo n.º 29
0
        public AbstractBundle(BundleData bundleData, Framework framework)
        {
            if (framework == null)
            {
                throw new ArgumentNullException();
            }
            _stateChangingLock           = new object();
            _stateChangingAutoResetEvent = new AutoResetEvent(false);
            BundleData = bundleData;
            Framework  = framework;
            _state     = BundleState.Installed;
            if (bundleData != null)
            {
                SymbolicName = bundleData.SymbolicName;
            }
            var proxy = new BundleLoaderProxy(this)
            {
                Framework = framework
            };

            BundleLoaderProxy = proxy;
            BundleType        = string.IsNullOrEmpty(bundleData.HostBundleSymbolicName) ? BundleType.Host : BundleType.Fragment;
        }
Ejemplo n.º 30
0
        public void Stop()
        {
            try
            {
                this.state = BundleState.Stopping;
                IBundleActivator activator = this.Activator;
                if (activator == null)
                {
                    throw new Exception("No activator for: " + this.Location);
                }

                activator.Stop(this.Context);
            }
            catch (Exception e)
            {
                TracesProvider.TracesOutput.OutputTrace(e.Message);
                throw new BundleException(e.Message, e);
            }

            this.state = BundleState.Installed;
            EventManager.OnBundleChanged(new BundleEventArgs(BundleTransition.Stopped, this));
        }
Ejemplo n.º 31
0
 public void Uninstall()
 {
     TracesProvider.TracesOutput.OutputTrace("Not implemented, can't unload an assembly");
     this.state = BundleState.Uninstalled;
 }
Ejemplo n.º 32
0
 //////////////////////////////////////////////////////////////////////////
 protected virtual void PostStop()
 {
     m_state = BundleState.RESOLVED;
     m_systemBundle.RaiseBundleEvent(new BundleEvent(BundleEvent.Type.STOPPED, this));
 }
Ejemplo n.º 33
0
        //////////////////////////////////////////////////////////////////////////
        protected virtual void PreStart()
        {
            m_state = BundleState.STARTING;
            m_systemBundle.RaiseBundleEvent(new BundleEvent(BundleEvent.Type.STARTING, this));

            m_activator = null;

            try
            {
                m_assembly = m_systemBundle.getBundleRepository().LoadBundleAssembly(this);

                Type[] exports = m_assembly.GetExportedTypes();
                foreach (Type t in exports)
                {
                    TypeAttributes attrs = t.Attributes;
                    if ((attrs & TypeAttributes.Interface) == TypeAttributes.Interface ||
                        (attrs & TypeAttributes.Abstract) == TypeAttributes.Abstract)
                        continue;

                    if (t.GetInterface(typeof(IBundleActivator).FullName) != null)
                    {
                        m_activator = m_assembly.CreateInstance(t.FullName) as IBundleActivator;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                m_state = BundleState.RESOLVED;
                throw new BundleException("Failed to load bundle assembly", BundleException.ErrorCode.STATECHANGE_ERROR, ex);
            }

            m_context = new CBundleContext(this, m_systemBundle);
        }
Ejemplo n.º 34
0
        public virtual void Stop()
        {
            try
            {
                this.state = BundleState.Stopping;
                EventManager.OnBundleChanged(new BundleEventArgs(BundleTransition.Stopping, this));

                foreach (IBundleActivator activator in this.Acitvators)
                {
                    if (activator == null)
                    {
                        throw new Exception("No activator for: " + this.Location);
                    }

                    activator.Stop(this.Context);
                }
                activators = null;
                framework.UnloadDomain(domain);
            }
            catch (Exception ex)
            {
                throw new BundleException(ex.Message, ex);
            }

            this.state = BundleState.Installed;
            EventManager.OnBundleChanged(new BundleEventArgs(BundleTransition.Stopped, this));
        }
Ejemplo n.º 35
0
        private void Transform(BundleState bundle)
        {
            if (bundle.Transformed)
            {
                // IF we've already transformed this file
                // THEN bail

                return;
            }
            else if (bundle.Includes.Count == 0)
            {
                // IF nothing to do
                // THEN mark it as transformed and bail

                bundle.Transformed = true;
                return;
            }

            LogInfo("Ensuring the bundle \"{0}\" is up-to-date.", bundle.BundleFile);

            // what are the input files
            var inputFiles = new List<FileInfo>();
            inputFiles.Add(bundle.BundleFile);
            inputFiles.AddRange(bundle.Includes.Select(s => s.OutputFile));

            // find the most recent date from all the includes and the bundle file itself
            var inputMostRecentLastWriteTimeUtc = inputFiles
                .Select(f => f.LastWriteTimeUtc)
                // add the frappe lib as a last write utc source so the
                // output will be updated when frappe is published to fix
                // bugs and improve the output
                .Concat(new [] {
                    ExecutingAssemblyFile.LastWriteTimeUtc
                })
                .OrderByDescending(d => d)
                .First();

            // get the output file
            var outputFile = bundle.BundleOutputFile;

            // determine whether or not the bundle needs to be transformed
            if (!outputFile.Exists || outputFile.Length == 0 || outputFile.LastWriteTimeUtc < inputMostRecentLastWriteTimeUtc)
            {
                // IF the output file does NOT exist
                //   OR the last write time of the output file is less than the input most recent last write time
                // THEN we need to transform this bundle

                LogInfo("The output \"{0}\" for bundle \"{1}\" does not exist or is out-of-date.", bundle.BundleOutputFile, bundle.BundleFile);

                // concat the bundle together to create the output file
                ConcatBundle(bundle);

                // refresh the file now
                outputFile.Refresh();

                // set the last write time utc to the input because the output is based on the inputs
                outputFile.LastWriteTimeUtc = inputMostRecentLastWriteTimeUtc;

                LogInfo("The output \"{0}\" for bundle \"{1}\" has been updated.", bundle.BundleOutputFile, bundle.BundleFile);
            }

            bundle.Transformed = true;
        }
Ejemplo n.º 36
0
 public void Uninstall()
 {
     TracesProvider.TracesOutput.OutputTrace("Not implemented, can't unload an assembly");
     this.state = BundleState.Uninstalled;
 }
Ejemplo n.º 37
0
 /// <summary>
 /// 关闭插件
 /// </summary>
 internal virtual void Close()
 {
     state = BundleState.Resolved;
 }
Ejemplo n.º 38
0
        public virtual void Start()
        {
            try
            {
                this.state = BundleState.Starting;

                EventManager.OnBundleChanged(new BundleEventArgs(BundleTransition.Starting, this));

                domain = framework.CreateDomain(this.Context);
                Debug.Assert(domain != null, "Bundle AppDomain can't be set to null.");

                AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(AssemblyResolve);

                assembly = Assembly.LoadFrom(Utility.FileHelper.FileCopyToDynamicDirectory(location));

                Debug.Assert(assembly != null, "Bundle Assembly can's be set to null.");

                foreach (IBundleActivator activator in this.Acitvators)
                {
                    if (activator == null)
                    {
                        throw new BundleException("No activator for: " + this.Location);
                    }

                    activator.Start(this.Context);
                }

                this.state = BundleState.Active;

                EventManager.OnBundleChanged(new BundleEventArgs(BundleTransition.Started, this));
            }
            catch (Exception ex)
            {
                this.state = BundleState.Installed;
                throw new BundleException(ex.Message, ex);
            }
        }
Ejemplo n.º 39
0
 public void Uninstall()
 {
     TracesProvider.TracesOutput.OutputTrace("Not implemented, can't unload an assembly");
     this.state = BundleState.Uninstalled;
     EventManager.OnBundleChanged(new BundleEventArgs(BundleTransition.Uninstalled, this));
 }
Ejemplo n.º 40
0
 //////////////////////////////////////////////////////////////////////////
 protected virtual void Resolve()
 {
     m_state = BundleState.RESOLVED;
     m_systemBundle.RaiseBundleEvent(new BundleEvent(BundleEvent.Type.RESOLVED, this));
 }
Ejemplo n.º 41
0
 private static void WaitFor(IBundleContext context, string bundleName, BundleState bundleState)
 {
     while(context.GetBundle(bundleName).State != bundleState)
         Thread.Sleep(1000);
 }
Ejemplo n.º 42
0
 public static BundleState SetBundleVersionState(int id, BundleState state)
 {
     return(BundleStates.AddOrUpdate(id, state, (i, s) => state));
 }
Ejemplo n.º 43
0
        //////////////////////////////////////////////////////////////////////////
        protected void setState(BundleState state)
        {
            Debug.Assert(m_state != BundleState.INSTALLED || state == BundleState.RESOLVED);
            Debug.Assert(m_state != BundleState.RESOLVED || state == BundleState.STARTING);
            Debug.Assert(m_state != BundleState.STARTING || state == BundleState.ACTIVE || state == BundleState.STOPPING);
            Debug.Assert(m_state != BundleState.ACTIVE || state == BundleState.STOPPING);
            Debug.Assert(m_state != BundleState.STOPPING || state == BundleState.RESOLVED);

            m_state = state;
        }
Ejemplo n.º 44
0
        //////////////////////////////////////////////////////////////////////////
        protected virtual void PreStop()
        {
            /*
            This bundle's state is set to STOPPING.
            A bundle event of type BundleEvent.STOPPING is fired.
            Any services registered by this bundle must be unregistered.
            Any services used by this bundle must be released.
            Any listeners registered by this bundle must be removed.
            */
            m_state = BundleState.STOPPING;
            m_systemBundle.RaiseBundleEvent(new BundleEvent(BundleEvent.Type.STOPPING, this));

            m_context.Dispose();
            m_context = null;
            // TODO: unregister all links
        }
Ejemplo n.º 45
0
 /// <summary>
 /// Bundle Uninstall
 /// </summary>
 public void Uninstall()
 {
     _framework.UninstallBundle(id);
     _state = BundleState.Uninstalled;
     EventManager.OnBundleChanged(new BundleEventArgs(BundleTransition.Uninstalled, this));
 }
Ejemplo n.º 46
0
 //////////////////////////////////////////////////////////////////////////
 protected virtual void PostStart()
 {
     m_state = BundleState.ACTIVE;
     m_systemBundle.RaiseBundleEvent(new BundleEvent(BundleEvent.Type.STARTED, this));
 }
Ejemplo n.º 47
0
        public void Stop()
        {
            try
            {
                this.state = BundleState.Stopping;
                IBundleActivator activator = this.Activator;
                if (activator == null)
                {
                    throw new Exception("No activator for: " + this.Location);
                }

                activator.Stop(this.Context);
            }
            catch (Exception e)
            {
                TracesProvider.TracesOutput.OutputTrace(e.Message);
                throw new BundleException(e.Message, e);
            }

            this.state = BundleState.Installed;
        }
Ejemplo n.º 48
0
        private void ConcatBundle(BundleState bundle)
        {
            if (bundle == null)
            {
                throw new System.ArgumentNullException("bundle");
            }

            var outputFileInfo = bundle.BundleOutputFile;
            var outputFile = outputFileInfo.FullName;
            var includeFileInfos = bundle.Includes.Select(include => include.OutputFile).ToList();

            try
            {

                // clear the output file
                File.WriteAllText(outputFile, "");

                // concat all the output of the includes together
                foreach (var includeFileInfo in includeFileInfos)
                {
                    var file = includeFileInfo.FullName;
                    try
                    {
                        if (FileExtension.IsCss(file)
                            || FileExtension.IsLess(file))
                        {
                            var css = Css.CssParser.GetCss(file, true, import =>
                            {
                                LogWarning("An import file could not be found. File: {0}, RelativeTo: {1}, Import: {2}, Statement: {3}", file, import.File, import.ImportFile, import.Statement);
                            });

                            // fix the relative paths
                            css = Css.CssParser.UpdateRelativePaths(css, includeFileInfo.DirectoryName, outputFileInfo.DirectoryName);

                            // append the css to the file
                            File.AppendAllText(outputFile, css);
                        }
                        else
                        {
                            File.AppendAllText(outputFile, File.ReadAllText(file));
                        }

                        OnFileBundled(outputFile, file);
                    }
                    catch (Exception ex)
                    {
                        throw new ApplicationException(string.Format("Failed to append include to bundle output. An error occurred trying to append the include to the bundle output.  File: {0}", file), ex);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException(string.Format("Failed to create bundle output. An error occurred trying to create the bundle output. OutputFile: {0}, Files: {1}", outputFile, string.Join(", ", includeFileInfos.Where(s => s != null).Select(s => string.Format("\"{0}\"", s)))), ex);
            }
        }
Ejemplo n.º 49
0
 public void Uninstall()
 {
     framework.UninstallBundle(id);
     this.state = BundleState.Uninstalled;
     EventManager.OnBundleChanged(new BundleEventArgs(BundleTransition.Uninstalled, this));
 }