Ejemplo n.º 1
0
        public virtual void ReadProcessData(XmlElement xmlElement, ProcessDefinitionBuildContext creationContext)
        {
            this._processDefinition = creationContext.ProcessDefinition;

            Type delegatingObjectClass = creationContext.DelegatingObject.GetType();

            if (delegatingObjectClass == typeof(AttributeImpl))
            {
                String type = xmlElement.GetProperty("type");
                if ((Object)type != null)
                {
                    this._className = ((String)attributeTypes[type]);
                    string suportedTypes = "supported types: ";
                    foreach (Object o in attributeTypes.Keys)
                    {
                        suportedTypes += o.ToString() + " ,";
                    }
                    creationContext.Check(((Object)this._className != null), "attribute type '" + type + "' is not supported. " + suportedTypes + " !");
                }
                else
                {
                    this._className = xmlElement.GetProperty("serializer");
                    creationContext.Check(((Object)this._className != null), "for an attribute, you must specify either a type or a serializer");
                }
            }
            else if (delegatingObjectClass == typeof(FieldImpl))
            {
                this._className = xmlElement.GetProperty("class");
                creationContext.Check(((Object)this._className != null), "no class specified for a delegation : " + xmlElement);
            }
            else
            {
                this._className = xmlElement.GetProperty("handler");
                creationContext.Check(((Object)this._className != null), "no handler specified for a delegation : " + xmlElement);
            }

            log.Debug("parsing delegation for tag '" + xmlElement.Name + "' : " + this._className);

            // parse the exception handler
            String exceptionHandlerText = xmlElement.GetAttribute("on-exception");

            if ((Object)exceptionHandlerText != null)
            {
                _exceptionHandlingType = ExceptionHandlingTypeHelper.FromText(exceptionHandlerText);
                creationContext.Check((_exceptionHandlingType != 0), "unknown exception handler '" + exceptionHandlerText + "' in delegation " + xmlElement);
            }

            // create the configuration string
            XmlElement  configurationXml = new XmlElement("cfg");
            IEnumerator iter             = xmlElement.GetChildElements("parameter").GetEnumerator();

            while (iter.MoveNext())
            {
                configurationXml.AddChild((XmlElement)iter.Current);
            }
            _configuration = configurationXml.ToString();
        }
Ejemplo n.º 2
0
        public void ReadProcessDataTest()
        {
            XmlElement                    xmlElement               = helloWorld1();
            ProcessDefinitionImpl         processDefinition        = new ProcessDefinitionImpl();
            ProcessDefinitionBuildContext processDefinitionBuilder = new ProcessDefinitionBuildContext(processDefinition, null, null);

            processDefinition.ReadProcessData(xmlElement, processDefinitionBuilder);

            Assert.AreEqual("Hello world 1", processDefinition.Name);
            Assert.AreEqual("This is the simples process.", processDefinition.Description);
            Assert.IsNotNull(processDefinition.StartState);
            Assert.AreEqual("start", processDefinition.StartState.Name);
            Assert.IsNotNull(processDefinition.EndState);
            Assert.AreEqual("end", processDefinition.EndState.Name);
            //activity-state在Nodes裏面,以後再換掉
        }
Ejemplo n.º 3
0
        private Int32 GetVersionNr(ProcessDefinitionBuildContext creationContext, string name)
        {
            int         newVersion = 1;
            IEnumerator iter       = creationContext.DbSession.Iterate(queryFindVersionNumbers, name, DbType.STRING).GetEnumerator();

            if (iter.MoveNext())
            {
                Int32 highestVersionNumber = (Int32)iter.Current;
                if ((Object)highestVersionNumber != null)
                {
                    newVersion = highestVersionNumber + 1;
                }
            }
            if (iter.MoveNext())
            {
                throw new NetBpm.Util.DB.DbException("duplicate value");
            }
            return(newVersion);
        }
Ejemplo n.º 4
0
        public virtual ISet GetAssemblyFiles(ProcessDefinitionBuildContext creationContext, IProcessDefinition processDefinition)
        {
            ISet classFiles = new HashedSet();
            IDictionary <string, byte[]> entries = creationContext.Entries;
            IEnumerator iter = entries.Keys.GetEnumerator();

            while (iter.MoveNext())
            {
                String entryName = (String)iter.Current;
                if ((entryName.StartsWith("lib")) && (entryName.EndsWith(".dll")))
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("attaching assembly file " + entryName);
                    }

                    byte[] classBytes = (byte[])entries[entryName];

                    if (log.IsDebugEnabled)
                    {
                        log.Debug("found assembly " + entryName);
                    }

                    Assembly assemply = Assembly.Load(classBytes);
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("attaching assembly name: " + assemply.GetName().Name + " Version:" + assemply.GetName().Version.ToString());
                    }

                    AssemblyFileImpl assemblyFile = new AssemblyFileImpl();
                    assemblyFile.FileName          = entryName;
                    assemblyFile.Bytes             = classBytes;
                    assemblyFile.AssemblyName      = assemply.GetName().Name;
                    assemblyFile.AssemblyVersion   = assemply.GetName().Version.ToString();
                    assemblyFile.ProcessDefinition = processDefinition;
                    classFiles.Add(assemblyFile);
                }
            }
            return(classFiles);
        }
Ejemplo n.º 5
0
        public void DeployProcessArchive(Stream processArchiveStream, DbSession dbSession)
        {
            log.Debug("reading process archive...");

            // construct an empty process definition
            ProcessDefinitionImpl processDefinition = new ProcessDefinitionImpl();

            // Then save the process definition
            // This is done so hibernate will assign an id to this object.
            dbSession.Save(processDefinition);

            IDictionary <string, byte[]> entries = null;

            entries = ZipUtility.ReadEntries(processArchiveStream);

            ProcessDefinitionBuildContext processDefinitionBuilder = new ProcessDefinitionBuildContext(processDefinition, entries, dbSession);

            try
            {
                if (!entries.ContainsKey("processdefinition.xml"))
                {
                    processDefinitionBuilder.AddError("entry '" + "processdefinition.xml" + "' found not found in the process archive");
                    throw new SystemException("entry '" + "processdefinition.xml" + "' found not found in the process archive");
                }
                // parse the  processdefinition.xml
                XmlElement xmlElement = getXmlElementFromBytes(entries["processdefinition.xml"]);
                // build the object model from the xml
                processDefinitionBuilder.PushScope("in processdefinition.xml");
                processDefinition.ReadProcessData(xmlElement, processDefinitionBuilder);
                processDefinition.Version    = GetVersionNr(processDefinitionBuilder, processDefinition.Name);
                processDefinition.ClassFiles = GetAssemblyFiles(processDefinitionBuilder, processDefinition);
                processDefinitionBuilder.PopScope();
                // resolve all forward references
                processDefinitionBuilder.ResolveReferences();

                processDefinition.Validate(processDefinitionBuilder);

                if (processDefinitionBuilder.HasErrors())
                {
                    throw new NpdlException(processDefinitionBuilder.Errors);
                }
                // read the optional web-interface information
                if (entries.ContainsKey("web/webinterface.xml"))
                {
                    log.Debug("processing webinterface.xml...");
                    xmlElement = getXmlElementFromBytes(entries["web/webinterface.xml"]);
                    processDefinitionBuilder.PushScope("in webinterface.xml");
                    processDefinition.ReadWebData(xmlElement, processDefinitionBuilder);
                    processDefinitionBuilder.PopScope();
                }
                else
                {
                    log.Debug("no web/webinterface.xml was supplied");
                }

                processDefinitionRepository.Save(processDefinition, dbSession);
            }
            catch (SystemException e)
            {
                log.Error("xml parsing error :", e);
                processDefinitionBuilder.AddError(e.GetType().FullName + " : " + e.Message);
                processDefinitionBuilder.AddError("couldn't continue to parse the process archive");
                throw new NpdlException(processDefinitionBuilder.Errors);
            }
        }