protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity <TrackedFile>() .HasIndex(d => d.FileName) .IsUnique(); modelBuilder.Entity <BackupFolder>() .Property(nameof(BackupFolder.Size)) .HasDefaultValue(-1); modelBuilder.Entity <BackupFolder>() .HasMany <BackupFolderJob>() .WithOne(x => x.Folder); modelBuilder.Entity <BackupFolder>() .Property(t => t.SyncTime) .HasConversion(to => to.ToString(), from => TimeValue.Parse(from)); modelBuilder.Entity <BackupFolderJob>() .Property(j => j.Status) .HasConversion(new EnumToStringConverter <BackupFolderJobStatus>()); modelBuilder.Entity <BackupFileUploadJob>() .Property(x => x.LocalFile) .HasConversion(fileInfo => fileInfo.FullName, path => new FileInfo(path)); modelBuilder.Entity <BackupFileUploadJob>() .Property(j => j.Status) .HasConversion(new EnumToStringConverter <BackupFileUploadJobStatus>()); modelBuilder.Entity <BackupRemote>() .Property(t => t.ConnectionString) .HasConversion(unencrypted => EncryptString(unencrypted), encrypted => DecryptString(encrypted)); }
public async Task <IActionResult> AddNewFolder(int remoteId, [FromBody] AddFolderFormData data) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (var context = _contextFactory.CreateContext()) { var remote = await context.BackupRemotes.FindAsync(remoteId); if (remote == null) { return(NotFound()); } var backupFolder = new BackupFolder(data.Path, remote) { Name = data.Name, RemoteBaseFolder = data.RemoteFolder, SyncTime = TimeValue.Parse(data.SyncTime), SyncTimeSpan = TimeSpan.Parse(data.SyncTimeSpan) }; await context.BackupFolders.AddAsync(backupFolder); await context.SaveChangesAsync(); await _mediator.Publish(new FolderCreatedNotification(backupFolder)); return(Created(Request.Path.ToString() + "/" + backupFolder.BackupFolderId, backupFolder)); } }
public async Task <IActionResult> EditBackupFolder(int remoteId, int id, [FromBody] AddFolderFormData data) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (var context = _contextFactory.CreateContext()) { var folder = await context.BackupFolders.FindAsync(id); if (folder == null) { return(NotFound()); } if (folder.BackupRemoteId != remoteId) { return(NotFound()); } folder.Name = data.Name; folder.RemoteBaseFolder = data.RemoteFolder; folder.SyncTime = TimeValue.Parse(data.SyncTime); folder.SyncTimeSpan = TimeSpan.Parse(data.SyncTimeSpan); await context.SaveChangesAsync(); await _mediator.Publish(new FolderChangedNotification(folder)); return(Created(Request.Path.ToString() + "/" + folder.BackupFolderId, folder)); } }
public void ParseTest(string val, int hours, int minutes, int seconds, bool utc) { var offset = TimeValue.Parse(val); Assert.AreEqual(hours, offset.Hours); Assert.AreEqual(minutes, offset.Minutes); Assert.AreEqual(seconds, offset.Seconds); Assert.AreEqual(utc, offset.Utc); }
public static object GetTypedValue(this XPathItem item) { XPathNavigator nav = item as XPathNavigator; if (nav == null) { return(item.TypedValue); } IXmlSchemaInfo schemaInfo = nav.SchemaInfo; if (schemaInfo == null || schemaInfo.SchemaType == null) { switch (nav.NodeType) { case XPathNodeType.Comment: case XPathNodeType.ProcessingInstruction: case XPathNodeType.Namespace: return(nav.Value); default: return(new UntypedAtomic(nav.Value)); } } XmlTypeCode typeCode = schemaInfo.SchemaType.TypeCode; if (typeCode == XmlTypeCode.AnyAtomicType && schemaInfo.MemberType != null) { typeCode = schemaInfo.MemberType.TypeCode; } switch (typeCode) { case XmlTypeCode.UntypedAtomic: return(new UntypedAtomic(nav.Value)); case XmlTypeCode.Integer: case XmlTypeCode.PositiveInteger: case XmlTypeCode.NegativeInteger: case XmlTypeCode.NonPositiveInteger: return((Integer)(decimal)nav.TypedValue); case XmlTypeCode.Date: return(DateValue.Parse(nav.Value)); case XmlTypeCode.DateTime: return(DateTimeValue.Parse(nav.Value)); case XmlTypeCode.Time: return(TimeValue.Parse(nav.Value)); case XmlTypeCode.Duration: return(DurationValue.Parse(nav.Value)); case XmlTypeCode.DayTimeDuration: return(new DayTimeDurationValue((TimeSpan)nav.TypedValue)); case XmlTypeCode.YearMonthDuration: return(new YearMonthDurationValue((TimeSpan)nav.TypedValue)); case XmlTypeCode.GDay: return(GDayValue.Parse(nav.Value)); case XmlTypeCode.GMonth: return(GMonthValue.Parse(nav.Value)); case XmlTypeCode.GMonthDay: return(GMonthDayValue.Parse(nav.Value)); case XmlTypeCode.GYear: return(GYearValue.Parse(nav.Value)); case XmlTypeCode.GYearMonth: return(GYearMonthValue.Parse(nav.Value)); case XmlTypeCode.QName: case XmlTypeCode.Notation: { XmlNamespaceManager nsmgr = new XmlNamespaceManager(nav.NameTable); ExtFuncs.ScanLocalNamespaces(nsmgr, nav.Clone(), true); if (schemaInfo.SchemaType.TypeCode == XmlTypeCode.Notation) { return(NotationValue.Parse(nav.Value, nsmgr)); } else { return(QNameValue.Parse(nav.Value, nsmgr)); } } case XmlTypeCode.AnyUri: return(new AnyUriValue(nav.Value)); case XmlTypeCode.HexBinary: return(new HexBinaryValue((byte[])nav.TypedValue)); case XmlTypeCode.Base64Binary: return(new Base64BinaryValue((byte[])nav.TypedValue)); case XmlTypeCode.Idref: if (schemaInfo.SchemaType == SequenceType.XmlSchema.IDREFS) { return(new IDREFSValue((string[])nav.TypedValue)); } goto default; case XmlTypeCode.NmToken: if (schemaInfo.SchemaType == SequenceType.XmlSchema.NMTOKENS) { return(new NMTOKENSValue((string[])nav.TypedValue)); } goto default; case XmlTypeCode.Entity: if (schemaInfo.SchemaType == SequenceType.XmlSchema.ENTITIES) { return(new ENTITIESValue((string[])nav.TypedValue)); } goto default; default: return(nav.TypedValue); } }
public static object ChangeType(XmlSchemaType xmlType, object value, SequenceType type, XmlNameTable nameTable, XmlNamespaceManager nsmgr) { if (type.TypeCode == XmlTypeCode.AnyAtomicType || xmlType.TypeCode == type.TypeCode) { return(value); } try { switch (xmlType.TypeCode) { case XmlTypeCode.String: case XmlTypeCode.UntypedAtomic: switch (type.TypeCode) { case XmlTypeCode.UntypedAtomic: return(new UntypedAtomic(value.ToString())); case XmlTypeCode.String: return(value.ToString()); case XmlTypeCode.DateTime: return(DateTimeValue.Parse(value.ToString())); case XmlTypeCode.Date: return(DateValue.Parse(value.ToString())); case XmlTypeCode.Time: return(TimeValue.Parse(value.ToString())); case XmlTypeCode.GYearMonth: return(GYearMonthValue.Parse(value.ToString())); case XmlTypeCode.GYear: return(GYearValue.Parse(value.ToString())); case XmlTypeCode.GMonth: return(GMonthValue.Parse(value.ToString())); case XmlTypeCode.GMonthDay: return(GMonthDayValue.Parse(value.ToString())); case XmlTypeCode.GDay: return(GDayValue.Parse(value.ToString())); case XmlTypeCode.Duration: return(DurationValue.Parse(value.ToString())); case XmlTypeCode.QName: if (xmlType.TypeCode == XmlTypeCode.UntypedAtomic) { throw new XPath2Exception("XPTY0004", Properties.Resources.XPTY0004, new SequenceType(xmlType, XmlTypeCardinality.One, null), type); } return(QNameValue.Parse(value.ToString(), nsmgr)); case XmlTypeCode.Notation: return(NotationValue.Parse(value.ToString(), nsmgr)); case XmlTypeCode.AnyUri: return(new AnyUriValue(value.ToString())); default: { string text = value.ToString(); object res = type.SchemaType.Datatype.ParseValue(text, nameTable, nsmgr); switch (type.TypeCode) { case XmlTypeCode.Integer: case XmlTypeCode.PositiveInteger: case XmlTypeCode.NegativeInteger: case XmlTypeCode.NonPositiveInteger: case XmlTypeCode.NonNegativeInteger: return((Integer)Convert.ToDecimal(res)); case XmlTypeCode.DayTimeDuration: return(new DayTimeDurationValue((TimeSpan)res)); case XmlTypeCode.YearMonthDuration: return(new YearMonthDurationValue((TimeSpan)res)); case XmlTypeCode.HexBinary: return(new HexBinaryValue((byte[])res)); case XmlTypeCode.Base64Binary: if (text.EndsWith("==") && (text.Length < 3 || "AQgw".IndexOf(text[text.Length - 3]) == -1)) { throw new XPath2Exception("FORG0001", Properties.Resources.FORG0001, value); } return(new Base64BinaryValue((byte[])res)); case XmlTypeCode.Idref: if (type.SchemaType == SequenceType.XmlSchema.IDREFS) { return(new IDREFSValue((string[])res)); } goto default; case XmlTypeCode.NmToken: if (type.SchemaType == SequenceType.XmlSchema.NMTOKENS) { return(new NMTOKENSValue((string[])res)); } goto default; case XmlTypeCode.Entity: if (type.SchemaType == SequenceType.XmlSchema.ENTITIES) { return(new ENTITIESValue((string[])res)); } goto default; default: return(res); } } } case XmlTypeCode.Boolean: switch (type.TypeCode) { case XmlTypeCode.Decimal: case XmlTypeCode.Float: case XmlTypeCode.Double: case XmlTypeCode.Integer: case XmlTypeCode.NonPositiveInteger: case XmlTypeCode.NegativeInteger: case XmlTypeCode.Long: case XmlTypeCode.Int: case XmlTypeCode.Short: case XmlTypeCode.Byte: case XmlTypeCode.NonNegativeInteger: case XmlTypeCode.UnsignedLong: case XmlTypeCode.UnsignedInt: case XmlTypeCode.UnsignedShort: case XmlTypeCode.UnsignedByte: case XmlTypeCode.PositiveInteger: return(ChangeType(value, type.ItemType)); case XmlTypeCode.String: return(XPath2Convert.ToString((bool)value)); case XmlTypeCode.UntypedAtomic: return(new UntypedAtomic(XPath2Convert.ToString((bool)value))); } break; case XmlTypeCode.Integer: case XmlTypeCode.NonPositiveInteger: case XmlTypeCode.NegativeInteger: case XmlTypeCode.Long: case XmlTypeCode.Int: case XmlTypeCode.Short: case XmlTypeCode.Byte: case XmlTypeCode.NonNegativeInteger: case XmlTypeCode.UnsignedLong: case XmlTypeCode.UnsignedInt: case XmlTypeCode.UnsignedShort: case XmlTypeCode.UnsignedByte: case XmlTypeCode.PositiveInteger: case XmlTypeCode.Decimal: case XmlTypeCode.Float: case XmlTypeCode.Double: switch (type.TypeCode) { case XmlTypeCode.String: return(ToString(value)); case XmlTypeCode.UntypedAtomic: return(new UntypedAtomic(ToString(value))); case XmlTypeCode.Boolean: return(CoreFuncs.BooleanValue(value)); case XmlTypeCode.AnyUri: throw new XPath2Exception("XPTY0004", Properties.Resources.XPTY0004, new SequenceType(xmlType, XmlTypeCardinality.One, null), type); default: return(ChangeType(value, type.ItemType)); } default: { IXmlConvertable convert = value as IXmlConvertable; if (convert != null) { return(convert.ValueAs(type, nsmgr)); } if (type.TypeCode == XmlTypeCode.String) { return(ToString(value)); } if (type.TypeCode == XmlTypeCode.UntypedAtomic) { return(new UntypedAtomic(ToString(value))); } return(type.SchemaType.Datatype.ChangeType(value, type.ValueType)); } } } catch (XmlSchemaException ex) { throw new XPath2Exception(ex.Message, ex); } catch (InvalidCastException) { throw new XPath2Exception("XPTY0004", Properties.Resources.XPTY0004, new SequenceType(xmlType, XmlTypeCardinality.One, null), type); } catch (FormatException) { throw new XPath2Exception("XPTY0004", Properties.Resources.XPTY0004, new SequenceType(xmlType, XmlTypeCardinality.One, null), type); } throw new XPath2Exception("XPTY0004", Properties.Resources.XPTY0004, new SequenceType(xmlType, XmlTypeCardinality.One, null), type); }