public ClientData Import (IDataStoreContext ctx, ClientJson json, Guid? localIdHint = null, ClientData mergeBase = null) { var data = GetByRemoteId<ClientData> (ctx, json.Id.Value, localIdHint); var merger = mergeBase != null ? new ClientMerger (mergeBase) : null; if (merger != null && data != null) merger.Add (new ClientData (data)); if (json.DeletedAt.HasValue) { if (data != null) { ctx.Delete (data); data = null; } } else if (merger != null || ShouldOverwrite (data, json)) { data = data ?? new ClientData (); ImportJson (ctx, data, json); if (merger != null) { merger.Add (data); data = merger.Result; } data = ctx.Put (data); } return data; }
public void ImportNew() { RunAsync(async delegate { var workspaceData = await DataStore.PutAsync(new WorkspaceData() { RemoteId = 1, Name = "Test", ModifiedAt = new DateTime(2014, 1, 2), }); var clientJson = new ClientJson() { Id = 2, Name = "Github", WorkspaceId = 1, ModifiedAt = new DateTime(2014, 1, 3), }; var clientData = await DataStore.ExecuteInTransactionAsync(ctx => converter.Import(ctx, clientJson)); Assert.AreNotEqual(Guid.Empty, clientData.Id); Assert.AreEqual(2, clientData.RemoteId); Assert.AreEqual("Github", clientData.Name); Assert.AreEqual(new DateTime(2014, 1, 3), clientData.ModifiedAt); Assert.AreEqual(workspaceData.Id, clientData.WorkspaceId); Assert.IsFalse(clientData.IsDirty); Assert.IsFalse(clientData.RemoteRejected); Assert.IsNull(clientData.DeletedAt); }); }
public static ClientData Import(this ClientJson json, IDataStoreContext ctx, Guid?localIdHint = null, ClientData mergeBase = null) { var converter = ServiceContainer.Resolve <ClientJsonConverter> (); return(converter.Import(ctx, json, localIdHint, mergeBase)); }
public void ImportPastDeleted() { RunAsync(async delegate { var workspaceData = await DataStore.PutAsync(new WorkspaceData() { RemoteId = 1, Name = "Test", ModifiedAt = new DateTime(2014, 1, 2), }); var clientData = await DataStore.PutAsync(new ClientData() { RemoteId = 2, Name = "Github", WorkspaceId = workspaceData.Id, ModifiedAt = new DateTime(2014, 1, 3), }); var clientJson = new ClientJson() { Id = 2, DeletedAt = new DateTime(2014, 1, 2), }; var ret = await DataStore.ExecuteInTransactionAsync(ctx => converter.Import(ctx, clientJson)); Assert.IsNull(ret); var rows = await DataStore.Table <ClientData> ().QueryAsync(m => m.Id == clientData.Id); Assert.That(rows, Has.Exactly(0).Count); }); }
public void ImportUpdatedKeepDirtyLocal() { RunAsync(async delegate { var workspaceData = await DataStore.PutAsync(new WorkspaceData() { RemoteId = 1, Name = "Test", ModifiedAt = new DateTime(2014, 1, 2), }); var clientData = await DataStore.PutAsync(new ClientData() { RemoteId = 2, Name = "", WorkspaceId = workspaceData.Id, ModifiedAt = new DateTime(2014, 1, 2, 10, 0, 0, DateTimeKind.Utc), IsDirty = true, }); var clientJson = new ClientJson() { Id = 2, Name = "Github", WorkspaceId = 1, ModifiedAt = new DateTime(2014, 1, 2, 10, 0, 0, DateTimeKind.Utc).ToLocalTime(), }; clientData = await DataStore.ExecuteInTransactionAsync(ctx => converter.Import(ctx, clientJson)); Assert.AreEqual("", clientData.Name); Assert.AreEqual(new DateTime(2014, 1, 2, 10, 0, 0, DateTimeKind.Utc), clientData.ModifiedAt); }); }
public ClientData Import(IDataStoreContext ctx, ClientJson json, Guid?localIdHint = null, ClientData mergeBase = null) { var log = ServiceContainer.Resolve <Logger> (); var data = GetByRemoteId <ClientData> (ctx, json.Id.Value, localIdHint); var merger = mergeBase != null ? new ClientMerger(mergeBase) : null; if (merger != null && data != null) { merger.Add(new ClientData(data)); } if (json.DeletedAt.HasValue) { if (data != null) { log.Info(Tag, "Deleting local data for {0}.", data.ToIdString()); ctx.Delete(data); data = null; } } else if (merger != null || ShouldOverwrite(data, json)) { data = data ?? new ClientData(); ImportJson(ctx, data, json); if (merger != null) { merger.Add(data); data = merger.Result; } if (merger != null) { log.Info(Tag, "Importing {0}, merging with local data.", data.ToIdString()); } else { log.Info(Tag, "Importing {0}, replacing local data.", data.ToIdString()); } data = ctx.Put(data); } else { log.Info(Tag, "Skipping import of {0}.", json.ToIdString()); } return(data); }
public ClientData Import (IDataStoreContext ctx, ClientJson json, Guid? localIdHint = null, bool forceUpdate = false) { var data = GetByRemoteId<ClientData> (ctx, json.Id.Value, localIdHint); if (json.DeletedAt.HasValue) { if (data != null) { ctx.Delete (data); data = null; } } else if (data == null || forceUpdate || data.ModifiedAt < json.ModifiedAt) { data = data ?? new ClientData (); Merge (ctx, data, json); data = ctx.Put (data); } return data; }
public void ImportUpdated() { RunAsync(async delegate { var workspaceData = await DataStore.PutAsync(new WorkspaceData() { RemoteId = 1, Name = "Test", ModifiedAt = new DateTime(2014, 1, 2), }); var clientData = await DataStore.PutAsync(new ClientData() { RemoteId = 2, Name = "", WorkspaceId = workspaceData.Id, ModifiedAt = new DateTime(2014, 1, 2, 10, 0, 0, DateTimeKind.Utc), }); var clientJson = new ClientJson() { Id = 2, Name = "Github", WorkspaceId = 1, ModifiedAt = new DateTime(2014, 1, 2, 10, 1, 0, DateTimeKind.Utc).ToLocalTime(), // JSON deserialized to local }; clientData = await DataStore.ExecuteInTransactionAsync(ctx => converter.Import(ctx, clientJson)); Assert.AreNotEqual(Guid.Empty, clientData.Id); Assert.AreEqual(2, clientData.RemoteId); Assert.AreEqual("Github", clientData.Name); Assert.AreEqual(new DateTime(2014, 1, 2, 10, 1, 0, DateTimeKind.Utc), clientData.ModifiedAt); Assert.AreEqual(workspaceData.Id, clientData.WorkspaceId); Assert.IsFalse(clientData.IsDirty); Assert.IsFalse(clientData.RemoteRejected); Assert.IsNull(clientData.DeletedAt); }); // Warn the user that the test result might be invalid if (TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).TotalMinutes >= 0) { Assert.Inconclusive("The test machine timezone should be set to GTM-1 or less to test datetime comparison."); } }
static string Remap_tablespace(ClientJson config) { if (!config.RemapTablespaceHabilitado) { return(string.Empty); } StringBuilder linhaCmd = new StringBuilder(); linhaCmd.Append("remap_tablespace=("); Action <string, ClientJson> remap = (x, y) => linhaCmd.Append($"{x}:{y.Tablespace},"); config.RemapTablespace.ToList().ForEach(x => remap(x, config)); linhaCmd.Remove(linhaCmd.Length - 1, 1); linhaCmd.Append(") "); return(linhaCmd.ToString()); }
public void ImportMissingWorkspace() { RunAsync(async delegate { var clientJson = new ClientJson() { Id = 2, Name = "Github", WorkspaceId = 1, ModifiedAt = new DateTime(2014, 1, 3), }; var clientData = await DataStore.ExecuteInTransactionAsync(ctx => converter.Import(ctx, clientJson)); Assert.AreNotEqual(Guid.Empty, clientData.WorkspaceId); var rows = await DataStore.Table <WorkspaceData> ().QueryAsync(m => m.Id == clientData.WorkspaceId); var workspaceData = rows.FirstOrDefault(); Assert.IsNotNull(workspaceData); Assert.IsNotNull(workspaceData.RemoteId); Assert.AreEqual(DateTime.MinValue, workspaceData.ModifiedAt); }); }
public ClientData Import (IDataStoreContext ctx, ClientJson json, Guid? localIdHint = null, ClientData mergeBase = null) { var log = ServiceContainer.Resolve<ILogger> (); var data = GetByRemoteId<ClientData> (ctx, json.Id.Value, localIdHint); var merger = mergeBase != null ? new ClientMerger (mergeBase) : null; if (merger != null && data != null) { merger.Add (new ClientData (data)); } if (json.DeletedAt.HasValue) { if (data != null) { log.Info (Tag, "Deleting local data for {0}.", data.ToIdString ()); ctx.Delete (data); data = null; } } else if (merger != null || ShouldOverwrite (data, json)) { data = data ?? new ClientData (); ImportJson (ctx, data, json); if (merger != null) { merger.Add (data); data = merger.Result; } if (merger != null) { log.Info (Tag, "Importing {0}, merging with local data.", data.ToIdString ()); } else { log.Info (Tag, "Importing {0}, replacing local data.", data.ToIdString ()); } data = ctx.Put (data); } else { log.Info (Tag, "Skipping import of {0}.", json.ToIdString ()); } return data; }
private static void ImportJson (IDataStoreContext ctx, ClientData data, ClientJson json) { data.Name = json.Name; data.WorkspaceId = GetLocalId<WorkspaceData> (ctx, json.WorkspaceId); ImportCommonJson (data, json); }
public Task DeleteClient(ClientJson jsonObject) { var url = new Uri(v8Url, String.Format("clients/{0}", jsonObject.Id.Value.ToString())); return(DeleteObject(url)); }
public Task <ClientJson> CreateClient(ClientJson jsonObject) { var url = new Uri(v8Url, "clients"); return(CreateObject(url, jsonObject)); }
private static void ImportJson(IDataStoreContext ctx, ClientData data, ClientJson json) { data.Name = json.Name; data.WorkspaceId = GetLocalId <WorkspaceData> (ctx, json.WorkspaceId); ImportCommonJson(data, json); }
public void CreateConfig() { string pathCmd = Path.Combine(Directory.GetCurrentDirectory(), "client_command"); if (!Directory.Exists(pathCmd)) { throw new DomainException($"Directory not found. {pathCmd}"); } using (StreamReader file = File.OpenText(_pathCfg)) { _clientJson = JsonConvert.DeserializeObject <ClientJson>(file.ReadToEnd()); } string datahora = DateTime.Now.ToString("yyyy-MM-ddTHH-mm-ss"); string fileCommand = Path.Combine(pathCmd, $"command_{_clientJson.Cliente.ToLower()}_{datahora}.txt"); string tableSpaceName = _clientJson.Cliente.ToUpper(); string tnsNames = _clientJson.TnsNames.ToUpper(); StringBuilder linhaCmd = new StringBuilder(); linhaCmd.AppendLine("( Abrir o prompt com permissão de admin )"); linhaCmd.AppendLine(string.Empty.PadRight(111, '-')); linhaCmd.AppendLine(); linhaCmd.AppendLine("( Editando o tnsnames.ora )"); linhaCmd.AppendLine(string.Empty.PadRight(111, '-')); linhaCmd.AppendLine(); linhaCmd.AppendLine(string.Empty.PadRight(111, '=')); linhaCmd.AppendLine(tnsNames + " ="); linhaCmd.AppendLine(" (DESCRIPTION ="); linhaCmd.AppendLine(" (SOURCE_ROUTE = on)"); linhaCmd.AppendLine(" (CONNECT_TIMEOUT = 10) (RETRY_COUNT = 3) (RETRY_DELAY = 2)"); linhaCmd.AppendLine(" (COMPRESSION = on)"); linhaCmd.AppendLine(" (COMPRESSION_LEVELS = (LEVEL = high))"); linhaCmd.AppendLine(" (ADDRESS = (PROTOCOL = TCP) (HOST = " + _clientJson.BaseIpAddress + ") (PORT = " + _clientJson.BasePort + ") (IP = first))"); linhaCmd.AppendLine(" (CONNECT_DATA = (SERVER = DEDICATED) (SID = " + _clientJson.OraInst + "))"); linhaCmd.AppendLine(" )"); linhaCmd.AppendLine(string.Empty.PadRight(111, '=')); linhaCmd.AppendLine(); linhaCmd.AppendLine("( Editando arquivo sqlora.net )"); linhaCmd.AppendLine(string.Empty.PadRight(111, '-')); linhaCmd.AppendLine(); linhaCmd.AppendLine(string.Empty.PadRight(111, '=')); linhaCmd.AppendLine("NAMES.DIRECTORY_PATH= (TNSNAMES, HOSTNAME, LDAP)"); linhaCmd.AppendLine("##NAMES.DEFAULT_DOMAIN = ORACLE.COM"); linhaCmd.AppendLine("TRACE_LEVEL_CLIENT = ON"); linhaCmd.AppendLine("##SQLNET.EXPIRE_TIME = 30"); linhaCmd.AppendLine("SQLNET.IDENTIX_FINGERPRINT_DATABASE = FINGRDB"); linhaCmd.AppendLine("AUTOMATIC_IPC = ON"); linhaCmd.AppendLine("SQLNET.EXPIRE_TIME = 0"); linhaCmd.AppendLine("SQLNET.AUTHENTICATION_SERVICES = (ALL)"); linhaCmd.AppendLine("SQLNET.CRYPTO_CHECKSUM_CLIENT = ACCEPTED"); linhaCmd.AppendLine("##TNSPING.TRACE_DIRECTORY = /oracle/traces"); linhaCmd.AppendLine(string.Empty.PadRight(111, '=')); linhaCmd.AppendLine(); linhaCmd.AppendLine(string.Empty.PadRight(111, '=')); linhaCmd.AppendLine(@"sqlplus /nolog"); linhaCmd.AppendLine(@"connect sys/viewinfo@" + tnsNames + " as sysdba;"); linhaCmd.AppendLine("grant all privileges to system with admin option;"); linhaCmd.AppendLine("grant resource, connect, dba, advisor, sysdba, sysoper to system with admin option;"); linhaCmd.AppendLine("quit"); linhaCmd.AppendLine(); linhaCmd.AppendLine(string.Empty.PadRight(111, '=')); linhaCmd.AppendLine(@"sqlplus " + _clientJson.UserNameBase + @"/" + _clientJson.PasswordBase + "@" + tnsNames + " as sysdba"); linhaCmd.AppendLine("set linesize 500;"); linhaCmd.AppendLine("set pagesize 1000;"); linhaCmd.AppendLine(); _clientJson.UsersDump.ToList().ForEach(x => linhaCmd.AppendLine($"drop user {x} cascade;")); linhaCmd.AppendLine("commit;"); linhaCmd.AppendLine(); linhaCmd.AppendLine(string.Empty.PadRight(111, '=')); linhaCmd.AppendLine("select distinct"); linhaCmd.AppendLine(" owner"); linhaCmd.AppendLine("from"); linhaCmd.AppendLine(" dba_tables"); linhaCmd.AppendLine("where"); linhaCmd.AppendLine($" tablespace_name='{tableSpaceName}';"); linhaCmd.AppendLine(); linhaCmd.AppendLine("select"); linhaCmd.AppendLine(" owner,"); linhaCmd.AppendLine(" constraint_name,"); linhaCmd.AppendLine(" table_name,"); linhaCmd.AppendLine(" index_owner,"); linhaCmd.AppendLine(" index_name"); linhaCmd.AppendLine("from"); linhaCmd.AppendLine(" dba_constraints"); linhaCmd.AppendLine("where"); linhaCmd.AppendLine($" (index_owner,index_name) in (select owner, index_name from dba_indexes where tablespace_name ='{tableSpaceName}')"); linhaCmd.AppendLine(); linhaCmd.AppendLine($"drop tablespace {tableSpaceName} including contents and datafiles cascade constraints;"); linhaCmd.AppendLine("commit;"); linhaCmd.AppendLine(); linhaCmd.AppendLine($"create bigfile tablespace {tableSpaceName} datafile '{_clientJson.TablespaceDir}\\{tableSpaceName}.DBF' size 10000M autoextend on;"); linhaCmd.AppendLine("commit;"); linhaCmd.AppendLine(); linhaCmd.AppendLine("select"); linhaCmd.AppendLine(" username,"); linhaCmd.AppendLine(" default_tablespace,"); linhaCmd.AppendLine(" temporary_tablespace"); linhaCmd.AppendLine("from"); linhaCmd.AppendLine(" dba_users"); linhaCmd.AppendLine("where"); linhaCmd.Append(" username in ("); _clientJson.UsersDump.ToList().ForEach(x => linhaCmd.Append($"'{x}',")); linhaCmd.Remove(linhaCmd.Length - 1, 1); linhaCmd.AppendLine(");"); linhaCmd.AppendLine(); linhaCmd.AppendLine("SELECT"); linhaCmd.AppendLine(" TABLESPACE_NAME,"); linhaCmd.AppendLine(" ROUND((USED_SPACE * (8192 / 1048576))) AS USED_SPACE, --Espaço em MB"); linhaCmd.AppendLine(" ROUND((TABLESPACE_SIZE * (8192 / 1048576))) AS TABLESPACE_SIZE, --Espaço em MB"); linhaCmd.AppendLine(" ROUND(((USED_SPACE / TABLESPACE_SIZE) * 100)) || '%' AS PERCENT_USED"); linhaCmd.AppendLine("FROM"); linhaCmd.AppendLine(" DBA_TABLESPACE_USAGE_METRICS"); linhaCmd.AppendLine("WHERE"); linhaCmd.AppendLine($" TABLESPACE_NAME IN('SYSTEM', '{tableSpaceName}')"); linhaCmd.AppendLine(); linhaCmd.AppendLine(string.Empty.PadRight(111, '=')); foreach (string user in _clientJson.UsersDump) { linhaCmd.AppendLine($"create user {user} default tablespace {tableSpaceName} identified by {_clientJson.PasswordUser} quota unlimited on users;"); linhaCmd.AppendLine($"grant all privileges to {user} with admin option;"); linhaCmd.AppendLine($"grant resource, connect, dba, advisor, sysdba, sysoper to {user} with admin option;"); linhaCmd.AppendLine(); } linhaCmd.AppendLine("commit;"); linhaCmd.AppendLine(); linhaCmd.AppendLine($"drop directory {_clientJson.Cliente};"); linhaCmd.AppendLine("commit;"); linhaCmd.AppendLine(); linhaCmd.AppendLine($"create directory {_clientJson.Cliente} as '{_clientJson.DirDump}';"); linhaCmd.AppendLine("commit;"); linhaCmd.AppendLine(); linhaCmd.AppendLine(string.Empty.PadRight(111, '=')); linhaCmd.AppendLine($"impdp {_clientJson.UserNameBase}/{_clientJson.PasswordBase}@{tnsNames} directory={_clientJson.Cliente} dumpfile={_clientJson.FileNameDump} logfile=IMPDP_{_clientJson.Cliente}_{datahora}.log table_exists_action=replace transform=segment_attributes:n {Remap_tablespace(_clientJson)} full=y data_options=SKIP_CONSTRAINT_ERRORS"); linhaCmd.AppendLine(); linhaCmd.AppendLine(string.Empty.PadRight(111, '=')); linhaCmd.AppendLine($"imp {_clientJson.UserNameBase}/{_clientJson.PasswordBase}@{tnsNames} fromuser={_clientJson.UsersDump[0]} touser={_clientJson.UsersDump[0]} file={_clientJson.FileNameDump} log=IMP_{_clientJson.Cliente}_{datahora}.log ignore=y commit=y"); // Executando a gravação do arquivo de comando. using (StreamWriter fileCmd = File.CreateText(fileCommand)) { fileCmd.WriteLine(linhaCmd); } }