/// <summary> /// Instantiate a new OracleDatabase instance using the specified serverName /// connectionName and credentials /// </summary> /// <param name="directoryPath"></param> /// <param name="connectionName"></param> public OracleDatabase(string serverName, string connectionName, OracleCredentials creds = null) : base() { ConnectionStringResolver = new OracleConnectionStringResolver(serverName, creds); ConnectionName = connectionName; Register(); }
public async Task BasicConnectivityTest() { using var connection = new OracleConnection(OracleCredentials.GetConnectionString(TestContext.CurrentContext.TestDirectory)); await connection.OpenAsync(); using var command = connection.CreateCommand(); command.CommandText = "SELECT 10 FROM DUAL"; (await command.ExecuteScalarAsync()).ShouldEqual(10); }
public async Task TestCommandImplicitlyParticipatesInTransaction() { using var connection = new OracleConnection(OracleCredentials.GetConnectionString(TestContext.CurrentContext.TestDirectory)); await connection.OpenAsync(); using var transaction = connection.BeginTransaction(); using var command = connection.CreateCommand(); command.Transaction.ShouldEqual(transaction); }
protected override void Initialize() { OracleDatabase database = new OracleDatabase(); OracleCredentials creds = new OracleCredentials { UserId = OracleUserId, Password = OraclePassword }; OracleConnectionStringResolver conn = new OracleConnectionStringResolver { ServerName = OracleServerName, InstanceName = OracleInstanceName, Port = OraclePort, Credentials = creds }; database.ConnectionStringResolver = conn; Database = database; }
public void TestOracleSqlProvider() { string serverName = "chumsql2"; OracleJavaScriptSqlProvider db = new OracleJavaScriptSqlProvider(); OracleCredentials creds = new OracleCredentials { UserId = "C##ORACLEUSER", Password = "******" }; OracleDatabase oracle = new OracleDatabase(); oracle.ConnectionStringResolver = new OracleConnectionStringResolver { ServerName = serverName, Port = "1521", InstanceName = "orcl", Credentials = creds }; db.Database = oracle; RunTestQuery(db); }
/// <summary> /// Instantiate a new OracleDatabase instance using the specified serverName and /// credentials /// </summary> public OracleDatabase(string serverName, OracleCredentials creds = null) : this(serverName, "Oracle", creds) { }
public string SetDocument(string xml, string sender, string receiver, string fasti2sender, string fasti2receiver, string cspProfile, string documentType) { OracleCredentials oracleCredentials = new OracleCredentials(); oracleCredentials.Database = settings.DatabaseServer; oracleCredentials.User = settings.DatabaseUsername; oracleCredentials.Password = settings.DatabaseUserPassword; OracleConnectionClass oracle = new OracleConnectionClass(oracleCredentials); Logger.setOracleConnector(oracle); settings.CspProfile = cspProfile; string result = "0"; string id = ""; string file = ""; string error = ""; XmlDocument signed = null; string reference = "", confirmation = ""; int errorCode = 0; try { XmlDocument document = new XmlDocument(); document.LoadXml(xml); signed = SignDocument(document, sender, receiver); id = signed.DocumentElement["SignedData"]["Data"]["Root"]["DocumentUniqueIdentifier"].InnerText; file = documentType + id + ".xml"; result = "1"; signed.Save(settings.OutXmlDir + file); } catch (ArgumentException) { error = "Неверный формат XML файла"; Logger.Add(LoggerEventsType.ERROR, "Неверный формат XML файла " + id); } catch (Exception ex) { error = ex.Message; Logger.Add(ex); } if (!String.IsNullOrEmpty(error)) { errorCode = -1; } if (errorCode != -1) { error = fasti2.SendMessage(fasti2sender, fasti2receiver, settings.CspProfile, /* Ref */ out reference, /* Conf */ out confirmation); if (!String.IsNullOrEmpty(error)) { errorCode = -1; } } XDocument answer = new XDocument( new XDeclaration("1.0", Encoding.GetEncoding("UTF-8").HeaderName, "yes"), new XElement("root", new XElement("Result", result), new XElement("DocumentUniqueIdentifier", id), new XElement("FileName", file), new XElement("Reference", reference), new XElement("Confirmation", confirmation), new XElement("Error", error), new XElement("ErrorCode", errorCode), new XElement("SignedXml", XElement.Parse(signed.OuterXml)) ) ); return(answer.ToString()); }
public String GetAnswers(string receiver, string cspProfile) { string file_name_err = ""; try { OracleCredentials oracleCredentials = new OracleCredentials(); oracleCredentials.Database = settings.DatabaseServer; oracleCredentials.User = settings.DatabaseUsername; oracleCredentials.Password = settings.DatabaseUserPassword; OracleConnectionClass oracle = new OracleConnectionClass(oracleCredentials); Logger.setOracleConnector(oracle); Logger.Add(LoggerEventsType.UNKNOWN, "receiver = " + receiver + "\r\ncspProfile = " + cspProfile); fasti2.ReceiveMessages(receiver, cspProfile); var nonXmlFiles = Array.FindAll(Directory.GetFiles(settings.InXmlDir), x => !x.EndsWith(".xml")); foreach (var file in nonXmlFiles) { string new_file_name = "", eng_file_name = "", new_eng_file_name = ""; try { eng_file_name = new_eng_file_name = oracle.Transliterate(Path.GetFileName(file)); if (!File.Exists(settings.WebServerKfmFilesDir + eng_file_name) && !File.Exists(settings.InNonXmlDir + Path.GetFileName(file))) { new_file_name = Path.GetFileName(file); File.Copy(file, settings.WebServerKfmFilesDir + eng_file_name); File.Move(file, settings.InNonXmlDir + Path.GetFileName(file)); } else { int j = 1; while (true) { new_file_name = j.ToString() + "_" + Path.GetFileName(file); new_eng_file_name = j.ToString() + "_" + eng_file_name; if (!File.Exists(settings.WebServerKfmFilesDir + new_eng_file_name) && !File.Exists(settings.InNonXmlDir + new_file_name)) { File.Copy(file, settings.WebServerKfmFilesDir + new_eng_file_name); File.Move(file, settings.InNonXmlDir + new_file_name); break; } j++; } } oracle.SaveKfmFilename(new_file_name + "/" + new_eng_file_name, File.GetLastWriteTime(settings.InNonXmlDir + new_file_name)); Logger.Add(LoggerEventsType.DEBUG, "File " + new_file_name + " successfully moved to NoXmlFilesDir and copied to web-server. Eng Name: " + new_eng_file_name); } catch (Exception ex) { Logger.Add(LoggerEventsType.ERROR, "Try to copy and move file. Initial name: " + file + ". Final name: " + new_file_name + ". Eng Name: " + new_eng_file_name + ". " + ex.ToString()); } } var files = Directory.GetFiles(settings.InXmlDir, "*.xml"); XmlDocument document = new XmlDocument(); foreach (var file in files) { file_name_err = Path.GetFileName(file); document.Load(file); var status = SignatureValidateStatus.Valid; // Verify(document); string originalid; string version; string id; try { originalid = document.DocumentElement["SignedData"]["Data"]["Check"]["OriginalDocumentGuid"].InnerText; version = document.DocumentElement["SignedData"]["Data"]["Check"]["Version"].InnerText; id = document.DocumentElement["SignedData"]["Data"]["Check"]["DocumentUniqueIdentifier"].InnerText; } catch (Exception ex) { Logger.Add(ex); Logger.Add(LoggerEventsType.ERROR, "Не возможно получить доступ к объектам:"); try { originalid = document.DocumentElement["SignedData"]["Data"]["Root"]["OriginalDocumentGuid"].InnerText; version = document.DocumentElement["SignedData"]["Data"]["Root"]["Version"].InnerText; id = document.DocumentElement["SignedData"]["Data"]["Root"]["DocumentUniqueIdentifier"].InnerText; } catch (Exception e) { Logger.Add(e); Logger.Add(LoggerEventsType.ERROR, "Не возможно получить доступ к объектам:"); Logger.Add(LoggerEventsType.ERROR, "Файл " + file + " некоректный."); continue; } } decimal errorcode = -1; string error; if (status == SignatureValidateStatus.Valid) { try { try { errorcode = decimal.Parse(document.DocumentElement["SignedData"]["Data"]["Check"]["ErrorCode"].InnerText); error = document.DocumentElement["SignedData"]["Data"]["Check"]["ErrorName"].InnerText; } catch { errorcode = decimal.Parse(document.DocumentElement["SignedData"]["Data"]["Root"]["ErrorCode"].InnerText); error = document.DocumentElement["SignedData"]["Data"]["Root"]["ErrorName"].InnerText; } oracle.SaveReceiveMessage(id, errorcode, error, document.OuterXml, id, version, originalid); } catch (Exception e) { Logger.Add(e); string description = ""; try { description = document.DocumentElement["SignedData"]["Data"]["Root"]["Description"].InnerText; description += " Количество дней на ответ: " + document.DocumentElement["SignedData"]["Data"]["Root"]["CountDays"].InnerText; } finally { oracle.SaveReceiveMessage(id, 0, description, document.OuterXml, id, version, originalid); } } } else { oracle.SaveReceiveMessage(id, -1 * (int)status, Enum.GetName(typeof(SignatureValidateStatus), status), document.OuterXml, id, version, originalid); } try { File.Move(file, fasti2.GetArchiveDayFolder(settings.InXmlDirArchive) + Path.GetFileName(file)); } catch (Exception ex) { File.Delete(file); Logger.Add(ex); } } } catch (Exception e) { Logger.Add(e); if (File.Exists(settings.InXmlErrDir + file_name_err)) { File.Move(settings.InXmlDir + file_name_err, settings.InXmlErrDir + "exists_" + file_name_err); } else { File.Move(settings.InXmlDir + file_name_err, settings.InXmlErrDir + file_name_err); } return(e.Message + "\nИмя некорректного файла: " + file_name_err); } return(""); }
public static int Main(string[] args) { var type = args[0]; var name = args[1]; IDisposable?handle; switch (type) { case nameof(SqlDistributedLock): handle = new SqlDistributedLock(name, SqlServerCredentials.ConnectionString).Acquire(); break; case "Write" + nameof(SqlDistributedReaderWriterLock): handle = new SqlDistributedReaderWriterLock(name, SqlServerCredentials.ConnectionString).AcquireWriteLock(); break; case nameof(SqlDistributedSemaphore) + "1AsMutex": handle = new SqlDistributedSemaphore(name, maxCount: 1, connectionString: SqlServerCredentials.ConnectionString).Acquire(); break; case nameof(SqlDistributedSemaphore) + "5AsMutex": handle = new SqlDistributedSemaphore(name, maxCount: 5, connectionString: SqlServerCredentials.ConnectionString).Acquire(); break; case nameof(PostgresDistributedLock): handle = new PostgresDistributedLock(new PostgresAdvisoryLockKey(name), PostgresCredentials.GetConnectionString(Environment.CurrentDirectory)).Acquire(); break; case "Write" + nameof(PostgresDistributedReaderWriterLock): handle = new PostgresDistributedReaderWriterLock(new PostgresAdvisoryLockKey(name), PostgresCredentials.GetConnectionString(Environment.CurrentDirectory)).AcquireWriteLock(); break; case nameof(MySqlDistributedLock): handle = new MySqlDistributedLock(name, MySqlCredentials.GetConnectionString(Environment.CurrentDirectory)).Acquire(); break; case "MariaDB" + nameof(MySqlDistributedLock): handle = new MySqlDistributedLock(name, MariaDbCredentials.GetConnectionString(Environment.CurrentDirectory)).Acquire(); break; case nameof(OracleDistributedLock): handle = new OracleDistributedLock(name, OracleCredentials.GetConnectionString(Environment.CurrentDirectory)).Acquire(); break; case "Write" + nameof(OracleDistributedReaderWriterLock): handle = new OracleDistributedReaderWriterLock(name, OracleCredentials.GetConnectionString(Environment.CurrentDirectory)).AcquireWriteLock(); break; case nameof(EventWaitHandleDistributedLock): handle = new EventWaitHandleDistributedLock(name).Acquire(); break; case nameof(WaitHandleDistributedSemaphore) + "1AsMutex": handle = new WaitHandleDistributedSemaphore(name, maxCount: 1).Acquire(); break; case nameof(WaitHandleDistributedSemaphore) + "5AsMutex": handle = new WaitHandleDistributedSemaphore(name, maxCount: 5).Acquire(); break; case nameof(AzureBlobLeaseDistributedLock): handle = new AzureBlobLeaseDistributedLock( new BlobClient(AzureCredentials.ConnectionString, AzureCredentials.DefaultBlobContainerName, name), o => o.Duration(TimeSpan.FromSeconds(15)) ) .Acquire(); break; case nameof(FileDistributedLock): handle = new FileDistributedLock(new FileInfo(name)).Acquire(); break; case nameof(RedisDistributedLock) + "1": handle = AcquireRedisLock(name, serverCount: 1); break; case nameof(RedisDistributedLock) + "3": handle = AcquireRedisLock(name, serverCount: 3); break; case nameof(RedisDistributedLock) + "2x1": handle = AcquireRedisLock(name, serverCount: 2); // we know the last will fail; don't bother (we also don't know its port) break; case nameof(RedisDistributedLock) + "1WithPrefix": handle = AcquireRedisLock("distributed_locks:" + name, serverCount: 1); break; case "Write" + nameof(RedisDistributedReaderWriterLock) + "1": handle = AcquireRedisWriteLock(name, serverCount: 1); break; case "Write" + nameof(RedisDistributedReaderWriterLock) + "3": handle = AcquireRedisWriteLock(name, serverCount: 3); break; case "Write" + nameof(RedisDistributedReaderWriterLock) + "2x1": handle = AcquireRedisWriteLock(name, serverCount: 2); // we know the last will fail; don't bother (we also don't know its port) break; case "Write" + nameof(RedisDistributedReaderWriterLock) + "1WithPrefix": handle = AcquireRedisWriteLock("distributed_locks:" + name, serverCount: 1); break; case string _ when type.StartsWith(nameof(RedisDistributedSemaphore)): { var maxCount = type.EndsWith("1AsMutex") ? 1 : type.EndsWith("5AsMutex") ? 5 : throw new ArgumentException(type); handle = new RedisDistributedSemaphore( name, maxCount, GetRedisDatabases(serverCount: 1).Single(), // in order to see abandonment work in a reasonable timeframe, use very short expiry options => options.Expiry(TimeSpan.FromSeconds(1)) .BusyWaitSleepTime(TimeSpan.FromSeconds(.1), TimeSpan.FromSeconds(.3)) ).Acquire(); break; } case nameof(ZooKeeperDistributedLock): handle = new ZooKeeperDistributedLock(new ZooKeeperPath(name), ZooKeeperPorts.DefaultConnectionString, options: ZooKeeperOptions).AcquireAsync().Result; break; case "Write" + nameof(ZooKeeperDistributedReaderWriterLock): handle = new ZooKeeperDistributedReaderWriterLock(new ZooKeeperPath(name), ZooKeeperPorts.DefaultConnectionString, options: ZooKeeperOptions).AcquireWriteLockAsync().Result; break; case string _ when type.StartsWith(nameof(ZooKeeperDistributedSemaphore)): { var maxCount = type.EndsWith("1AsMutex") ? 1 : type.EndsWith("5AsMutex") ? 5 : throw new ArgumentException(type); handle = new ZooKeeperDistributedSemaphore( new ZooKeeperPath(name), maxCount, ZooKeeperPorts.DefaultConnectionString, options: ZooKeeperOptions ).AcquireAsync().Result; break; } default: Console.Error.WriteLine($"type: {type}"); return(123); } Console.WriteLine("Acquired"); Console.Out.Flush(); if (Console.ReadLine() != "abandon") { handle.Dispose(); } return(0); }