protected ProcessDef LoadPDFromFile(string fileName) { string did = Path.GetFileNameWithoutExtension(fileName); string[] pts = did.Split('.'); if (pts.Length != 2) { throw new Exception("Invalid file name format"); } if (string.IsNullOrEmpty(pts[0].Trim())) { throw new Exception("Invalid file name format"); } int v; if (!Int32.TryParse(pts[1], out v)) { throw new Exception("Invalid file name format"); } var pname = char.ToUpper(pts[0][0]) + pts[0].Substring(1).ToLower(); var pd = ProcessDefJsonSerializer.DeserializeFile(fileName); pd.ProcessName = pname; pd.Version = v; pd.Package = this.GetPackageDef(); pd.FinishModelBuild(); return(pd); }
/// <summary> /// Attempts to update process definition. If the attempt fails current definition will not /// be modified. /// </summary> /// <param name="pd"></param> /// <param name="errors"></param> /// <returns></returns> public bool TryUpdateProcess(ProcessDef pd) { EnsureProcessesLoaded(); var ce = TryReloadProcessDef(pd); string fn = Path.Combine(BaseDir, pd.ShortDefinitionId + ".npd"); log.Info("Saving process file {0}", fn); using (var sw = new StreamWriter(fn, false, Encoding.UTF8)) { ProcessDefJsonSerializer.Serialize(ce.Process, sw); } ce.ReadDate = DateTime.Now; _processCache.AddOrUpdate(ce.Process.ShortDefinitionId.ToLower(), ce, (id, oc) => ce); return(true); }