示例#1
0
        private List <Application> ReadApplications()
        {
            Log.Info(typeof(Database), "Reading application data...");

            try
            {
                using (var connection = new SqliteConnection(Settings.SQLiteConnectionString))
                {
                    PersistenceStorage.PersistentDataContext persistenceDb = new PersistenceStorage.PersistentDataContext(connection);
                    List <Application> applications = new List <Application>();

                    foreach (PersistenceStorage.Application persistenceApp in persistenceDb.Application.ToList())
                    {
                        Monoscape.Common.Model.Application app = new Monoscape.Common.Model.Application();
                        app.Id       = persistenceApp.ID;
                        app.Name     = persistenceApp.Name;
                        app.Version  = persistenceApp.Version;
                        app.State    = ConvertApplicationState(persistenceApp.State.ToString());
                        app.FileName = persistenceApp.FilePath;
                        app.Tenants  = ConvertTenants(persistenceApp.Tenant);
                        app.RowState = EntityState.Queried;
                        applications.Add(app);
                    }
                    Log.Info(typeof(Database), applications.Count + " applications found");
                    return(applications);
                }
            }
            catch (Exception e)
            {
                Log.Error(typeof(Database), "Could not connect to the database", e);
                throw e;
            }
        }
示例#2
0
 public static bool ApplicationExists(Application application)
 {
     foreach (Application app in Database.Applications)
     {
         if (application.Id == app.Id)
             return true;
     }
     return false;
 }
示例#3
0
        public Application Clone()
        {
            Application clone = new Application();
            clone.Id = Id;
            clone.Name = Name;
            clone.Version = Version;
            clone.FileName = FileName;
            clone.State = State;

            clone.ApplicationInstances = new List<ApplicationInstance>();
            foreach (ApplicationInstance instance in ApplicationInstances)
                clone.ApplicationInstances.Add(instance.Clone());

            clone.RowState = RowState;
            clone.RowVersion = RowVersion;
            return clone;
        }
示例#4
0
        private ApplicationInstance StartWebServer(Application application, Tenant tenant, int port)
        {
            try {
                string xsp = Settings.WindowsXSPWebServerPath;
                if (MonoscapeUtil.IsRunningOnMono () && (Environment.OSVersion.Platform == PlatformID.Unix))
                    xsp = Settings.UnixXSPWebServerPath;

                string arguments = "--port " + port + " --applications /" + tenant.Name.Replace (" ", "").ToLower () + "/" + MonoscapeUtil.PrepareApplicationVirtualFolderName (application.Name) + ":.";
                string workingDirectory = PrepareApplicationDeployPath (application, tenant.Name, port);
                var p = new Process ()
                {
                    StartInfo = new ProcessStartInfo(xsp, arguments)
                    {
                        RedirectStandardOutput = false,
                        RedirectStandardError = false,
                        UseShellExecute = false,
                        CreateNoWindow = true,
                        WorkingDirectory = workingDirectory
                    }
                };
                if (p.Start ()) {
                    Database.LastWebServerPort = port;
                    ApplicationInstance instance = new ApplicationInstance ();
                    instance.Id = FindNextInstanceId (application);
                    instance.ProcessId = p.Id;
                    instance.ApplicationId = application.Id;
                    instance.ApplicationName = application.Name;
                    instance.NodeId = Database.Node.Id;
                    instance.IpAddress = Database.Node.IpAddress;
                    instance.Port = port;
                    instance.Tenant = tenant;
                    instance.CreatedTime = DateTime.Now;
                    instance.State = "Started";
                    instance.Url = "http://" + instance.IpAddress + ":" + instance.Port + "/" + tenant.Name.Replace (" ", "").ToLower () + "/" + MonoscapeUtil.PrepareApplicationVirtualFolderName (application.Name);

                    Database.ChildProcesses.Add (p);
                    Log.Info (typeof(NcApplicationGridService), "Started web server: " + instance.Url);
                    return instance;
                }
                else {
                    Database.ChildProcesses.Add (p);
                    Log.Error (typeof(NcApplicationGridService), "Could not start web server for application " + application.Name + " " + application.Version);
                    return null;
                }
            }
            catch (Exception e) {
                Log.Error (this, "Could not start web server");
                throw e;
            }
        }
示例#5
0
 private int FindNextInstanceId(Application application)
 {
     int nextId = 1;
     if ((application.ApplicationInstances != null) && (application.ApplicationInstances.Count > 0)) {
         ApplicationInstance lastInstance = application.ApplicationInstances.OrderByDescending (x => x.Id).FirstOrDefault ();
         return lastInstance.Id + 1;
     }
     return nextId;
 }
示例#6
0
        private int ExtractApplicationPackage(Application app, string tenantName)
        {
            try {
                string filePath = Path.Combine (Settings.ApplicationStorePath, app.FileName);
                if (!MonoscapeUtil.WebConfigExistsInRoot (filePath))
                    throw new MonoscapeException ("Application package is not valid. Re-package the application without any folders and try again.");

                int port = (Database.LastWebServerPort + 1);
                string extractPath = PrepareApplicationDeployPath (app, tenantName, port);

                if (Directory.Exists (extractPath)) {
                    // Remove previously extracted application content
                    Directory.Delete (extractPath, true);
                    Directory.CreateDirectory (extractPath);
                }
                else if (!Directory.Exists (Settings.ApplicationDeployPath)) {
                    // Create application deployment path
                    Directory.CreateDirectory (Settings.ApplicationDeployPath);
                }

                SharpZip.Extract (extractPath, filePath);
                return port;
            }
            catch (Exception e) {
                throw new MonoscapeException ("Application package extraction failed", e);
            }
        }
示例#7
0
 private static string PrepareApplicationDeployPath(Application app, string tenantName, int port)
 {
     return Settings.ApplicationDeployPath + Path.DirectorySeparatorChar + app.Name + " - " + app.Version + " - " + tenantName + " - " + port;
 }
        public UploadApplicationResponse UploadApplication(UploadApplicationRequest request)
        {
            Log.Info(this, "UploadApplication()");

            try
            {
                UploadApplicationResponse response = new UploadApplicationResponse();

                string basePath = GetApplicationStorePath();
                if (!Directory.Exists(basePath))
                    Directory.CreateDirectory(basePath);

                string serverFileName = Path.Combine(basePath, request.Metadata.RemoteFileName);
                using (FileStream outfile = new FileStream(serverFileName, FileMode.Create))
                {
                    const int bufferSize = 65536; // 64K

                    Byte[] buffer = new Byte[bufferSize];
                    int bytesRead = request.FileByteStream.Read(buffer, 0, bufferSize);

                    while (bytesRead > 0)
                    {
                        outfile.Write(buffer, 0, bytesRead);
                        bytesRead = request.FileByteStream.Read(buffer, 0, bufferSize);
                    }
                    outfile.Close();
                }

                //using (ZipFile zip = ZipFile.Read(serverFileName, options))
                {
                    if (!MonoscapeUtil.WebConfigExistsInRoot(serverFileName))
                    {
                        if (File.Exists(serverFileName))
                            File.Delete(serverFileName);
                        throw new MonoscapeException("Application package is not valid. Re-package the application excluding any project folders and try again.");
                    }
                }

                Application application = new Application();
                application.Id = request.Metadata.ApplicationId;
                application.Name = request.Metadata.ApplicationName;
                application.Version = request.Metadata.ApplicationVersion;
                application.FileName = Path.GetFileName(serverFileName);
                application.State = ApplicationState.Uploaded;

                ApplicationUploaded(application);
                return response;
            }
            catch (Exception e)
            {
                Log.Error(this, e);
                throw e;
            }
        }
 protected abstract void ApplicationUploaded(Application application);
示例#10
0
        private List<Application> ReadApplications()
        {
            Log.Info(typeof(Database), "Reading application data...");			
			
			try
			{
	            using(var connection = new SqliteConnection(Settings.SQLiteConnectionString))
				{
		            PersistenceStorage.PersistentDataContext persistenceDb = new PersistenceStorage.PersistentDataContext(connection);
					List<Application> applications = new List<Application>();
		            
		            foreach (PersistenceStorage.Application persistenceApp in persistenceDb.Application.ToList())
		            {
		                Monoscape.Common.Model.Application app = new Monoscape.Common.Model.Application();
		                app.Id = persistenceApp.ID;
		                app.Name = persistenceApp.Name;
		                app.Version = persistenceApp.Version;
		                app.State = ConvertApplicationState(persistenceApp.State.ToString());
		                app.FileName = persistenceApp.FilePath;
	                    app.Tenants = ConvertTenants(persistenceApp.Tenant);
		                app.RowState = EntityState.Queried;
		                applications.Add(app);
		            }
					Log.Info(typeof(Database), applications.Count + " applications found");
					return applications;
				}	            
			}
			catch(Exception e)
			{				
				Log.Error(typeof(Database), "Could not connect to the database", e);
				throw e;
			}            
        }
        private void UploadFile(Stream fileStream, Application application)
        {
            ApGetConfigurationSettingsRequest request1 = new ApGetConfigurationSettingsRequest(Credentials);
            ApGetConfigurationSettingsResponse response1 = EndPoints.ApDashboardService.GetConfigurationSettings(request1);

            IPAddress appGridIpAddress = response1.ConfigurationSettings.IpAddress;
            ApFileTransferSocket socket = new ApFileTransferSocket(appGridIpAddress, Settings.ApFileTransferSocketPort);
            socket.SendFile(fileStream, application.FileName);

            ApAddApplicationRequest request = new ApAddApplicationRequest(Credentials);
            request.Application = application;
            EndPoints.ApDashboardService.AddApplication(request);
        }
 private bool IsApplicationValid(Application application)
 {
     bool valid = true;
     if (string.IsNullOrEmpty(application.Name))
     {
         ModelState.AddModelError("Name", "Application name is required");
         valid = false;
     }
     if (string.IsNullOrEmpty(application.Version))
     {
         ModelState.AddModelError("Version", "Application version is required");
         valid = false;
     }
     if (Request.Files["applicationPackage"].ContentLength == 0)
     {
         ModelState.AddModelError("applicationPackage", "Application package is required");
         valid = false;
     }
     return valid;
 }
        public ActionResult UploadApplication(Application application)
        {
            try
            {
                if (!IsApplicationValid(application))
                {
                    return View(application);
                }

                // Check application exists in Application Grid
                ApApplicationExistsRequest request = new ApApplicationExistsRequest(Credentials);
                ApApplicationExistsResponse response = EndPoints.ApDashboardService.ApplicationExists(request);

                if (response.Exists)
                {
                    ModelState.AddModelError("Application", "Application version already exists.");
                    return View(application);
                }
                else
                {
                    HttpPostedFileBase file = Request.Files["applicationPackage"];
                    application.FileName = file.FileName;
                    UploadFile(file.InputStream, application);
                    return RedirectToAction("Applications");
                }
            }
            catch (Exception e)
            {
                return ShowError(e);
            }
        }