Exemplo n.º 1
0
        public Image getImagen(int id_voluntario)
        {
            Image   ret    = null;
            CnxBase myBase = new CnxBase();
            string  reqSQL = "SELECT foto FROM z_voluntarios WHERE id_voluntario=" + id_voluntario;

            try
            {
                NpgsqlConnection myConn    = myBase.OpenConnection(myBase.cnxString);
                NpgsqlCommand    myCommand = new NpgsqlCommand(reqSQL, myConn);
                NpgsqlDataReader myReader  = myCommand.ExecuteReader();
                if (myReader.Read() && myReader[0] != DBNull.Value)
                {
                    NpgsqlTransaction t = myConn.BeginTransaction();
                    NpgsqlTypes.LargeObjectManager lbm = new NpgsqlTypes.LargeObjectManager(myConn);
                    NpgsqlTypes.LargeObject        lo  = lbm.Open(Convert.ToInt32(myReader[0]), NpgsqlTypes.LargeObjectManager.READ);
                    byte[] buf = new byte[lo.Size()];
                    buf = lo.Read(lo.Size());
                    MemoryStream ms = new MemoryStream();
                    ms.Write(buf, 0, lo.Size());
                    lo.Close();
                    t.Commit();
                    ret = Image.FromStream(ms);
                }
                myConn.Close();
            }
            catch (Exception myErr)
            {
                throw (new Exception(myErr.ToString() + reqSQL));
            }
            return(ret);
        }
        public void DownloadQuestao(Dominio.Questao questao)
        {
            Dominio.Configuracao configuracao = new Dominio.Configuracao();

            string caminhoEntrada = System.IO.Path.Combine(configuracao.CaminhoSalvarSubmissoes, questao.ArquivoEntrada);
            string caminhoSaida = System.IO.Path.Combine(configuracao.CaminhoSalvarSubmissoes, questao.ArquivoSaida);

            NpgsqlConnection conexao = new NpgsqlConnection("Server=187.45.196.224;Database=bubblesort9;User ID=bubblesort9;Password=BSboca;");

            NpgsqlTransaction transacao = null;
            try
            {
                conexao.Open();

                transacao = conexao.BeginTransaction();

                LargeObjectManager lbm = new LargeObjectManager(conexao);

                LargeObject lo = lbm.Open(questao.IdArquivoEntrada, LargeObjectManager.READ);

                FileStream fsout = File.OpenWrite(caminhoEntrada);

                byte[] buf = new byte[lo.Size()];

                buf = lo.Read(lo.Size());

                fsout.Write(buf, 0, (int)lo.Size());
                fsout.Flush();
                fsout.Close();
                lo.Close();

                lo = lbm.Open(questao.IdArquivoSaida, LargeObjectManager.READ);

                fsout = File.OpenWrite(caminhoSaida);

                byte[] buffer = new byte[lo.Size()];

                buffer = lo.Read(lo.Size());

                fsout.Write(buffer, 0, (int)lo.Size());
                fsout.Flush();
                fsout.Close();
                lo.Close();
                transacao.Commit();
            }
            catch
            {
                if (transacao != null)
                    transacao.Rollback();
                throw;
            }
            finally
            {
                conexao.Close();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Deletes a large object matching the id from the database.
        /// </summary>
        /// <param name="largeObjectId">The id of the largeobject.</param>
        /// <param name="connectionString">The connectionString to the database. Please refer to .Net Data Provider for Postgresql for format specifications</param>
        /// <seealso cref="CreateLargeObject"/>
        /// <seealso cref="CreateLargeObject"/>
        /// <seealso cref="UpdateLargeObject"/>
        public static void DeleteLargeObject(int largeObjectId, string connectionString)
        {
            NpgsqlConnection con = new NpgsqlConnection(connectionString);

            con.Open();
            NpgsqlTypes.LargeObjectManager lm = new NpgsqlTypes.LargeObjectManager(con);

            var TransRead = con.BeginTransaction();

            lm.Delete(largeObjectId);
            TransRead.Commit();
            con.Close();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the large object content from the database for the given large object id.
        /// </summary>
        /// <param name="largeObjectId">The id of the largeobject.</param>
        /// <param name="connectionString">The connectionString to the database. Please refer to .Net Data Provider for Postgresql for format specifications</param>
        /// <returns>Returns the content of the large object.</returns>
        /// <seealso cref="CreateLargeObject"/>
        /// <seealso cref="DeleteLargeObject"/>
        /// <seealso cref="UpdateLargeObject"/>
        public static byte[] GetLargeObject(int largeObjectId, string connectionString)
        {
            NpgsqlConnection con = new NpgsqlConnection(connectionString);

            con.Open();
            NpgsqlTypes.LargeObjectManager lm = new NpgsqlTypes.LargeObjectManager(con);
            var TransRead = con.BeginTransaction();
            var readlo    = lm.Open(largeObjectId, LargeObjectManager.READWRITE);
            var resultLo  = readlo.Read(readlo.Size());

            TransRead.Commit();
            con.Close();
            return(resultLo);
        }
        public void DownloadArquivos(Dominio.Submissao submissao)
        {
            Dominio.Configuracao configuracao = new Dominio.Configuracao();
            string caminho=string.Empty;
            switch (submissao.Linguagem)
            {
                case Dominio.Linguagem.C:
                    caminho = System.IO.Path.Combine(configuracao.CaminhoSalvarSubmissoes, submissao.Id + ".c");
                    break;
                case Dominio.Linguagem.Cmaismais:
                    caminho = System.IO.Path.Combine(configuracao.CaminhoSalvarSubmissoes, submissao.Id + ".cpp");
                    break;
            }

            NpgsqlConnection conexao = new NpgsqlConnection("Server=187.45.196.224;Database=bubblesort9;User ID=bubblesort9;Password=BSboca;");
            NpgsqlTransaction transacao = null;
            try
            {
                conexao.Open();
                transacao = conexao.BeginTransaction();

                LargeObjectManager lbm = new LargeObjectManager(conexao);

                LargeObject lo = lbm.Open(submissao.IdData, LargeObjectManager.READWRITE);

                FileStream fsout = File.OpenWrite(caminho);

                byte[] buf = new byte[lo.Size()];

                buf = lo.Read(lo.Size());

                fsout.Write(buf, 0, (int)lo.Size());
                fsout.Flush();
                fsout.Close();
                lo.Close();
                transacao.Commit();
            }
            catch
            {
                if (transacao != null)
                    transacao.Rollback();
                throw;
            }
            finally
            {
                conexao.Close();
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Updates a large object on the database with matching the id.
        /// </summary>
        /// <param name="largeObjectId">The id of the largeobject.</param>
        /// <param name="data">The updated data</param>
        /// <param name="connectionString">The connectionString to the database. Please refer to .Net Data Provider for Postgresql for format specifications</param>
        /// <seealso cref="CreateLargeObject"/>
        /// <seealso cref="DeleteLargeObject"/>
        /// <seealso cref="GetLargeObject"/>
        public static void UpdateLargeObject(int largeObjectId, byte[] data, string connectionString)
        {
            NpgsqlConnection con = new NpgsqlConnection(connectionString);

            con.Open();
            NpgsqlTypes.LargeObjectManager lm = new NpgsqlTypes.LargeObjectManager(con);

            var generatedLO = lm.Create(NpgsqlTypes.LargeObjectManager.READWRITE);
            var TransWrite  = con.BeginTransaction();
            var readlo      = lm.Open(largeObjectId, LargeObjectManager.READWRITE);

            readlo.Write(data);
            readlo.Close();
            TransWrite.Commit();
            con.Close();
        }
Exemplo n.º 7
0
        public void NpgsqlErrorRepro2()
        {
            NpgsqlConnection connection = new NpgsqlConnection(TheConnectionString);
            connection.Open();
            NpgsqlTransaction transaction = connection.BeginTransaction();
            LargeObjectManager largeObjectMgr = new LargeObjectManager(connection);
            try
            {
                LargeObject largeObject = largeObjectMgr.Open(-1, LargeObjectManager.READWRITE);
                transaction.Commit();
            }
            catch
            {
                // ignore the LO failure
                try
                {
                    transaction.Dispose();
                }
                catch
                {
                    // ignore dispose failure
                }
                try
                {
                    connection.Dispose();
                }
                catch
                {
                    // ignore dispose failure
                }
            }

            using (connection = new NpgsqlConnection(TheConnectionString))
            {
                connection.Open();
                using (NpgsqlCommand command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM pg_database";
                    using (NpgsqlDataReader reader = command.ExecuteReader())
                    {
                        Assert.IsTrue(reader.Read());
                        // *1* this fails if the connection for the pool happens to be the bad one from above
                        Assert.IsTrue(!String.IsNullOrEmpty((string)reader["datname"]));
                    }
                }
            }
        }
Exemplo n.º 8
0
        public void NpgsqlErrorRepro1()
        {
            using (NpgsqlConnection connection = new NpgsqlConnection(TheConnectionString))
            {
                connection.Open();
                using (NpgsqlTransaction transaction = connection.BeginTransaction())
                {
                    LargeObjectManager largeObjectMgr = new LargeObjectManager(connection);
                    try
                    {
                        LargeObject largeObject = largeObjectMgr.Open(-1, LargeObjectManager.READWRITE);
                        transaction.Commit();
                    }
                    catch(Exception ex)
                    {
                        //Console.WriteLine(ex.ToString());
                        // ignore the LO failure
                    }
                } // *1* sometimes it throws "System.NotSupportedException: This stream does not support seek operations"

                using (NpgsqlCommand command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM pg_database";
                    using (NpgsqlDataReader reader = command.ExecuteReader())
                    {
                        Assert.IsTrue(reader.Read()); // *2* this fails if the initial connection is used
                    }
                }
            } // *3* sometimes it throws "System.NotSupportedException: This stream does not support seek operations"
        }
Exemplo n.º 9
0
        public void NpgsqlErrorRepro1()
        {
            throw new NotImplementedException();
#if WHAT_TO_DO_WITH_THIS
            using (var connection = new NpgsqlConnection(ConnectionString))
            {
                connection.Open();
                using (var transaction = connection.BeginTransaction())
                {
                    var largeObjectMgr = new LargeObjectManager(connection);
                    try
                    {
                        var largeObject = largeObjectMgr.Open(-1, LargeObjectManager.READWRITE);
                        transaction.Commit();
                    }
                    catch
                    {
                        // ignore the LO failure
                    }
                } // *1* sometimes it throws "System.NotSupportedException: This stream does not support seek operations"

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM pg_database";
                    using (var reader = command.ExecuteReader())
                    {
                        Assert.IsTrue(reader.Read()); // *2* this fails if the initial connection is used
                    }
                }
            } // *3* sometimes it throws "System.NotSupportedException: This stream does not support seek operations"
#endif
        }
        /// <summary>
        /// Sets the extension stream.
        /// </summary>
        /// <param name="guid">The GUID.</param>
        /// <param name="extensionStream">The extension stream.</param>
        public void SetExtensionStream(Guid guid, Stream extensionStream)
        {
            using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
            {
                NpgsqlTransaction tran = con.BeginTransaction();

                LargeObjectManager lbm = new LargeObjectManager(con);
                int noid = lbm.Create(LargeObjectManager.READWRITE);
                LargeObject largeObject = lbm.Open(noid, LargeObjectManager.READWRITE);
                byte[] buffer = new byte[extensionStream.Length];
                extensionStream.Read(buffer, 0, (int)extensionStream.Length);
                BufferToLargeObject(buffer, largeObject);
                largeObject.Close();

                using (NpgsqlCommand cmd = con.CreateCommand())
                {
                    cmd.CommandText = "UPDATE \"Extensions\" SET data=:data WHERE guid=:guid";
                    cmd.Parameters.Add("data", noid);
                    cmd.Parameters.Add("guid", guid.ToString());
                    PostgreSQLConn.ExecuteNonQuery(cmd, Parent.CurrentUser);
                }
                tran.Commit();
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Gets the media.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="cacheConnector">The cache connector.</param>
        /// <returns>A memory stream for the media object.</returns>
        /// <remarks>Documented by Dev03, 2008-08-05</remarks>
        /// <remarks>Documented by Dev03, 2009-01-13</remarks>
        public Stream GetMediaStream(int id, IDbMediaConnector cacheConnector)
        {
            CachingStream stream = null;
            using (NpgsqlConnection conn = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
            {
                int noid = 0;
                using (NpgsqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "SELECT data FROM \"MediaContent\" WHERE id=:id;";
                    cmd.Parameters.Add("id", id);
                    noid = Convert.ToInt32(PostgreSQLConn.ExecuteScalar(cmd, Parent.CurrentUser));
                }

                NpgsqlTransaction tran = conn.BeginTransaction();
                LargeObjectManager lbm = new LargeObjectManager(conn);
                LargeObject largeObject = lbm.Open(noid, LargeObjectManager.READWRITE);
                byte[] buffer = LargeObjectToBuffer(largeObject);
                stream = new CachingStream(buffer, id, cacheConnector);
                largeObject.Close();
                tran.Commit();
            }
            return stream;
        }
        /// <summary>
        /// Writes the extension data.
        /// </summary>
        /// <param name="extensionId">The extension id.</param>
        /// <param name="output">The output.</param>
        /// <remarks>Documented by Dev02, 2009-07-06</remarks>
        private void WriteExtensionData(Guid extensionId, Stream output)
        {
            using (NpgsqlConnection conn = FileHandlerHelpers.GetPgConnection())
            {
                int noid = 0;
                using (NpgsqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "SELECT data FROM \"Extensions\" WHERE guid=:guid;";
                    cmd.Parameters.Add("guid", extensionId.ToString());
                    noid = Convert.ToInt32(cmd.ExecuteScalar());
                }

                NpgsqlTransaction tran = conn.BeginTransaction();
                LargeObjectManager lbm = new LargeObjectManager(conn);
                LargeObject largeObject = lbm.Open(noid, LargeObjectManager.READWRITE);
                largeObject.Seek(0);
                int size = largeObject.Size();
                byte[] buffer = new byte[size];
                int read = 0;
                int offset = 0;
                while (offset < size)
                {
                    read = largeObject.Read(buffer, offset, Math.Min(102400, size - offset));
                    output.Write(buffer, offset, read);
                    offset += 102400;
                }
                largeObject.Close();
                tran.Commit();
            }
        }
Exemplo n.º 13
0
		public byte[] GetLargeObject(StorageTypes storageType, string dbConnString, int largeObjectId)
		{
			try
			{
				if(storageType == StorageTypes.Postgresql)
				{
					NpgsqlConnection connPgsql = new NpgsqlConnection(dbConnString);
					connPgsql.Open();

					NpgsqlTransaction t = connPgsql.BeginTransaction();

					LargeObjectManager lbm = new LargeObjectManager(connPgsql);
					LargeObject lo =  lbm.Open(largeObjectId, LargeObjectManager.READWRITE);
        
					byte[] buffer = lo.Read(lo.Size());

					lo.Close();
					t.Commit();

					// If using the Npgsql pooling close the connection to place it back in the pool.
					connPgsql.Close();

					return buffer;
				}
				else
				{
					throw new ApplicationException("Not supported in StorageLayer.StoreLargeObject");
				}
			}
			catch(Exception excp)
			{
				logger.Error("Exception StoreLargeObject. " + excp.Message);
				throw excp;
			}
		}
Exemplo n.º 14
0
		public int StoreLargeObject(StorageTypes storageType, string dbConnString, Stream largeObjectStream)
		{
			try
			{
				if(storageType == StorageTypes.Postgresql)
				{
					NpgsqlConnection connPgsql = new NpgsqlConnection(dbConnString);
					connPgsql.Open();

					NpgsqlTransaction t = connPgsql.BeginTransaction();
				
					LargeObjectManager lbm = new LargeObjectManager(connPgsql);

					int noid = lbm.Create(LargeObjectManager.READWRITE);
					LargeObject lo =  lbm.Open(noid, LargeObjectManager.READWRITE);

					long offset = 0;

					while(offset < largeObjectStream.Length)
					{
						long bytesToWrite = (largeObjectStream.Length - offset > 1024) ? 1024 : largeObjectStream.Length - offset;
						
						byte[] buf = new byte[bytesToWrite];
						largeObjectStream.Read(buf, 0, (int)bytesToWrite);

						lo.Write(buf);
						offset += bytesToWrite;
					}

					lo.Close();
					t.Commit();
					
					// If using the Npgsql pooling close the connection to place it back in the pool.
					connPgsql.Close();

					return noid;
				}
				else
				{
					throw new ApplicationException("Not supported in StorageLayer.StoreLargeObject");
				}
			}
			catch(Exception excp)
			{
				logger.Error("Exception StoreLargeObject. " + excp.Message);
				throw excp;
			}
		}
Exemplo n.º 15
0
        static void MainTemp(string[] args)
        {
            NpgsqlConnection schemaConnection = new NpgsqlConnection(connPostGreSql);

            schemaConnection.Open();
            var       databaseName = "GIS";
            DataTable dataTables   = schemaConnection.GetSchema("Tables", new string[] { databaseName, "public", null, null });

            foreach (DataRow rowTable in dataTables.Rows)
            {
                string tableName = rowTable["table_name"].ToString();
                if (tableName != "geometry_collection")
                {
                    continue;
                }
                DataTable     dataColumns = schemaConnection.GetSchema("Columns", new string[] { databaseName, "public", tableName });
                StringBuilder sb          = new StringBuilder();
                sb.AppendLine("public class " + tableName);
                sb.AppendLine("{");
                sb.AppendLine("\tpublic " + tableName + "(){}");

                foreach (DataRow rowColumn in dataColumns.Rows)
                {
                    string columnName = rowColumn["column_name"].ToString();
                    string type       = rowColumn["data_type"].ToString();
                    sb.AppendLine("\tpublic " + type + " " + columnName + " {get;set;}");
                }
                sb.AppendLine("}");
                sb.Replace("int8", "long");
                sb.Replace("int4", "int");
                sb.Replace("text", "string");
                sb.Replace("oid", "long");
                sb.Replace("numeric", "float");
                sb.Replace("timestamp", "DateTime");
                var def = sb.ToString();
            }

            schemaConnection.Close();
            return;

            var geometryRetrieval = geometryCollection.GetSingleObjectWithId("8", true, connPostGreSql);

            // testing GeometryCollection
            Aram.OSMParser.geometryCollection col = new Aram.OSMParser.geometryCollection();

            // col.gisId =
            col.gisType     = "dummy";
            col.format      = "txt";
            col.largeObject = null;
            col.lastUpdate  = DateTime.Now;
            col.latitude    = 563213212;
            col.longitude   = 171231231;
            col.name        = "Test2";
            col.pivot       = new Aram.OSMParser.Vector3GaPS()
            {
                x = 1f, y = 2f, z = 3f
            };
            col.version = new Aram.OSMParser.GaPSlabsVersion()
            {
                versionTitle = "development", major = 0, minor = 1
            };

            col.AddGeometryCollectionToDatabase(connPostGreSql, false);
            var bytes = File.ReadAllBytes(@"C:\Users\admgaming\Documents\Visual Studio 2012\Projects\GaPSLabs\AramOSMParser\OsmParserTestApplication\bin\Debug\Npgsql.xml");

            col.largeObject = bytes;
            col.UpdateThisGeometryOnDatabase(connPostGreSql, true);
            var resultBytes = geometryCollection.GetLargeObject(col.largeObjectReference, connPostGreSql);

            File.WriteAllBytes("c:\\dummy", resultBytes);

            return;

            // ERROR: 42704: invalid large-object descriptor: 0 ??
            // largeobject only works within a transaction. Use bytea as an alternative to large objects.
            // http://www.postgresql.org/message-id/002701c49d7e$0f059240$d604460a@zaphod
            NpgsqlConnection testConnection = new NpgsqlConnection(connPostGreSql);

            testConnection.Open();

            NpgsqlTypes.LargeObjectManager lm = new NpgsqlTypes.LargeObjectManager(testConnection);

            var generatedLO = lm.Create(NpgsqlTypes.LargeObjectManager.READWRITE);

            // It must be within a transaction
            var         TransWrite = testConnection.BeginTransaction();
            LargeObject lo         = lm.Open(generatedLO, LargeObjectManager.READWRITE);

            lo.Write(new byte[] { 0, 10, 50, 24 });
            lo.Close();
            TransWrite.Commit();

            var TransRead = testConnection.BeginTransaction();
            var loOid     = lo.GetOID();
            var readlo    = lm.Open(loOid, LargeObjectManager.READWRITE);
            var resultLo  = readlo.Read(readlo.Size());

            lm.Delete(generatedLO);
            TransRead.Commit();

            testConnection.Close();
            return;

            OSMPostgresqlSource sourceVisTest = new OSMPostgresqlSource(connPostGreSql);
            var bounds = sourceVisTest.Bounds;



            return;

            GaPSlabsSimulationLibrary.SUMOSimulationFCD df = new GaPSlabsSimulationLibrary.SUMOSimulationFCD();
            //df.LoadFromXML(@"C:\Users\admgaming\Desktop\Dropbox\GaPSLabs\SUMO Packet Tester\Pedestrians.xml");
            //df.LoadFromXML(@"C:\Users\admgaming\Desktop\Dropbox\GaPSLabs\SUMO Packet Tester\bufferoutput - 500.xml");

            ServiceGapslabsClient client2 = ServicePropertiesClass.GetGapslabsService(ServicePropertiesClass.ServiceUri);
            int id = client2.LoadSUMOFCDSimulationList(@"C:\Users\admgaming\Desktop\Dropbox\GaPSLabs\SUMO Packet Tester\bufferoutput - 500.xml", "__POSTFIX");

            //client.LoadSUMOFCDSimulation(@"C:\Users\admgaming\Desktop\Dropbox\GaPSLabs\SUMO Packet Tester\bufferoutput - 500.xml");
            while (!client2.IsSimulationLoadedList(id))
            {
            }
            var vvvv  = client2.GetTimestepAtList(6, id);
            var vvvv2 = client2.GetTimestepAtList(7, id);


            return;


            int size = 16777216;

            int[] aa   = new int[size];
            int[] bbb  = new int[size];
            int[] cccc = new int[size];
            for (int i = 0; i < size; i++)
            {
                aa[i]  = i;
                bbb[i] = i;
            }
            var apointer = aa.ToIntPtr <int[]>();
            var bpointer = bbb.ToIntPtr <int[]>();
            var cpointer = cccc.ToIntPtr <int[]>();

            long      MinGPU         = 1000000;
            long      MinCPU         = 1000000;
            long      MinCPUParallel = 100000;
            Stopwatch watch          = new Stopwatch();

            bool SkipCpu = false;

            GPU_WarmUp();
            int TestCounter = 0;
            int blockSize   = 16;

            while (TestCounter++ < 7)
            {
                watch.Restart();
                GPU_Add(apointer, bpointer, cpointer, size, blockSize);
                watch.Stop();
                Console.WriteLine("Total GPU" + "(" + blockSize + ")" + ": " + watch.ElapsedMilliseconds);
                if (watch.ElapsedMilliseconds < MinGPU)
                {
                    MinGPU = watch.ElapsedMilliseconds;
                }
                blockSize *= 2;
            }
            Console.WriteLine("Minimum GPU was " + MinGPU);

            if (!SkipCpu)
            {
                TestCounter = 0;
                while (TestCounter++ < 10)
                {
                    watch.Restart();
                    CPU_AddParallel(apointer, bpointer, cpointer, size);
                    watch.Stop();
                    Console.WriteLine("Total CPU Parallel: " + watch.ElapsedMilliseconds);
                    if (watch.ElapsedMilliseconds < MinCPUParallel)
                    {
                        MinCPUParallel = watch.ElapsedMilliseconds;
                    }
                }
                Console.WriteLine("Minimum CPU was " + MinCPU);

                TestCounter = 0;
                while (TestCounter++ < 10)
                {
                    watch.Restart();
                    CPU_Add(apointer, bpointer, cpointer, size);
                    watch.Stop();
                    Console.WriteLine("Total CPU: " + watch.ElapsedMilliseconds);
                    if (watch.ElapsedMilliseconds < MinCPU)
                    {
                        MinCPU = watch.ElapsedMilliseconds;
                    }
                }
                Console.WriteLine("Minimum CPU was " + MinCPU);
            }
            //apointer.Free();
            //bpointer.Free();
            //cpointer.Free();
            Console.ReadLine();
            return;

            //GaPSlabsSimulationLibrary.SUMOSimulationFCD simulation = new GaPSlabsSimulationLibrary.SUMOSimulationFCD();
            //simulation.LoadFromXML(@"C:\Users\admgaming\Desktop\Dropbox\GaPSLabs\SUMOData\fcdoutput.xml");
            //simulation.LoadFromCSV(@"C:\Users\admgaming\Desktop\Notable Software\iMobility\stkhlm-taxi.csv");

            ServiceGapslabsClient client = ServicePropertiesClass.GetGapslabsService(ServicePropertiesClass.ServiceUri);
            //client.LoadSUMOFCDSimulation(@"C:\Users\admgaming\Desktop\Dropbox\GaPSLabs\SUMO Packet Tester\bufferoutput - 500.xml");
            //while (!client.IsSimulationLoaded())
            //    Console.WriteLine("Loading...");
            //Console.WriteLine("Load finished");
            //Console.ReadLine();
            //return;



            OSMPostgresqlSource sour = new OSMPostgresqlSource(connPostGreSql);
            // var TrafficNodes = sour.GetNodeIdsInBoundWithInfo(sour.Bounds, "traffic_signals");



            var result = client.GetWayTags("134972364", connPostGreSql);



            BoundsWCF b = new BoundsWCF();

            b.minlat = 59.32973;
            b.maxlat = 59.34481;
            b.minlon = 18.07556;
            b.maxlon = 18.1062;
            client.GetWayExtIdsInBound(connPostGreSql, b);

            client.InitializeRouter(connPostGreSql);

            OsmNodeWCF n1 = new OsmNodeWCF();

            n1.id    = "none";
            n1.order = -1;
            n1.lat   = 59.330957;
            n1.lon   = 18.059285;
            //n1.lat = 59.374563;
            //n1.lon = 18.0135727;
            OsmNodeWCF n2 = new OsmNodeWCF();

            n2.id    = "none";
            n2.order = -1;
            n2.lat   = 59.33784;
            n2.lon   = 18.088558;
            //n2.lat = 59.37225;
            //n2.lon = 18.00733;


            var RouterResult = client.RouteUsingDykstra(VehicleEnum.Car, n1, n2);

            OsmGeo.ShapeInterperter = new SimpleShapeInterpreter();
            PostgreSQLSimpleSchemaSource source = new PostgreSQLSimpleSchemaSource(connPostGreSql);

            // keeps a memory-efficient version of the osm-tags.
            OsmTagsIndex tags_index = new OsmTagsIndex();

            // creates a routing interpreter. (used to translate osm-tags into a routable network)
            OsmRoutingInterpreter interpreter = new OsmRoutingInterpreter();

            // create routing inter
            OsmSourceRouterDataSource routing_data = new OsmSourceRouterDataSource(
                interpreter, tags_index, source);

            // create the router object.
            //IRouter<RouterPoint> router = new Router<PreProcessedEdge>(routing_data, interpreter,
            //    new DykstraRoutingPreProcessed(routing_data.TagsIndex));
            IRouter <RouterPoint> router = new Router <PreProcessedEdge>(routing_data, interpreter
                                                                         , new DykstraRoutingPreProcessed(routing_data.TagsIndex));


            // resolve both points; find the closest routable road.

            //RouterPoint point1 = router.Resolve(VehicleEnum.Car, new GeoCoordinate(60.1674654,18.454302));
            // RouterPoint point2 = router.Resolve(VehicleEnum.Car, new GeoCoordinate(60.1673373,18.4541732));

            // Working
            //RouterPoint point1 = router.Resolve(VehicleEnum.Car, new GeoCoordinate(59.3863281, 18.0176665));
            //RouterPoint point2 = router.Resolve(VehicleEnum.Car, new GeoCoordinate(59.3675634, 18.0140447));

            // Working
            RouterPoint point1 = router.Resolve(VehicleEnum.Car, new GeoCoordinate(59.374563, 18.0135727));
            RouterPoint point2 = router.Resolve(VehicleEnum.Car, new GeoCoordinate(59.37225, 18.00733));

            //ArrayList al=new ArrayList();
            //foreach (var en in Enum.GetValues(typeof(VehicleEnum)))
            //{
            //    al.Add(Enum.GetName(typeof(VehicleEnum), (VehicleEnum)en) + "=" + router.SupportsVehicle((VehicleEnum)en));
            //}

            // calculate route.
            OsmSharpRoute route = router.Calculate(VehicleEnum.Car, point1, point2);

            route.SaveAsGpx(new FileInfo("route.gpx"));



            Console.ReadLine();
        }
Exemplo n.º 16
0
        private void StartupForm_Load(object sender, EventArgs e)
        {
            Login FormLogin = new Login();
            FormLogin.ShowDialog();
            if (DBExchange.Inst.connectDb.State == ConnectionState.Open && DBExchange.Inst.CheckProgramVersion() == true)
            {

                if ((MessageBox.Show("Провести обновление сейчас?", "Есть обновленная версия программы", MessageBoxButtons.YesNo)) == DialogResult.Yes)
                {

                    if (File.Exists(Application.StartupPath + @"\setup.exe"))
                    {
                        File.Delete(Application.StartupPath + @"\setup.exe");
                    }

                    try
                    {

                                                //newcon.Open();
                                                //NpgsqlTransaction t = newcon.BeginTransaction();
                                                //LargeObjectManager lbm = new LargeObjectManager(newcon);
                                                //int noid = lbm.Create(LargeObjectManager.READWRITE);
                                                //LargeObject lo =  lbm.Open(noid,LargeObjectManager.READWRITE);

                                                //FileStream fs = File.OpenRead(args[0]);
                                                //byte[] buf = new byte[fs.Length];
                                                //fs.Read(buf,0,(int)fs.Length);

                                                //lo.Write(buf);
                                                //lo.Close();
                                                //t.Commit();

                                                //t = newcon.BeginTransaction();
                                                //lo =  lbm.Open(noid,LargeObjectManager.READWRITE);
                                                //FileStream fsout = File.OpenWrite(args[0] + "database");
                                                //buf = lo.Read(lo.Size());
                                                //fsout.Write(buf, 0, (int)lo.Size());
                                                //fsout.Flush();
                                                //fsout.Close();
                                                //lo.Close();
                                                //t.Commit();

                        NpgsqlCommand geetO = new NpgsqlCommand("Select MAX(prog_oid) from settings", DBExchange.Inst.connectDb);
                        long getOid = (long)geetO.ExecuteScalar();
                        SaveFileDialog sf1 = new SaveFileDialog();
                        sf1.FileName = Application.StartupPath + @"\setup.exe";
                        sf1.Filter = "exe (*.exe)|*.exe";
                        sf1.ShowDialog();
                        // FileStream fs = new FileStream(sf1.FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, lo.Size());
                        FileStream fs = new FileStream(sf1.FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                        NpgsqlConnection cdb = DBExchange.Inst.connectDb;
                      //  cdb.Open();
                        NpgsqlTransaction t = cdb.BeginTransaction();
                        LargeObjectManager lbm = new LargeObjectManager(cdb);

                        LargeObject lo = lbm.Open(Convert.ToInt32(getOid), LargeObjectManager.READ);
                        byte[] buf = new byte[lo.Size()];
                        buf = lo.Read(lo.Size());
                     //   MemoryStream ms = new MemoryStream();

                     //   ms.Write(buf, 0, lo.Size());

                      //  StreamWriter s = new StreamWriter(fs);
                        fs.Write(buf, 0, lo.Size());

                       // s.Write(buf, 0, lo.Size());

                       // s.Close();
                        fs.Close();
                        lo.Close();
                        t.Commit();
                       // cdb.Close();
                        System.Diagnostics.Process.Start(sf1.FileName);
                        Application.Exit();

                    }
                    catch (Exception exception)
                    {
                        Warnings.WarnLog log = new Warnings.WarnLog();
                        log.writeLog(MethodBase.GetCurrentMethod().Name, exception.Message.ToString(), exception.StackTrace.ToString());
                        try
                        {
                            System.Net.WebClient Client = new System.Net.WebClient();

                            Client.DownloadFile("http://medx.spb.ru/latest/setup.exe", Application.StartupPath + @"\setup.exe");
                            System.Diagnostics.Process.Start(Application.StartupPath + @"\setup.exe");
                            Application.Exit();

                        }
                        catch (Exception exception1)
                        {
                            Warnings.WarnLog log1 = new Warnings.WarnLog();
                            log1.writeLog(MethodBase.GetCurrentMethod().Name, exception1.Message.ToString(), exception1.StackTrace.ToString());
                        }
                    }

                    //Client.DownloadFileCompleted += new AsyncCompletedEventHandler(AppUpdate);

                }

            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Creates a new media object.
        /// </summary>
        /// <param name="media">The memory stream containing the media.</param>
        /// <param name="type">The media type.</param>
        /// <param name="rpu">A delegate of type <see cref="StatusMessageReportProgress"/> used to send messages back to the calling object.</param>
        /// <param name="caller">The calling object.</param>
        /// <returns>The id for the new media object.</returns>
        /// <remarks>Documented by Dev03, 2008-08-05</remarks>
        /// <remarks>Documented by Dev03, 2009-01-13</remarks>
        public int CreateMedia(Stream media, EMedia type, StatusMessageReportProgress rpu, object caller)
        {
            using (NpgsqlConnection conn = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
            {
                NpgsqlTransaction tran = conn.BeginTransaction();

                LargeObjectManager lbm = new LargeObjectManager(conn);
                int noid = lbm.Create(LargeObjectManager.READWRITE);
                LargeObject largeObject = lbm.Open(noid, LargeObjectManager.READWRITE);
                byte[] buffer = new byte[media.Length];
                media.Read(buffer, 0, (int)media.Length);
                BufferToLargeObject(buffer, largeObject, rpu, caller);
                largeObject.Close();

                int newId = 0;
                using (NpgsqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "INSERT INTO \"MediaContent\" (data, media_type) VALUES (:data, :type) RETURNING id;";
                    cmd.Parameters.Add("data", noid);
                    cmd.Parameters.Add("type", type.ToString());
                    newId = Convert.ToInt32(PostgreSQLConn.ExecuteScalar(cmd, Parent.CurrentUser));
                }
                tran.Commit();

                return newId;
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Deletes the media object.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <remarks>Documented by Dev03, 2008-08-05</remarks>
        /// <remarks>Documented by Dev03, 2009-01-13</remarks>
        public void DeleteMedia(int id)
        {
            using (NpgsqlConnection conn = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
            {
                int noid = 0;
                using (NpgsqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "SELECT data FROM \"MediaContent\" WHERE id=:id;";
                    cmd.Parameters.Add("id", id);
                    noid = Convert.ToInt32(PostgreSQLConn.ExecuteScalar(cmd, Parent.CurrentUser));
                }

                NpgsqlTransaction tran = conn.BeginTransaction();
                LargeObjectManager lbm = new LargeObjectManager(conn);
                lbm.Delete(noid);

                using (NpgsqlCommand deletecmd = conn.CreateCommand())
                {
                    deletecmd.CommandText = "DELETE FROM \"MediaContent\" WHERE id=:id;";
                    deletecmd.Parameters.Add("id", id);
                    PostgreSQLConn.ExecuteNonQuery(deletecmd, Parent.CurrentUser);
                }
                tran.Commit();
            }
        }
        /// <summary>
        /// Gets the extension stream.
        /// </summary>
        /// <param name="guid">The GUID.</param>
        /// <returns></returns>
        public Stream GetExtensionStream(Guid guid)
        {
            MemoryStream stream = null;
            using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
            {
                int noid = 0;
                using (NpgsqlCommand cmd = con.CreateCommand())
                {
                    cmd.CommandText = "SELECT data FROM \"Extensions\" WHERE guid=:guid;";
                    cmd.Parameters.Add("guid", guid.ToString());
                    object obj = PostgreSQLConn.ExecuteScalar(cmd, Parent.CurrentUser);
                    if (obj == null || obj == DBNull.Value || !(obj as long?).HasValue)
                        return stream;
                    noid = Convert.ToInt32((obj as long?).Value);
                }

                NpgsqlTransaction tran = con.BeginTransaction();
                try
                {
                    LargeObjectManager lbm = new LargeObjectManager(con);
                    LargeObject largeObject = lbm.Open(noid, LargeObjectManager.READWRITE);
                    byte[] buffer = LargeObjectToBuffer(largeObject);
                    stream = new MemoryStream(buffer);
                    largeObject.Close();
                }
                catch { }
                finally { tran.Commit(); }
            }
            return stream;
        }
Exemplo n.º 20
0
        /// <summary>
        /// Updates the media.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="media">The media.</param>
        /// <remarks>Documented by Dev02, 2008-08-06</remarks>
        /// <remarks>Documented by Dev03, 2009-01-13</remarks>
        public void UpdateMedia(int id, Stream media)
        {
            using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
            {
                NpgsqlTransaction tran = con.BeginTransaction();

                int noid;
                using (NpgsqlCommand cmd = con.CreateCommand())
                {
                    cmd.CommandText = "SELECT data FROM \"MediaContent\" WHERE id=:id";
                    cmd.Parameters.Add("id", id);
                    noid = Convert.ToInt32(PostgreSQLConn.ExecuteScalar(cmd, Parent.CurrentUser));
                }

                LargeObjectManager lbm = new LargeObjectManager(con);
                lbm.Delete(noid);

                noid = lbm.Create(LargeObjectManager.READWRITE);
                LargeObject largeObject = lbm.Open(noid, LargeObjectManager.READWRITE);
                byte[] buffer = new byte[media.Length];
                media.Read(buffer, 0, (int)media.Length);
                BufferToLargeObject(buffer, largeObject);
                largeObject.Close();

                using (NpgsqlCommand cmd = con.CreateCommand())
                {
                    cmd.CommandText = "UPDATE \"MediaContent\" SET data=:data WHERE id=:id";
                    cmd.Parameters.Add("id", id);
                    cmd.Parameters.Add("data", noid);
                    PostgreSQLConn.ExecuteNonQuery(cmd, Parent.CurrentUser);
                }

                tran.Commit();
            }
        }
Exemplo n.º 21
0
		public DBFile Upload (string md5, string path_to_contents, string filename, string extension, bool hidden, string compressed_mime)
		{
			IDbTransaction transaction = null;
			LargeObjectManager manager;
			LargeObject obj;
			int? oid;
			DBFile result;
			long filesize;
			string gzFilename = null;

			try {
				filesize = new FileInfo (path_to_contents).Length;
				if (filesize > 1024 * 1024 * 500)
					throw new Exception ("Max file size is 500 MB");

				using (IDbCommand cmd = CreateCommand ()) {
					cmd.CommandText = "SELECT * FROM File WHERE md5 = '" + md5 + "'";
					using (IDataReader reader = cmd.ExecuteReader ()) {
						if (reader.Read ())
							return new DBFile (reader);
					}
				}

				//Console.WriteLine ("Uploading {0} {1} with compressed mime: {2}", Filename, md5, compressed_mime);

				// The file is not in the database
				// Note: there is a race condition here,
				// the same file might get added to the db before we do it here.
				// not quite sure how to deal with that except retrying the above if the insert below fails.

				if (compressed_mime == MimeTypes.GZ) {
					gzFilename = path_to_contents;
				} else {
					gzFilename = FileUtilities.GZCompress (path_to_contents);
					compressed_mime = MimeTypes.GZ;
				}

				transaction = BeginTransaction ();

				if (Configuration.StoreFilesInDB) {
					manager = new LargeObjectManager (this.dbcon);
					oid = manager.Create (LargeObjectManager.READWRITE);
					obj = manager.Open (oid.Value, LargeObjectManager.READWRITE);

					using (FileStream st = new FileStream (gzFilename, FileMode.Open, FileAccess.Read, FileShare.Read)) {
						byte [] buffer = new byte [1024];
						int read = -1;
						while (read != 0) {
							read = st.Read (buffer, 0, buffer.Length);
							obj.Write (buffer, 0, read);
						}
					}
					obj.Close ();
				} else {
					oid = null;
					string fn = FileUtilities.CreateFilename (md5, true, true);

					File.Copy (gzFilename, fn, true);
					log.DebugFormat ("Saved file to: {0}", fn);
				}

				result = new DBFile ();
				result.file_id = oid;
				result.filename = Path.GetFileName (filename);
				result.md5 = md5;
				result.size = (int) filesize;
				result.hidden = hidden;
				switch (extension.ToLower ()) {
				case ".log":
				case ".stdout":
				case ".stderr":
					result.mime = MimeTypes.LOG;
					break;
				case ".txt":
					result.mime = MimeTypes.TXT;
					break;
				case ".htm":
				case ".html":
					result.mime = MimeTypes.HTML;
					break;
				case ".png":
					result.mime = MimeTypes.PNG;
					break;
				case ".jpg":
					result.mime = MimeTypes.JPG;
					break;
				case ".bmp":
					result.mime = MimeTypes.BMP;
					break;
				case ".tar":
					result.mime = MimeTypes.TAR;
					break;
				case ".bz":
					result.mime = MimeTypes.BZ;
					break;
				case ".bz2":
					result.mime = MimeTypes.BZ2;
					break;
				case ".zip":
					result.mime = MimeTypes.ZIP; ;
					break;
				case ".gz":
					result.mime = MimeTypes.GZ;
					break;
				case ".xpi":
					result.mime = MimeTypes.XPI;
					break;
				case ".crx":
					result.mime = MimeTypes.CRX;
					break;
				default:
					result.mime = MimeTypes.OCTET_STREAM;
					break;
				}
				result.compressed_mime = compressed_mime;
				result.Save (this);

				transaction.Commit ();
				transaction = null;

				return result;
			} finally {
				FileUtilities.TryDeleteFile (gzFilename);

				if (transaction != null)
					transaction.Rollback ();
			}
		}