/// <summary> /// Called to create a batch that saves items from the joining tables /// </summary> /// <param name="Object">Object</param> /// <param name="Source">Source info</param> /// <param name="ObjectsSeen">Objects seen thus far</param> /// <returns>Batch object with the appropriate commands</returns> public override IBatch CascadeJoinsSave(ClassType Object, ISourceInfo Source, IList<object> ObjectsSeen) { var Provider = IoC.Manager.Bootstrapper.Resolve<QueryProvider.Manager>(); var MappingProvider = IoC.Manager.Bootstrapper.Resolve<Mapper.Manager>(); IMapping PropertyMapping = MappingProvider[typeof(DataType), Source]; var Batch = Provider.Batch(Source); var AspectObject = Object as IORMObject; if (Object == null || (AspectObject != null && ObjectsSeen.Contains(Mapping.IDProperties.FirstOrDefault().GetValue(Object)))) return Batch; if (AspectObject != null) ObjectsSeen.Add(Mapping.IDProperties.FirstOrDefault().GetValue(Object)); IEnumerable<DataType> IList = CompiledExpression(Object); if (IList == null) return Batch; foreach (DataType Item in IList.Where(x => x != null)) { foreach (IProperty<DataType> Property in PropertyMapping.Properties) { if (!Property.Cascade && (Property is IMultiMapping || Property is ISingleMapping)) { Batch.AddCommand(Property.JoinsSave(Item, Source, ObjectsSeen.ToList())); } else if (Property.Cascade) { Batch.AddCommand(Property.CascadeJoinsSave(Item, Source, ObjectsSeen.ToList())); } } } Batch.AddCommand(Provider.Generate<ClassType>(Source, Mapping, Structure).JoinsSave<ICollection<DataType>, DataType>(this, Object)); return Batch; }
/// <summary> /// Creates a document from a stream. /// </summary> /// <returns>The document.</returns> /// <param name="sourceStream">Source stream.</param> /// <param name="sourceInfo">Source info.</param> /// <param name="encoding">Encoding.</param> public IZptDocument CreateDocument(Stream sourceStream, ISourceInfo sourceInfo, Encoding encoding) { if(sourceStream == null) { throw new ArgumentNullException(nameof(sourceStream)); } if(sourceInfo == null) { throw new ArgumentNullException(nameof(sourceInfo)); } if(encoding == null) { throw new ArgumentNullException(nameof(encoding)); } var settings = new System.Xml.XmlReaderSettings() { XmlResolver = _resolverFactory.GetResolver(), DtdProcessing = System.Xml.DtdProcessing.Parse, }; System.Xml.Linq.XDocument doc; using(var streamReader = new StreamReader(sourceStream, encoding)) using(var reader = System.Xml.XmlReader.Create(streamReader, settings)) { var options = System.Xml.Linq.LoadOptions.PreserveWhitespace | System.Xml.Linq.LoadOptions.SetLineInfo; doc = System.Xml.Linq.XDocument.Load(reader, options); } return CreateDocument(doc, sourceInfo); }
/// <summary> /// Generates a list of commands used to modify the source. If it does not exist prior, the /// commands will create the source from scratch. Otherwise the commands will only add new /// fields, tables, etc. It does not delete old fields. /// </summary> /// <param name="DesiredStructure">Desired source structure</param> /// <param name="Source">Source to use</param> /// <returns>List of commands generated</returns> public IEnumerable<string> GenerateSchema(ISource DesiredStructure, ISourceInfo Source) { Contract.Requires<ArgumentNullException>(Source != null, "Source"); return SchemaGenerators.ContainsKey(Source.SourceType) ? SchemaGenerators[Source.SourceType].GenerateSchema(DesiredStructure, Source) : new List<string>(); }
/// <summary> /// Gets the structure of a source /// </summary> /// <param name="Source">Source to use</param> /// <returns>The source structure</returns> public ISource GetSourceStructure(ISourceInfo Source) { string DatabaseName = Regex.Match(Source.Connection, "Initial Catalog=(.*?;)").Value.Replace("Initial Catalog=", "").Replace(";", ""); ISourceInfo DatabaseSource = SourceProvider.GetSource(Regex.Replace(Source.Connection, "Initial Catalog=(.*?;)", "")); if (!SourceExists(DatabaseName, DatabaseSource)) { return(null); } var Temp = new Database(DatabaseName); IBatch Batch = Provider.Batch(Source); IBuilder[] Builders = { new Tables(), new TableColumns(), new TableTriggers(), new TableForeignKeys(), new Views(), new StoredProcedures(), new StoredProcedureColumns(), new Functions() }; Builders.ForEach(x => x.GetCommand(Batch)); var Results = Batch.Execute(); Builders.For(0, Builders.Length - 1, (x, y) => y.FillDatabase(Results[x], Temp)); return(Temp); }
/// <summary> /// Does a cascade save of an object for this property /// </summary> /// <param name="Object">Object</param> /// <param name="Source">Source info</param> /// <param name="ObjectsSeen">Objects seen thus far</param> /// <returns>Batch object with the appropriate commands</returns> public override IBatch CascadeSave(ClassType Object, ISourceInfo Source, IList <object> ObjectsSeen) { var Provider = IoC.Manager.Bootstrapper.Resolve <QueryProvider.Manager>(); var MappingProvider = IoC.Manager.Bootstrapper.Resolve <Mapper.Manager>(); IMapping PropertyMapping = MappingProvider[typeof(DataType), Source]; var Batch = Provider.Batch(Source); var AspectObject = Object as IORMObject; if (Object == null || (AspectObject != null && ObjectsSeen.Contains(Mapping.IDProperties.FirstOrDefault().GetValue(Object)))) { return(Provider.Batch(Source)); } if (AspectObject != null) { ObjectsSeen.Add(Mapping.IDProperties.FirstOrDefault().GetValue(Object)); } IEnumerable <DataType> List = CompiledExpression(Object); if (List == null) { return(Batch); } foreach (DataType Item in List.Where(x => x != null)) { foreach (IProperty <DataType> Property in PropertyMapping.Properties.Where(x => x.Cascade)) { Batch.AddCommand(Property.CascadeSave(Item, Source, ObjectsSeen.ToList())); } Batch.AddCommand(((IProperty <DataType>)PropertyMapping.IDProperties.FirstOrDefault()).CascadeSave(Item, Source, ObjectsSeen.ToList())); } IoC.Manager.Bootstrapper.Resolve <DataTypes.Caching.Manager>().Cache().RemoveByTag(typeof(DataType).GetName()); return(Batch); }
/// <summary> /// Constructor /// </summary> /// <param name="QueryProvider">Query provider</param> /// <param name="Source">Source info</param> /// <param name="Mapping">Mapping info</param> /// <param name="Structure">The structure.</param> public SQLServerGenerator(SQLServerQueryProvider QueryProvider, ISourceInfo Source, IMapping Mapping, Graph <IMapping> Structure) { this.QueryProvider = QueryProvider; this.Source = Source; this.Mapping = Mapping; this.Structure = Structure; }
/// <summary> /// Metoda tworząca reader - główny obiekt odpowiedzialny za import /// </summary> protected override IImportReader CreateReader(Stream stream, ISourceInfo sourceInfo) { return(new ExampleFormatReader(stream) { SourceInfo = sourceInfo }); }
public SourceInfoImpl(ISourceInfo cloneFrom) { if (cloneFrom == null) throw new ArgumentNullException("cloneFrom"); this.Position = cloneFrom.Position; this.Length = cloneFrom.Length; }
public IOperationResult Map(ISourceInfo sourceInfo, Type destType) { if (!destType.IsAssignableFrom(typeof(string))) { return(OperationResult.Failed()); } return(TryMap(sourceInfo) as IOperationResult <string>); }
private bool Exists(string Command, string Value, ISourceInfo Source) { Contract.Requires <ArgumentNullException>(Source != null, "Source"); Contract.Requires <NullReferenceException>(Provider != null, "Provider"); return(Provider.Batch(Source) .AddCommand(null, null, Command, CommandType.Text, Value) .Execute()[0] .Count() > 0); }
/// <summary> /// Does a cascade save of an object for this property /// </summary> /// <param name="Object">Object</param> /// <param name="Source">Source info</param> /// <param name="ObjectsSeen">Objects that have been seen thus far</param> /// <returns>Batch object with the appropriate commands</returns> public override IBatch CascadeSave(ClassType Object, ISourceInfo Source, IList <object> ObjectsSeen) { QueryProvider.Manager Provider = IoC.Manager.Bootstrapper.Resolve <QueryProvider.Manager>(); if (Object == null || ObjectsSeen.Contains(GetValue(Object))) { return(Provider.Batch(Source)); } return(Provider.Generate <ClassType>(Source, Mapping).Save <DataType>(Object)); }
public void RemoveAccount(ISourceInfo source) { TaskChainHandler handler = delegate() { return(RemoveAccountInternal(source)); }; AddTaskToChain(handler); }
private static void CascadeDelete <ObjectType>(ObjectType Object, ISourceInfo Source, IMapping Mapping, IBatch TempBatch, List <object> ObjectsSeen) where ObjectType : class { Contract.Requires <ArgumentNullException>(Mapping != null, "Mapping"); Contract.Requires <ArgumentNullException>(Mapping.Properties != null, "Mapping.Properties"); foreach (IProperty <ObjectType> Property in Mapping.Properties.Where(x => x.Cascade)) { TempBatch.AddCommand(Property.CascadeDelete(Object, Source, ObjectsSeen.ToList())); } }
internal void Sync(ISourceInfo parent, ILabelSource source) { mParent = parent; mSource = source; Id = source.Id; Name = source.Name; Type = source.Type; UnreadCount = source.UnreadCount; IsVirtual = source.IsVirtual; }
/// <summary> /// Called to create a batch that saves items from the joining table /// </summary> /// <param name="Object">Object</param> /// <param name="Source">Source info</param> /// <param name="ObjectsSeen">Objects seen thus far</param> /// <returns>Batch object with the appropriate commands</returns> public override IBatch JoinsSave(ClassType Object, ISourceInfo Source, IList<object> ObjectsSeen) { var Provider = IoC.Manager.Bootstrapper.Resolve<QueryProvider.Manager>(); var AspectObject = Object as IORMObject; if (Object == null || (AspectObject != null && ObjectsSeen.Contains(Mapping.IDProperties.FirstOrDefault().GetValue(Object)))) return Provider.Batch(Source); if (AspectObject != null) ObjectsSeen.Add(Mapping.IDProperties.FirstOrDefault().GetValue(Object)); return Provider.Generate<ClassType>(Source, Mapping, Structure).JoinsSave<ICollection<DataType>, DataType>(this, Object); }
protected AstNode(NodeType nodeType, ISourceInfo sourceInfo) { if (sourceInfo == null) throw new ArgumentNullException("sourceInfo"); this.Type = nodeType; // this is cloned so that we don't end up holding on to the ISourceInfo instance this.SourceInfo = new SourceInfoImpl(sourceInfo); }
public async Task SetMailView(ISourceInfo source) { MailView.Source = source; if (source == null || source.AccountSource == null) { MailView.Reset(); MailView.CanSend = mSendAccounts.Count > 0; return; } await((Account)source.AccountSource).LoadMailView(source.LabelSource); }
public async Task RemoveAccountWait(ISourceInfo source) { TaskChainHandler handler = delegate() { return(RemoveAccountInternal(source)); }; TaskCompletionSource <object> waitfor = new TaskCompletionSource <object>(); AddTaskToChain(handler, waitfor); await waitfor.Task; }
public void GetSource() { var Temp = new Utilities.ORM.Manager.SourceProvider.Manager(Utilities.IoC.Manager.Bootstrapper.ResolveAll <IDatabase>()); ISourceInfo Source = Temp.GetSource("Temp"); Assert.Equal("Temp", Source.Connection); Assert.Equal("Temp", Source.Name); Assert.Equal("@", Source.ParameterPrefix); Assert.Equal(true, Source.Readable); Assert.Equal("System.Data.SqlClient", Source.SourceType); Assert.Equal(true, Source.Writable); }
private void readVideoTimePeriodsPacket(ISourceInfo source, ITimePeriod tp, IVideoInfo vi) { try { VideoDownloadCmd cmd = new VideoDownloadCmd(new DownloadInfoParam(source, tp, vi, null)); cmd.VideoTimePeriodsEvent += onVideoTimePeriodsEvent; cmd.GetTimePeriods(); } catch (Exception ex) { Console.WriteLine("Read Video Time Periods Packet Error! {0}({1}) - {2} : {3}", vi.VideoName, vi.VideoId, vi.StreamId, ex.ToString()); } }
/// <summary> /// Creates a document from an <c>XmlDocument</c> object and information about the source of the document. /// </summary> /// <returns>The ZPT document implementation.</returns> /// <param name="xmlDocument">An XML document.</param> /// <param name="sourceInfo">The source info.</param> public IZptDocument CreateDocument(System.Xml.XmlDocument xmlDocument, ISourceInfo sourceInfo) { if(xmlDocument == null) { throw new ArgumentNullException(nameof(xmlDocument)); } if(sourceInfo == null) { throw new ArgumentNullException(nameof(sourceInfo)); } return new ZptXmlDocument(xmlDocument, sourceInfo); }
/// <summary> /// Creates a document from a HAP document object and information about the source of the document. /// </summary> /// <returns>The ZPT document implementation.</returns> /// <param name="hapDocument">A HTML Agility pack document.</param> /// <param name="sourceInfo">The source info.</param> public IZptDocument CreateDocument(HtmlAgilityPack.HtmlDocument hapDocument, ISourceInfo sourceInfo) { if(hapDocument == null) { throw new ArgumentNullException(nameof(hapDocument)); } if(sourceInfo == null) { throw new ArgumentNullException(nameof(sourceInfo)); } return new ZptHtmlDocument(hapDocument, sourceInfo); }
/// <summary> /// Initializes a new instance of the <see cref="CSF.Zpt.BatchRendering.BatchRenderingDocumentResponse"/> class. /// </summary> /// <param name="sourceInfo">Source info.</param> /// <param name="exception">Exception.</param> public BatchRenderingDocumentResponse(ISourceInfo sourceInfo, ZptException exception) { if(sourceInfo == null) { throw new ArgumentNullException(nameof(sourceInfo)); } if(exception == null) { throw new ArgumentNullException(nameof(exception)); } this.SourceInfo = sourceInfo; this.Exception = exception; }
/// <summary> /// Initializes a new instance of the <see cref="CSF.Zpt.BatchRendering.BatchRenderingDocumentResponse"/> class. /// </summary> /// <param name="sourceInfo">Source info.</param> /// <param name="outputInfo">Output info.</param> public BatchRenderingDocumentResponse(ISourceInfo sourceInfo, string outputInfo) { if(sourceInfo == null) { throw new ArgumentNullException(nameof(sourceInfo)); } if(outputInfo == null) { throw new ArgumentNullException(nameof(outputInfo)); } this.SourceInfo = sourceInfo; this.OutputInfo = outputInfo; }
async Task RemoveAccountInternal(ISourceInfo source) { Account account = (Account)source.AccountSource; await mAccountDB.RemoveAccountAsync(account.DBAccount); mAccounts.Remove(account); mViewAccounts.Remove(account.ViewAccount); mSendAccounts.Remove(account.ViewAccount); if (MailView.Source == source) { await SetMailView(null); } }
/// <summary> /// Initializes a new instance of the <see cref="CSF.Zpt.DocumentProviders.ZptHtmlElement"/> class. /// </summary> /// <param name="node">The source HTML node.</param> /// <param name="sourceFile">Information about the element's source file.</param> /// <param name="isRoot">Whether or not this is the root element.</param> /// <param name="isImported">Whether or not this element is imported.</param> /// <param name="ownerDocument">The ZPT document which owns the element.</param> public ZptHtmlElement(HtmlNode node, ISourceInfo sourceFile, IZptDocument ownerDocument, bool isRoot = false, bool isImported = false) : base(sourceFile, isRoot, isImported, ownerDocument) { if(node == null) { throw new ArgumentNullException(nameof(node)); } _node = node; }
/// <summary> /// Called to create a batch that deletes items from the joining table /// </summary> /// <param name="Object">Object</param> /// <param name="Source">Source info</param> /// <param name="ObjectsSeen">Objects seen thus far</param> /// <returns>Batch object with the appropriate commands</returns> public override IBatch JoinsDelete(ClassType Object, ISourceInfo Source, IList <object> ObjectsSeen) { QueryProvider.Manager Provider = IoC.Manager.Bootstrapper.Resolve <QueryProvider.Manager>(); var AspectObject = Object as IORMObject; if (Object == null || (AspectObject != null && ObjectsSeen.Contains(Mapping.IDProperties.FirstOrDefault().GetValue(Object)))) { return(Provider.Batch(Source)); } if (AspectObject != null) { ObjectsSeen.Add(Mapping.IDProperties.FirstOrDefault().GetValue(Object)); } return(Provider.Generate <ClassType>(Source, Mapping).JoinsDelete(this, Object)); }
private void AccountRemove_Click(object sender, RoutedEventArgs e) { FrameworkElement item = e.Source as FrameworkElement; ISourceInfo account = item.Tag as ISourceInfo; var result = MessageBox.Show("Are you sure to want to remove " + account.AccountSource.UserName + "?" , "Confirm Action", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No); if (result == MessageBoxResult.No) { return; } Client.RemoveAccount(account); }
private static void CascadeSave <ObjectType>(ObjectType Object, ISourceInfo Source, IMapping Mapping, IBatch TempBatch, List <object> ObjectsSeen) where ObjectType : class { Contract.Requires <ArgumentNullException>(Mapping != null, "Mapping"); Contract.Requires <ArgumentNullException>(Mapping.Properties != null, "Mapping.Properties"); var ORMObject = Object as IORMObject; foreach (IProperty <ObjectType> Property in Mapping.Properties.Where(x => x.Cascade)) { if (ORMObject == null || ORMObject.PropertiesChanged0.Contains(Property.Name)) { TempBatch.AddCommand(Property.CascadeSave(Object, Source, ObjectsSeen.ToList())); } } }
public void Setup(ISourceInfo Source, Utilities.ORM.Manager.Mapper.Manager MappingProvider, Utilities.ORM.Manager.QueryProvider.Manager QueryProvider) { QueryProvider.Generate <ClassType>(Source, this, MappingProvider.GetStructure(DatabaseConfigType)) .SetupCommands(this); foreach (IProperty Property in Properties) { if (Property is IMultiMapping || Property is ISingleMapping || Property is IMap) { Property.Setup(Source, MappingProvider, QueryProvider); } } }
/// <summary> /// Creates a batch object that can be used to run ad hoc queries /// </summary> /// <param name="ConnectionString"> /// Connection string (can be the name of connection string in config file or the actual /// connection string) /// </param> /// <returns>An appropriate batch object</returns> public static IBatch Batch(string ConnectionString) { ISourceInfo Source = SourceManager.GetSource(ConnectionString); if (Source == null) { throw new NullReferenceException("Source not found"); } IBatch Batch = QueryManager.Batch(Source); if (Batch == null) { throw new NullReferenceException("Batch could not be created"); } return(Batch); }
/// <summary> /// Creates a document from a stream. /// </summary> /// <returns>The document.</returns> /// <param name="sourceStream">Source stream.</param> /// <param name="sourceInfo">Source info.</param> /// <param name="encoding">Encoding.</param> public IZptDocument CreateDocument(Stream sourceStream, ISourceInfo sourceInfo, Encoding encoding) { if(sourceStream == null) { throw new ArgumentNullException(nameof(sourceStream)); } if(encoding == null) { throw new ArgumentNullException(nameof(encoding)); } var doc = new HtmlAgilityPack.HtmlDocument(); doc.Load(sourceStream, encoding); return CreateDocument(doc, sourceInfo); }
/// <summary> /// Initializes a new instance of the <see cref="CSF.Zpt.DocumentProviders.ZptHtmlDocument"/> class. /// </summary> /// <param name="document">An HTML document from which to create the current instance.</param> /// <param name="sourceFile">Information about the document's source file.</param> /// <param name="elementRenderer">The element renderer.</param> public ZptHtmlDocument(HtmlDocument document, ISourceInfo sourceFile, IElementRenderer elementRenderer = null) : base(elementRenderer) { if(document == null) { throw new ArgumentNullException(nameof(document)); } if(sourceFile == null) { throw new ArgumentNullException(nameof(sourceFile)); } _document = document; _sourceFile = sourceFile; }
/// <summary> /// Sets up the specified database schema /// </summary> /// <param name="Mappings">The mappings.</param> /// <param name="Database">The database.</param> /// <param name="QueryProvider">The query provider.</param> public void Setup(ListMapping <IDatabase, IMapping> Mappings, IDatabase Database, QueryProvider.Manager QueryProvider) { ISourceInfo TempSource = SourceProvider.GetSource(Database.Name); var TempDatabase = new Schema.Default.Database.Database(Regex.Match(TempSource.Connection, "Initial Catalog=(.*?;)").Value.Replace("Initial Catalog=", "").Replace(";", "")); SetupTables(Mappings, Database, TempDatabase); SetupJoiningTables(Mappings, Database, TempDatabase); SetupAuditTables(Database, TempDatabase); foreach (ITable Table in TempDatabase.Tables) { Table.SetupForeignKeys(); } List <string> Commands = GenerateSchema(TempDatabase, SourceProvider.GetSource(Database.Name)).ToList(); IBatch Batch = QueryProvider.Batch(SourceProvider.GetSource(Database.Name)); for (int x = 0; x < Commands.Count; ++x) { if (Commands[x].ToUpperInvariant().Contains("CREATE DATABASE")) { QueryProvider.Batch(SourceProvider.GetSource(Regex.Replace(SourceProvider.GetSource(Database.Name).Connection, "Initial Catalog=(.*?;)", ""))).AddCommand(null, null, CommandType.Text, Commands[x]).Execute(); } else if (Commands[x].Contains("CREATE TRIGGER") || Commands[x].Contains("CREATE FUNCTION")) { if (Batch.CommandCount > 0) { Batch.Execute(); Batch = QueryProvider.Batch(SourceProvider.GetSource(Database.Name)); } Batch.AddCommand(null, null, CommandType.Text, Commands[x]); if (x < Commands.Count - 1) { Batch.Execute(); Batch = QueryProvider.Batch(SourceProvider.GetSource(Database.Name)); } } else { Batch.AddCommand(null, null, CommandType.Text, Commands[x]); } } Batch.Execute(); }
public IOperationResult TryMap(ISourceInfo sourceInfo) { if (sourceInfo.Attributes == null) { return(OperationResult <string> .Failed()); } var formated = sourceInfo.Attributes.FirstOrDefault(x => x is FormatedAttribute) as FormatedAttribute; if (formated != null) { //Debugger.Assert(() => formated.Format != null, "Formated attribute shoud provide format value."); var propertyConverter = (IFormattable)sourceInfo.Value; var formatedString = propertyConverter.ToString(formated.Format, CultureInfo.InvariantCulture); return(OperationResult <string> .Successful(formatedString)); } return(OperationResult <string> .Failed()); }
/// <summary> /// Initializes a new instance of the <see cref="CSF.Zpt.DocumentProviders.ZptXmlDocument"/> class. /// </summary> /// <param name="document">An XML document from which to create the current instance.</param> /// <param name="sourceFile">Information about the document's source file.</param> /// <param name="elementRenderer">The element renderer.</param> public ZptXmlDocument(XmlDocument document, ISourceInfo sourceFile, IElementRenderer elementRenderer = null) : base(elementRenderer) { if(document == null) { throw new ArgumentNullException(nameof(document)); } if(sourceFile == null) { throw new ArgumentNullException(nameof(sourceFile)); } _document = document; _sourceFile = sourceFile; this.IndentOutput = DefaultIndentMode; this.IndentationCharacters = DefaultIndentationCharacters; }
/// <summary> /// Initializes a new instance of the <see cref="CSF.Zpt.DocumentProviders.ZptXmlLinqElement"/> class. /// </summary> /// <param name="node">The source XML Node.</param> /// <param name="sourceFile">Information about the element's source file.</param> /// <param name="isRoot">Whether or not this is the root element.</param> /// <param name="isImported">Whether or not this element is imported.</param> /// <param name="ownerDocument">The ZPT document which owns the element.</param> public ZptXmlLinqElement(XNode node, ISourceInfo sourceFile, IZptDocument ownerDocument, bool isRoot = false, bool isImported = false) : base(sourceFile, isRoot, isImported, ownerDocument) { if(node == null) { throw new ArgumentNullException(nameof(node)); } _node = node as XElement; if(_node.NodeType == XmlNodeType.Document) { _node = node.Document.Root; } EnforceNodeType("XML", XmlNodeType.Element, _node.NodeType); }
/// <summary> /// Does a cascade delete of an object for this property /// </summary> /// <param name="Object">Object</param> /// <param name="Source">Source info</param> /// <param name="ObjectsSeen">Objects seen thus far</param> /// <returns>Batch object with the appropriate commands</returns> public override IBatch CascadeDelete(ClassType Object, ISourceInfo Source, IList<object> ObjectsSeen) { var Provider = IoC.Manager.Bootstrapper.Resolve<QueryProvider.Manager>(); var MappingProvider = IoC.Manager.Bootstrapper.Resolve<Mapper.Manager>(); IMapping PropertyMapping = MappingProvider[typeof(DataType), Source]; var Batch = Provider.Batch(Source); var AspectObject = Object as IORMObject; if (Object == null || (AspectObject != null && ObjectsSeen.Contains(Mapping.IDProperties.FirstOrDefault().GetValue(Object)))) return Provider.Batch(Source); if (AspectObject != null) ObjectsSeen.Add(Mapping.IDProperties.FirstOrDefault().GetValue(Object)); var Item = CompiledExpression(Object); if (Item == null) return Batch; foreach (IProperty<DataType> Property in PropertyMapping.Properties.Where(x => x.Cascade)) { Batch.AddCommand(Property.CascadeDelete(Item, Source, ObjectsSeen.ToList())); } Batch.AddCommand(Provider.Generate<DataType>(Source, PropertyMapping, Structure).Delete(Item)); Utilities.IoC.Manager.Bootstrapper.Resolve<DataTypes.Caching.Manager>().Cache().RemoveByTag(typeof(DataType).GetName()); return Batch; }
/// <summary> /// Called to create a batch that deletes items from the joining tables /// </summary> /// <param name="Object">Object</param> /// <param name="Source">Source info</param> /// <param name="ObjectsSeen">Objects seen thus far</param> /// <returns>Batch object with the appropriate commands</returns> public override IBatch CascadeJoinsDelete(ClassType Object, ISourceInfo Source, IList <object> ObjectsSeen) { QueryProvider.Manager Provider = IoC.Manager.Bootstrapper.Resolve <QueryProvider.Manager>(); Mapper.Manager MappingProvider = IoC.Manager.Bootstrapper.Resolve <Mapper.Manager>(); IMapping PropertyMapping = MappingProvider[typeof(DataType), Source]; IBatch Batch = Provider.Batch(Source); var AspectObject = Object as IORMObject; if (Object == null || (AspectObject as IORMObject != null && ObjectsSeen.Contains(Mapping.IDProperties.FirstOrDefault().GetValue(Object)))) { return(Provider.Batch(Source)); } if (AspectObject != null) { ObjectsSeen.Add(Mapping.IDProperties.FirstOrDefault().GetValue(Object)); } DataType Item = CompiledExpression(Object); if (Item == null) { return(Batch); } foreach (IProperty <DataType> Property in PropertyMapping.Properties) { if (!Property.Cascade && (Property is IMultiMapping || Property is ISingleMapping)) { Batch.AddCommand(Property.JoinsDelete(Item, Source, ObjectsSeen.ToList())); } else if (Property.Cascade) { Batch.AddCommand(Property.CascadeJoinsDelete(Item, Source, ObjectsSeen.ToList())); } } Batch.AddCommand(Provider.Generate <ClassType>(Source, Mapping, Structure).JoinsDelete(this, Object)); return(Batch); }
private static void JoinsDelete <ObjectType>(ObjectType Object, ISourceInfo Source, IMapping Mapping, IBatch TempBatch, List <object> ObjectsSeen) where ObjectType : class { Contract.Requires <ArgumentNullException>(Mapping != null, "Mapping"); Contract.Requires <ArgumentNullException>(Mapping.Properties != null, "Mapping.Properties"); var ORMObject = Object as IORMObject; foreach (IProperty <ObjectType> Property in Mapping.Properties) { if (ORMObject == null || ORMObject.PropertiesChanged0.Contains(Property.Name)) { if (!Property.Cascade && (Property is IMultiMapping || Property is ISingleMapping)) { TempBatch.AddCommand(Property.JoinsDelete(Object, Source, ObjectsSeen.ToList())); } else if (Property.Cascade) { TempBatch.AddCommand(Property.CascadeJoinsDelete(Object, Source, ObjectsSeen.ToList())); } } } }
public Sequence(ISourceInfo sourceInfo, IEnumerable<AstNode> elements) : base(NodeType.Sequence, sourceInfo) { this.Elements = elements.ToArray(); }
private void SetupViews(ISourceInfo Source, Database Temp) { Contract.Requires<ArgumentNullException>(Temp != null, "Temp"); Contract.Requires<ArgumentNullException>(Temp.Views != null, "Temp.Views"); foreach (View View in Temp.Views) { IEnumerable<dynamic> Values = Provider.Batch(Source) .AddCommand(null, null, @"SELECT OBJECT_DEFINITION(sys.views.object_id) as Definition FROM sys.views WHERE sys.views.name=@0", CommandType.Text, View.Name) .Execute()[0]; View.Definition = Values.First().Definition; Values = Provider.Batch(Source) .AddCommand(null, null, @"SELECT sys.columns.name AS [Column], sys.systypes.name AS [COLUMN_TYPE], sys.columns.max_length as [MAX_LENGTH], sys.columns.is_nullable as [IS_NULLABLE] FROM sys.views INNER JOIN sys.columns on sys.columns.object_id=sys.views.object_id INNER JOIN sys.systypes ON sys.systypes.xtype = sys.columns.system_type_id WHERE (sys.views.name = @0) AND (sys.systypes.xusertype <> 256)", CommandType.Text, View.Name) .Execute()[0]; foreach (dynamic Item in Values) { string ColumnName = Item.Column; string ColumnType = Item.COLUMN_TYPE; int MaxLength = Item.MAX_LENGTH; if (ColumnType == "nvarchar") MaxLength /= 2; bool Nullable = Item.IS_NULLABLE; View.AddColumn<string>(ColumnName, ColumnType.To<string, SqlDbType>().To(DbType.Int32), MaxLength, Nullable); } } }
private void SetupTriggers(ISourceInfo Source, Utilities.ORM.Manager.Schema.Default.Database.Table Table, IEnumerable<dynamic> Values) { Contract.Requires<ArgumentNullException>(Table != null, "Table"); Contract.Requires<ArgumentNullException>(Source != null, "Source"); Contract.Requires<NullReferenceException>(Provider != null, "Provider"); Values = Provider.Batch(Source) .AddCommand(null, null, @"SELECT sys.triggers.name as Name,sys.trigger_events.type as Type, OBJECT_DEFINITION(sys.triggers.object_id) as Definition FROM sys.triggers INNER JOIN sys.trigger_events ON sys.triggers.object_id=sys.trigger_events.object_id INNER JOIN sys.tables on sys.triggers.parent_id=sys.tables.object_id where sys.tables.name=@0", CommandType.Text, Table.Name) .Execute()[0]; foreach (dynamic Item in Values) { string Name = Item.Name; int Type = Item.Type; string Definition = Item.Definition; Table.AddTrigger(Name, Definition, Type.ToString(CultureInfo.InvariantCulture).To<string, TriggerType>()); } }
private void SetupTables(ISourceInfo Source, Database Temp) { Contract.Requires<ArgumentNullException>(Temp != null, "Temp"); Contract.Requires<ArgumentNullException>(Temp.Tables != null, "Temp.Tables"); foreach (Utilities.ORM.Manager.Schema.Default.Database.Table Table in Temp.Tables) { IEnumerable<dynamic> Values = Provider.Batch(Source) .AddCommand(null, null, @"SELECT sys.columns.name AS [Column], sys.systypes.name AS [COLUMN_TYPE], sys.columns.max_length as [MAX_LENGTH], sys.columns.is_nullable as [IS_NULLABLE], sys.columns.is_identity as [IS_IDENTITY], sys.index_columns.index_id as [IS_INDEX], key_constraints.name as [PRIMARY_KEY], key_constraints_1.name as [UNIQUE], tables_1.name as [FOREIGN_KEY_TABLE], columns_1.name as [FOREIGN_KEY_COLUMN], sys.default_constraints.definition as [DEFAULT_VALUE] FROM sys.tables INNER JOIN sys.columns on sys.columns.object_id=sys.tables.object_id INNER JOIN sys.systypes ON sys.systypes.xtype = sys.columns.system_type_id LEFT OUTER JOIN sys.index_columns on sys.index_columns.object_id=sys.tables.object_id and sys.index_columns.column_id=sys.columns.column_id LEFT OUTER JOIN sys.key_constraints on sys.key_constraints.parent_object_id=sys.tables.object_id and sys.key_constraints.parent_object_id=sys.index_columns.object_id and sys.index_columns.index_id=sys.key_constraints.unique_index_id and sys.key_constraints.type='PK' LEFT OUTER JOIN sys.foreign_key_columns on sys.foreign_key_columns.parent_object_id=sys.tables.object_id and sys.foreign_key_columns.parent_column_id=sys.columns.column_id LEFT OUTER JOIN sys.tables as tables_1 on tables_1.object_id=sys.foreign_key_columns.referenced_object_id LEFT OUTER JOIN sys.columns as columns_1 on columns_1.column_id=sys.foreign_key_columns.referenced_column_id and columns_1.object_id=tables_1.object_id LEFT OUTER JOIN sys.key_constraints as key_constraints_1 on key_constraints_1.parent_object_id=sys.tables.object_id and key_constraints_1.parent_object_id=sys.index_columns.object_id and sys.index_columns.index_id=key_constraints_1.unique_index_id and key_constraints_1.type='UQ' LEFT OUTER JOIN sys.default_constraints on sys.default_constraints.object_id=sys.columns.default_object_id WHERE (sys.tables.name = @0) AND (sys.systypes.xusertype <> 256)", CommandType.Text, Table.Name) .Execute()[0]; SetupColumns(Table, Values); SetupTriggers(Source, Table, Values); } foreach (Utilities.ORM.Manager.Schema.Default.Database.Table Table in Temp.Tables) { Table.SetupForeignKeys(); } }
private void SetupStoredProcedures(ISourceInfo Source, Database Temp) { Contract.Requires<ArgumentNullException>(Source != null, "Source"); Contract.Requires<NullReferenceException>(Provider != null, "Provider"); IEnumerable<dynamic> Values = Provider.Batch(Source) .AddCommand(null, null, CommandType.Text, "SELECT sys.procedures.name as NAME,OBJECT_DEFINITION(sys.procedures.object_id) as DEFINITION FROM sys.procedures") .Execute()[0]; foreach (dynamic Item in Values) { Temp.AddStoredProcedure(Item.NAME, Item.DEFINITION); } foreach (StoredProcedure Procedure in Temp.StoredProcedures) { Values = Provider.Batch(Source) .AddCommand(null, null, @"SELECT sys.systypes.name as TYPE,sys.parameters.name as NAME,sys.parameters.max_length as LENGTH,sys.parameters.default_value as [DEFAULT VALUE] FROM sys.procedures INNER JOIN sys.parameters on sys.procedures.object_id=sys.parameters.object_id INNER JOIN sys.systypes on sys.systypes.xusertype=sys.parameters.system_type_id WHERE sys.procedures.name=@0 AND (sys.systypes.xusertype <> 256)", CommandType.Text, Procedure.Name) .Execute()[0]; foreach (dynamic Item in Values) { string Type = Item.TYPE; string Name = Item.NAME; int Length = Item.LENGTH; if (Type == "nvarchar") Length /= 2; string Default = Item.DEFAULT_VALUE; Procedure.AddColumn<string>(Name, Type.To<string, SqlDbType>().To(DbType.Int32), Length, DefaultValue: Default); } } }
/// <summary> /// Generates a list of commands used to modify the source. If it does not exist prior, the /// commands will create the source from scratch. Otherwise the commands will only add new /// fields, tables, etc. It does not delete old fields. /// </summary> /// <param name="DesiredStructure">Desired source structure</param> /// <param name="Source">Source to use</param> /// <returns>List of commands generated</returns> public IEnumerable<string> GenerateSchema(ISource DesiredStructure, ISourceInfo Source) { return new List<string>(); }
/// <summary> /// Checks if a trigger exists /// </summary> /// <param name="Trigger">Trigger to check</param> /// <param name="Source">Source to use</param> /// <returns>True if it exists, false otherwise</returns> public bool TriggerExists(string Trigger, ISourceInfo Source) { return false; }
/// <summary> /// Checks if a stored procedure exists /// </summary> /// <param name="StoredProcedure">Stored procedure to check</param> /// <param name="Source">Source to use</param> /// <returns>True if it exists, false otherwise</returns> public bool StoredProcedureExists(string StoredProcedure, ISourceInfo Source) { return false; }
/// <summary> /// Gets the structure of a source /// </summary> /// <param name="Source">Source to use</param> /// <returns>The source structure</returns> public ISource GetSourceStructure(ISourceInfo Source) { return null; }
/// <summary> /// Sets up the property /// </summary> /// <param name="MappingProvider">Mapping provider</param> /// <param name="QueryProvider">Query provider</param> /// <param name="Source">Source info</param> public override void Setup(ISourceInfo Source, Mapper.Manager MappingProvider, QueryProvider.Manager QueryProvider) { ForeignMapping = MappingProvider[Type, Source]; Structure = MappingProvider.GetStructure(Mapping.DatabaseConfigType); QueryProvider.Generate <ClassType>(Source, Mapping, Structure).SetupLoadCommands(this); }
/// <summary> /// Checks if a source exists /// </summary> /// <param name="Source">Source to check</param> /// <param name="Info">Source info to use</param> /// <returns>True if it exists, false otherwise</returns> public bool SourceExists(string Source, ISourceInfo Info) { return true; }
/// <summary> /// Checks if a view exists /// </summary> /// <param name="View">View to check</param> /// <param name="Source">Source to use</param> /// <returns>True if it exists, false otherwise</returns> public bool ViewExists(string View, ISourceInfo Source) { return Exists("SELECT * FROM sys.views WHERE name=@0", View, Source); }
/// <summary> /// Checks if a table exists /// </summary> /// <param name="Table">Table to check</param> /// <param name="Source">Source to use</param> /// <returns>True if it exists, false otherwise</returns> public bool TableExists(string Table, ISourceInfo Source) { return false; }
private bool Exists(string Command, string Value, ISourceInfo Source) { Contract.Requires<ArgumentNullException>(Source != null, "Source"); Contract.Requires<NullReferenceException>(Provider != null, "Provider"); return Provider.Batch(Source) .AddCommand(null, null, Command, CommandType.Text, Value) .Execute()[0] .Count() > 0; }
/// <summary> /// Checks if a view exists /// </summary> /// <param name="View">View to check</param> /// <param name="Source">Source to use</param> /// <returns>True if it exists, false otherwise</returns> public bool ViewExists(string View, ISourceInfo Source) { return false; }
private void GetTables(ISourceInfo Source, Database Temp) { Contract.Requires<ArgumentNullException>(Source != null, "Source"); Contract.Requires<NullReferenceException>(Provider != null, "Provider"); IEnumerable<dynamic> Values = Provider.Batch(Source) .AddCommand(null, null, CommandType.Text, "SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES") .Execute()[0]; foreach (dynamic Item in Values) { string TableName = Item.TABLE_NAME; string TableType = Item.TABLE_TYPE; if (TableType == "BASE TABLE") Temp.AddTable(TableName); else if (TableType == "VIEW") Temp.AddView(TableName); } }
/// <summary> /// Creates a generator object /// </summary> /// <typeparam name="T">Class type the generator uses</typeparam> /// <param name="Source">Source to use</param> /// <param name="Mapping">Mapping info</param> /// <returns>The generator object</returns> public IGenerator <T> Generate <T>(ISourceInfo Source, IMapping Mapping) where T : class, new() { Contract.Requires <ArgumentNullException>(Source != null, "Source"); return(Providers.ContainsKey(Source.SourceType) ? Providers[Source.SourceType].Generate <T>(Source, Mapping) : null); }
private void SetupFunctions(ISourceInfo Source, Database Temp) { Contract.Requires<ArgumentNullException>(Source != null, "Source"); Contract.Requires<NullReferenceException>(Provider != null, "Provider"); IEnumerable<dynamic> Values = Provider.Batch(Source) .AddCommand(null, null, CommandType.Text, "SELECT SPECIFIC_NAME as NAME,ROUTINE_DEFINITION as DEFINITION FROM INFORMATION_SCHEMA.ROUTINES WHERE INFORMATION_SCHEMA.ROUTINES.ROUTINE_TYPE='FUNCTION'") .Execute()[0]; foreach (dynamic Item in Values) { Temp.AddFunction(Item.NAME, Item.DEFINITION); } }
private async Task <List <ViewMailItem> > LoadMailsWorker(ILabelSource label, ISourceInfo source, int?from = null, long?to = null, bool fresh = false) { List <int?> labels = null; if (label != null && !label.IsVirtual) { labels = new List <int?>(); labels.Add(label.Id); } MailApi api = new MailApi(); int id = (int)DBAccount.CharacterId; List <GetCharactersCharacterIdMail200Ok> mails; mails = await api.GetCharactersCharacterIdMailAsync( characterId : id, datasource : ESIConfiguration.DataSource, labels : labels, lastMailId : from, token : DBAccount.AccessToken); List <ViewMailItem> viewmails = new List <ViewMailItem>(); List <MailRecipient> recipients = new List <MailRecipient>(); foreach (var i in mails) { if (!i.MailId.HasValue) { continue; } if (to.HasValue && to.Value == i.MailId.Value) { break; } if (label != null && label.Type == LabelType.MailingList) { if (!HasRecipient(i, EntityType.Mailinglist, label.Id)) { continue; } } recipients.Clear(); ViewMailItem item; if (!fresh && GetItemFromCache(i.MailId.Value, out item)) { viewmails.Add(item); continue; } item = new ViewMailItem(i.MailId.Value, i.IsRead.HasValue && i.IsRead.Value); item.Source = source; item.From = new MailRecipient(EntityType.Character, i.From.HasValue ? i.From.Value : -1); await mClient.AddLookupAsync(item.From); item.MailSubject = i.Subject; item.Timestamp = i.Timestamp.HasValue ? i.Timestamp.Value : DateTime.MinValue; foreach (var j in i.Recipients) { MailRecipient recipient = new MailRecipient(ESIConvert.RecipientTypeToEntityType(j.RecipientType.GetValueOrDefault()), j.RecipientId.Value); recipients.Add(recipient); } foreach (var j in mViewAccount.Labels) { if (j.IsVirtual) { continue; } item.Labels.Add(new ViewMailLabelLink(item, j, i.Labels.Contains(j.Id), label != null && label.Id == j.Id)); } item.Recipients = recipients.ToArray(); viewmails.Add(item); } await mClient.FinishLookupsAsync(); return(viewmails); }
/// <summary> /// Checks if a trigger exists /// </summary> /// <param name="Trigger">Trigger to check</param> /// <param name="Source">Source to use</param> /// <returns>True if it exists, false otherwise</returns> public bool TriggerExists(string Trigger, ISourceInfo Source) { return Exists("SELECT * FROM sys.triggers WHERE name=@0", Trigger, Source); }