/// <summary> /// Saves a project config to disk. /// </summary> /// <param name="projectName">Name of the project</param> /// <returns>True if saved successfully. False otherwise.</returns> public bool SaveProject(string projectName) { try { if (projectName == null) { throw new ArgumentException("ProjectName cannot be null."); } if (!Projects.ContainsKey(projectName)) { throw new ArgumentException("Project not found: " + projectName); } string path = Path.Combine(MasterConfig.ProjectRoot, projectName); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } // File.WriteAllText(Path.Combine(path, "config.conf"), Projects[projectName].ToXML()); // File.WriteAllText(Path.Combine(path, "log.xml"), Projects[projectName].GetHistory().ExportXml()); File.WriteAllText(Path.Combine(path, "config.conf"), Projects[projectName].Serialize(AutoBuild.SerialSeperator, true)); File.WriteAllText(Path.Combine(path, "log.log"), Projects[projectName].GetHistory().Serialize(AutoBuild.SerialSeperator, true)); return(true); } catch (Exception e) { WriteEvent("Unable to save project config (" + projectName + "):\n" + e.Message, EventLogEntryType.Error, 0, 0); return(false); } }
/// <summary> /// Get project by Guid string. /// </summary> /// <param name="guid">Identifier of project.</param> /// <returns></returns> public ProjectItem GetProjectBy(string guid) { if (String.IsNullOrWhiteSpace(guid) || !Projects.ContainsKey(guid)) { return(default(ProjectItem)); } return(Projects[guid]); }
public void ImportProject(string filepath) { var p = new Project(filepath); if (Projects.ContainsKey(p.ProjName)) { throw new IOException("A project with this name already exists."); } Projects.Add(p.ProjName, p); Runtime.Instance.FileTree.Nodes.Add(p); }
public void AddProject(string projectName, ProjectData project) { if (Projects.ContainsKey(projectName)) { throw new ArgumentException("A project with this name already exists: " + projectName); } Projects[projectName] = project; Projects[projectName].LoadHistory(new BuildHistory()); SaveProject(projectName); // save this so we don't run into other problems later Projects[projectName].Changed2 += ProjectChanged; InitProject(projectName); }
public static void InitProject(string projectName) { if (projectName == null) { throw new ArgumentException("ProjectName cannot be null."); } if (!Projects.ContainsKey(projectName)) { throw new ArgumentException("Project not found: " + projectName); } foreach (var trigger in Projects[projectName].BuildTriggers) { trigger.Init(); } }
public static void Trigger(string projectName) { if (projectName == null) { throw new ArgumentException("ProjectName cannot be null."); } if (!Projects.ContainsKey(projectName)) { throw new ArgumentException("Project not found: " + projectName); } if (!(RunQueue.Contains(projectName) || Running.Contains(projectName)) || Projects[projectName].AllowConcurrentBuilds) { RunQueue.Enqueue(projectName); } Task.Factory.StartNew(ProcessQueue); }
//Добавить к потоку новый файл проекта public void AddProject() { var op = new OpenFileDialog { AddExtension = true, CheckFileExists = true, DefaultExt = "accbd", Multiselect = false, Title = "Файл проекта", Filter = "Файлы MS Access (.accdb) | *.accdb" }; op.ShowDialog(); if (op.FileName.IsEmpty()) { return; } using (Start()) { var proj = new Project(op.FileName, this); if (Command.IsError) { if (Command.IsError && Projects.ContainsKey(proj.Code)) { AddError("Проект уже есть в потоке", null, "Код=" + proj.Code); } Different.MessageError(Command.ErrorMessage()); } else { ProjectsList.Add(proj); Projects.Add(proj.Code, proj); AddEvent("Добавлен проект", proj.Code + ", " + proj.File); proj.ReadProviders(); if (Command.IsError) { Different.MessageError(Command.ErrorMessage()); } } MakeProviders(); MakeProjectString(); } }
public static void StandBy(string projectName) { if (projectName == null) { throw new ArgumentException("ProjectName cannot be null."); } if (!Projects.ContainsKey(projectName)) { throw new ArgumentException("Project not found: " + projectName); } Waiting[projectName] = Waiting[projectName] ?? new Timer(o => { Waiting[projectName].Dispose(); Waiting.Remove(projectName); Trigger(projectName); }); Waiting[projectName].Change(MasterConfig.PreTriggerWait, Timeout.Infinite); }
//Загрузка параметров из файла данных в память (Projects) private void ParamsFileToMemory() { AddEvent("Загрузка параметров из файла данных в память"); try { Projects.Clear(); using (var db = new DaoDb(DataFile)) { using (var rec = new ReaderAdo(db, "SELECT * FROM Projects")) while (rec.Read()) { var proj = new ReportProjectForLinks(this, rec); Projects.Add(proj.CodeFinal, proj); } foreach (var pr in SysPage.GetProjects().Values) { if (Projects.ContainsKey(pr.CodeFinal)) { Projects[pr.CodeFinal].CalcMode = pr.CalcMode; } } using (var rec = new ReaderAdo(db, "SELECT * FROM CalcParams")) while (rec.Read()) { var par = new ReportParam(rec); if (Projects.ContainsKey(par.Project)) { Projects[par.Project].Params.Add(par.FullCode, par); } } } foreach (var proj in Projects.Values) { proj.MakeFilters(); } } catch (Exception ex) { AddError("Ошибка при загрузке параметров", ex); } }
private static int BuildActions(string projectName, BuildStatus status = null, string checkoutRef = null) { if (projectName == null) { throw new ArgumentException("ProjectName cannot be null."); } if (!Projects.ContainsKey(projectName)) { throw new ArgumentException("Project not found: " + projectName); } WriteVerbose("Start Build: " + projectName); if (checkoutRef != null) { XDictionary <string, string> macros = new XDictionary <string, string>(); macros["checkout"] = checkoutRef; return(doActions(projectName, Projects[projectName].BuildCheckouts[checkoutRef].BuildCmd, status, macros)); } // else return(doActions(projectName, Projects[projectName].Build, status)); }
/// <summary> /// Loads a project configuration from disk. /// </summary> /// <param name="projectName">The name of the project to load.</param> /// <param name="overwrite">If true, will reload the project config data even if the project already has a configuration loaded. (False by default)</param> /// <returns>True if the project was loaded successfully. False otherwise.</returns> public bool LoadProject(string projectName, bool overwrite = false) { if (Projects.ContainsKey(projectName) && !overwrite) { return(false); } try { if (projectName == null) { throw new ArgumentException("ProjectName cannot be null."); } Projects[projectName] = new ProjectData(); if (!Projects.ContainsKey(projectName)) { throw new ArgumentException("Project not found: " + projectName); } string file = Path.Combine(MasterConfig.ProjectRoot, projectName, "config.conf"); UrlEncodedMessage UEM = new UrlEncodedMessage(File.ReadAllText(file), AutoBuild.SerialSeperator, true); UEM.DeserializeTo(Projects[projectName]); Projects[projectName].SetName(projectName); string logPath = Path.Combine(MasterConfig.ProjectRoot, projectName, "Log.log"); if (!File.Exists(logPath)) { logPath = String.Empty; } Projects[projectName].LoadHistory(logPath); Projects[projectName].Changed2 += ProjectChanged; return(true); } catch (Exception e) { WriteEvent("Unable to load project config (" + projectName + "):\n" + e.Message, EventLogEntryType.Error, 0, 0); return(false); } }
public string Validate(List <Entity <string, PMProjectRate, PMProject> > data1, List <Entity <string, PMTaskRate, PMTask> > data2, List <Entity <int?, PMAccountGroupRate, PMAccountGroup> > data3, List <Entity <int?, PMItemRate, InventoryItem> > data4, List <Entity <int?, PMEmployeeRate, BAccount> > data5) { string errors = null; StringBuilder sb = new StringBuilder(); foreach (Entity <string, PMProjectRate, PMProject> i1 in data1) { foreach (Entity <string, PMTaskRate, PMTask> i2 in data2) { foreach (Entity <int?, PMAccountGroupRate, PMAccountGroup> i3 in data3) { foreach (Entity <int?, PMItemRate, InventoryItem> i4 in data4) { foreach (Entity <int?, PMEmployeeRate, BAccount> i5 in data5) { bool isDuplicate = true; if (i1.Key != null && !Projects.ContainsKey(i1.Key.ToUpper().Trim())) { isDuplicate = false; continue; } if (i2.Key != null && !Tasks.ContainsKey(i2.Key.ToUpper().Trim())) { isDuplicate = false; continue; } if (i3.Key != null && !AccountGroups.ContainsKey(i3.Key)) { isDuplicate = false; continue; } if (i4.Key != null && !Inventory.ContainsKey(i4.Key)) { isDuplicate = false; continue; } if (i5.Key != null && !Employees.ContainsKey(i5.Key)) { isDuplicate = false; continue; } if (isDuplicate) { bool hasError = false; if (i1.Key != null) { sb.AppendFormat("{0}:{1}, ", PXMessages.LocalizeNoPrefix(Messages.Project), i1.Key); hasError = true; } if (i2.Key != null) { sb.AppendFormat("{0}:{1}, ", PXMessages.LocalizeNoPrefix(Messages.ProjectTask), i2.Key); hasError = true; } if (i3.Key != null) { sb.AppendFormat("{0}:{1}, ", PXMessages.LocalizeNoPrefix(Messages.AccountGroup), i3.Object.GroupCD); hasError = true; } if (i4.Key != null) { sb.AppendFormat("{0}:{1}, ", PXMessages.LocalizeNoPrefix(IN.Messages.InventoryItem), i4.Object.InventoryCD); hasError = true; } if (i5.Key != null) { sb.AppendFormat("{0}:{1}, ", PXMessages.LocalizeNoPrefix(EP.Messages.Employee), i5.Object.AcctCD); hasError = true; } if (hasError) { sb.AppendLine(""); } } } } } } } if (sb.Length > 0) { errors = string.Format("{0} = {1} ", PXMessages.LocalizeNoPrefix(Messages.RateCode), RateCode) + sb.ToString(); } return(errors); }
//Загружет списки проектов и провайдеров для потока public void ReadSetup() { try { Projects.Clear(); ProjectsList.Clear(); foreach (var provider in ProvidersDic.Values) { var pi = provider.ProviderInstance; if (pi != null) { if (ApplicationType == ApplicationType.Controller && General.ProvidersQueues.ContainsKey(pi.Hash)) { General.ProvidersQueues.Remove(pi.Hash); } pi.Dispose(); } } ProvidersDic.Clear(); Sources.Clear(); Receivers.Clear(); Imitators.Clear(); Archive = null; ArchivePr = null; using (var rec = new RecDao(General.ControllerFile, "SELECT * FROM Projects WHERE ThreadId =" + Id + " ORDER BY Project")) while (rec.Read()) { var proj = new Project(rec, this); if (!Command.IsError && !Projects.ContainsKey(proj.Code)) { Projects.Add(proj.Code, proj); ProjectsList.Add(proj); AddEvent("Добавлен проект", proj.Code + ", " + proj.File); proj.ReadProviders();//Чтение списка провайдеров } } MakeProviders(); MakeProjectString(); } catch (Exception ex) { AddError("Ошибка загрузки списка проектов. Необходимо повторить настройку", ex); } Procent = 70; try //Список провайдеров { AddEvent("Чтение настроек провайдеров"); using (var rec = new RecDao(General.ControllerFile, "SELECT * FROM Providers WHERE ThreadId =" + Id)) while (rec.Read()) { var name = rec.GetString("ProviderName"); if (ProvidersDic.ContainsKey(name)) { var prov = ProvidersDic[name]; prov.Code = rec.GetString("ProviderCode"); prov.Inf = rec.GetString("ProviderInf"); prov.Otm = rec.GetBool("Otm"); } } foreach (var prov in ProvidersDic.Values) { if (prov.Otm) { prov.ProviderInstance = General.RunProvider(prov.Code, prov.Name, prov.Inf, this); if (prov.ProviderInstance != null) { switch (prov.Type.ToProviderType()) { case ProviderType.Archive: Archive = (IArchive)prov.ProviderInstance; ArchivePr = prov; break; case ProviderType.Source: Sources.Add(prov.Name, (ISource)prov.ProviderInstance); break; case ProviderType.Imitator: var ims = (Imitator)prov.ProviderInstance; Imitators.Add(prov.Name, ims); var pname = prov.Name.Substring(0, prov.Name.Length - 4); if (Projects.ContainsKey(pname)) { Projects[pname].Imitator = ims; } else { AddError("Недопустимое имя провайдера имитатора", null, prov.Name); } break; case ProviderType.Receiver: Receivers.Add(prov.Name, (IReceiver)prov.ProviderInstance); break; } if (ApplicationType == ApplicationType.Controller) { string hash = prov.ProviderInstance.Hash; if (!General.ProvidersQueues.ContainsKey(hash)) { General.ProvidersQueues.Add(hash, new Queue <int>()); } prov.ProviderQueue = General.ProvidersQueues[hash]; } } } } MakeProviders(); } catch (Exception ex) { AddError("Ошибка при чтении настроек провайдеров", ex); } }
private static int doActions(string projectName, IEnumerable <string> commands, BuildStatus status = null, XDictionary <string, string> Macros = null) { if (projectName == null) { throw new ArgumentException("ProjectName cannot be null."); } if (!Projects.ContainsKey(projectName)) { throw new ArgumentException("Project not found: " + projectName); } Macros = Macros ?? new XDictionary <string, string>(); status = status ?? new BuildStatus(); string ArchiveLoc = Path.Combine(MasterConfig.ProjectRoot, projectName, "Archive", status.TimeStamp.ToString(DateTimeDirFormat)); if (!Directory.Exists(ArchiveLoc)) { Directory.CreateDirectory(ArchiveLoc); } ProjectData proj = Projects[projectName]; ProcessUtility _cmdexe = new ProcessUtility("cmd.exe"); // Redirect stdout and stderr to the same output Func <string> getToolSwitches = () => { string ret = String.Empty; foreach ( string s in MasterConfig.VersionControlList[proj.VersionControl].Tool. Switches) { if (s.Contains(" ")) { ret += " \"" + s + "\""; } else { ret += " " + s; } } return(ret); }; Macros["project"] = projectName; Macros["vcstool"] = MasterConfig.VersionControlList[proj.VersionControl].Tool.Path; Macros["vcsswitches"] = getToolSwitches(); Macros["keepclean"] = proj.KeepCleanRepo.ToString(); string rootPath = MasterConfig.ProjectRoot + @"\" + projectName; Macros["projectroot"] = rootPath; Macros["repo_url"] = proj.RepoURL; Macros["build_datetime"] = status.TimeStamp.ToString(DateTimeDirFormat); Macros["archive"] = ArchiveLoc; Macros["output_store"] = MasterConfig.OutputStore; foreach (string command in commands) { StringBuilder std = new StringBuilder(); _cmdexe.ResetStdOut(std); _cmdexe.ResetStdErr(std); status.Append("AutoBuild - Begin command: " + command); Macros["currentcommand"] = command; CommandScript tmp; if (proj.Commands.ContainsKey(command)) { tmp = proj.Commands[command]; } else if (MasterConfig.Commands.ContainsKey(command)) { tmp = MasterConfig.Commands[command]; } else { // Can't locate the specified command. Bail with error. status.Append("AutoBuild Error: Unable to locate command script: " + command); return((int)Errors.NoCommand); } int retVal = tmp.Run(_cmdexe, rootPath, projectName, new XDictionary <string, string>(Macros)); status.Append(_cmdexe.StandardOut); if (retVal != 0) { return(retVal); } } return(0); }
//Сохранение одной ссылки private void SaveLink(Comment c, Shape sh, RecDao rp, RecDao rc, RecDao rs, Worksheet sheet) { var dic = (sh == null ? c.Text() : sh.Title).ToPropertyDicS(); if (dic != null && dic.ContainsKey("Field") && dic.ContainsKey("Project") && dic.ContainsKey("Code")) { LinkType linkType = dic["LinkType"].ToLinkType(); var projcode = dic["Project"]; string parcode = dic["Code"]; if (Projects.ContainsKey(projcode)) { ReportProjectForLinks proj = Projects[projcode]; ReportParam param = null; if (proj.IsSave) { //Сохранение if (proj.Params.ContainsKey(parcode)) { param = proj.Params[parcode]; } else { rp.AddNew(); param = new ReportParam(projcode, new ArchiveParam(parcode, DataType.String, null, new CalcParamBase(parcode, dic["CellComment"]), new CalcParamBase(dic["Field"]))) { Id = rp.GetInt("ParamId") }; rp.Put("Project", projcode); rp.Put("Code", parcode); rp.Put("CodeParam", parcode); rp.Put("DataType", DataType.String.ToRussian()); rp.Put("IsUsed", true); rp.Put("IsHandInput", false); proj.Params.Add(parcode, param); rp.Update(); } } else if (proj.Params.ContainsKey(parcode)) { param = proj.Params[parcode]; if (linkType == LinkType.HandInput) { //Ручной ввод param.IsHandInput = true; proj.IsHandInput = true; } else { //Обычное получние данных param.IsUsed = true; proj.IsUsed = true; } } if (param != null) { var itype = IntervalType.Empty; if (proj.CalcMode == CalcModeType.Internal) { if (linkType == LinkType.Result || linkType == LinkType.MomentsList) { itype = IntervalType.Single; } } else { switch (linkType) { case LinkType.Combined: case LinkType.CombinedList: if (dic.ContainsKey("LengthMinute") || dic.ContainsKey("PartBeginMinute") || dic.ContainsKey("PartEndMinute")) { itype = IntervalType.Base; } else if (dic.ContainsKey("LengthHour") || dic.ContainsKey("PartBeginHour") || dic.ContainsKey("PartEndHour")) { itype = IntervalType.Hour; } else if (dic.ContainsKey("LengthDay") || dic.ContainsKey("PartByTime")) { itype = IntervalType.Day; } else { itype = IntervalType.Combined; } break; case LinkType.Absolute: case LinkType.AbsoluteEdit: itype = IntervalType.Absolute; break; case LinkType.AbsoluteCombined: itype = IntervalType.AbsoluteCombined; break; case LinkType.AbsoluteList: if (dic.ContainsKey("LengthMinute") && dic["LengthMinute"].ToInt() != 0) { itype = IntervalType.AbsoluteListBase; } else if (dic.ContainsKey("LengthHour") && dic["LengthHour"].ToInt() != 0) { itype = IntervalType.AbsoluteListHour; } else { itype = IntervalType.AbsoluteListDay; } break; case LinkType.MomentsList: case LinkType.Result: itype = IntervalType.Moments; break; } } if (!param.IntervalTypes.Contains(itype)) { param.IntervalTypes.Add(itype); } if (sh == null) { //Добавление в таблицу Cells rc.AddNew(); rc.Put("Page", sheet.Name); rc.Put("Y", ((Range)c.Parent).Row); rc.Put("X", ((Range)c.Parent).Column); rc.Put("LinkType", linkType.ToEnglish()); rc.Put("LinkField", dic["Field"]); if (dic.ContainsKey("AllowEdit")) { rc.Put("AllowEdit", dic["AllowEdit"] == "True"); } string prop = ""; foreach (var k in dic.Keys) { if (k != "LinkType" && k != "Field" && k != "Project" && k != "Code") { prop += k + "=" + dic[k] + ";"; } } rc.Put("Properties", prop); rc.Put("ParamId", param.Id); rc.Put("IntervalType", itype.ToRussian()); rc.Put("SaveCode", dic["SaveCode"]); rc.Update(); } else { //Добавление в таблицу Shapes rs.AddNew(); rs.Put("Page", sheet.Name); rs.Put("ShapeId", sh.ID); rs.Put("ShapeType", sh.Type.ToEnglish()); if (sh.Type == MsoShapeType.msoGroup) { rs.Put("Formula", sh.AlternativeText); } rs.Put("LinkType", linkType.ToEnglish()); rs.Put("LinkField", dic["Field"]); string prop = ""; foreach (var k in dic.Keys) { if (k != "LinkType" && k != "Field" && k != "Project" && k != "Code") { prop += k + "=" + dic[k] + ";"; } } rs.Put("Properties", prop); rs.Put("ParamId", param.Id); rs.Put("IntervalType", itype.ToRussian()); rs.Update(); } } } } }
public ITranslationModule this[string moduleName] { get { return(Projects.ContainsKey(moduleName) ? Projects[moduleName] : null); } }