예제 #1
0
        public void TestInstallMultipleFiles()
        {
            var descriptor = new ApplicationDescriptor
            {
                Name = "TestInstallSingleFile",
            };

            InstalledApplication app;

            using (var installer = new ApplicationInstaller(_watchdog, descriptor))
            {
                installer.AddFiles(_binFolder, Environment.SpecialFolder.CommonDocuments);
                app = installer.Commit();
            }

            string[]             expectedFiles = Directory.GetFiles(_binFolder);
            List <InstalledFile> actualFiles   = app.Files;

            actualFiles.Count.Should().Be(expectedFiles.Length);
            for (int i = 0; i < expectedFiles.Length; ++i)
            {
                string fullPath = InternalWatchdog.Resolve(descriptor.Name, Environment.SpecialFolder.CommonDocuments,
                                                           actualFiles[i].Filename);
                FilesAreEqual(new FileInfo(expectedFiles[i]), new FileInfo(fullPath));
            }
        }
예제 #2
0
        /// <summary>
        /// This method validates application attributes.
        /// </summary>
        /// <param name="applicationDescriptor">Application descriptor to validate</param>
        /// <returns>List of messages</returns>
        List <Message> validateAttributes(ApplicationDescriptor applicationDescriptor)
        {
            List <Message> messages = new List <Message>();

            // Attributes of user-defined datasets
            foreach (var dataset in applicationDescriptor.Datasets)
            {
                foreach (var attribute in dataset.Attributes)
                {
                    messages.AddRange(validateOneAttribute(applicationDescriptor, dataset, attribute));
                }
            }
            // Attributes of system users dataset
            foreach (var attribute in applicationDescriptor.SystemDatasets.UsersDatasetDescriptor.Attributes)
            {
                messages.AddRange(validateOneAttribute(applicationDescriptor, applicationDescriptor.SystemDatasets.UsersDatasetDescriptor, attribute));
            }
            // Password attribute
            messages.AddRange(validateOneAttribute(applicationDescriptor, applicationDescriptor.SystemDatasets.UsersDatasetDescriptor,
                                                   applicationDescriptor.SystemDatasets.UsersDatasetDescriptor.PasswordAttribute, true));
            // Username validation
            messages.AddRange(usernameValidations(applicationDescriptor));

            return(messages);
        }
예제 #3
0
        public void TestColdUpdate1()
        {
            var watchdog = new SharpRemote.Watchdog.Watchdog(CreateWatchdog());

            InstalledApplication  app, update;
            ApplicationDescriptor desc = SharpRemote("0.5");

            using (IApplicationInstaller installer = watchdog.StartInstallation(desc))
            {
                DeploySharpRemote(installer);
                app = installer.Commit();
            }

            // Let's try patching the pdb...
            using (IApplicationInstaller installer = watchdog.StartInstallation(desc, Installation.ColdUpdate))
            {
                string pdb = Path.Combine(SharpRemoteFolder, "SharpRemote.pdb");
                installer.AddFile(pdb, Environment.SpecialFolder.LocalApplicationData);
                update = installer.Commit();
            }

            // The update should consists of all files from the first installation *AND* the pdb
            // we installed as an update
            update.Files.Count.Should().Be(app.Files.Count + 1);
            List <InstalledFile> updated = update.Files.Except(app.Files).ToList();

            updated.Count.Should().Be(1);
            updated[0].Filename.Should().Be("SharpRemote.pdb");
            updated[0].Folder.Should().Be(Environment.SpecialFolder.LocalApplicationData);
            updated[0].Id.Should().Be(4);
        }
예제 #4
0
파일: Siminov.cs 프로젝트: mathewdenis/core
        /// <summary>
        /// It is used to check whether database exists or not.
        /// </summary>
        protected static void DoesDatabaseExists()
        {
            ApplicationDescriptor            applicationDescriptor = coreResourceManager.GetApplicationDescriptor();
            IEnumerator <DatabaseDescriptor> databaseDescriptors   = applicationDescriptor.GetDatabaseDescriptors();

            bool databaseExists = true;

            while (databaseDescriptors.MoveNext())
            {
                DatabaseDescriptor databaseDescriptor = databaseDescriptors.Current;
                String             databasePath       = new DatabaseUtils().GetDatabasePath(databaseDescriptor);

                String databaseName = databaseDescriptor.GetDatabaseName();
                if (!databaseName.EndsWith(".db"))
                {
                    databaseName = databaseName + ".db";
                }


                bool fileExists = FileUtils.DoesFileExists(databasePath, databaseName, FileUtils.LOCAL_FOLDER);
                if (!fileExists)
                {
                    databaseExists = false;
                }
            }

            if (!databaseExists)
            {
                firstTimeProcessed = true;
            }
            else
            {
                firstTimeProcessed = false;
            }
        }
        public static IServiceCollection AddConfigurableAspNetCoreApplicationInsights(
            this IServiceCollection services,
            ILogger logger,
            IConfiguration configuration,
            string applicationName,
            Type typeFromEntryAssembly)
        {
            var applicationInsightsOptions = configuration.GetApplicationInsightsAspNetCoreOptions(typeFromEntryAssembly);

            services.ConfigureTelemetryChannelStorageFolder(
                logger,
                applicationInsightsOptions.TelemetryChannel.StorageFolder,
                RuntimeInformation.IsOSPlatform(OSPlatform.Windows));

            services.AddApplicationInsightsTelemetry(options =>
            {
                options.ApplicationVersion     = applicationInsightsOptions.ApplicationVersion;
                options.EnableAdaptiveSampling = applicationInsightsOptions.EnableAdaptiveSampling;
                options.InstrumentationKey     = applicationInsightsOptions.InstrumentationKey;
                options.DeveloperMode          = applicationInsightsOptions.TelemetryChannel.DeveloperMode;
            });

            var applicationDescriptor = new ApplicationDescriptor(applicationName, applicationInsightsOptions.ApplicationVersion);

            TelemetryConfiguration.Active.TelemetryInitializers.Add(new ApplicationInitializer(applicationDescriptor));

            return(services);
        }
예제 #6
0
        /// <summary>
        /// This method validates application datasets and their attributes
        /// </summary>
        /// <param name="applicationDescriptor">Application descriptor to validate</param>
        /// <returns>List of messages</returns>
        public List <Message> ValidateDescriptor(ApplicationDescriptor applicationDescriptor)
        {
            List <Message> messages = new List <Message>();

            messages.AddRange(validateDatasets(applicationDescriptor));
            messages.AddRange(validateAttributes(applicationDescriptor));

            return(messages);
        }
예제 #7
0
        /// <summary>
        /// This method fills LoggedMenuPartialData structure with values based on application descriptor and
        /// rights provided in the parametres.
        /// </summary>
        /// <param name="applicationDescriptor">Application descriptor to fill the structure from</param>
        /// <param name="rights">Rights dictionary of user that wants the LoggedMenuPartialData</param>
        /// <returns>Filled LoggedMenuPartialData structure</returns>
        public static LoggedMenuPartialData GetMenuData(ApplicationDescriptor applicationDescriptor, Dictionary <long, RightsEnum> rights)
        {
            var menuData = new LoggedMenuPartialData();

            menuData.SystemDatasetsRights   = AccessHelper.GetSystemDatasetsRightsDict(rights);
            menuData.ApplicationName        = applicationDescriptor.ApplicationName;
            menuData.UsersDatasetName       = applicationDescriptor.SystemDatasets.UsersDatasetDescriptor.Name;
            menuData.ReadAuthorizedDatasets = AccessHelper.GetReadAuthorizedUserDefinedDatasets(applicationDescriptor, rights);
            return(menuData);
        }
예제 #8
0
 /// <summary>
 /// This function returns dataset descriptor based on datasetName parameter.static If this parameter is not specified
 /// descriptor of first dataset with at least read rights is returned.
 /// </summary>
 /// <param name="applicationDescriptor">Application descriptor to get the dataset descriptor from</param>
 /// <param name="rights">Rights of the user that wants the dataset</param>
 /// <param name="datasetName">Optional name of the dataset to get</param>
 /// <returns>Dataset descriptor based on its name or first with at least read rights</returns>
 public static DatasetDescriptor GetActiveDatasetDescriptor(ApplicationDescriptor applicationDescriptor, Dictionary <long, RightsEnum> rights, string datasetName)
 {
     // If datasetName was specified
     if (datasetName != null)
     {
         return(applicationDescriptor.Datasets.Where(d => d.Name == datasetName).FirstOrDefault());
     }
     // If dataset name was not specified, select first dataset with at least read right
     return(AccessHelper.GetReadAuthorizedUserDefinedDatasets(applicationDescriptor, rights).FirstOrDefault());
 }
        public void GivenApplicationDescriptorIsConstructed_ThenUseMachineNameAsInstance()
        {
            // Act

            var actualApplicationDescriptor = new ApplicationDescriptor("some-app-name", "20190101.03");

            // Assert

            Assert.Equal(Environment.MachineName, actualApplicationDescriptor.Instance);
        }
예제 #10
0
        /// <summary>
        /// This method validates username.
        /// </summary>
        /// <param name="applicationDescriptor">Application descriptor to validate</param>
        /// <returns>List of messages</returns>
        List <Message> usernameValidations(ApplicationDescriptor applicationDescriptor)
        {
            var messages = new List <Message>();

            // No attribute in user define datasets can be of type "username"
            foreach (var datasetDescriptor in applicationDescriptor.Datasets)
            {
                foreach (var usernameTypeAttribute in datasetDescriptor.Attributes.Where(a => a.Type == "username"))
                {
                    messages.Add(new Message(MessageTypeEnum.Error,
                                             0020,
                                             new List <string>()
                    {
                        usernameTypeAttribute.Name, datasetDescriptor.Name
                    }));
                }
            }
            // There must be exactly one attribute of type "username" in system users dataset
            var systemUsersUsernameTypeAttributes = applicationDescriptor.SystemDatasets.UsersDatasetDescriptor.Attributes.Where(a => a.Type == "username");

            if (systemUsersUsernameTypeAttributes.Count() != 1)
            {
                messages.Add(new Message(MessageTypeEnum.Error,
                                         0021,
                                         new List <string>()
                {
                    applicationDescriptor.SystemDatasets.UsersDatasetDescriptor.Name, systemUsersUsernameTypeAttributes.Count().ToString()
                }));
                return(messages);
            }
            // Username attribute must be required
            var usernameAttribute = systemUsersUsernameTypeAttributes.First();

            if (usernameAttribute.Required != true)
            {
                messages.Add(new Message(MessageTypeEnum.Error,
                                         0022,
                                         new List <string>()
                {
                    usernameAttribute.Name, applicationDescriptor.SystemDatasets.UsersDatasetDescriptor.Name
                }));
            }
            // Username attribute must be unique
            if (usernameAttribute.Unique != true)
            {
                messages.Add(new Message(MessageTypeEnum.Error,
                                         0023,
                                         new List <string>()
                {
                    usernameAttribute.Name, applicationDescriptor.SystemDatasets.UsersDatasetDescriptor.Name
                }));
            }

            return(messages);
        }
        public void Process()
        {
            ApplicationDescriptor applicationDescriptor  = connectResourceManager.GetApplicationDescriptor();
            IEnumerator <String>  serviceDescriptorPaths = applicationDescriptor.GetServiceDescriptorPaths();

            while (serviceDescriptorPaths.MoveNext())
            {
                String serviceDescriptorPath = serviceDescriptorPaths.Current;

                String serviceDescriptorFileName = null;
                String serviceDescriptorFilePath = null;

                serviceDescriptorFilePath = serviceDescriptorPath.Substring(0, serviceDescriptorPath.LastIndexOf("/"));
                serviceDescriptorFileName = serviceDescriptorPath.Substring(serviceDescriptorPath.LastIndexOf("/") + 1, (serviceDescriptorPath.Length - serviceDescriptorPath.LastIndexOf("/")) - 1);

                Stream serviceDescriptorStream = null;

                try
                {
                    #if XAMARIN
                    serviceDescriptorStream = FileUtils.ReadFileFromEmbeddedResources("Assets." + serviceDescriptorFilePath + "." + serviceDescriptorFileName);
                    if (serviceDescriptorStream == null)
                    {
                        serviceDescriptorStream = FileUtils.ReadFileFromEmbeddedResources(serviceDescriptorFilePath + "." + serviceDescriptorFileName);
                    }
                    #elif WINDOWS
                    serviceDescriptorStream = FileUtils.SearchFile(serviceDescriptorFilePath, serviceDescriptorFileName, FileUtils.INSTALLED_FOLDER);
                    #endif
                }
                catch (System.Exception ioException)
                {
                    Log.Error(this.GetType().Name, "Process", "IOException caught while getting input stream of Service Descriptor: " + serviceDescriptorPath + ", " + ioException.Message);
                    throw new SiminovException(this.GetType().Name, "process", "IOException caught while getting input stream of Service Descriptor: " + serviceDescriptorPath + ", " + ioException.Message);
                }

                try
                {
                    ParseMessage(serviceDescriptorStream);
                }
                catch (PrematureEndOfParseException exception)
                {
                    Log.Error(this.GetType().Name, "Process", "PrematureEndOfParseException caught while parsing Service Descriptor: " + serviceDescriptorPath + ", " + exception.Message);
                }

                if (doesMatch)
                {
                    ServiceDescriptorReader serviceDescriptor = new ServiceDescriptorReader(serviceDescriptorPath);
                    this.serviceDescriptor = serviceDescriptor.GetServiceDescriptor();

                    return;
                }
            }
        }
예제 #12
0
        /// <summary>
        /// This method validates rights dictionary.
        /// </summary>
        /// <param name="applicationDescriptor">Application descriptor the rights belongs to</param>
        /// <param name="rightsDictionary">Rights data dictionary</param>
        /// <returns>List of messages.</returns>
        public List <Message> ValidateRights(ApplicationDescriptor applicationDescriptor, Dictionary <long, RightsEnum> rightsDictionary)
        {
            // Check that all oligatory rights are filled and are in a correct format
            var messages = validateRightsData(applicationDescriptor, rightsDictionary);

            // Only if the rights are correct, check the logical validity
            if (messages.Count == 0)
            {
                messages.AddRange(validateRightsLogic(applicationDescriptor, rightsDictionary));
            }
            return(messages);
        }
예제 #13
0
        /// <summary>
        /// Parse the entity descriptor descriptor defined
        /// </summary>
        /// <exception cref="Siminov.Core.Exception.SiminovException">Any exception during parsing the descriptor file</exception>
        public void Process()
        {
            ApplicationDescriptor applicationDescriptor = resourceManager.GetApplicationDescriptor();

            if (applicationDescriptor == null)
            {
                Log.Log.Error(typeof(QuickEntityDescriptorReader).FullName, "Process", "Invalid Application Descriptor Found");
                throw new DeploymentException(typeof(QuickEntityDescriptorReader).FullName, "Process", "Invalid Application Descriptor Found.");
            }

            if (!applicationDescriptor.IsDatabaseNeeded())
            {
                doesMatch = false;
                return;
            }


            IEnumerator <DatabaseDescriptor> databaseDescriptors = applicationDescriptor.GetDatabaseDescriptors();

            while (databaseDescriptors.MoveNext())
            {
                DatabaseDescriptor   databaseDescriptor = databaseDescriptors.Current;
                IEnumerator <String> entityDescriptors  = databaseDescriptor.GetEntityDescriptorPaths();

                while (entityDescriptors.MoveNext())
                {
                    String entityDescriptorPath = entityDescriptors.Current;

                    Stream entityDescriptorStream = null;

                    try
                    {
                        ParseMessage(entityDescriptorStream);
                    }
                    catch (SiminovException exception)
                    {
                        Log.Log.Error(typeof(QuickEntityDescriptorReader).FullName, "Process", "Exception caught while parsing ENTITY-DESCRIPTOR: " + entityDescriptorPath + ", " + exception.GetMessage());
                        throw new SiminovException(typeof(QuickEntityDescriptorReader).FullName, "Process", "Exception caught while parsing ENTITY-DESCRIPTOR: " + entityDescriptorPath + ", " + exception.GetMessage());
                    }

                    if (doesMatch)
                    {
                        EntityDescriptorReader entityDescriptorParser = new EntityDescriptorReader(entityDescriptorPath);

                        this.entityDescriptor = entityDescriptorParser.GetEntityDescriptor();
                        databaseDescriptor.AddEntityDescriptor(entityDescriptorPath, entityDescriptor);

                        return;
                    }
                }
            }
        }
예제 #14
0
파일: Siminov.cs 프로젝트: mathewdenis/core
        /// <summary>
        /// It process ApplicationDescriptor.xml file defined in Application, and stores in Resource Manager.
        /// </summary>
        protected static void ProcessApplicationDescriptor()
        {
            ApplicationDescriptorReader applicationDescriptorParser = new ApplicationDescriptorReader();

            ApplicationDescriptor applicationDescriptor = applicationDescriptorParser.GetApplicationDescriptor();

            if (applicationDescriptor == null)
            {
                Log.Log.Debug(typeof(Siminov).FullName, "ProcessApplicationDescriptor", "Invalid Application Descriptor Found.");
                throw new DeploymentException(typeof(Siminov).FullName, "ProcessApplicationDescriptor", "Invalid Application Descriptor Found.");
            }

            coreResourceManager.SetApplicationDescriptor(applicationDescriptor);
        }
예제 #15
0
        /// <summary>
        /// Get internal memory database path
        /// </summary>
        /// <param name="databaseDescriptor">Database Descriptor Object</param>
        /// <returns></returns>
        public String InternalMemoryDatabasePath(DatabaseDescriptor databaseDescriptor)
        {
            #if XAMARIN
            var rootFolder = FileSystem.Current.LocalStorage;
            return(rootFolder.Path);
            #elif WINDOWS
            ResourceManager       resourceManager       = ResourceManager.GetInstance();
            ApplicationDescriptor applicationDescriptor = resourceManager.GetApplicationDescriptor();

            String databaseDirName = databaseDescriptor.GetDatabaseName();

            String databaseDirPath = applicationDescriptor.GetName() + FileUtils.Separator + Constants.DATABASE_PATH_DATABASE + FileUtils.Separator + databaseDirName + FileUtils.Separator;
            return(databaseDirPath);
            #endif
        }
예제 #16
0
        public override void StartElement(XmlReader reader, IDictionary <String, String> attributes)
        {
            String localName = reader.Name;

            tempValue = new StringBuilder();

            if (localName.Equals(Constants.APPLICATION_DESCRIPTOR_SIMINOV, StringComparison.OrdinalIgnoreCase))
            {
                applicationDescriptor = new ApplicationDescriptor();
            }
            else if (localName.Equals(Constants.APPLICATION_DESCRIPTOR_PROPERTY))
            {
                InitializeProperty(attributes);
            }
        }
예제 #17
0
        public static ApplicationInsightsSimpleOptions GetApplicationInsightsOptions(
            this IConfiguration configuration,
            Type type)
        {
            var options = configuration
                          .GetSection("ApplicationInsights")
                          .Get <ApplicationInsightsSimpleOptions>() ?? new ApplicationInsightsSimpleOptions();

            if (string.IsNullOrWhiteSpace(options.ApplicationVersion))
            {
                options.ApplicationVersion = ApplicationDescriptor.GetAssemblyInformationalVersion(type);
            }

            return(options);
        }
예제 #18
0
        /// <summary>
        /// This method returns list of user-defined dataset descriptors that can be read by the user with rights from the parameter.
        /// </summary>
        /// <param name="applicationDescriptor">Application descriptor containing all available datasets</param>
        /// <param name="rights">Rights dictionary with rights for each dataset from application descriptor</param>
        /// <returns>List of user-defined dataset descriptors with at least R rights</returns>
        public static List <DatasetDescriptor> GetReadAuthorizedUserDefinedDatasets(ApplicationDescriptor applicationDescriptor, Dictionary <long, RightsEnum> rights)
        {
            // Get user-defined datasets with at least R rights
            var readAuthorizedDatasetsDict = rights.Where(r => r.Value >= RightsEnum.R && r.Key != (long)SystemDatasetsEnum.Users && r.Key != (long)SystemDatasetsEnum.Rights)
                                             .ToDictionary(pair => pair.Key, pair => pair.Value);
            // For every read authorized dataset get its descriptor
            var readAuthorizedDatasets = new List <DatasetDescriptor>();

            foreach (var dataset in applicationDescriptor.Datasets)
            {
                if (readAuthorizedDatasetsDict.ContainsKey(dataset.Id))
                {
                    readAuthorizedDatasets.Add(dataset);
                }
            }
            return(readAuthorizedDatasets);
        }
예제 #19
0
        /// <summary>
        /// This method sets default values to the application descriptor.
        /// </summary>
        /// <param name="applicationDescriptor">Application descriptor to set the values to</param>
        public void SetDefaultDescriptorValues(ApplicationDescriptor applicationDescriptor)
        {
            // Add unique Id for each dataset
            for (int i = 0; i < applicationDescriptor.Datasets.Count; i++)
            {
                applicationDescriptor.Datasets[i].Id = i + 1;
            }
            // Add id SystemDatasetsEnum.Users to users dataset
            applicationDescriptor.SystemDatasets.UsersDatasetDescriptor.Id = (long)SystemDatasetsEnum.Users;
            // Defalut values to attributes properties
            var allAttributeDescriptors = applicationDescriptor.Datasets.SelectMany(d => d.Attributes).ToList();

            allAttributeDescriptors.AddRange(applicationDescriptor.SystemDatasets.UsersDatasetDescriptor.Attributes);
            allAttributeDescriptors.Add(applicationDescriptor.SystemDatasets.UsersDatasetDescriptor.PasswordAttribute);
            foreach (var attributeDescriptor in allAttributeDescriptors)
            {
                // Relation between required and min for references
                if (!AttributeType.Types.Contains(attributeDescriptor.Type))
                {
                    // If min is set and Required is not set
                    if (attributeDescriptor.Min != null && attributeDescriptor.Required == null)
                    {
                        attributeDescriptor.Required = true;
                    }
                    // If required is set and min is not set
                    else if (attributeDescriptor.Required != null && attributeDescriptor.Min == null)
                    {
                        attributeDescriptor.Min = 1;
                    }
                }
                // If Required or Unique properties are not set, set them to false
                if (attributeDescriptor.Required == null)
                {
                    attributeDescriptor.Required = false;
                }
                if (attributeDescriptor.Unique == null)
                {
                    attributeDescriptor.Unique = false;
                }
            }
            // If password Safer property is not set, set it to false
            if (applicationDescriptor.SystemDatasets.UsersDatasetDescriptor.PasswordAttribute.Safer == null)
            {
                applicationDescriptor.SystemDatasets.UsersDatasetDescriptor.PasswordAttribute.Safer = false;
            }
        }
예제 #20
0
        /// <summary>
        /// Turns DeveloperMode on and disable adaptive sampling
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="instrumentationKey"></param>
        /// <returns></returns>
        public static IWebHostBuilder UseDeveloperApplicationInsights(this IWebHostBuilder builder, string instrumentationKey)
        {
            builder.ConfigureServices(services =>
            {
                services.AddApplicationInsightsTelemetry();
                // Based on: https://github.com/Microsoft/ApplicationInsights-aspnetcore/blob/0edd28dad8529546ce337629f05f0d7383a5f489/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsServiceOptions.cs#L14-L21
                services.Configure <ApplicationInsightsServiceOptions>(o =>
                {
                    o.ApplicationVersion     = ApplicationDescriptor.GetAssemblyInformationalVersion(typeof(Startup));
                    o.DeveloperMode          = true;
                    o.EnableAdaptiveSampling = false;
                    o.InstrumentationKey     = instrumentationKey;
                });
            });

            return(builder);
        }
예제 #21
0
        /// <summary>
        /// This method checks that rights dictionary contains rights for all application datasets
        /// and that the rights are in a correct format.
        /// </summary>
        /// <param name="applicationDescriptor">Application descriptor the rights belongs to</param>
        /// <param name="rightsDictionary">Rights data dictionary</param>
        /// <returns>List of messages.</returns>
        List <Message> validateRightsData(ApplicationDescriptor applicationDescriptor, Dictionary <long, RightsEnum> rightsDictionary)
        {
            var messages = new List <Message>();
            // Check user-defined datasets
            var datasetsToCheck = new List <DatasetDescriptor>();

            datasetsToCheck.AddRange(applicationDescriptor.Datasets);
            // And users dataset
            datasetsToCheck.Add(applicationDescriptor.SystemDatasets.UsersDatasetDescriptor);
            // And also rights for rights need to be checked by creating mock dataset
            datasetsToCheck.Add(new DatasetDescriptor()
            {
                Id   = (long)SystemDatasetsEnum.Rights,
                Name = SystemDatasetsEnum.Rights.ToString()
            });
            foreach (var datasetDescriptor in datasetsToCheck)
            {
                var rightsForDataset = rightsDictionary.FirstOrDefault(r => r.Key == datasetDescriptor.Id);
                // If no rights for dataset found
                if (rightsForDataset.Equals(new KeyValuePair <string, List <long> >()))
                {
                    messages.Add(new Message(MessageTypeEnum.Error,
                                             6011,
                                             new List <string>()
                    {
                        datasetDescriptor.Name
                    })
                                 );
                }
                else if (!Enum.IsDefined(typeof(RightsEnum), rightsForDataset.Value))
                {
                    messages.Add(new Message(MessageTypeEnum.Error,
                                             6012,
                                             new List <string>()
                    {
                        datasetDescriptor.Name,
                        rightsForDataset.Value.ToString()
                    })
                                 );
                }
            }
            return(messages);
        }
        public void GivenApplicationDescriptor_ThenSetTelemetryItem()
        {
            // Arrange

            var applicationDescriptor  = new ApplicationDescriptor("application-name", "20190110.03");
            var applicationInitializer = new ApplicationInitializer(applicationDescriptor);

            var telemetryItem = new TraceTelemetry();

            // Act

            applicationInitializer.Initialize(telemetryItem);

            // Assert

            Assert.Equal(applicationDescriptor.Name, telemetryItem.Context.Cloud.RoleName);
            Assert.Equal(applicationDescriptor.Instance, telemetryItem.Context.Cloud.RoleInstance);
            Assert.Equal(applicationDescriptor.Version, telemetryItem.Context.Component.Version);
        }
예제 #23
0
        public void TestHotUpdate1()
        {
            var watchdog = new SharpRemote.Watchdog.Watchdog(CreateWatchdog());

            InstalledApplication  app;
            ApplicationDescriptor desc = SharpRemote("0.7");

            using (IApplicationInstaller installer = watchdog.StartInstallation(desc))
            {
                DeploySharpRemote(installer);
                app = installer.Commit();
            }

            // Let's start a browser application to ensure that some files from the update are now in use...
            ApplicationInstanceDescription instance = CreateBrowserInstance(app);

            watchdog.RegisterApplicationInstance(instance);
            IsBrowserRunning().Should().BeTrue();

            // Performing a cold update should be possible because it kills the app(s) first..
            using (IApplicationInstaller installer = watchdog.StartInstallation(desc, Installation.HotUpdate))
            {
                IsBrowserRunning().Should().BeTrue("because the update shouldn't kill any instance");

                string browser = Path.Combine(SharpRemoteFolder, "SampleBrowser.exe");
                installer.AddFile(browser, Environment.SpecialFolder.LocalApplicationData);

                InstallationFailedException exception = null;
                try
                {
                    installer.Commit();
                }
                catch (InstallationFailedException e)
                {
                    exception = e;
                }
                exception.Should().NotBeNull();
                exception.Message.Should().Be("Application of 'SharpRemote 0.7' failed");
                var inner = exception.InnerException;
                (inner is IOException || inner is UnauthorizedAccessException).Should().BeTrue();
            }
        }
예제 #24
0
        protected override bool RunTest()
        {
            using (var accessor = new LogInterceptor(Log))
                using (var endPoint = new SocketEndPoint(EndPointType.Client))
                {
                    endPoint.Connect(WatchdogHost.PeerName, TimeSpan.FromSeconds(5));

                    var remote   = endPoint.CreateProxy <IInternalWatchdog>(WatchdogHost.ObjectId);
                    var watchdog = new Watchdog(remote);

                    var app = new ApplicationDescriptor
                    {
                        Name = "SharpRemote 0.1 Developer Build"
                    };
                    using (var installer = watchdog.StartInstallation(app, Installation.CleanInstall))
                    {
                        installer.AddFiles(new[]
                        {
                            // Full deployment
                            "SharpRemote.dll",
                            "SharpRemote.pdb",
                            "SharpRemote.Watchdog.exe",
                            "SharpRemote.Watchdog.exe.config",
                            "SharpRemote.Watchdog.pdb",
                            "SharpRemote.Watchdog.Service.exe",
                            "SharpRemote.Watchdog.Service.exe.config",
                            "SharpRemote.Watchdog.Service.pdb",
                            "SharpRemote.Host.exe",
                            "SharpRemote.Host.exe.config",
                            "SharpRemote.Host.pdb",

                            // 3rd party
                            "log4net.dll"
                        },
                                           Environment.SpecialFolder.LocalApplicationData);

                        installer.Commit();
                    }

                    return(true);
                }
        }
예제 #25
0
        /// <summary>
        /// Returns default rights for admin
        /// </summary>
        /// <param name="applicationModel">Model of application the rights belongs to</param>
        /// <param name="applicationDescriptor">Descriptor of the application</param>
        /// <returns>Admin RightsModel</returns>
        public RightsModel GetAdminRights(ApplicationModel applicationModel, ApplicationDescriptor applicationDescriptor)
        {
            var rights = new RightsModel();

            rights.Application = applicationModel;
            rights.Name        = "admin";

            // Full CRUD rights for all datasets
            Dictionary <long, RightsEnum> rightsDict = new Dictionary <long, RightsEnum>();

            rightsDict[(long)SystemDatasetsEnum.Users]  = RightsEnum.CRUD;
            rightsDict[(long)SystemDatasetsEnum.Rights] = RightsEnum.CRUD;
            foreach (var dataset in applicationDescriptor.Datasets)
            {
                rightsDict[dataset.Id] = RightsEnum.CRUD;
            }

            // Serialize rights to JSON
            rights.Data = JsonConvert.SerializeObject(rightsDict);
            return(rights);
        }
예제 #26
0
        /// <summary>
        /// This method validates that referenced datasets in dataset with rights at least read have also at least read rights.
        /// </summary>
        /// <param name="applicationDescriptor">Application descriptor the rights belongs to</param>
        /// <param name="rightsDictionary">Rights data dictionary</param>
        /// <returns>List of messages.</returns>
        List <Message> validateRightsLogic(ApplicationDescriptor applicationDescriptor, Dictionary <long, RightsEnum> rightsDictionary)
        {
            var messages = new List <Message>();
            // Check user-defined datasets
            var datasetsToCheck = new List <DatasetDescriptor>();

            datasetsToCheck.AddRange(applicationDescriptor.Datasets);
            // And users dataset
            datasetsToCheck.Add(applicationDescriptor.SystemDatasets.UsersDatasetDescriptor);
            // Dictionary containing <dataset id, dataset name>
            var idNameDictionary = datasetsToCheck.ToDictionary(d => d.Name, d => d.Id);

            // Check that for each dataset with at least read right, all datasets referenced in it have at least read rights
            foreach (var datasetDescriptor in datasetsToCheck)
            {
                if (rightsDictionary[datasetDescriptor.Id] >= RightsEnum.R)
                {
                    foreach (var attribute in datasetDescriptor.Attributes)
                    {
                        // If attribute type is reference
                        if (!AttributeType.Types.Contains(attribute.Type))
                        {
                            // And rights for the reference are less than read rights
                            if (rightsDictionary[idNameDictionary[attribute.Type]] < RightsEnum.R)
                            {
                                messages.Add(new Message(MessageTypeEnum.Error,
                                                         6013,
                                                         new List <string>()
                                {
                                    datasetDescriptor.Name,
                                    attribute.Type
                                })
                                             );
                            }
                        }
                    }
                }
            }
            return(messages);
        }
예제 #27
0
파일: Siminov.cs 프로젝트: mathewdenis/core
        /// <summary>
        /// It process all LibraryDescriptor.xml files defined by application, and stores in Resource Manager.
        /// </summary>
        protected static void ProcessLibraries()
        {
            ApplicationDescriptor applicationDescriptor = coreResourceManager.GetApplicationDescriptor();
            IEnumerator <String>  libraries             = applicationDescriptor.GetLibraryDescriptorPaths();

            while (libraries.MoveNext())
            {
                String library = libraries.Current;

                /*
                 * Parse LibraryDescriptor.
                 */
                LibraryDescriptorReader libraryDescriptorReader = new LibraryDescriptorReader(library);
                LibraryDescriptor       libraryDescriptor       = libraryDescriptorReader.GetLibraryDescriptor();


                /*
                 * Map Entity Descriptors
                 */
                IEnumerator <String> entityDescriptors = libraryDescriptor.GetEntityDescriptorPaths();
                while (entityDescriptors.MoveNext())
                {
                    String libraryEntityDescriptorPath = entityDescriptors.Current;

                    String databaseDescriptorName = libraryEntityDescriptorPath.Substring(0, libraryEntityDescriptorPath.IndexOf(Constants.LIBRARY_DESCRIPTOR_ENTITY_DESCRIPTOR_SEPRATOR));
                    String entityDescriptor       = libraryEntityDescriptorPath.Substring(libraryEntityDescriptorPath.IndexOf(Constants.LIBRARY_DESCRIPTOR_ENTITY_DESCRIPTOR_SEPRATOR) + 1, ((libraryEntityDescriptorPath.Length - libraryEntityDescriptorPath.IndexOf(Constants.LIBRARY_DESCRIPTOR_ENTITY_DESCRIPTOR_SEPRATOR)) - 1));


                    IEnumerator <DatabaseDescriptor> databaseDescriptors = applicationDescriptor.GetDatabaseDescriptors();
                    while (databaseDescriptors.MoveNext())
                    {
                        DatabaseDescriptor databaseDescriptor = databaseDescriptors.Current;
                        if (databaseDescriptor.GetDatabaseName().Equals(databaseDescriptorName, StringComparison.OrdinalIgnoreCase))
                        {
                            databaseDescriptor.AddEntityDescriptorPath(library.Replace(".", "/") + FileUtils.Separator + entityDescriptor);
                        }
                    }
                }
            }
        }
예제 #28
0
        public void TestInstallSingleFile()
        {
            var descriptor = new ApplicationDescriptor
            {
                Name = "TestInstallSingleFile",
            };
            string fullPath = InternalWatchdog.Resolve(descriptor.Name, Environment.SpecialFolder.CommonApplicationData,
                                                       "SharpRemote.dll");
            var original = new FileInfo(_sharpRemoteLibraryLocation);

            if (File.Exists(fullPath))
            {
                File.Delete(fullPath);
            }

            InstalledApplication app;

            using (var installer = new ApplicationInstaller(_watchdog, descriptor))
            {
                installer.AddFile(_sharpRemoteLibraryLocation, Environment.SpecialFolder.CommonApplicationData);
                app = installer.Commit();
            }

            app.Descriptor.Should().Be(descriptor);
            app.Files.Count.Should().Be(1);
            InstalledFile file = app.Files[0];

            file.Id.Should().Be(1);
            file.Folder.Should().Be(Environment.SpecialFolder.CommonApplicationData);
            file.Filename.Should().Be("SharpRemote.dll");
            file.FileLength.Should().Be(original.Length);

            var copy = new FileInfo(fullPath);

            copy.Exists.Should().BeTrue("Because the file should've been created during the installation");
            copy.Length.Should().Be(file.FileLength);

            FilesAreEqual(original, copy).Should().BeTrue();
        }
예제 #29
0
파일: Siminov.cs 프로젝트: mathewdenis/core
        /// <summary>
        /// It process all EntityDescriptor.xml file defined in Application, and stores in Resource Manager.
        /// </summary>
        protected static void ProcessEntityDescriptors()
        {
            DoesDatabaseExists();

            ApplicationDescriptor applicationDescriptor = coreResourceManager.GetApplicationDescriptor();

            IEnumerator <DatabaseDescriptor> databaseDescriptors = applicationDescriptor.GetDatabaseDescriptors();

            while (databaseDescriptors.MoveNext())
            {
                DatabaseDescriptor   databaseDescriptor    = databaseDescriptors.Current;
                IEnumerator <String> entityDescriptorPaths = databaseDescriptor.GetEntityDescriptorPaths();

                while (entityDescriptorPaths.MoveNext())
                {
                    String entityDescriptorPath = entityDescriptorPaths.Current;
                    EntityDescriptorReader entityDescriptorParser = new EntityDescriptorReader(entityDescriptorPath);

                    databaseDescriptor.AddEntityDescriptor(entityDescriptorPath, entityDescriptorParser.GetEntityDescriptor());
                }
            }
        }
예제 #30
0
        public void TestColdUpdate2()
        {
            var watchdog = new SharpRemote.Watchdog.Watchdog(CreateWatchdog());

            InstalledApplication  app, update;
            ApplicationDescriptor desc = SharpRemote("0.6");

            using (IApplicationInstaller installer = watchdog.StartInstallation(desc))
            {
                DeploySharpRemote(installer);
                app = installer.Commit();
            }

            // Let's start a browser application to ensure that some files from the update are now in use...
            ApplicationInstanceDescription instance = CreateBrowserInstance(app);

            watchdog.RegisterApplicationInstance(instance);
            IsBrowserRunning().Should().BeTrue();

            // Performing a cold update should be possible because it kills the app(s) first..
            using (IApplicationInstaller installer = watchdog.StartInstallation(desc, Installation.ColdUpdate))
            {
                IsBrowserRunning().Should().BeFalse("because the update needed to kill the browser");

                string pdb = Path.Combine(SharpRemoteFolder, "SharpRemote.dll");
                installer.AddFile(pdb, Environment.SpecialFolder.LocalApplicationData);
                string browser = Path.Combine(SharpRemoteFolder, "SampleBrowser.exe");
                installer.AddFile(browser, Environment.SpecialFolder.LocalApplicationData);
                update = installer.Commit();

                IsBrowserRunning()
                .Should()
                .BeTrue("because after the update's finished all application instances should be running again");
            }

            // The update shouldn't have written new files, not even their file sizes should've changed...
            app.Files.Should().BeEquivalentTo(update.Files);
        }