Esempio n. 1
0
 public static int Compare(ProcessDefInformation left, ProcessDefInformation right)
 {
     int ret = String.Compare(left.Name, right.Name);
     if (ret != 0) return ret;
     if (left.Version < right.Version)
     {
         return -1;
     }
     else return left.Version == right.Version ? 0 : 1;
 }
Esempio n. 2
0
        /// <summary>
        /// Scan package files for process information
        /// </summary>
        /// <returns></returns>
        protected Dictionary<String, List<ProcessDefInformation>> LoadProcessInformationIfNecessary()
        {
            lock (this)
            {
                if (_processInfoCache != null) return _processInfoCache;
                Dictionary<string, List<ProcessDefInformation>> cache = new Dictionary<string, List<ProcessDefInformation>>();
                foreach (string file in _processFiles)
                {
                    log.Info("Loading process file : {0}", file);
                    ProcessDefInformation pdi = new ProcessDefInformation();
                    pdi.FileName = file;
                    using (Stream stm = DataStore.GetPackageContentStream(file))
                    {
                        XmlReader xr = XmlReader.Create(stm);
                        XmlNodeType ntype = xr.MoveToContent();
                        if (ntype != XmlNodeType.Element) throw new Exception("Expected root element node");
                        string pname = xr.GetAttribute("name");
                        if (pname == null) throw new Exception("Missing 'name' attribute");
                        string pver = xr.GetAttribute("version");
                        if (pver == null) throw new Exception("Missing 'version' attribute");
                        pdi.Name = pname;
                        pdi.Version = Int32.Parse(pver);
                    }
                    List<ProcessDefInformation> lst;
                    if (!cache.TryGetValue(pdi.Name, out lst))
                    {
                        lst = new List<ProcessDefInformation>(); cache.Add(pdi.Name, lst);
                    }
                    foreach (ProcessDefInformation pdi2 in lst)
                    {
                        if (pdi2.Version == pdi.Version &&
                            pdi2.Name == pdi.Name)
                            throw new ApplicationException(string.Format("Process {0}.{1} already defined in file {2}", pdi2.Name, pdi2.Version, pdi2.FileName));
                    }
                    lst.Add(pdi);
                }

                foreach (List<ProcessDefInformation> lst in cache.Values)
                {
                    lst.Sort(new Comparison<ProcessDefInformation>(ProcessDefInformation.Compare));
                }
                _processInfoCache = cache;
                return _processInfoCache;
            }
        }