Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        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;
            }
        }
Exemplo n.º 3
0
        public ApAddApplicationResponse AddApplication(ApAddApplicationRequest request)
        {
            Log.Debug(this, "AddApplication()");

            try
            {
                Authenticate(request);
                Log.Info(this, "Application " + request.Application.Name + " received");

                if (!ControllerUtil.ApplicationExists(request.Application))
                {
                    string filePath = Settings.ApplicationStorePath + Path.DirectorySeparatorChar + request.Application.FileName;
                    if (!MonoscapeUtil.WebConfigExistsInRoot(filePath))
                    {
                        if (File.Exists(filePath))
                        {
                            File.Delete(filePath);
                        }
                        throw new MonoscapeException("Application package is not valid. Re-package the application excluding any project folders and try again.");
                    }

                    try
                    {
                        Database.GetInstance().Applications.Add(request.Application);
                        Database.GetInstance().Commit();
                        Log.Debug(this, "Application added to the database");
                    }
                    catch (Exception)
                    {
                        Log.Debug(this, "Application package not found");
                    }
                }
                else
                {
                    Log.Debug(this, "Application already exists in the database");
                }
                return(new ApAddApplicationResponse());
            }
            catch (Exception e)
            {
                Log.Error(this, e);
                throw e;
            }
        }