Exemplo n.º 1
0
        //public CancellationTokenSource cts = CancellationTokenSource.CreateLinkedTokenSource();
        public async Task <List <Transmittal> > SearchForAnyAsync(IProgress <Transmittal> e, CancellationToken cancellationToken)
        {
            List <Transmittal> res = new List <Transmittal>();

            using (SqlConnection connection = new SqlConnection(connString))
            {
                string     query   = SqlScripts.GetAllTransmittals;
                SqlCommand command = new SqlCommand(query, connection);
                await connection.OpenAsync(cancellationToken);

                using (SqlDataReader reader = await command.ExecuteReaderAsync(cancellationToken))
                {
                    while (await reader.ReadAsync(cancellationToken))
                    {
                        Transmittal tran = new Transmittal(reader);// LoadTransmittal(reader);
                        res.Add(tran);
                        e.Report(tran);

                        if (cancellationToken.IsCancellationRequested)
                        {
                            reader.Close();
                            connection.Close();
                            return(res);
                        }
                    }
                }
            }
            e.Report(null);
            return(res);
        }
Exemplo n.º 2
0
        public async Task <List <Transmittal> > SearchByIdAsync(int id, CancellationToken cancellationToken)
        {
            List <Transmittal> res = new List <Transmittal>();

            using (SqlConnection connection = new SqlConnection(connString))
            {
                string     query1  = "SELECT * FROM Transmittal where Id = " + id.ToString();
                SqlCommand command = new SqlCommand(query1, connection);
                await connection.OpenAsync(cancellationToken);

                using (SqlDataReader reader = await command.ExecuteReaderAsync(cancellationToken))
                {
                    while (await reader.ReadAsync(cancellationToken))
                    {
                        Transmittal tran = new Transmittal(reader);// LoadTransmittal(reader);
                        res.Add(tran);
                    }
                }
            }
            return(res);
        }
Exemplo n.º 3
0
        public async Task <List <Transmittal> > SearchByParametersAsync(SearchViewModel search, IProgress <Transmittal> e, CancellationToken cancellationToken)
        {
            List <Transmittal> res = new List <Transmittal>();

            using (SqlConnection connection = new SqlConnection(connString))
            {
                string query;

                bool hasFiles = !string.IsNullOrEmpty(search.FileName);

                if (hasFiles)
                {
                    query = string.Format(SqlScripts.GetTransmitalsFileName, search.FileName, AddParameters(search));
                }
                else
                {
                    query = string.Format(SqlScripts.GetTransmittals, AddParameters(search));
                }

                SqlCommand command = new SqlCommand(query, connection);
                await connection.OpenAsync(cancellationToken);

                using (SqlDataReader reader = await command.ExecuteReaderAsync(cancellationToken))
                {
                    if (hasFiles)
                    {
                        Transmittal activeTran = null;
                        while (await reader.ReadAsync(cancellationToken))
                        {
                            var file = new Document(reader); //LoadDocument(reader);
                            if (activeTran == null || file.TransmittalId != activeTran.Id)
                            {
                                if (activeTran != null)
                                {
                                    res.Add(activeTran);
                                    e.Report(activeTran);
                                }

                                activeTran = new Transmittal(reader);// LoadTransmittal(reader);
                            }
                            activeTran.Files.Add(file);
                        }
                    }
                    else
                    {
                        while (await reader.ReadAsync(cancellationToken))
                        {
                            Transmittal tran = new Transmittal(reader);// LoadTransmittal(reader);
                            res.Add(tran);
                            e.Report(tran);
                            if (cancellationToken.IsCancellationRequested)
                            {
                                reader.Close();
                                connection.Close();
                                return(null);
                            }
                        }
                    }
                }
            }
            e.Report(null);
            return(res);
        }
Exemplo n.º 4
0
 public Publisher(Transmittal trans)
 {
     Transmittal = trans;
     OutputDir   = Path.Combine(System.IO.Path.GetTempPath(), "TransmitalMgr", $"Prj{Transmittal.Id}");
 }