public static void BeforeFeature() { AppSettings.LocalHost = "http://localhost:3142"; IEnvironmentModel environmentModel = EnvironmentRepository.Instance.Source; environmentModel.Connect(); }
/// <summary> /// Connects to a server considering the auxilliry connection field. /// </summary> /// <param name="environment">The environment.</param> void Connect(IEnvironmentModel environment) { if (environment.IsConnected) { return; } environment.Connect(); }
static void EnsureEnvironmentConnected(IEnvironmentModel environmentModel) { var i = 0; while (!environmentModel.IsConnected) { environmentModel.Connect(); Thread.Sleep(1000); i++; if (i == 30) { Assert.Fail("Server {0} did not connect within 30 secs{1}", environmentModel.DisplayName, DateTime.Now); } } }
static void EnsureEnvironmentConnected(IEnvironmentModel environmentModel) { var i = 0; while (!environmentModel.IsConnected) { environmentModel.Connect(); Thread.Sleep(100); i++; if (i == 100) { Assert.Fail("Server {0} did not start within 10 secs", environmentModel.DisplayName); } } }
/// <summary> /// Deploys the <see cref="IResourceModel" />'s represented by the given DTO. /// </summary> /// <param name="deployDto">The DTO to be deployed.</param> /// <param name="environmentModel">The environment model to be queried.</param> public void Deploy(IDeployDto deployDto, IEnvironmentModel environmentModel) { if (deployDto == null || deployDto.ResourceModels == null || environmentModel == null || environmentModel.ResourceRepository == null) { return; } if (!environmentModel.IsConnected) { environmentModel.Connect(); } if (environmentModel.IsConnected) { foreach (var resourceModel in deployDto.ResourceModels) { environmentModel.ResourceRepository.DeployResource(resourceModel); } } }
/// <summary> /// Deploys the <see cref="IResourceModel" />'s represented by the given DTO. /// </summary> /// <param name="deployDto">The DTO to be deployed.</param> /// <param name="environmentModel">The environment model to be queried.</param> public void Deploy(IDeployDto deployDto, IEnvironmentModel environmentModel) { if(deployDto == null || deployDto.ResourceModels == null || environmentModel == null || environmentModel.ResourceRepository == null) { return; } if(!environmentModel.IsConnected) { environmentModel.Connect(); } if(environmentModel.IsConnected) { foreach(var resourceModel in deployDto.ResourceModels) { environmentModel.ResourceRepository.DeployResource(resourceModel); } } }
public void GivenHasAScheduleOf(string scheduleName, Table table) { AppSettings.LocalHost = "http://localhost:3142"; SchedulerViewModel scheduler = new SchedulerViewModel(EventPublishers.Aggregator, new DirectoryObjectPickerDialog(), new PopupController(), new TestAsyncWorker(), new Mock <IConnectControlViewModel>().Object); IEnvironmentModel environmentModel = EnvironmentRepository.Instance.Source; environmentModel.Connect(); scheduler.ScheduledResourceModel = new ClientScheduledResourceModel(environmentModel); scheduler.CurrentEnvironment = environmentModel; scheduler.CreateNewTask(); scheduler.SelectedTask.Name = ScenarioContext.Current["ScheduleName"].ToString(); scheduler.SelectedTask.OldName = "bob"; scheduler.SelectedTask.UserName = ScenarioContext.Current["UserName"].ToString(); scheduler.SelectedTask.Password = ScenarioContext.Current["Password"].ToString(); scheduler.SelectedTask.WorkflowName = ScenarioContext.Current["WorkFlow"].ToString(); scheduler.SelectedTask.NumberOfHistoryToKeep = (int)ScenarioContext.Current["HistoryCount"]; scheduler.SelectedTask.Status = (SchedulerStatus)ScenarioContext.Current["TaskStatus"]; scheduler.Errors.ClearErrors(); var task = scheduler.SelectedTask; UpdateTrigger(task, table); PrivateObject po = new PrivateObject(scheduler.CurrentEnvironment); var mockAuth = new Mock <IAuthorizationService>(); mockAuth.Setup(a => a.IsAuthorized(It.IsAny <AuthorizationContext>(), null)).Returns(true); po.SetFieldOrProperty("AuthorizationService", mockAuth.Object); ScenarioContext.Current["Scheduler"] = scheduler; try { scheduler.SaveCommand.Execute(""); } catch (Exception e) { ScenarioContext.Current["Error"] = e.Message; } }
/// <summary> /// Lookups the environments. /// <remarks> /// If <paramref name="environmentGuids"/> is <code>null</code> or empty then this returns all <see cref="enSourceType.Dev2Server"/> sources. /// </remarks> /// </summary> /// <param name="defaultEnvironment">The default environment.</param> /// <param name="environmentGuids">The environment guids to be queried; may be null.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">defaultEnvironment</exception> public IList<IEnvironmentModel> LookupEnvironments(IEnvironmentModel defaultEnvironment, IList<string> environmentGuids = null) { if (defaultEnvironment == null) { throw new ArgumentNullException("defaultEnvironment"); } var result = new List<IEnvironmentModel>(); try { defaultEnvironment.Connect(); } // ReSharper disable EmptyGeneralCatchClause catch (Exception err) // ReSharper restore EmptyGeneralCatchClause { Dev2Logger.Log.Info((err)); //Swallow exception for localhost connection } if (!defaultEnvironment.IsConnected) { return result; } var hasEnvironmentGuids = environmentGuids != null; if (hasEnvironmentGuids) { var servers = defaultEnvironment.ResourceRepository.FindResourcesByID(defaultEnvironment, environmentGuids, ResourceType.Source); foreach (var env in servers) { var payload = env.WorkflowXaml; if (payload != null) { #region Parse connection string values // Let this use of strings go, payload should be under the LOH size limit if 85k bytes ;) XElement xe = XElement.Parse(payload.ToString()); var conStr = xe.AttributeSafe("ConnectionString"); Dictionary<string, string> connectionParams = ParseConnectionString(conStr); string tmp; if (!connectionParams.TryGetValue("AppServerUri", out tmp)) { continue; } Uri appServerUri; try { appServerUri = new Uri(tmp); } catch { continue; } if (!connectionParams.TryGetValue("WebServerPort", out tmp)) { continue; } int webServerPort; if (!int.TryParse(tmp, out webServerPort)) { continue; } if (!connectionParams.TryGetValue("AuthenticationType", out tmp)) { tmp = ""; } AuthenticationType authenticationType; if (!Enum.TryParse(tmp, true, out authenticationType)) { authenticationType = AuthenticationType.Windows; } string userName; connectionParams.TryGetValue("UserName", out userName); string password; connectionParams.TryGetValue("Password", out password); #endregion var environment = CreateEnvironmentModel(env.ID, appServerUri, authenticationType, userName, password, env.DisplayName); result.Add(environment); } } } else { var servers = defaultEnvironment.ResourceRepository.FindSourcesByType<Connection>(defaultEnvironment, enSourceType.Dev2Server); if (servers != null) { foreach(var connection in servers) { if (!string.IsNullOrEmpty(connection.Address) && !string.IsNullOrEmpty(connection.WebAddress)) { result.Add(CreateEnvironmentModel(connection)); } } } } return result; }
public static bool ShowDialog(IEnvironmentModel environment, ResourceType resourceType, string resourcePath, string cateogy, string resourceId = null, string srcId = null, string resourceName = null) { const int ServiceDialogHeight = 582; const int ServiceDialogWidth = 941; bool? isSuccessful = true; if (environment == null) { throw new ArgumentNullException("environment"); } // Silly people not checking for nulls on properties that warper other properties?! ;) if (environment.Connection == null) { if (!environment.IsConnected) { environment.Connect(); } // server must not be up, just do nothing ;) if (!environment.IsConnected) { return(false); } // else we managed to connect ;) } if (environment.Connection != null) { var workspaceId = GlobalConstants.ServerWorkspaceID; string pageName; WebsiteCallbackHandler pageHandler; double width; double height; string leftTitle = string.Empty; string rightTitle = environment.Name + " (" + environment.Connection.AppServerUri + ")"; switch (resourceType) { case ResourceType.Server: pageName = "sources/server"; pageHandler = new ConnectCallbackHandler(); if (!String.IsNullOrEmpty(resourceId) && !String.IsNullOrEmpty(resourceName)) { leftTitle = "Edit - " + resourceName; } else { leftTitle = "New Server"; } width = 704; height = 520; break; case ResourceType.ServerSource: pageName = "sources/server"; pageHandler = new ConnectCallbackHandler(); if (!String.IsNullOrEmpty(resourceId) && !String.IsNullOrEmpty(resourceName)) { leftTitle = "Edit - " + resourceName; } else { leftTitle = "New Server"; } width = 704; height = 520; break; case ResourceType.DbService: pageName = "services/dbservice"; pageHandler = new DbServiceCallbackHandler(); width = ServiceDialogWidth; height = ServiceDialogHeight; break; case ResourceType.DbSource: pageName = "sources/dbsource"; srcId = resourceId; pageHandler = new SourceCallbackHandler(); width = 704; height = 517; if (!String.IsNullOrEmpty(resourceId) && !String.IsNullOrEmpty(resourceName)) { leftTitle = "Edit - " + resourceName; } else { leftTitle = "New Datbase Source"; } break; case ResourceType.PluginService: pageName = "services/pluginservice"; pageHandler = new ServiceCallbackHandler(); width = ServiceDialogWidth; height = ServiceDialogHeight; break; case ResourceType.PluginSource: pageName = "sources/pluginsource"; srcId = resourceId; pageHandler = new SourceCallbackHandler(); if (!String.IsNullOrEmpty(resourceId) && !String.IsNullOrEmpty(resourceName)) { leftTitle = "Edit - " + resourceName; } else { leftTitle = "New Plugin Source"; } width = 700; height = 517; break; case ResourceType.EmailSource: // PBI 953 - 2013.05.16 - TWR - Added pageName = "sources/emailsource"; srcId = resourceId; pageHandler = new SourceCallbackHandler(); if (!String.IsNullOrEmpty(resourceId) && !String.IsNullOrEmpty(resourceName)) { leftTitle = "Edit - " + resourceName; } else { leftTitle = "New Email Source"; } width = 704; height = 488; break; case ResourceType.WebSource: // PBI 5656 - 2013.05.20 - TWR - Added pageName = "sources/websource"; srcId = resourceId; pageHandler = new WebSourceCallbackHandler(); if (!String.IsNullOrEmpty(resourceId) && !String.IsNullOrEmpty(resourceName)) { leftTitle = "Edit - " + resourceName; } else { leftTitle = "New Web Source"; } width = 704; height = 517; break; case ResourceType.WebService: // PBI 1220 - 2013.05.20 - TWR - Added pageName = "services/webservice"; pageHandler = new ServiceCallbackHandler(); width = ServiceDialogWidth; height = ServiceDialogHeight; break; default: return(false); } var envirDisplayName = FullyEncodeServerDetails(environment.Connection); resourcePath = HttpUtility.UrlEncode(resourcePath); string selectedPath = ""; if (cateogy != null) { selectedPath = cateogy.Equals("Unassigned") || string.IsNullOrEmpty(cateogy) ? "" : cateogy; var lastIndexOf = selectedPath.LastIndexOf("\\", StringComparison.Ordinal); if (lastIndexOf != -1) { selectedPath = selectedPath.Substring(0, lastIndexOf); } selectedPath = selectedPath.Replace("\\", "\\\\"); } string relativeUriString = string.Format("{0}?wid={1}&rid={2}&envir={3}&path={4}&sourceID={5}&category={6}", pageName, workspaceId, resourceId, envirDisplayName, resourcePath, srcId, selectedPath); if (!IsTestMode) { // this must be a property ;) isSuccessful = environment.ShowWebPageDialog(SiteName, relativeUriString, pageHandler, width, height, leftTitle, rightTitle); } else { TestModeRelativeUri = relativeUriString; } } return(isSuccessful.HasValue && isSuccessful.Value); }
static void EnsureEnvironmentConnected(IEnvironmentModel environmentModel) { var i = 0; while(!environmentModel.IsConnected) { environmentModel.Connect(); Thread.Sleep(1000); i++; if (i == 30) { Assert.Fail("Server {0} did not connect within 30 secs{1}", environmentModel.DisplayName,DateTime.Now); } } }
public static bool ShowDialog(IEnvironmentModel environment, ResourceType resourceType, string resourcePath, string cateogy, string resourceId = null, string srcId = null, string resourceName = null) { const int ServiceDialogHeight = 582; const int ServiceDialogWidth = 941; bool? isSuccessful = true; if(environment == null) { throw new ArgumentNullException("environment"); } // Silly people not checking for nulls on properties that warper other properties?! ;) if(environment.Connection == null) { if(!environment.IsConnected) { environment.Connect(); } // server must not be up, just do nothing ;) if(!environment.IsConnected) { return false; } // else we managed to connect ;) } if(environment.Connection != null) { var workspaceId = GlobalConstants.ServerWorkspaceID; string pageName; WebsiteCallbackHandler pageHandler; double width; double height; string leftTitle = string.Empty; string rightTitle = environment.Name + " (" + environment.Connection.AppServerUri + ")"; switch(resourceType) { case ResourceType.Server: pageName = "sources/server"; pageHandler = new ConnectCallbackHandler(); if(!String.IsNullOrEmpty(resourceId) && !String.IsNullOrEmpty(resourceName)) { leftTitle = "Edit - " + resourceName; } else { leftTitle = "New Server"; } width = 704; height = 520; break; case ResourceType.ServerSource: pageName = "sources/server"; pageHandler = new ConnectCallbackHandler(); if(!String.IsNullOrEmpty(resourceId) && !String.IsNullOrEmpty(resourceName)) { leftTitle = "Edit - " + resourceName; } else { leftTitle = "New Server"; } width = 704; height = 520; break; case ResourceType.DbService: pageName = "services/dbservice"; pageHandler = new DbServiceCallbackHandler(); width = ServiceDialogWidth; height = ServiceDialogHeight; break; case ResourceType.DbSource: pageName = "sources/dbsource"; srcId = resourceId; pageHandler = new SourceCallbackHandler(); width = 704; height = 517; if(!String.IsNullOrEmpty(resourceId) && !String.IsNullOrEmpty(resourceName)) { leftTitle = "Edit - " + resourceName; } else { leftTitle = "New Datbase Source"; } break; case ResourceType.PluginService: pageName = "services/pluginservice"; pageHandler = new ServiceCallbackHandler(); width = ServiceDialogWidth; height = ServiceDialogHeight; break; case ResourceType.PluginSource: pageName = "sources/pluginsource"; srcId = resourceId; pageHandler = new SourceCallbackHandler(); if(!String.IsNullOrEmpty(resourceId) && !String.IsNullOrEmpty(resourceName)) { leftTitle = "Edit - " + resourceName; } else { leftTitle = "New Plugin Source"; } width = 700; height = 517; break; case ResourceType.EmailSource: // PBI 953 - 2013.05.16 - TWR - Added pageName = "sources/emailsource"; srcId = resourceId; pageHandler = new SourceCallbackHandler(); if(!String.IsNullOrEmpty(resourceId) && !String.IsNullOrEmpty(resourceName)) { leftTitle = "Edit - " + resourceName; } else { leftTitle = "New Email Source"; } width = 704; height = 488; break; case ResourceType.WebSource: // PBI 5656 - 2013.05.20 - TWR - Added pageName = "sources/websource"; srcId = resourceId; pageHandler = new WebSourceCallbackHandler(); if(!String.IsNullOrEmpty(resourceId) && !String.IsNullOrEmpty(resourceName)) { leftTitle = "Edit - " + resourceName; } else { leftTitle = "New Web Source"; } width = 704; height = 517; break; case ResourceType.WebService: // PBI 1220 - 2013.05.20 - TWR - Added pageName = "services/webservice"; pageHandler = new ServiceCallbackHandler(); width = ServiceDialogWidth; height = ServiceDialogHeight; break; default: return false; } var envirDisplayName = FullyEncodeServerDetails(environment.Connection); resourcePath = HttpUtility.UrlEncode(resourcePath); string selectedPath = ""; if(cateogy != null) { selectedPath = cateogy.Equals("Unassigned") || string.IsNullOrEmpty(cateogy) ? "" : cateogy; var lastIndexOf = selectedPath.LastIndexOf("\\", StringComparison.Ordinal); if(lastIndexOf != -1) { selectedPath = selectedPath.Substring(0, lastIndexOf); } selectedPath = selectedPath.Replace("\\", "\\\\"); } string relativeUriString = string.Format("{0}?wid={1}&rid={2}&envir={3}&path={4}&sourceID={5}&category={6}", pageName, workspaceId, resourceId, envirDisplayName, resourcePath, srcId, selectedPath); if(!IsTestMode) { // this must be a property ;) isSuccessful = environment.ShowWebPageDialog(SiteName, relativeUriString, pageHandler, width, height, leftTitle, rightTitle); } else { TestModeRelativeUri = relativeUriString; } } return isSuccessful.HasValue && isSuccessful.Value; }
/// <summary> /// Lookups the environments. /// <remarks> /// If <paramref name="environmentGuids"/> is <code>null</code> or empty then this returns all <see cref="enSourceType.Dev2Server"/> sources. /// </remarks> /// </summary> /// <param name="defaultEnvironment">The default environment.</param> /// <param name="environmentGuids">The environment guids to be queried; may be null.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">defaultEnvironment</exception> public IList <IEnvironmentModel> LookupEnvironments(IEnvironmentModel defaultEnvironment, IList <string> environmentGuids = null) { if (defaultEnvironment == null) { throw new ArgumentNullException("defaultEnvironment"); } var result = new List <IEnvironmentModel>(); try { defaultEnvironment.Connect(); } // ReSharper disable EmptyGeneralCatchClause catch (Exception) // ReSharper restore EmptyGeneralCatchClause { //Swallow exception for localhost connection } if (!defaultEnvironment.IsConnected) { return(result); } var hasEnvironmentGuids = environmentGuids != null; if (hasEnvironmentGuids) { var servers = defaultEnvironment.ResourceRepository.FindResourcesByID(defaultEnvironment, environmentGuids, ResourceType.Source); foreach (var env in servers) { var payload = env.WorkflowXaml; if (payload != null) { #region Parse connection string values // Let this use of strings go, payload should be under the LOH size limit if 85k bytes ;) XElement xe = XElement.Parse(payload.ToString()); var conStr = xe.AttributeSafe("ConnectionString"); Dictionary <string, string> connectionParams = ParseConnectionString(conStr); string tmp; if (!connectionParams.TryGetValue("AppServerUri", out tmp)) { continue; } Uri appServerUri; try { appServerUri = new Uri(tmp); } catch { continue; } if (!connectionParams.TryGetValue("WebServerPort", out tmp)) { continue; } int webServerPort; if (!int.TryParse(tmp, out webServerPort)) { continue; } if (!connectionParams.TryGetValue("AuthenticationType", out tmp)) { tmp = ""; } AuthenticationType authenticationType; if (!Enum.TryParse(tmp, true, out authenticationType)) { authenticationType = AuthenticationType.Windows; } string userName; connectionParams.TryGetValue("UserName", out userName); string password; connectionParams.TryGetValue("Password", out password); #endregion var environment = CreateEnvironmentModel(env.ID, appServerUri, authenticationType, userName, password, env.DisplayName); result.Add(environment); } } } else { var servers = defaultEnvironment.ResourceRepository.FindSourcesByType <Connection>(defaultEnvironment, enSourceType.Dev2Server); if (servers != null) { result.AddRange(from env in servers let uri = new Uri(env.Address) select CreateEnvironmentModel(env)); } } return(result); }