public static string GetKerberosContext(string user, string pass, string domain, string sts) { IntPtr iSPN = Marshal.StringToBSTR(sts); IntPtr iUser = Marshal.StringToBSTR(user); IntPtr iPass = Marshal.StringToBSTR(pass); IntPtr iDomain = Marshal.StringToBSTR(domain); var sb = new StringBuilder(4096); var result = SsoSsspiInterop.InitSecurityContext(iSPN, iUser, iPass, iDomain, sb); if (sb.Length > 0) { throw new Exception(sb.ToString()); } string op = Marshal.PtrToStringBSTR(result); var dto = XmlConvert.Deserialize <SecurityContext>(op); bool deleteResult = SsoSsspiInterop.CloseSecurityContext(dto.ID, sb); if (sb.Length > 0) { throw new Exception(sb.ToString()); } return(dto.Context); }
public static string ImportProjects(TeisterMaskContext context, string xmlString) { var sb = new StringBuilder(); var projectsDto = XmlConvert.Deserialize <XmlProjectImportModel>(xmlString, "Projects"); foreach (var projectDto in projectsDto) { if (IsValid(projectDto) == false || DateTime.TryParseExact(projectDto.OpenDate, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime projectOpenDate) == false) { sb.AppendLine(ErrorMessage); continue; } bool hasDueDate = DateTime.TryParseExact(projectDto.DueDate, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime projectDueDate); var project = new Project { Name = projectDto.Name, DueDate = hasDueDate ? (DateTime?)projectDueDate : null, OpenDate = projectOpenDate, }; foreach (var taskDto in projectDto.Tasks) { if (IsValid(taskDto) == false || DateTime.TryParseExact(taskDto.OpenDate, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime taskOpenDate) == false || DateTime.TryParseExact(taskDto.DueDate, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime taskDueDate) == false || taskOpenDate.Date < projectOpenDate.Date) { sb.AppendLine(ErrorMessage); continue; } if (hasDueDate) { if (taskDueDate.Date > projectDueDate.Date) { sb.AppendLine(ErrorMessage); continue; } } project.Tasks.Add(new Task { Name = taskDto.Name, DueDate = taskDueDate, LabelType = (LabelType)taskDto.LabelType, OpenDate = taskOpenDate, ExecutionType = (ExecutionType)taskDto.ExecutionType, }); } context.Projects.Add(project); sb.AppendLine(string.Format(SuccessfullyImportedProject, project.Name, project.Tasks.Count)); } context.SaveChanges(); return(sb.ToString().TrimEnd()); }
static void Main(string[] args) { var model = new ClassA() { Name = "I'm ClassA.", BArray = new[] { new ClassB() { Name = "I'm ClassB." }, new ClassB() { Name = "I'm ClassB too." } } }; var xml = XmlConvert.Serialize(model); Console.WriteLine(xml); var model2 = XmlConvert.Deserialize(xml); Console.WriteLine("----------------"); Console.WriteLine(model2); Console.ReadLine(); }
public void EditConnectionInfo(ConnectionInfo connectionInfo) { this.ConnectionInfo = XmlConvert.Deserialize <ConnectionInfo>(XmlConvert.Serialize(connectionInfo)); txtName.Text = connectionInfo.Name; var qpClientTypeInfo = QpClientTypeManager.Instance.GetAll().FirstOrDefault(t => t.QpClientType.FullName == connectionInfo.QpClientTypeName); cbConnectType.SelectedItem = qpClientTypeInfo; Text = "编辑连接"; }
private void LoadMap() { _logger.LogDebug($"DbTypeConverter Load DbTypeMap:{_xmlPath} Start!"); DbTypeMap = XmlConvert.Deserialize <DbTypeMap>(_xmlPath); _logger.LogDebug($"DbTypeConverter Load DbTypeMap:{_xmlPath} End!"); }
public static Level Load(string filepath) { string json = File.ReadAllText(filepath); return((Level)XmlConvert.Deserialize(json, typeof(Level))); }