private void MemberJoin(Vsync.Group vsyncGroup) { string memberDirectory = _name; string eventName = _name + "/new_node"; string cloudMakeDirectory = memberDirectory + Path.DirectorySeparatorChar + "CloudMake"; string cloudMakeConfigFilename = cloudMakeDirectory + Path.DirectorySeparatorChar.ToString() + "config.xml"; List <Tuple <string, int> > newNodeEntries; HashSet <int> nameSet, cloudMakeConfigSet; if (_localCloudMakefile == null) { throw new Exception("CloudMakeLocal: There is no CloudMakefile."); } nameSet = _localCloudMakefile.Compatible(memberDirectory); if (nameSet.Count > 0) { Directory.SetCurrentDirectory(_name); #if DEBUG CloudManager.WriteLine(_debugFilename, "Create Directory: " + memberDirectory); #endif Directory.CreateDirectory(memberDirectory); cloudMakeConfigSet = _localCloudMakefile.Compatible(cloudMakeConfigFilename, nameSet); if (cloudMakeConfigSet.Count > 0) { #if DEBUG CloudManager.WriteLine(_debugFilename, "Create Directory: " + cloudMakeDirectory); CloudManager.WriteLine(_debugFilename, "Added CloudMake Config: " + cloudMakeConfigFilename); #endif Directory.CreateDirectory(cloudMakeDirectory); _dependencyStructure.AddCloudMakeConfigFile(cloudMakeConfigFilename); } Directory.SetCurrentDirectory(_curDirectory); newNodeEntries = _localCloudMakefile.FindMatchingEntries(eventName); if (newNodeEntries.Count > 1) { throw new Exception("It is impossible for a NEW_NODE event to have more than one corresponding " + "DFA."); } if (newNodeEntries.Count == 1) { _dependencyStructure.AddEntry(newNodeEntries [0]); _dependencyStructure.AddTokenToEntry(newNodeEntries [0].Item1); #if DEBUG CloudManager.WriteLine(_debugFilename, "Added Token to New Node Event: " + eventName); #endif RunCloudMake(vsyncGroup); } } else { throw new Exception("CloudMakeLocal: There is no matching entry for " + _name + "/new_node"); } }
// Run CloudMake public void Run() { #if DEBUG CloudManager.WriteLine(_debugFilename, "Started Running CloudMake."); #endif List <HashSet <int> > outputs = _cloudMakefile.GetOutputs(); HashSet <int> activeEntryTokens = new HashSet <int> (_entryTokens); int tier = 0; while ((activeEntryTokens.Count > 0) || (_policyTokens.Count > 0)) { HashSet <int> entryTokensToRemove = new HashSet <int> (activeEntryTokens); #if DEBUG foreach (int token in activeEntryTokens) { CloudManager.WriteLine(_debugFilename, "Active Entry: " + _entries [token]); foreach (int policyToken in _reverseInputs[token]) { _policyTokens.Add(policyToken); } } #endif // If there are no more transitions to run. if (tier >= _order.Count) { break; } // Find active policies in this tier of policies. HashSet <int> activeTransitions = new HashSet <int> (_order [tier]); #if DEBUG CloudManager.WriteLine(_debugFilename, "Active Transitions:"); foreach (int transition in activeTransitions) { CloudManager.WriteLine(_debugFilename, "Transition " + transition.ToString()); } CloudManager.WriteLine(_debugFilename, ""); #endif activeTransitions.IntersectWith(_policyTokens); // Execute the active policies. foreach (int token in activeTransitions) { CloudManager.WriteLine(_debugFilename, "Active Policy: " + _policies [token]); Dictionary <string, string> outputEntries = new Dictionary <string, string> (); string policy = _policies [token]; if (policy.Contains("$(inputs)")) { String inputs = ""; HashSet <int> entriesToConsider = new HashSet <int> (_inputs [token]); entriesToConsider.IntersectWith(_entryTokens); foreach (int entry in entriesToConsider) { inputs += " " + _entries [entry]; } policy = policy.Replace(" $(inputs)", inputs); } foreach (int entryToken in _outputs[token]) { string entryname = _entries [entryToken]; outputEntries.Add(entryname, HashEntry(entryname)); } string[] program = policy.Split(new char[] { ' ', '\t' }, 2); CloudManager.WriteLine(_debugFilename, "Directory: " + Directory.GetCurrentDirectory()); CloudManager.WriteLine(_debugFilename, "Execute: " + program [0] + " " + program [1]); using (Process proc = new System.Diagnostics.Process()) { proc.EnableRaisingEvents = false; proc.StartInfo.FileName = program [0]; proc.StartInfo.Arguments = program [1]; proc.Start(); proc.WaitForExit(); } ; List <Tuple <string, int> > outputEntriesToConsider = _cloudMakefile.FindMatchingEntries("", new HashSet <int> (outputs [token])); foreach (Tuple <string, int> entry in outputEntriesToConsider) { string entryname = entry.Item1; if ((outputEntries.ContainsKey(entryname)) && (HashEntry(entryname) != outputEntries [entryname])) { int entryIndex = _entries.IndexOf(entryname); _entryTokens.Add(entryIndex); activeEntryTokens.Add(entryIndex); } else if (!outputEntries.ContainsKey(entryname)) { _entryTokens.Add(_entries.Count); activeEntryTokens.Add(_entries.Count); AddEntry(entry); } } _policyTokens.Remove(token); } // Remove the appropriate entries. foreach (int token in entryTokensToRemove) { activeEntryTokens.Remove(token); } tier++; } // Update modifies config and CloudMake config files. foreach (int token in _entryTokens) { string entryname = _entries [token]; string filename; filename = MatchEntryToConfigFile(entryname); if (filename != null) { _modifiedConfigFiles.Add(filename); } filename = MatchEntryToCloudMakeConfigFile(entryname); if (filename != null) { _modifiedCloudMakeConfigFiles.Add(filename); } } }