//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ protected OauthSession(IFabricClientConfig pConfig, IOauthService pClientOauth) { Config = pConfig; ClientOauth = pClientOauth; SessionId = Guid.NewGuid().ToString("N"); OAuthRedirectUri = pConfig.GetOauthRedirectUri(); ClearToken(); }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ public void Out(string pType, IFabricClientConfig pConfig, string pText) { IFabricSessionContainer sc = pConfig.GetSessionContainer(); IFabricPersonSession p = (sc != null ? sc.Person : null); string psId = (p == null ? Empty32 : p.SessionId); Console.WriteLine("Fabric | " + pType.PadRight(5) + " | " + psId + " | " + pText); }
/*--------------------------------------------------------------------------------------------*/ /// <summary /> public static void AddConfig(IFabricClientConfig config) { lock ( ConfigMap ) { if (!IsInit) { throw new Exception("FabricClient.InitOnce() has not been called yet."); } AttachNewConfigGroup(config); } }
/*--------------------------------------------------------------------------------------------*/ /// <summary /> public static void InitOnce(IFabricClientConfig config) { lock ( ConfigMap ) { if (IsInit) { throw new Exception("FabricClient.InitOnce() has already been called."); } IsInit = true; AttachNewConfigGroup(config); DefaultConfigKey = config.ConfigKey; JsConfig.TreatEnumAsInteger = true; } }
/*--------------------------------------------------------------------------------------------*/ /// <summary /> public FabricClient(string pConfigKey) { if (!IsInit) { throw new Exception("FabricClient.InitOnce() has not been called yet."); } if (!ConfigMap.ContainsKey(pConfigKey)) { throw new Exception("Configuration not found for configKey '" + pConfigKey + "'."); } IFabricClientConfig config = ConfigMap[pConfigKey]; Context = new ClientContext(config); Context.AppSess = AppSessMap[pConfigKey]; Context.LogInfo("New FabricClient"); Services = new FabricServices(Context); }
/*--------------------------------------------------------------------------------------------*/ private static void AttachNewConfigGroup(IFabricClientConfig pConfig) { if (pConfig == null) { throw new Exception("The provided IFabricClientConfig is null."); } if (ConfigMap.ContainsKey(pConfig.ConfigKey)) { throw new Exception("The configKey '" + pConfig.ConfigKey + "' is already in use."); } ConfigMap.Add(pConfig.ConfigKey, pConfig); var context = new ClientContext(pConfig); var services = new FabricServices(context); var appSess = new AppSession(pConfig, services.Oauth); context.AppSess = appSess; AppSessMap[pConfig.ConfigKey] = appSess; ApiVersion = services.ApiVersion; }
/*--------------------------------------------------------------------------------------------*/ public void Warn(IFabricClientConfig pConfig, string pText) { Out("Warn", pConfig, pText); }
/*--------------------------------------------------------------------------------------------*/ public void Fatal(IFabricClientConfig pConfig, string pText) { Out("Fatal", pConfig, pText); }
/*--------------------------------------------------------------------------------------------*/ public void Error(IFabricClientConfig pConfig, string pText) { Out("Error", pConfig, pText); }
/*--------------------------------------------------------------------------------------------*/ public void Debug(IFabricClientConfig pConfig, string pText) { //Out("Debug", pConfig, pText); }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ public void Info(IFabricClientConfig pConfig, string pText) { //Out("Info", pConfig, pText); }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ public AppSession(IFabricClientConfig pConfig, IOauthService pClientOauth) : base(pConfig, pClientOauth) { }
/*--------------------------------------------------------------------------------------------*/ internal abstract OauthSession NewOauthSess(IFabricClientConfig pConfig, IOauthService pClientOauth);
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ internal override OauthSession NewOauthSess(IFabricClientConfig pConfig, IOauthService pClientOauth) { return(new PersonSession(pConfig, pClientOauth)); }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ public ClientContext(IFabricClientConfig pConfig) { Config = pConfig; }