def create_user_control(filename): userControl = None try: s = None if filename: s = StreamReader(filename) userControl = XamlReader.Load(s.BaseStream) except Exception as e: CommonUtil.sprint("Failed to Create UserControl: {}".format(e)) finally: if s: s.Close() s.Dispose() return userControl
path = r"lib/EnyimMemcached/build/CommonProperties.targets" sr = StreamReader(path) sb = StringBuilder() line = sr.ReadLine() while not line is None: #I'm sure this could all be done in a couple of lines with a nice multi-line Regex #All this does is comment out property groups that attempt to set signing if line.Trim().StartsWith("<PropertyGroup") and line.Contains("PrivateKey"): sb.AppendFormat("<!--{0}\r\n", line) while line is not None and line.Trim() != "</PropertyGroup>": sb.AppendLine(line) line = sr.ReadLine() else: sb.AppendFormat("{0}-->\r\n", line) else: sb.AppendLine(line) line = sr.ReadLine() content = sb.ToString() content = content.Replace("<DelaySign>true</DelaySign>", "<DelaySign>false</DelaySign>") content = content.Replace("<SignAssembly>true</SignAssembly>", "<SignAssembly>false</SignAssembly>") sr.Dispose() sw = StreamWriter(path, False) sw.Write(sb.ToString()) sw.Dispose()