public void SaveDatabaseConfiguration(string id, DatabaseInfo data) { using (var session = DocumentStoreLocator.Resolve(DocumentStoreLocator.RootLocation)) { var database = session.Load <DatabaseInfo>(id); if (database == null) { database = new DatabaseInfo { Application = "Control Aware", DatabaseSchemaVersion = "1.0.0.0", InstallDate = DateTime.UtcNow, Url = data.Url, }; session.Store(database); } database.Url = data.Url; session.SaveChanges(); } SaveGlobalConfigItem(new GlobalConfigItem { Name = GlobalConfigItemEnum.DefaultDataConnection.EnumName(), Value = data.Url }, GlobalConfigItemEnum.DefaultDataConnection.EnumName()); }
public Invitation GetInvitationByAuthCode(string code) { var invitingTenant = InvitationAuthCode.GetInvitingTenancyFromCode(code); if (!string.IsNullOrEmpty(invitingTenant)) { Invitation invitation; using ( var session = invitingTenant.Equals( DefaultRoles.SuperAdmin, StringComparison.InvariantCultureIgnoreCase) ? DocumentStoreLocator.ResolveOrRoot(CommonConfiguration.CoreDatabaseRoute) : DocumentStoreLocator.Resolve( string.Format( "{0}{1}/{2}", DocumentStoreLocator.SchemeRavenRoute, UnikContextTypes.UnikTenantContextResourceKind, invitingTenant))) { invitation = SearchInvitationByCode(code, session); } return(invitation); } return(null); }
public DatabaseInfo GetDataBaseConfiguration(string id) { using (var session = DocumentStoreLocator.Resolve(DocumentStoreLocator.RootLocation)) { var dataBaseInfo = session.Load <DatabaseInfo>(id); if (dataBaseInfo == null) { var cf = GetGlobalConfig(); var url = ErrorLoadingConfigValue; if (cf.ContainsKey(GlobalConfigItemEnum.DefaultDataConnection.EnumName())) { url = cf[GlobalConfigItemEnum.DefaultDataConnection.EnumName()].Value; } return(new DatabaseInfo { Url = url }); } return(dataBaseInfo); } }
private static void DistributeDefaultApplications(IDocumentSession coreSession, IEnumerable <Tenant> tenants) { var log = ClassLogger.Create(typeof(ApplicationManager)); var applications = new List <Application>(); var query = (from apps in coreSession.Query <Application>() select apps).ToList(); if (query.Any()) { applications.AddRange(query); } foreach (var tenant in tenants) { using (var session = DocumentStoreLocator.Resolve(tenant.Site)) { var q = (from apps in session.Query <Application>() select apps).ToList(); if (!q.Any()) { Storage(ref applications); foreach (var app in applications) { session.Store(app); log.InfoFormat("The {0} Application has been Stored in {1} Tenant sucessfully", app.Name, tenant.Name); } } session.SaveChanges(); } } }
public void SetAlertHandled(string applicationNodeId, string alertId) { try { using (var dc = DocumentStoreLocator.Resolve(DocumentStoreLocator.RootLocation)) { var item = dc.Load <ApplicationNode>(applicationNodeId); if (null != item) { var alertItem = item.Alerts.FirstOrDefault(it => it.Id == alertId); if (null != alertItem) { item.Alerts.Remove(alertItem); dc.Advanced.UseOptimisticConcurrency = false; dc.SaveChanges(); } } } } catch (Exception ex) { var aa = Catalog.Factory.Resolve <IApplicationAlert>(); aa.RaiseAlert(ApplicationAlertKind.System, ex.TraceInformation()); } }
public void ConfigureLogging(string applicationNodeId, string filter = null, int level = -1, string file = null) { var loggingConfig = new LoggingConfiguration { ClassFilter = filter, File = file, LogLevel = level }; try { using (var dc = DocumentStoreLocator.Resolve(DocumentStoreLocator.RootLocation)) { var item = dc.Load <ApplicationNode>(applicationNodeId); if (null != item) { item.LoggingConfiguration = loggingConfig; dc.SaveChanges(); } } } catch (Exception ex) { var aa = Catalog.Factory.Resolve <IApplicationAlert>(); aa.RaiseAlert(ApplicationAlertKind.System, ex.TraceInformation()); } }
private IDictionary <string, GlobalConfigItem> GetGlobalConfig() { using (var session = DocumentStoreLocator.Resolve(DocumentStoreLocator.RootLocation)) { var qry = session.Query <GlobalConfigItem>(); return(qry.GetAllUnSafe().ToDictionary(it => it.Name)); } }
//catch an event that any caller can catch when a tenant is created //then the caller can create indexes or any other actions private void TenantHelperOnTenantCreated(object sender, TenantCreatedArgs tenantCreatedArgs) { //Put your code when a tenant is created on the DB using (var tenantSession = DocumentStoreLocator.Resolve(tenantCreatedArgs.TenantDocumentDBSite)) { IndexesManager.CreateIndexes(tenantSession.Advanced.DocumentStore, tenantCreatedArgs.TenantName, typeof(SchedulePlanByTagFullPath)); } }
public void CreateDatabaseConfiguration(DatabaseInfo data) { _log.DebugFormat("Save Application Node [{0}]. databse Url [{1}]", data.Url); using (var session = DocumentStoreLocator.Resolve(DocumentStoreLocator.RootLocation)) { session.Store(data); session.SaveChanges(); } }
public IEnumerable <Invitation> GetInvitationsFrom(string id) { var tenancy = string.Empty; var tenancyUris = ContextRegistry.ContextsOf("Tenancy"); var invitations = new List <Invitation>(); if (tenancyUris.Any()) { tenancy = tenancyUris.First().Segments.LastOrDefault(); } if (!string.IsNullOrEmpty(tenancy) && tenancy.Equals( DefaultRoles.SuperAdmin.ToString(CultureInfo.InvariantCulture), StringComparison.InvariantCultureIgnoreCase)) { using (var session = DocumentStoreLocator.ResolveOrRoot(CommonConfiguration.CoreDatabaseRoute)) { var q = session.Query <Invitation>().Where( invitation => invitation.Status != InvitationStatus.Deleted && invitation.InvitingUserId == id); invitations.AddRange(q); } var tenantCollection = new TenantManager().GetAllTenants(); foreach (var tenant in tenantCollection) { using (var globalSession = DocumentStoreLocator.Resolve(tenant.Site)) { var q = globalSession.Query <Invitation>().Where( invitation => invitation.Status != InvitationStatus.Deleted && invitation.InvitingUserId == id); invitations.AddRange(q); } } return(invitations); } using (var session = ReturnContext(tenancy)) { var q = session.Query <Invitation>().Where( invitation => invitation.Status != InvitationStatus.Deleted && invitation.InvitingUserId == id); return(q.ToArray()); } }
public static void CreateIndexes(string dbName, Type indexType) { using ( var session = DocumentStoreLocator.Resolve( string.Format( "{0}{1}/{2}", DocumentStoreLocator.SchemeRavenRoute, UnikContextTypes.UnikTenantContextResourceKind, dbName))) { CreateIndexes(session.Advanced.DocumentStore, dbName, indexType); } }
public bool RejectInvitation(Invitation invitation) { try { using (var session = ReturnContext()) { var invit = session.Load <Invitation>(invitation.Id); if (invit != null) { if (invitation.AcceptingUser != null) { invit.AcceptingUser.Status = UserStatus.RejectInvitation; } invit.Status = InvitationStatus.Rejected; session.SaveChanges(); } else { var tenants = session.Query <Tenant>().ToArray(); foreach (Tenant tenant in tenants) { using (var tenantContext = DocumentStoreLocator.Resolve(tenant.Site)) { var invitationTenant = tenantContext.Load <Invitation>(invitation.Id); if (invitationTenant != null) { if (invitationTenant.AcceptingUser != null) { invitationTenant.AcceptingUser.Status = UserStatus.RejectInvitation; } invitationTenant.Status = InvitationStatus.Rejected; tenantContext.SaveChanges(); break; } } } } } } catch (Exception ex) { _log.ErrorFormat("InvitationManager: An exception occurred with the following message: {0}", ex.Message); _applicationAlert.RaiseAlert(ApplicationAlertKind.System, ex.TraceInformation()); } return(true); }
public Invitation GetInvitationById(Guid id) { Invitation invitation; using (var session = ReturnContext()) { invitation = session.Load <Invitation>(id); if (invitation != null) { invitation.AcceptingUser = session.Load <ApplicationUser>(invitation.AcceptingAppUserId); } } if (invitation == null) { if (TenantManager.CurrentTenancy.Equals( DefaultRoles.SuperAdmin, StringComparison.InvariantCultureIgnoreCase)) { var tenants = new TenantManager().GetAllTenants(); foreach (var tenant in tenants) { using (var tenantSession = DocumentStoreLocator.Resolve(tenant.Site)) { invitation = tenantSession.Load <Invitation>(id); } if (invitation != null) { break; } } } } if (invitation != null && (invitation.AcceptingUser == null && !invitation.Role.Equals(DefaultRoles.SuperAdmin, StringComparison.InvariantCultureIgnoreCase))) { using (var coreSession = DocumentStoreLocator.ResolveOrRoot(CommonConfiguration.CoreDatabaseRoute)) { invitation.AcceptingUser = coreSession.Load <ApplicationUser>(invitation.AcceptingAppUserId); } } return(invitation); }
public void AddHotfix(string hotfixId) { using (var dc = DocumentStoreLocator.Resolve(DocumentStoreLocator.RootLocation)) { var an = dc.Load <ApplicationNode>(_reg.Id); if (null == an) { throw new ApplicationNodeNotInstalledException(); } if (!an.HotfixNames.Contains(hotfixId)) { an.HotfixNames.Add(hotfixId); dc.SaveChanges(); } } }
/// <summary> /// Saves the item registration /// </summary> /// <param name="registrationCode"></param> /// <returns></returns> public bool SaveItemRegistration(Lok.Unik.ModelCommon.ItemRegistration.ItemRegistration registrationCode) { using (var session = DocumentStoreLocator.Resolve(DocumentStoreLocator.RootLocation)) { var itemRegistrationCode = session.Query <Lok.Unik.ModelCommon.ItemRegistration.ItemRegistration>().FirstOrDefault(dr => dr.PassCode == registrationCode.PassCode); if (null != itemRegistrationCode) { return(false); } registrationCode.TimeRegistered = DateTime.UtcNow; session.Store(registrationCode); session.SaveChanges(); return(true); } }
public IEnumerable <ApplicationNode> GetTopology() { try { using (var dc = DocumentStoreLocator.Resolve(DocumentStoreLocator.RootLocation)) { var qry = (IRavenQueryable <ApplicationNode>)dc.Query <ApplicationNode>(); var all = qry.GetAllUnSafe(); return(all); } } catch (Exception ex) { var aa = Catalog.Factory.Resolve <IApplicationAlert>(); aa.RaiseAlert(ApplicationAlertKind.System, ex.TraceInformation()); } return(null); }
/// <summary> /// Registers an item on a previous invite. /// </summary> /// <param name="registrationCode"></param> /// <param name="itemRegistrationCode"></param> /// <returns>Result of the registration operation.</returns> public ItemRegistrationResult RegisterItem(string registrationCode, out Lok.Unik.ModelCommon.ItemRegistration.ItemRegistration itemRegistrationCode) { var itemId = Guid.NewGuid(); var retval = new Lok.Unik.ModelCommon.ItemRegistration.ItemRegistrationResult { ItemId = itemId, PassCodeName = registrationCode, Result = ResultCode.RegistrationAccepted }; using (var coreSession = DocumentStoreLocator.Resolve(DocumentStoreLocator.RootLocation)) { // get the item matching the given registration code itemRegistrationCode = coreSession.Query <Lok.Unik.ModelCommon.ItemRegistration.ItemRegistration>().FirstOrDefault(dr => dr.PassCode == registrationCode); // not found? registration not accepted. if (null == itemRegistrationCode) { retval.ItemId = Guid.Empty; retval.AuthCode = string.Empty; retval.Result = ResultCode.RegistrationInvalidPasscode; return(retval); } // save the item authorization code used to log it in var ac = new Lok.Unik.ModelCommon.ItemRegistration.AuthCode { Principal = itemId.ToString(), AuthCodeId = Guid.NewGuid(), Code = AuthorizationCode.GenerateCode(), Tenant = itemRegistrationCode.TenancyId }; retval.AuthCode = ac.Code; retval.PassCodeId = itemRegistrationCode.Id; coreSession.Store(ac); coreSession.SaveChanges(); } return(retval); }
public void LocalInstall( string id, string componentType, string version, string requiredDB, string dbConnection, string dbName, string dbUN, string dbPW) { _reg.DBConnection = dbConnection; _reg.DBPassword = dbPW; _reg.DBUser = dbUN; _reg.RootDB = dbName; using (var dc = DocumentStoreLocator.Resolve(DocumentStoreLocator.RootLocation)) { var db = dc.Load <DatabaseInfo>(_product); if (null == db) { throw new ApplicationNodeNotInstalledException("Database"); } if (db.DatabaseSchemaVersion != requiredDB) { throw new ApplicationNodeNotInstalledException(string.Format("Require database {0}", requiredDB)); } } if (string.IsNullOrEmpty(_reg.Id)) { _reg.Id = id; } if (string.IsNullOrEmpty(_reg.ComponentType)) { _reg.ComponentType = componentType; } else { _reg.ComponentType = _reg.ComponentType + ", " + componentType; } _reg.Version = version; _reg.InstallDate = DateTime.UtcNow; }
public void PauseNode(string applicationNodeId) { try { using (var dc = DocumentStoreLocator.Resolve(DocumentStoreLocator.RootLocation)) { var item = dc.Load <ApplicationNode>(applicationNodeId); if (null != item) { item.State = ApplicationNodeStates.Paused; dc.SaveChanges(); } } } catch (Exception ex) { var aa = Catalog.Factory.Resolve <IApplicationAlert>(); aa.RaiseAlert(ApplicationAlertKind.System, ex.TraceInformation()); } }
private void SaveGlobalConfigItem(GlobalConfigItem info, string configItemName) { using (var session = DocumentStoreLocator.Resolve(DocumentStoreLocator.RootLocation)) { var item = session.Load <GlobalConfigItem>(configItemName); if (item != null) { item.Value = info.Value; } else { item = new GlobalConfigItem { Value = info.Value, Name = configItemName }; session.Store(item); } session.SaveChanges(); } }
public void SaveGlobalConfigItem(GlobalConfigItem info) { using (var session = DocumentStoreLocator.Resolve(DocumentStoreLocator.RootLocation)) { var item = session.Load <GlobalConfigItem>(GlobalConfigItemEnum.DistributedFileShare.ToString()); if (item != null) { item.Value = info.Value; } else { item = new GlobalConfigItem { Value = info.Value, Name = GlobalConfigItemEnum.DistributedFileShare.ToString() }; session.Store(item); } session.SaveChanges(); } }
/// <summary> /// saves the item registration with tags /// </summary> /// <param name="name"> </param> /// <param name="passcode"></param> /// <param name="type"></param> /// <param name="newTags"></param> /// <param name="selectTag"></param> /// <param name="facilityId"> </param> /// <returns></returns> public bool SaveItemRegistration( string name, string passcode, string type, IList <Tag> newTags, IList <string> selectTag, string facilityId = null) { using (var session = DocumentStoreLocator.Resolve(DocumentStoreLocator.RootLocation)) { var tenancy = ContextRegistry.ContextsOf("Tenancy").First().Segments[1]; var query = from entity in session.Query <Lok.Unik.ModelCommon.ItemRegistration.ItemRegistration>() where entity.TenancyId == tenancy select entity; // all item registrations in the tenant var dRegistration = query.ToArray(); var oldTag = new List <Tag>(); // list of existing tags matching the selection var oldTagFind = new List <Tag>(); if (null != selectTag && selectTag.Count > 0) { // record all distinct tags used for all registered items oldTag.AddRange(dRegistration.SelectMany(deviceRegistration => deviceRegistration.Tags)); oldTag = oldTag.Distinct().ToList(); // for every tag selected foreach (var tag2 in selectTag.Where(tag => !string.IsNullOrEmpty(tag))) { var tag3 = tag2; // find all recorded tags matching the selection tags foreach (var tag1 in oldTag.Where(tag1 => tag3.Equals(tag1.Value))) { oldTagFind.Add(tag1); break; } } } oldTagFind = oldTagFind.Distinct().ToList(); foreach (var old in oldTagFind) { newTags.Add(old); } // retain all old tags, add in a grouping tag var dr = new Lok.Unik.ModelCommon.ItemRegistration.ItemRegistration { Id = Guid.NewGuid(), TenancyId = tenancy, PassCode = passcode, Name = name, Tags = newTags, TimeRegistered = DateTime.UtcNow, Type = type, FacilityId = facilityId }; //Add Default Tag for Grouping. dr.Tags.Add( new Tag { Id = Guid.NewGuid(), Type = TagType.ItemRegistration, Attribute = dr.Name, Value = dr.PassCode, CreateDate = DateTime.UtcNow, Category = new TagCategory { Name = TagType.ItemRegistration.EnumName(), Color = KnownColor.Transparent } }); session.Store(dr); session.SaveChanges(); return(true); } }
private void Action(object o) { try { using (var dc = DocumentStoreLocator.Resolve(DocumentStoreLocator.RootLocation)) { var qry = (IRavenQueryable <GlobalConfigItem>)dc.Query <GlobalConfigItem>(); var all = qry.GetAllUnSafe(); lock (_lock) { foreach (var globalConfigItem in all) { if (null == globalConfigItem.Value) { continue; } _cache[globalConfigItem.Name] = globalConfigItem.Value; var settings = ConfigurationManager.AppSettings; try { if (settings.AllKeys.Contains(globalConfigItem.Name)) { settings.Remove(globalConfigItem.Name); } settings.Add(globalConfigItem.Name, globalConfigItem.Value); } catch { // config is read-only ... } if (globalConfigItem.Name == CommonConfiguration.DefaultDataConnection.EnumName()) { if (_reg.DBConnection != globalConfigItem.Value) { _reg.DBConnection = globalConfigItem.Value; } } if (globalConfigItem.Name == CommonConfiguration.DefaultDataDatabase.EnumName()) { if (_reg.RootDB != globalConfigItem.Value) { _reg.RootDB = globalConfigItem.Value; } } if (globalConfigItem.Name == CommonConfiguration.DefaultDataUser.EnumName()) { if (_reg.DBUser != globalConfigItem.Value) { _reg.DBUser = globalConfigItem.Value; } } if (globalConfigItem.Name == CommonConfiguration.DefaultDataPassword.EnumName()) { if (_reg.DBPassword != globalConfigItem.Value) { _reg.DBPassword = globalConfigItem.Value; } } if (globalConfigItem.Name == CommonConfiguration.DistributedFileShare.EnumName()) { if (_reg.DBPassword != globalConfigItem.Value) { _reg.FileShare = globalConfigItem.Value; } } } } } } catch (Exception ex) { _log.Fatal(ex.TraceInformation()); if (Catalog.Factory.CanResolve <IApplicationAlert>()) { var aa = Catalog.Factory.Resolve <IApplicationAlert>(); aa.RaiseAlert(ApplicationAlertKind.System, ex.TraceInformation()); } } }
public static void MaybeInitDefaults() { try { for (int retry = 0; retry < 5; retry++) { try { if (retry > 0) { System.Threading.Thread.Sleep(500); } using (var dc = DocumentStoreLocator.Resolve(DocumentStoreLocator.RootLocation)) { var qry = (IRavenQueryable <GlobalConfigItem>)dc.Query <GlobalConfigItem>(); var config = qry.GetAllUnSafe().ToDictionary(it => it.Name); bool changed = false; var dbi = dc.Query <DatabaseInfo>().FirstOrDefault(); string dbUrl = (null == dbi) ? AssResource.RavenGlobalConfig_MaybeInitDefaults_RavenDB_database_url : dbi.Url; changed = changed || MaybeInitDefault(dc, config, GlobalConfigItemEnum.DistributedFileShare, AssResource.RavenGlobalConfig_MaybeInitDefaults_set_distributed_file_path); changed = changed || MaybeInitDefault(dc, config, GlobalConfigItemEnum.EmailServer, AssResource.RavenGlobalConfig_MaybeInitDefaults_set_email_server); changed = changed || MaybeInitDefault(dc, config, GlobalConfigItemEnum.UseSSL, "false"); changed = changed || MaybeInitDefault(dc, config, GlobalConfigItemEnum.DefaultDataConnection, dbUrl); changed = changed || MaybeInitDefault(dc, config, GlobalConfigItemEnum.EmailPort, AssResource.RavenGlobalConfig_MaybeInitDefaults_set_email_port); changed = changed || MaybeInitDefault(dc, config, GlobalConfigItemEnum.EmailAccount, AssResource.RavenGlobalConfig_MaybeInitDefaults_set_email_account_name); changed = changed || MaybeInitDefault(dc, config, GlobalConfigItemEnum.EmailPassword, AssResource.RavenGlobalConfig_MaybeInitDefaults_set_email_account_password); changed = changed || MaybeInitDefault(dc, config, GlobalConfigItemEnum.UseSSL, AssResource.RavenGlobalConfig_MaybeInitDefaults_email_uses_ssl); if (changed) { dc.SaveChanges(); } } break; } catch (ConcurrencyException) // lots of potential for // these due to race conditions // between application nodes { } } } catch (Exception ex) { var aa = Catalog.Factory.Resolve <IApplicationAlert>(); aa.RaiseAlert(ApplicationAlertKind.Unknown, ex.TraceInformation()); } }
public void DoTransactNodeInfo( IEnumerable <NodeMetric> currentMetrics, DateTime metricsCollectionTime, IEnumerable <NodeAlert> newAlerts, int activityLevel, out ApplicationNodeStates desiredState, out LoggingConfiguration desiredLogging) { desiredState = ApplicationNodeStates.Running; desiredLogging = null; try { using (var dc = DocumentStoreLocator.Resolve(DocumentStoreLocator.RootLocation)) { // try to load existing node var appNode = dc.Load <ApplicationNode>(_reg.Id); // create new if necessary bool created = false; if (null == appNode) { _log.Warn("Creating application node record"); created = true; appNode = new ApplicationNode { Id = _reg.Id, ComponentType = _reg.ComponentType, MachineName = Environment.MachineName, State = ApplicationNodeStates.Running, Version = _reg.Version, IPAddress = GetLocalIP(), LoggingConfiguration = new LoggingConfiguration { ClassFilter = "none", File = _logFilePath, LogLevel = 0 } }; } // update node data desiredLogging = appNode.LoggingConfiguration; desiredState = appNode.State; appNode.LastPing = DateTime.UtcNow; appNode.MetricCollectionTime = metricsCollectionTime; appNode.Metrics = currentMetrics.ToList(); appNode.Alerts.AddRange(newAlerts); appNode.ActivityLevel = activityLevel; if (created) { dc.Store(appNode); } dc.SaveChanges(); } } catch (ConcurrencyException) { // just get it next time } catch (Exception ex) { _log.Error(ex.TraceInformation()); _alert.RaiseAlert(ApplicationAlertKind.Unknown, ex.TraceInformation()); } }
public void RegisterServerConfig() { try { Catalog.Services.Register <IConfig>(SpecialFactoryContexts.Safe, _ => new ApplicationConfiguration()); Catalog.Services.Register <IRecurrence <object> >(_AppDomain => new ThreadedRecurrence <object>()); var globalConfig = Catalog.Preconfigure() .Add(ApplicationTopologyLocalConfig.CompanyKey, TopologyPath.Company) .Add(ApplicationTopologyLocalConfig.ApplicationKey, TopologyPath.Product) .ConfiguredCreate(() => new RavenGlobalConfig()); Catalog.Services.Register <IConfig>( _ => new AggregateConfiguration(globalConfig, new ApplicationConfiguration())).AsAssemblerSingleton(); Catalog.Services.Register <IConfig>(SpecialFactoryContexts.Safe, _ => globalConfig); globalConfig.Start(); using (var dc = DocumentStoreLocator.Resolve(DocumentStoreLocator.RootLocation)) { var db = dc.Load <DatabaseInfo>(TopologyPath.Product); if (null == db) { db = new DatabaseInfo { Application = TopologyPath.Product, DatabaseSchemaVersion = TopologyPath.DBVersion, InstallDate = DateTime.UtcNow, Url = "http://localhost:8080/raven/" }; dc.Store(db); var fc = new GlobalConfigItem { Name = "DistributedFileShare", Value = "C:\\Lok\\AppData" }; dc.Store(fc); var email = new EmailServerInfo() { Application = TopologyPath.EmailServerShared, ConfiguredDate = DateTime.UtcNow, IsSsl = false, SmtpServer = "localhost", Username = "******", Password = "******", Port = 10 }; dc.Store(email); dc.SaveChanges(); } } var installer = Catalog.Preconfigure() .Add(ApplicationTopologyLocalConfig.CompanyKey, TopologyPath.Company) .Add(ApplicationTopologyLocalConfig.ApplicationKey, TopologyPath.Product) .ConfiguredCreate(() => new RavenTopologyInstaller()); installer.LocalInstall( Guid.NewGuid().ToString(), "Development Environment", TopologyPath.Version, TopologyPath.DBVersion, "http://localhost:8080", "Control", "Admin", "b1f08cc1-7130-49d4-bffa-cd1211d2a743"); Console.WriteLine("Complete."); } catch (Exception ex) { Console.WriteLine(ex.TraceInformation()); } }
public void RegisterServerNodes() { try { Catalog.Services.Register <IConfig>(SpecialFactoryContexts.Safe, _ => new ApplicationConfiguration()); Catalog.Services.Register <IRecurrence <object> >(_AppDomain => new ThreadedRecurrence <object>()); var globalConfig = Catalog.Preconfigure() .Add(ApplicationTopologyLocalConfig.CompanyKey, TopologyPath.Company) .Add(ApplicationTopologyLocalConfig.ApplicationKey, TopologyPath.Product) .ConfiguredCreate(() => new RavenGlobalConfig()); Catalog.Services.Register <IConfig>( _ => new AggregateConfiguration(globalConfig, new ApplicationConfiguration())).AsAssemblerSingleton(); Catalog.Services.Register <IConfig>(SpecialFactoryContexts.Safe, _ => globalConfig); globalConfig.Start(); using (var dc = DocumentStoreLocator.Resolve(DocumentStoreLocator.RootLocation)) { ApplicationNode node = new ApplicationNode() { Id = Guid.NewGuid().ToString(), ComponentType = "Rest Server", MachineName = "Server 12", State = ApplicationNodeStates.Running, LastPing = DateTime.UtcNow, ActivityLevel = 1, Version = "1.1", RequiredDBVersion = "1.2" }; dc.Store(node); node = new ApplicationNode() { Id = Guid.NewGuid().ToString(), ComponentType = "Control Server", MachineName = "Server 13", State = ApplicationNodeStates.Running, LastPing = DateTime.UtcNow, ActivityLevel = 1, Version = "1.1", RequiredDBVersion = "1.2" }; dc.Store(node); node = new ApplicationNode() { Id = Guid.NewGuid().ToString(), ComponentType = "Task Hub Server", MachineName = "Server 13", State = ApplicationNodeStates.Running, LastPing = DateTime.UtcNow, ActivityLevel = 1, Version = "1.1", RequiredDBVersion = "1.2" }; dc.Store(node); dc.SaveChanges(); } var list = new List <ApplicationNode>(); using (var session = DocumentStoreLocator.Resolve(DocumentStoreLocator.RootLocation)) { var val = session.Query <ApplicationNode>(); list = val.ToList(); } foreach (var node in list) { Console.WriteLine("ID Node {0}, IP Address {1}", node.Id, node.IPAddress); } } catch (Exception e) { Console.WriteLine("Error [{0}] Stack trace [{1}]", e.Message, e.StackTrace); } }
public IDevice RegisterItem(ItemRegistrationResult itemRegistrationResult, ItemRegistration itemRegistration) { var net = new NetworkConfig { IpAddress = "128.0.0.1", MacAddress = "macAddress", MachineName = "name", DefaultGateway = "198.0.0.2", SubnetMask = "200.200.200.1" }; var os = new OSInfo { OsName = "nameOS", OsType = "Win", OsVersion = "10", OsBits = 64, OsDate = "34-34-34" }; var dev = new DeviceInfo { Processor = "proc", MemoryInBytes = "123", PrinterName = "canon", NumberOfMonitors = 3, PrimaryMonitorName = "primary mon" }; var path = string.Format( "{0}{1}/{2}", DocumentStoreLocator.SchemeRavenRoute, DocumentStoreLocator.GetStoreType(), itemRegistration.TenancyId); IDevice device; using (var session = DocumentStoreLocator.Resolve(path)) { var tagsDevRegistration = itemRegistration.Tags.Where(tag => tag.Category.Color != KnownColor.Transparent).ToList(); var name = string.Format("Device {0}", DateTime.UtcNow.ToShortTimeString()); tagsDevRegistration.Add( new Tag { Id = Guid.NewGuid(), Type = TagType.Device, Attribute = name, Value = itemRegistration.Id.ToString(), CreateDate = DateTime.UtcNow, Category = new TagCategory { Name = name, Color = KnownColor.Transparent } }); device = new Kiosk { Id = itemRegistrationResult.ItemId, Name = name, Description = string.Format("Kiosk Device Created {0}", DateTime.UtcNow.ToShortDateString()), Model = DeviceType.Kiosk.ToString(), TimeRegistered = DateTime.UtcNow, CurrentStatus = HealthStatus.Green, Tags = tagsDevRegistration, Inventory = new WindowsInventory { NetworkConfig = net, OSInfo = os, DeviceInfo = dev }, }; session.Store(device); var ev = new DeviceAuthorizationEvent { DeviceId = itemRegistrationResult.ItemId, InitialTags = tagsDevRegistration, IpAddress = HttpContext.Current == null ? string.Empty : HttpContext.Current.Request.UserHostAddress, PasscodeUsed = itemRegistrationResult.PassCodeName, TimeRegistered = DateTime.UtcNow }; session.Store(ev); session.SaveChanges(); } return(device); }