Ejemplo n.º 1
0
        /**
         * Returns the SourceEntry that contains the byte at the specified offset
         * sourceReleased is called as a notification callback so subclasses can take care of cleanup when the source is no longer the active source
         * @param offset the offset of the byte to look for
         * @return the SourceEntry that contains the byte at the specified offset
         * @throws IOException if there is a problem with IO (usually the result of the sourceReleased() call)
         */
        private SourceEntry GetSourceEntryForOffset(long offset)
        {
            if (offset >= size)
            {
                return(null);
            }

            if (offset >= currentSourceEntry.firstByte && offset <= currentSourceEntry.lastByte)
            {
                return(currentSourceEntry);
            }

            // hook to allow subclasses to release resources if necessary
            SourceReleased(currentSourceEntry.source);

            int startAt = GetStartingSourceIndex(offset);

            for (int i = startAt; i < sources.Length; i++)
            {
                if (offset >= sources[i].firstByte && offset <= sources[i].lastByte)
                {
                    currentSourceEntry = sources[i];
                    SourceInUse(currentSourceEntry.source);
                    return(currentSourceEntry);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        // Check if $Source classifications contains any classification from $Search.
        internal static bool IsClassifiedAs
        (
            string[] Source,
            string[] Search
        )
        {
            return
                (
                Source.Length > 0 &&
                Search.Length > 0 &&
                (
                    from SourceClassification in Source
                    from SearchClassification in Search

                    let SourceEntry = SourceClassification.ToLower()
                                      let SearchEntry = SearchClassification.ToLower()

                                                        where
                                                        (
                        SourceEntry == SearchEntry ||
                        SourceEntry.StartsWith(SearchEntry + ".")
                                                        )

                                                        select SourceEntry
                )

                .Any()
                );
        }
        /**
         * {@inheritDoc}
         * The source that contains the byte at position is retrieved, the correct offset into that source computed, then the value
         * from that offset in the underlying source is returned.
         */
        public virtual int Get(long position)
        {
            SourceEntry entry = GetSourceEntryForOffset(position);

            if (entry == null) // we have run out of data to read from
            {
                return(-1);
            }

            return(entry.source.Get(entry.OffsetN(position)));
        }
Ejemplo n.º 4
0
        private void ProcessRefreshResponse(object response, Exception error)
        {
            if (error != null)
            {
                if (OnRefresh != null)
                {
                    OnRefresh(null);
                }
                refreshInProgress = false;
                return;
            }
            var streams = (StreamData[])response;
            var sources = new List <SourceEntry>();

            foreach (StreamData stream in streams)
            {
                var e = new SourceEntry
                {
                    name        = stream.name,
                    uri         = String.Format("http://{0}:{1}", host, stream.port),
                    port        = stream.port,
                    isRecording = stream.is_recording_active
                };
                foreach (var bc in stream.outer_streams)
                {
                    SourceEntry.Broadcast.Status status;
                    if (bc.state >= (int)SourceEntry.Broadcast.Status.UNKNOWN)
                    {
                        status = SourceEntry.Broadcast.Status.UNKNOWN;
                    }
                    else
                    {
                        status = (SourceEntry.Broadcast.Status)bc.state;
                    }
                    e.broadcasts.Add(new SourceEntry.Broadcast
                    {
                        url       = bc.url,
                        status    = status,
                        statusMsg = bc.state_msg,
                        type      = bc.type,
                        errorCode = bc.error_code
                    });
                }
                sources.Add(e);
            }
            if (OnRefresh != null)
            {
                OnRefresh(sources);
            }
            refreshInProgress = false;
        }
    private async Task AddSourceCommon(SourceEntry source, string friendlyName, int durationMinutes)
    {
        source.Enabled               = true;
        source.FriendlyName          = friendlyName;
        source.MinutesBetweenRefresh = durationMinutes;
        _settings.Sources.Add(source);
        await _settings.SaveAsync();

        await _indexBuilder.ScheduleSource(source);

        await RespondAsync(embed : Extensions.MakeSuccessEmbed($"Successfully added source!"));

        _logger.Information("Added a Source for building: {@source}", source);
    }
 /**
  * Constructs a new {@link GroupedRandomAccessSource} based on the specified set of sources
  * @param sources the sources used to build this group
  */
 public GroupedRandomAccessSource(ICollection<IRandomAccessSource> sources) {
     this.sources = new SourceEntry[sources.Count];
     
     long totalSize = 0;
     int i = 0;
     foreach (IRandomAccessSource ras in sources) {
         this.sources[i] = new SourceEntry(i, ras, totalSize);
         ++i;
         totalSize += ras.Length;
     }
     size = totalSize;
     currentSourceEntry = this.sources[sources.Count-1];
     SourceInUse(currentSourceEntry.source);
 }
        private Boolean IsSourceEntryChanged()
        {
            if (listBoxSources.SelectedIndex == -1)
            {
                return(false);
            }
            if (IsNewEntrySelected())
            {
                return(!String.IsNullOrEmpty(textBoxSourcePath.Text) || !String.IsNullOrEmpty(textBoxConfigPath.Text));
            }
            SourceEntry entry = _configProvider.GetEntry(listBoxSources.SelectedIndex);

            return(!String.Equals(textBoxSourcePath.Text, entry.Source) ||
                   !String.Equals(textBoxConfigPath.Text, entry.Config));
        }
        /**
         * Constructs a new {@link GroupedRandomAccessSource} based on the specified set of sources
         * @param sources the sources used to build this group
         */
        public GroupedRandomAccessSource(ICollection <IRandomAccessSource> sources)
        {
            this.sources = new SourceEntry[sources.Count];

            long totalSize = 0;
            int  i         = 0;

            foreach (IRandomAccessSource ras in sources)
            {
                this.sources[i] = new SourceEntry(i, ras, totalSize);
                ++i;
                totalSize += ras.Length;
            }
            size = totalSize;
            currentSourceEntry = this.sources[sources.Count - 1];
            SourceInUse(currentSourceEntry.source);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Assigns a new key to this entry -
        /// creates a new source entry if the assignment is completely new.
        /// </summary>
        /// <param name="key"></param>
        internal void SetKey(string key)
        {
            if (IsTargetSet == false && IsSourceSet == false)
            {
                SourceEntry = new Entry(TargetEntry.KeyString, string.Empty, string.Empty);
                Diff        = TypeOfDiff.SourceOnly;
            }
            else
            {
                if (IsTargetSet == true)
                {
                    TargetEntry.SetKey(key);
                }

                if (IsSourceSet == true)
                {
                    SourceEntry.SetKey(key);
                }
            }
        }
Ejemplo n.º 10
0
        public CustomLogSummaryVm(LogEntry sourceEntry, CustomLogTemplate template, IEnumerable <string> matchValues)
            : base(sourceEntry)
        {
            _sourceModule = SourceEntry.GetModule();
            _matchValues  = matchValues?.ToArray() ?? Array.Empty <string>();
            Template      = template;
            var matchCollec = Regex.Match(Template.Details, @".*(\[(.*)\])");
            var details     = template.Details;

            details = Preformat(details);
            if (matchCollec.Success)
            {
                var collecString = matchCollec.Groups[1].Value;
                _details = TryFormat(details.Replace(collecString, "?"), _matchValues);
            }
            else
            {
                _details = TryFormat(details, _matchValues);
            }
            _typeName = Template.TypeName?.Replace("{m}", _sourceModule);
        }
    /// <summary>
    /// Adds a source to the schedule, runs it immediately.
    /// </summary>
    public async Task ScheduleSource(SourceEntry source)
    {
        var jobData = new JobDataMap();

        jobData[JobSourceEntryKey] = source;

        var job = JobBuilder.Create <IndexBuilderService>()
                  .WithIdentity(source.FriendlyName)
                  .UsingJobData(jobData)
                  .Build();

        var trigger = TriggerBuilder.Create()
                      .WithIdentity(source.FriendlyName)
                      .StartNow()
                      .WithSimpleSchedule(x => x
                                          .WithIntervalInMinutes(source.MinutesBetweenRefresh)
                                          .RepeatForever())
                      .Build();

        await _scheduler.ScheduleJob(job, trigger);
    }
        /**
         * {@inheritDoc}
         */
        public virtual int Get(long position, byte[] bytes, int off, int len)
        {
            SourceEntry entry = GetSourceEntryForOffset(position);

            if (entry == null) // we have run out of data to read from
            {
                return(-1);
            }

            long offN = entry.OffsetN(position);

            int remaining = len;

            while (remaining > 0)
            {
                if (entry == null) // we have run out of data to read from
                {
                    break;
                }
                if (offN > entry.source.Length)
                {
                    break;
                }

                int count = entry.source.Get(offN, bytes, off, remaining);
                if (count == -1)
                {
                    break;
                }

                off       += count;
                position  += count;
                remaining -= count;

                offN  = 0;
                entry = GetSourceEntryForOffset(position);
            }
            return(remaining == len ? -1 : len - remaining);
        }
 // Configs locations
 private void listBoxSources_SelectedIndexChanged(Object sender, EventArgs e)
 {
     if (listBoxSources.SelectedIndex == -1)
     {
         textBoxSourcePath.Text           = "";
         textBoxConfigPath.Text           = "";
         panelSelectedSourceEntry.Enabled = false;
     }
     else if (IsNewEntrySelected())
     {
         textBoxSourcePath.Text           = "";
         textBoxConfigPath.Text           = "";
         panelSelectedSourceEntry.Enabled = true;
     }
     else
     {
         SourceEntry entry = _configProvider.GetEntry(listBoxSources.SelectedIndex);
         textBoxSourcePath.Text           = entry.Source;
         textBoxConfigPath.Text           = entry.Config;
         panelSelectedSourceEntry.Enabled = true;
     }
 }
            private SourceEntry ParseSource()
            {
                SourceEntry src = new SourceEntry();

                while (_reader.ReadAttribute())
                    if (_reader.Name.Equals("id", true))
                        src._id = (string)_reader.Value;

                while (_reader.BeginElement())
                {
                    if (_reader.Name.Equals("float_array", true))
                    {
                        if (src._arrayType == SourceType.None)
                        {
                            src._arrayType = SourceType.Float;

                            while (_reader.ReadAttribute())
                                if (_reader.Name.Equals("id", true))
                                    src._arrayId = (string)_reader.Value;
                                else if (_reader.Name.Equals("count", true))
                                    src._arrayCount = int.Parse((string)_reader.Value);

                            UnsafeBuffer buffer = new UnsafeBuffer(src._arrayCount * 4);
                            src._arrayData = buffer;

                            float* pOut = (float*)buffer.Address;
                            for (int i = 0; i < src._arrayCount; i++)
                                if (!_reader.ReadValue(pOut++))
                                    break;
                        }
                    }
                    else if (_reader.Name.Equals("int_array", true))
                    {
                        if (src._arrayType == SourceType.None)
                        {
                            src._arrayType = SourceType.Int;

                            while (_reader.ReadAttribute())
                                if (_reader.Name.Equals("id", true))
                                    src._arrayId = (string)_reader.Value;
                                else if (_reader.Name.Equals("count", true))
                                    src._arrayCount = int.Parse((string)_reader.Value);

                            UnsafeBuffer buffer = new UnsafeBuffer(src._arrayCount * 4);
                            src._arrayData = buffer;

                            int* pOut = (int*)buffer.Address;
                            for (int i = 0; i < src._arrayCount; i++)
                                if (!_reader.ReadValue(pOut++))
                                    break;
                        }
                    }
                    else if (_reader.Name.Equals("Name_array", true))
                    {
                        if (src._arrayType == SourceType.None)
                        {
                            src._arrayType = SourceType.Name;

                            while (_reader.ReadAttribute())
                                if (_reader.Name.Equals("id", true))
                                    src._arrayId = (string)_reader.Value;
                                else if (_reader.Name.Equals("count", true))
                                    src._arrayCount = int.Parse((string)_reader.Value);

                            string[] list = new string[src._arrayCount];
                            src._arrayData = list;

                            for (int i = 0; i < src._arrayCount; i++)
                                if (!_reader.ReadStringSingle())
                                    break;
                                else
                                    list[i] = (string)_reader.Value;
                        }
                    }
                    else if (_reader.Name.Equals("technique_common", true))
                    {
                        while (_reader.BeginElement())
                        {
                            if (_reader.Name.Equals("accessor", true))
                            {
                                while (_reader.ReadAttribute())
                                    if (_reader.Name.Equals("source", true))
                                        src._accessorSource = _reader.Value[0] == '#' ? (string)(_reader.Value + 1) : (string)_reader.Value;
                                    else if (_reader.Name.Equals("count", true))
                                        src._accessorCount = int.Parse((string)_reader.Value);
                                    else if (_reader.Name.Equals("stride", true))
                                        src._accessorStride = int.Parse((string)_reader.Value);

                                //Ignore params
                            }

                            _reader.EndElement();
                        }
                    }

                    _reader.EndElement();
                }

                return src;
            }
Ejemplo n.º 15
0
        public IntroItem LoadIntroItem(INodePluginContext pc)
        {
            IntroItem currentItem = new IntroItem();
            string    exampleId   = pc.Evaluate("exampleName").Value?.ToString()?.Replace("'", string.Empty) ?? string.Empty;

            using (SqliteConnection connection = new SqliteConnection(_ConnectionString))
            {
                connection.Open();
                SqliteCommand readIntroItemCommand = new SqliteCommand
                {
                    Connection  = connection,
                    CommandText = _QueryBuilder.GetExampleByIdQuery()
                };
                readIntroItemCommand.Parameters.Add(new SqliteParameter("ExampleId", exampleId));
                int id = -1;
                using (SqliteDataReader reader = readIntroItemCommand.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            id = int.Parse(reader.GetString(reader.GetOrdinal("Id")));
                            currentItem.Caption     = reader.GetString(reader.GetOrdinal("Caption"));
                            currentItem.Description = reader.GetString(reader.GetOrdinal("Description"));
                            currentItem.Id          = reader.GetString(reader.GetOrdinal("Name"));
                            currentItem.OrderIdx    = int.Parse(reader.GetString(reader.GetOrdinal("OrderIdx")));
                            currentItem.Author      = reader.GetString(reader.GetOrdinal("Author"));
                            currentItem.Sources     = new Sources();
                            currentItem.LaunchSpec  = null;
                        }
                    }
                }

                if (id == -1)
                {
                    throw new Exception("Can not find the required example. Check the database");
                }

                SqliteCommand readIntroItemSourcesCommand = new SqliteCommand
                {
                    Connection  = connection,
                    CommandText = _QueryBuilder.GetExampleSourceFilesQuery()
                };
                readIntroItemSourcesCommand.Parameters.Add(new SqliteParameter("Id", id));

                using (SqliteDataReader reader = readIntroItemSourcesCommand.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            SourceEntry se = new SourceEntry
                            {
                                Content   = reader.GetString(reader.GetOrdinal("Content")),
                                Type      = (ESourceType)int.Parse(reader.GetString(reader.GetOrdinal("Type"))),
                                EntryName = reader.GetString(reader.GetOrdinal("EntryName"))
                            };
                            currentItem.Sources.Entries.Add(se);
                        }
                    }
                }
            }
            if (currentItem.Sources.Entries.Count == 0)
            {
                throw new Exception("Can not find the source section for this example in the database");
            }
            return(currentItem);
        }
Ejemplo n.º 16
0
        CommonConfigurationOptions ExtractSTM32CubeIDEOptions(XmlDocument cproject, XmlDocument project, XmlElement cconfiguration, string cprojectDir)
        {
            var toolchainConfigNode           = cconfiguration.SelectSingleNode(ToolchainConfigKey) as XmlNode ?? throw new Exception("Failed to locate the configuration node");
            CommonConfigurationOptions result = new CommonConfigurationOptions();

            var gccNode       = toolchainConfigNode.SelectSingleNode("tool[@superClass = 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler']") as XmlElement ?? throw new Exception("Missing gcc tool node");
            var linkerNode    = toolchainConfigNode.SelectSingleNode("tool[@superClass = 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker']") as XmlElement ?? throw new Exception("Missing linker tool node");
            var cppLinkerNode = toolchainConfigNode.SelectSingleNode("tool[@superClass = 'com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker']") as XmlElement;

            result.IncludeDirectories = gccNode.LookupOptionValueAsList("com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.includepaths")
                                        .Select(a => TranslatePath(cprojectDir, a, PathTranslationFlags.AddExtraComponentToBaseDir))
                                        .Where(d => d != null).ToArray();

            result.PreprocessorMacros = gccNode.LookupOptionValueAsList("com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols")
                                        .Select(a => a.Trim()).Where(a => a != "" && a != "DEBUG" && a != "RELEASE").ToArray();

            result.MCU       = toolchainConfigNode.LookupOptionValue("com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_mcu");
            result.BoardName = toolchainConfigNode.LookupOptionValue("com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board");

            var relLinkerScript = linkerNode.LookupOptionValue("com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.script");
            var linkerScript    = TranslatePath(cprojectDir, relLinkerScript, PathTranslationFlags.None);

            if (linkerScript != null)
            {
                result.LinkerScript = Path.GetFullPath(linkerScript);
            }

            result.LDFLAGS = linkerNode.LookupOptionValue("com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.otherflags", true);

            result.Libraries = new List <string>();

            List <SourceFilterEntry>         sourceFilters    = new List <SourceFilterEntry>();
            Dictionary <string, SourceEntry> sourceReferences = new Dictionary <string, SourceEntry>();

            foreach (var node in cconfiguration.SelectNodes(SourceEntriesKey).OfType <XmlElement>())
            {
                if (!string.IsNullOrEmpty(node.GetAttribute("name")))
                {
                    var entry = new SourceEntry(node);
                    if (entry.IsValid)
                    {
                        sourceReferences[entry.Name] = entry;
                    }
                }
                else if (!string.IsNullOrEmpty(node.GetAttribute("excluding")))
                {
                    var entry = new SourceFilterEntry(node);
                    if (entry.IsValid)
                    {
                        sourceFilters.Add(entry);
                    }
                }
            }

            var sources = ParseSourceList(project, cprojectDir, sourceFilters.ToArray(), sourceReferences)
                          .Where(f => !f.FullPath.EndsWith(".ioc")).ToList(); //.ioc files have too long names that will exceed our path length limit

            result.SourceFiles = ExpandSourcePaths(sources);

            return(result);
        }
 /// <summary>
 /// Removes a source from the scheduler.
 /// </summary>
 public async Task RemoveSourceAsync(SourceEntry source)
 {
     await _scheduler.DeleteJob(JobKey.Create(source.FriendlyName));
 }
 /**
  * Returns the SourceEntry that contains the byte at the specified offset  
  * sourceReleased is called as a notification callback so subclasses can take care of cleanup when the source is no longer the active source
  * @param offset the offset of the byte to look for
  * @return the SourceEntry that contains the byte at the specified offset
  * @throws IOException if there is a problem with IO (usually the result of the sourceReleased() call)
  */
 private SourceEntry GetSourceEntryForOffset(long offset) {
     if (offset >= size)
         return null;
     
     if (offset >= currentSourceEntry.firstByte && offset <= currentSourceEntry.lastByte)
         return currentSourceEntry;
     
     // hook to allow subclasses to release resources if necessary
     SourceReleased(currentSourceEntry.source);
     
     int startAt = GetStartingSourceIndex(offset);
     
     for(int i = startAt; i < sources.Length; i++){ 
         if (offset >= sources[i].firstByte && offset <= sources[i].lastByte){
             currentSourceEntry = sources[i];
             SourceInUse(currentSourceEntry.source);
             return currentSourceEntry;
         }
     }
     
     return null;
     
 }