Пример #1
0
        public void CreateProjectUploadingEntityTest()
        {
            //Arrange
            const string productName    = "productName";
            const string projectId      = "projectId";
            const string projectName    = "projectName";
            const string productVersion = "12.3";

            const ProjectType    projectType    = ProjectType.Tag;
            const ProjectSubtype projectSubtype = ProjectSubtype.Friend;

            var tableValueConverter = new Mock <ITableValueConverter>();
            var statEntityFactory   = new StatEntityFactory(tableValueConverter.Object);

            tableValueConverter.Setup(m => m.DateTimeToTickWithGuid(_dateTime)).Returns(TickWithGuid);
            tableValueConverter.Setup(m => m.UserAgentToProductName(UserAgent)).Returns(productName);
            tableValueConverter.Setup(m => m.UserAgentToVersion(UserAgent)).Returns(productVersion);

            //Act
            var projectUploadingEntity = statEntityFactory.CreateProjectUploadingEntity(EventId, _dateTime, _domain, projectId, projectName, projectType, projectSubtype);

            //Assert
            Assert.AreEqual(TickWithGuid, projectUploadingEntity.Tick);
            Assert.AreEqual(EventId, projectUploadingEntity.EventId);
            Assert.AreEqual(_dateTime, projectUploadingEntity.DateTime);
            Assert.AreEqual(productName, projectUploadingEntity.ProductName);
            Assert.AreEqual(UserId, projectUploadingEntity.UserId);
            Assert.AreEqual(projectId, projectUploadingEntity.ProjectId);
            Assert.AreEqual(projectName, projectUploadingEntity.ProjectName);
            Assert.AreEqual(IdentityProvider, projectUploadingEntity.IdentityProvider);
            Assert.AreEqual(productVersion, projectUploadingEntity.ProductVersion);
            Assert.AreEqual((int)projectType, projectUploadingEntity.ProjectType);
            Assert.AreEqual((int)projectSubtype, projectUploadingEntity.TagType);
        }
        public void LogProjectUploadingTest()
        {
            //Arrange
            const string         projectId      = "projectId";
            const string         projectName    = "projectName";
            const ProjectType    projectType    = ProjectType.Tag;
            const ProjectSubtype projectSubtype = ProjectSubtype.Friend;

            var timeSpan     = new DateTime(2013, 7, 16);
            var actionDomain = new DomainActionData();
            var project      = new FakeDomainStatProject();

            var eventLogger       = new Mock <IEventLogger>();
            var statDomainFactory = new Mock <IStatDomainFactory>();
            var dateTimeWrapper   = new Mock <IDateTimeWrapper>();

            var projectUploadingEventService = new ProjectUploadingEventService(eventLogger.Object, statDomainFactory.Object, dateTimeWrapper.Object);

            statDomainFactory.Setup(m => m.CreateProject(actionDomain, projectId, projectName, projectType.ToString(), projectSubtype.ToString())).Returns(project);
            dateTimeWrapper.Setup(m => m.CurrentDateTime()).Returns(timeSpan);

            //Act
            projectUploadingEventService.LogProjectUploading(actionDomain, projectId, projectName, projectType, projectSubtype);

            //Assert
            eventLogger.Verify(m => m.TrackProjectUploadingEvent(project, timeSpan), Times.Once());
        }
 public ProjectUploadingEventArg(DomainActionData actionData, string projectId, string projectName, ProjectType projectType, ProjectSubtype projectSubtype)
     : base(actionData)
 {
     ProjectId      = projectId;
     ProjectName    = projectName;
     ProjectType    = projectType;
     ProjectSubtype = projectSubtype;
 }
 public ProjectUploadingEventArg(DomainActionData actionData, string projectId, string projectName, ProjectType projectType, ProjectSubtype projectSubtype)
     : base(actionData)
 {
     ProjectId = projectId;
     ProjectName = projectName;
     ProjectType = projectType;
     ProjectSubtype = projectSubtype;
 }
        public Task AddProjectUploading(DomainActionData actionData, string projectId, string projectName, ProjectType projectType, ProjectSubtype projectSubtype)
        {
            string eventId = GuidWraper.Generate();
            DateTime curDateTime = DateTimeWrapper.CurrentDateTime();

            StatProjectUploadingV2Entity projectUploadingEntity = StatEntityFactory.CreateProjectUploadingEntity(eventId, curDateTime, actionData, projectId, projectName, projectType, projectSubtype);
            ITableRepository<StatProjectUploadingV2Entity> projectUploadingRepository = RepositoryFactory.Create<StatProjectUploadingV2Entity>();

            return projectUploadingRepository.AddAsync(projectUploadingEntity);
        }
Пример #6
0
        public StatProjectUploadingV2Entity CreateProjectUploadingEntity(string eventId, DateTime dateTime, DomainActionData domain, string projectId, string projectName, ProjectType projectType,
                                                                         ProjectSubtype projectSubtype)
        {
            string productName    = _tableValueConverter.UserAgentToProductName(domain.UserAgent);
            string productVersion = _tableValueConverter.UserAgentToVersion(domain.UserAgent);

            return(new StatProjectUploadingV2Entity
            {
                Tick = _tableValueConverter.DateTimeToTickWithGuid(dateTime),
                EventId = eventId,
                DateTime = dateTime,
                ProductName = productName,
                UserId = domain.UserId,
                ProjectId = projectId,
                ProjectName = projectName,
                IdentityProvider = domain.IdentityProvider,
                ProductVersion = productVersion,
                ProjectType = (int)projectType,
                TagType = (int)projectSubtype
            });
        }
Пример #7
0
        public StatProjectUploadingV2Entity CreateProjectUploadingEntity(string eventId, DateTime dateTime, DomainActionData domain, string projectId, string projectName, ProjectType projectType,
            ProjectSubtype projectSubtype)
        {
            string productName = _tableValueConverter.UserAgentToProductName(domain.UserAgent);
            string productVersion = _tableValueConverter.UserAgentToVersion(domain.UserAgent);

            return new StatProjectUploadingV2Entity
            {
                Tick = _tableValueConverter.DateTimeToTickWithGuid(dateTime),
                EventId = eventId,
                DateTime = dateTime,
                ProductName = productName,
                UserId = domain.UserId,
                ProjectId = projectId,
                ProjectName = projectName,
                IdentityProvider = domain.IdentityProvider,
                ProductVersion = productVersion,
                ProjectType = (int)projectType,
                TagType = (int)projectSubtype
            };
        }
Пример #8
0
        public List <VendorSample> ParseProjectFolder(string optionalProjectRootForLocatingHeaders,
                                                      string topLevelDir,
                                                      string boardName,
                                                      List <string> extraIncludeDirs,
                                                      ProjectSubtype subtype)
        {
            List <VendorSample> result = new List <VendorSample>();

            if (topLevelDir == null)
            {
                topLevelDir = Path.GetDirectoryName(optionalProjectRootForLocatingHeaders);
            }

            string[] cprojectFiles = Directory.GetFiles(optionalProjectRootForLocatingHeaders, ".cproject", SearchOption.AllDirectories);

            foreach (var projectFile in cprojectFiles)
            {
                var projectFileDir = Path.GetDirectoryName(projectFile);

                //E.g. convert "Applications\FatFs\FatFs_uSD\SW4STM32\STM32072B_EVAL" to "Applications\FatFs\FatFs_uSD"
                string virtualPath;
                if (cprojectFiles.Length > 1)
                {
                    virtualPath = projectFileDir.Substring(topLevelDir.Length); //This sample has multiple project files (e.g. <...>\SW4STM32\Board1, <...>\SW4STM32\Board2).
                }
                else
                {
                    virtualPath = optionalProjectRootForLocatingHeaders.Substring(topLevelDir.Length);
                }

                var virtualPathComponents = virtualPath.Trim('\\').Split('\\').Except(new[] { "SW4STM32", "Projects", "STM32CubeIDE" }, StringComparer.InvariantCultureIgnoreCase).ToArray();

                ParseSingleProject(optionalProjectRootForLocatingHeaders, projectFile, virtualPathComponents, boardName, extraIncludeDirs, subtype, result);
            }

            return(result);
        }
        public async Task AddProjectUploadingTest()
        {
            const string         eventId        = "eventId";
            const string         projectId      = "projectId";
            const string         projectName    = "projectName";
            const ProjectType    projectType    = ProjectType.Tag;
            const ProjectSubtype projectSubtype = ProjectSubtype.Friend;

            var dateTime = new DateTime(2013, 2, 13);

            var domain                 = new DomainActionData();
            var httpMessageEntity      = new StatHttpMessageV2Entity();
            var projectUploadingEntity = new StatProjectUploadingV2Entity();

            var guidWrapper                = new Mock <IGuidWrapper>();
            var dateTimeWrapper            = new Mock <IDateTimeWrapper>();
            var httpMessageRepository      = new Mock <IRepository <StatHttpMessageV2Entity> >();
            var projectUploadingRepository = new Mock <IRepository <StatProjectUploadingV2Entity> >();
            var repositoryFactory          = new Mock <IRepositoryFactory>();
            var statEntityFactory          = new Mock <IStatEntityFactory>();

            guidWrapper.Setup(m => m.Generate()).Returns(eventId);
            dateTimeWrapper.Setup(m => m.CurrentDateTime()).Returns(dateTime);

            repositoryFactory.Setup(m => m.Create <StatHttpMessageV2Entity>(Tables.StatHttpMessageV2)).Returns(httpMessageRepository.Object);
            repositoryFactory.Setup(m => m.Create <StatProjectUploadingV2Entity>(Tables.StatProjectUploadingV2)).Returns(projectUploadingRepository.Object);

            statEntityFactory.Setup(m => m.CreateHttpMessageEntity(eventId, dateTime, domain)).Returns(httpMessageEntity);
            statEntityFactory.Setup(m => m.CreateProjectUploadingEntity(eventId, dateTime, domain, projectId, projectName, projectType, projectSubtype)).Returns(projectUploadingEntity);
            httpMessageRepository.Setup(m => m.AddAsync(httpMessageEntity, It.IsAny <CancellationToken>())).Returns(async() => httpMessageEntity);
            projectUploadingRepository.Setup(m => m.AddAsync(projectUploadingEntity, It.IsAny <CancellationToken>())).Returns(async() => projectUploadingEntity);

            var userRegistrationService = new StatProjectUploadingService(repositoryFactory.Object, statEntityFactory.Object, guidWrapper.Object, dateTimeWrapper.Object);

            //Act & Assert
            await userRegistrationService.AddProjectUploading(domain, projectId, projectName, projectType, projectSubtype);
        }
Пример #10
0
        private VendorSample ParseSingleConfiguration(XmlDocument cproject,
                                                      XmlDocument project,
                                                      XmlElement cconfiguration,
                                                      string optionalProjectRootForLocatingHeaders,
                                                      string cprojectFileDir,
                                                      string boardName,
                                                      MultiConfigurationContext multiConfigurationContext,
                                                      ProjectSubtype subtype)
        {
            VendorSample result = new VendorSample
            {
                UserFriendlyName = (project.SelectSingleNode("projectDescription/name") as XmlElement)?.InnerText ?? throw new Exception("Failed to determine sample name"),
                                         NoImplicitCopy = true,
            };

            if (optionalProjectRootForLocatingHeaders == null)
            {
                optionalProjectRootForLocatingHeaders = cprojectFileDir;
            }

            CommonConfigurationOptions opts;

            if (subtype == ProjectSubtype.Auto)
            {
                var toolchainConfigNode = cconfiguration.SelectSingleNode(ToolchainConfigKey) as XmlNode ?? throw new Exception("Failed to locate the configuration node");
                if (toolchainConfigNode.SelectSingleNode("tool[starts-with(@id, 'fr.ac6.managedbuild.tool.gnu.cross.c.compiler')]") != null)
                {
                    subtype = ProjectSubtype.SW4STM32;
                }
                else if (toolchainConfigNode.SelectSingleNode("tool[@superClass = 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler']") != null)
                {
                    subtype = ProjectSubtype.STM32CubeIDE;
                }
                else
                {
                    throw new Exception("Failed to detect the project type");
                }
            }

            if (subtype == ProjectSubtype.SW4STM32)
            {
                opts = ExtractSW4STM32Options(cproject, project, cconfiguration, cprojectFileDir);
            }
            else
            {
                opts = ExtractSTM32CubeIDEOptions(cproject, project, cconfiguration, cprojectFileDir);
            }

            var mcu = opts.MCU;

            if (mcu.EndsWith("x"))
            {
                if (mcu.StartsWith("STM32MP1"))
                {
                    mcu = mcu.Substring(0, mcu.Length - 3) + "_M4";
                }
                else
                {
                    mcu = mcu.Remove(mcu.Length - 2, 2);
                }
            }
            else if (mcu.EndsWith("xP"))
            {
                mcu = mcu.Remove(mcu.Length - 3, 3);
            }

            AdjustMCUName(ref mcu);

            if (multiConfigurationContext is MultiConfigurationContext.MultiCore mc)
            {
                mcu += mc.DeviceSuffix;
                result.InternalUniqueID += mc.DeviceSuffix;
                result.UserFriendlyName += mc.UserFriendlyNameSuffix;
            }

            ValidateFinalMCUName(mcu);

            result.DeviceID           = mcu;
            result.SourceFiles        = opts.SourceFiles.Select(f => f.FullPath).Concat(opts.Libraries).Distinct().ToArray();
            result.IncludeDirectories = opts.IncludeDirectories;
            result.PreprocessorMacros = opts.PreprocessorMacros;
            result.BoardName          = boardName ?? opts.BoardName;
            result.LinkerScript       = opts.LinkerScript;
            OnVendorSampleParsed(result, opts);

            List <PropertyDictionary2.KeyValue> mcuConfig = new List <PropertyDictionary2.KeyValue>();

            if (opts.LDFLAGS?.Contains("rdimon.specs") == true)
            {
                mcuConfig.Add(new PropertyDictionary2.KeyValue {
                    Key = "com.sysprogs.toolchainoptions.arm.libctype", Value = "--specs=rdimon.specs"
                });
            }

            try
            {
                if (result.SourceFiles.Select(f => Path.GetFileName(f)).FirstOrDefault(f => f.StartsWith("startup_", StringComparison.InvariantCultureIgnoreCase) && f.EndsWith(".s", StringComparison.InvariantCultureIgnoreCase)) != null)
                {
                    mcuConfig.Add(new PropertyDictionary2.KeyValue {
                        Key = "com.sysprogs.mcuoptions.ignore_startup_file", Value = "1"
                    });
                }
            }
            catch { }

            if (mcuConfig.Count > 0)
            {
                result.Configuration.MCUConfiguration = new PropertyDictionary2
                {
                    Entries = mcuConfig.ToArray()
                };
            }

            result.Path = Path.GetDirectoryName(optionalProjectRootForLocatingHeaders);

            HashSet <string> possibleIncludeDirs = new HashSet <string>();

            foreach (var src in result.SourceFiles)
            {
                int idx = src.IndexOf(@"\Src\", StringComparison.InvariantCultureIgnoreCase);
                if (idx == -1)
                {
                    continue;
                }
                string possibleInc = src.Substring(0, idx) + @"\Inc";
                possibleIncludeDirs.Add(possibleInc);
            }

            string possibleRoot = optionalProjectRootForLocatingHeaders;

            for (; ;)
            {
                string possibleIncDir = Path.Combine(possibleRoot, "Inc");
                if (Directory.Exists(possibleIncDir))
                {
                    possibleIncludeDirs.Add(possibleIncDir);
                    break;
                }

                var baseDir = Path.GetDirectoryName(possibleRoot);
                if (string.IsNullOrEmpty(baseDir) || baseDir == possibleRoot)
                {
                    break;
                }

                possibleRoot = baseDir;
            }

            List <string> headers = new List <string>();

            foreach (var possibleIncDir in possibleIncludeDirs)
            {
                if (Directory.Exists(possibleIncDir))
                {
                    headers.AddRange(Directory.GetFiles(possibleIncDir, "*.h", SearchOption.AllDirectories));
                }
            }

            result.HeaderFiles = headers.ToArray();
            return(result);
        }
Пример #11
0
        public void ParseSingleProject(string optionalProjectRootForLocatingHeaders, string projectFile, string[] virtualPathComponents, string boardName, List <string> extraIncludeDirs, ProjectSubtype subtype, List <VendorSample> result)
        {
            var projectFileDir = Path.GetDirectoryName(projectFile);

            if (virtualPathComponents == null)
            {
                virtualPathComponents = new[] { "virtual", "sample", "path" }
            }
            ;

            XmlDocument cproject = new XmlDocument();

            cproject.Load(projectFile);

            XmlDocument project = new XmlDocument();

            try
            {
                project.Load(Path.Combine(projectFileDir, ".project"));
            }
            catch (Exception ex)
            {
                OnParseFailed(ex, string.Join("-", virtualPathComponents), projectFileDir, "Failed to load project file");
                return;
            }

            ConfigurationWithContext[] configs;

            try
            {
                configs = DetectConfigurationContexts(cproject, projectFile);
            }
            catch (Exception ex)
            {
                OnParseFailed(ex, string.Join("-", virtualPathComponents), projectFileDir, "Failed to compute configuration contexts");
                return;
            }

            foreach (var cfg in configs)
            {
                string sampleID = null;

                try
                {
                    sampleID = string.Join("-", virtualPathComponents) + cfg.Context?.IDSuffix;

                    var sample = ParseSingleConfiguration(cproject, project, cfg.CConfiguration, optionalProjectRootForLocatingHeaders, Path.GetDirectoryName(projectFile),
                                                          boardName, cfg.Context, subtype);
                    sample.IncludeDirectories = sample.IncludeDirectories.Concat(extraIncludeDirs ?? new List <string>()).ToArray();
                    sample.VirtualPath        = string.Join("\\", virtualPathComponents.Take(virtualPathComponents.Length - 1).ToArray());
                    sample.UserFriendlyName   = virtualPathComponents.Last();
                    sample.InternalUniqueID   = sampleID;

                    result.Add(sample);
                }
                catch (Exception ex)
                {
                    OnParseFailed(ex, sampleID, projectFileDir, "General error while parsing a sample");
                }
            }
        }
        public Task AddProjectUploading(DomainActionData actionData, string projectId, string projectName, ProjectType projectType, ProjectSubtype projectSubtype)
        {
            string   eventId     = GuidWraper.Generate();
            DateTime curDateTime = DateTimeWrapper.CurrentDateTime();

            StatProjectUploadingV2Entity projectUploadingEntity = StatEntityFactory.CreateProjectUploadingEntity(eventId, curDateTime, actionData, projectId, projectName, projectType, projectSubtype);
            ITableRepository <StatProjectUploadingV2Entity> projectUploadingRepository = RepositoryFactory.Create <StatProjectUploadingV2Entity>();

            return(projectUploadingRepository.AddAsync(projectUploadingEntity));
        }