public HStringIterator(IEnvironment environment, IString value)
     : base(environment)
 {
     _value = value;
     _length = value.BaseValue.Length;
     _index = -1;
 }
        private void SetSetting(Util.SettingInfo item)
        {
            string settingName = item._SettingName.ToString();

            Util.NodeType nodeType = item._NodeType;
            Util.NodeMap  nodeMap  = item._NodeMap;
            string        value    = item._Value;

            if (nodeType == Util.NodeType.String)
            {
                IString iNode = null;
                if (nodeMap == Util.NodeMap.GenICam)
                {
                    iNode = cam.nodeMap.GetNode <IString>(settingName);
                }
                else if (nodeMap == Util.NodeMap.TLDevice)
                {
                    iNode = cam.nodeMapTLDevice.GetNode <IString>(settingName);
                }
                else if (nodeMap == Util.NodeMap.TLStream)
                {
                    iNode = cam.nodeMapTLStream.GetNode <IString>(settingName);
                }

                string currentValue = string.Copy(iNode.Value.ToString());
                iNode.Value = value;
                string newValue = string.Copy(iNode.Value.ToString());
                printSettingChangeInfo(currentValue, newValue);
            }

            else if (nodeType == Util.NodeType.Integer)
            {
                IInteger iNode = null;
                if (nodeMap == Util.NodeMap.GenICam)
                {
                    iNode = cam.nodeMap.GetNode <IInteger>(settingName);
                }
                else if (nodeMap == Util.NodeMap.TLDevice)
                {
                    iNode = cam.nodeMapTLDevice.GetNode <IInteger>(settingName);
                }
                else if (nodeMap == Util.NodeMap.TLStream)
                {
                    iNode = cam.nodeMapTLStream.GetNode <IInteger>(settingName);
                }

                string currentValue = string.Copy(iNode.Value.ToString());
                iNode.Value = int.Parse(value);
                string newValue = string.Copy(iNode.Value.ToString());
                printSettingChangeInfo(currentValue, newValue);
            }

            else if (nodeType == Util.NodeType.Float)
            {
                IFloat iNode = null;
                if (nodeMap == Util.NodeMap.GenICam)
                {
                    iNode = cam.nodeMap.GetNode <IFloat>(settingName);
                }
                else if (nodeMap == Util.NodeMap.TLDevice)
                {
                    iNode = cam.nodeMapTLDevice.GetNode <IFloat>(settingName);
                }
                else if (nodeMap == Util.NodeMap.TLStream)
                {
                    iNode = cam.nodeMapTLStream.GetNode <IFloat>(settingName);
                }

                string currentValue = string.Copy(iNode.Value.ToString());
                iNode.Value = float.Parse(value, CultureInfo.InvariantCulture.NumberFormat);
                string newValue = string.Copy(iNode.Value.ToString());
                printSettingChangeInfo(currentValue, newValue);
            }

            else if (nodeType == Util.NodeType.Bool)
            {
                IBool iNode = null;
                if (nodeMap == Util.NodeMap.GenICam)
                {
                    iNode = cam.nodeMap.GetNode <IBool>(settingName);
                }
                else if (nodeMap == Util.NodeMap.TLDevice)
                {
                    iNode = cam.nodeMapTLDevice.GetNode <IBool>(settingName);
                }
                else if (nodeMap == Util.NodeMap.TLStream)
                {
                    iNode = cam.nodeMapTLStream.GetNode <IBool>(settingName);
                }

                string currentValue = string.Copy(iNode.Value.ToString());
                iNode.Value = bool.Parse(value);
                string newValue = string.Copy(iNode.Value.ToString());
                printSettingChangeInfo(currentValue, newValue);
            }

            else if (nodeType == Util.NodeType.Command)
            {
                ICommand iNode = null;
                if (nodeMap == Util.NodeMap.GenICam)
                {
                    iNode = cam.nodeMap.GetNode <ICommand>(settingName);
                }
                else if (nodeMap == Util.NodeMap.TLDevice)
                {
                    iNode = cam.nodeMapTLDevice.GetNode <ICommand>(settingName);
                }
                else if (nodeMap == Util.NodeMap.TLStream)
                {
                    iNode = cam.nodeMapTLStream.GetNode <ICommand>(settingName);
                }

                Console.WriteLine("Command to be executed: {0}: ", settingName);
                iNode.Execute();
            }

            else if (nodeType == Util.NodeType.Enumeration)
            {
                IEnum iNode = null;
                if (nodeMap == Util.NodeMap.GenICam)
                {
                    iNode = cam.nodeMap.GetNode <IEnum>(settingName);
                }
                else if (nodeMap == Util.NodeMap.TLDevice)
                {
                    iNode = cam.nodeMapTLDevice.GetNode <IEnum>(settingName);
                }
                else if (nodeMap == Util.NodeMap.TLStream)
                {
                    iNode = cam.nodeMapTLStream.GetNode <IEnum>(settingName);
                }

                string     currentValue = string.Copy(iNode.Value);
                IEnumEntry iEntry       = iNode.GetEntryByName(value);
                iNode.Value = iEntry.Symbolic;
                string newValue = string.Copy(iEntry.Symbolic);
                printSettingChangeInfo(currentValue, newValue);
            }



            void printSettingChangeInfo(string _currentValue, string _newValue, bool suppress = true)
            {
                if (!suppress)
                {
                    Console.WriteLine("{0} ({1}) changed from {2} to {3}", settingName, nodeType, _currentValue, _newValue);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Draws a text string (annotation)
        /// </summary>
        /// <param name="display">The display to draw to</param>
        /// <param name="text">The item of text</param>
        public void Render(ISpatialDisplay display, IString text)
        {
            // Draw the outline if it's too small
            Font f = text.CreateFont(display);
            IPosition[] outline = text.Outline;

            if (outline == null)
            {
                // This is a bit of a hack that covers the Backsight.Editor.Annotation class...
                if (f == null)
                    return;

                // Note that the order you apply the transforms is significant...

                IPointGeometry pg = text.Position;
                PointF p = CreatePoint(display, pg);
                display.Graphics.TranslateTransform(p.X, p.Y);

                double rotation = text.Rotation.Degrees;
                display.Graphics.RotateTransform((float)rotation);

                StringFormat sf = text.Format;
                if (sf == null)
                    sf = StringFormat.GenericTypographic;

                string s = text.Text;
                display.Graphics.DrawString(s, f, Brush, 0, 0, sf);
                display.Graphics.ResetTransform();

                // TEST -- draw rotated 180 to see if that's all we need to do flip... looks good
                /*
                display.Graphics.TranslateTransform(p.X, p.Y);
                display.Graphics.RotateTransform((float)rotation+180);
                display.Graphics.DrawString(s, f, Brush, 0, 0, sf);
                display.Graphics.ResetTransform();
                 */
            }
            else
            {
                if (f == null)
                {
                    Render(display, outline);
                }
                else
                {
                    string s = text.Text;

                    // Note that the order you apply the transforms is significant...

                    PointF p = CreatePoint(display, outline[0]);
                    display.Graphics.TranslateTransform(p.X, p.Y);

                    double rotation = text.Rotation.Degrees;
                    display.Graphics.RotateTransform((float)rotation);

                    Size size = TextRenderer.MeasureText(s, f);
                    double groundWidth = BasicGeom.Distance(outline[0], outline[1]);
                    float xScale = display.LengthToDisplay(groundWidth) / (float)size.Width;
                    float yScale = f.Size / (float)size.Height;

                    // ScaleTransform doesn't like values of 0 (single character names lead to outline with no width,
                    // should really see if proper character width can be determined in that case).
                    if (xScale < Single.Epsilon)
                        xScale = yScale;

                    display.Graphics.ScaleTransform(xScale, yScale);

                    // I tried StringFormat.GenericDefault, but that seems to leave too much
                    // leading space.
                    display.Graphics.DrawString(s, f, Brush, 0, 0, StringFormat.GenericTypographic);
                    display.Graphics.ResetTransform();
                }
            }
        }
Beispiel #4
0
        public int Search(IString text, int start, int end)
        {
            int ptr = start;


            if (reverse)
            {
                if (start < end)
                {
                    return(-1);
                }

                if (ptr > text.Length)
                {
                    ptr = text.Length;
                }

                // use simple scan for a single-character search string
                if (len == 1)
                {
                    while (--ptr >= end)
                    {
                        if (str[0] == GetChar(text[ptr]))
                        {
                            return(ptr);
                        }
                    }
                    return(-1);
                }


                if (end < len)
                {
                    end = len - 1;
                }

                ptr--;
                while (ptr >= end)
                {
                    int i = len - 1;
                    while (str[i] == GetChar(text[ptr - len + 1 + i]))
                    {
                        if (--i < 0)
                        {
                            return(ptr - len + 1);
                        }
                    }

                    if (ptr > end)
                    {
                        ptr -= GetShiftDistance(text[ptr - len]);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else
            {
                // use simple scan for a single-character search string
                if (len == 1)
                {
                    while (ptr <= end)
                    {
                        if (str[0] == GetChar(text[ptr]))
                        {
                            return(ptr);
                        }
                        else
                        {
                            ptr++;
                        }
                    }
                    return(-1);
                }

                if (end > text.Length - len)
                {
                    end = text.Length - len;
                }

                while (ptr <= end)
                {
                    int i = len - 1;
                    while (str[i] == GetChar(text[ptr + i]))
                    {
                        if (--i < 0)
                        {
                            return(ptr);
                        }
                    }

                    if (ptr < end)
                    {
                        ptr += GetShiftDistance(text[ptr + len]);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            return(-1);
        }
Beispiel #5
0
        private static void ShouldBeIdentical1 <TIndex, TEnumerator, TIndexEnumerable, TIndexEnumerator>(IString <TIndex, TEnumerator, TIndexEnumerable, TIndexEnumerator> s, uint[] expected)
            where TIndex : struct
            where TEnumerator : struct, IEnumerator <CodePoint>
            where TIndexEnumerator : struct, IEnumerator <TIndex>
            where TIndexEnumerable : struct, IIndexEnumerable <TIndex, TIndexEnumerator>
        {
            var codePoints = ((IEnumerable <CodePoint>)s).ToArray();
            var indexes    = ((IEnumerable <TIndex>)s.Indexes).ToArray();

            Assert.AreEqual(codePoints.Length, indexes.Length);

            for (int i = 0; i < codePoints.Length; i++)
            {
                Assert.AreEqual(expected[i], codePoints[i].Value);
                Assert.AreEqual(expected[i], s[indexes[i]].Value);
                Assert.AreEqual(codePoints[i], s[indexes[i]]);
            }
        }
Beispiel #6
0
 public string GetData(IString target, string str)
 {
     return(target.getDataString(str));
 }
Beispiel #7
0
        /// <summary>
        /// Wrap the provided text at the given width, indenting it with the
        /// given indentation width.
        /// </summary>
        /// <param name="text">Text to wrap.</param>
        /// <param name="width">Maximum width of the text, in number of
        /// characters.</param>
        /// <param name="blockIndent">The number of characters to block-indent
        /// all lines. Use 0 to indicate no block indentation should occur.</param>
        /// <param name="hangingIndent">The number of characters to hanging-indent
        /// the text; all lines after the first line are affected, and the first
        /// line is left unmodified.  Use 0 to indicate no hanging indentation
        /// should occur.</param>
        /// <returns>The wrapped text.</returns>
        public static IString Wrap(this IString text, int width, int blockIndent = 0, int hangingIndent = 0)
        {
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }
            if (width < 0 || width <= blockIndent + hangingIndent)
            {
                throw new ArgumentOutOfRangeException(nameof(width));
            }

            var builder = text.CreateNewBuilder();

            char[] whiteSpaceChars = { ' ', '\t', '\n' };

            var firstLine = true;

            var preprocessedAndSplitByLine =
                text.Replace("\r", string.Empty)
                .Split('\n')
                .Select(line => line.TrimEnd());

            foreach (var line in preprocessedAndSplitByLine)
            {
                // Handle empty lines specially.
                if (line.Length == 0)
                {
                    if (!firstLine)
                    {
                        builder.Append(Environment.NewLine);
                    }

                    // If there's a block indent, insert it.
                    if (blockIndent > 0)
                    {
                        builder.Append(' ', blockIndent);
                    }

                    // If we're not on the first line and there's a hanging indent,
                    // insert it.
                    if (hangingIndent > 0 && !firstLine)
                    {
                        builder.Append(' ', hangingIndent);
                    }

                    firstLine = false;
                    continue;
                }

                // Process this line.
                var index = 0;
                while (index < line.Length)
                {
                    // If we're not on the first line, then make sure to insert the
                    // newline.
                    if (!firstLine)
                    {
                        builder.Append(Environment.NewLine);
                    }

                    // If there's an indent for this line, then insert it.
                    var effectiveIndent = firstLine ? blockIndent : blockIndent + hangingIndent;
                    if (effectiveIndent > 0)
                    {
                        builder.Append(' ', effectiveIndent);
                    }

                    // Figure out how many non-indent characters we'll be able to write.
                    var textWidth = width - effectiveIndent;

                    // Figure out the end of the range we can include.
                    var endIndex = Math.Min(index + textWidth, line.Length);
                    var count    = endIndex - index;

                    // Now sort out whether we need to pick a better line break, on a
                    // whitespace (word) boundary. If the next character is a whitespace
                    // character, then we don't need to worry about this. If this is
                    // the last character in the line, then we don't need to worry either.
                    if ((endIndex < line.Length) && !char.IsWhiteSpace(line[endIndex]))
                    {
                        // Find the last whitespace character in the range of text
                        // we're considering adding.  If we found one, then break
                        // there.
                        var lastWhitespaceIndex = line.LastIndexOfAny(whiteSpaceChars, endIndex - 1, count);
                        if (lastWhitespaceIndex > index)
                        {
                            endIndex = lastWhitespaceIndex;
                        }
                    }

                    // Add chars.
                    builder.Append(line.Substring(index, endIndex - index));

                    // Advance the index to match what we just added.
                    index = endIndex;

                    // Don't start a new line with non-newline whitespace.
                    while ((index < line.Length) && char.IsWhiteSpace(line[index]))
                    {
                        ++index;
                    }

                    firstLine = false;
                }
            }

            return(builder.Generate());
        }
 /// <summary>
 /// ����ƥ��
 /// </summary>
 /// <param name="S">Ҫƥ����Ӵ�</param>
 /// <returns>�Ӵ��������е�λ��,�����ڷ���-1.</returns>
 public int FindParam(IString S)
 {
     if (S == null || S.Length == 0)
         throw new Exception("ƥ���ַ���Ϊnull���.");
     for (int i = 0; i <= Length - S.Length; i++)
     {
         if (CStr[i] == S[0])
         {
             int j;
             for (j = 1; j < S.Length; j++)
             {
                 if (CStr[j + i] != S[j])
                     break;
             }
             if (j == S.Length)
                 return i;
         }
     }
     return -1;
 }
Beispiel #9
0
 public bool IsMatch(IString input, int startat)
 {
     return(Match(input, startat).Success);
 }
Beispiel #10
0
        // match methods

        public bool IsMatch(IString input)
        {
            return(IsMatch(input, default_startat(input)));
        }
Beispiel #11
0
 int default_startat(IString input)
 {
     return((RightToLeft && input != null) ? input.Length : 0);
 }
Beispiel #12
0
 public static string[] Split(
     IString input, string pattern, RegexOptions options, TimeSpan matchTimeout)
 {
     return(Split(input, pattern, options));
 }
Beispiel #13
0
 public static string Replace(
     IString input, string pattern, MatchEvaluator evaluator, RegexOptions options,
     TimeSpan matchTimeout)
 {
     return(Replace(input, pattern, evaluator, options));
 }
        /// <summary>
        /// ��ָ��λ�ò����Ӵ�
        /// </summary>
        /// <param name="StartIndex">������</param>
        /// <param name="S">������Ӵ�</param>
        /// <returns>���봮��õ����´�</returns>
        public IString Insert(int StartIndex, IString S)
        {
            if (S == null)
                throw new Exception("�����ַ���Ϊnull.");

            if (StartIndex < 0 || StartIndex > Length)
                throw new Exception("����λ����Ч.");

            SeqString str = new SeqString(S.Length + Length);
            for (int i = 0; i < StartIndex; i++)
                str.CStr[i] = CStr[i];//ע��str[i]ֱ��ʹ���Ǵ����
            for (int i = 0; i < S.Length; i++)
                str.CStr[i + StartIndex] = S[i];
            for (int i = StartIndex; i < Length; i++)
                str.CStr[i + S.Length] = CStr[i];
            return str;
        }
Beispiel #15
0
 internal Group(IString text, int index, int length) : base(text, index, length)
 {
     success = true;
 }
 /// <summary>
 /// Create plain string format.
 /// </summary>
 public TextFormat()
 {
     _null  = new NullString(this);
     _empty = new EmptyString(this);
 }
Beispiel #17
0
 public Match Match(IString input)
 {
     return(Match(input, default_startat(input)));
 }
Beispiel #18
0
 public MatchCollection Matches(IString input)
 {
     return(Matches(input, default_startat(input)));
 }
Beispiel #19
0
        public MatchCollection Matches(IString input, int startat)
        {
            Match m = Match(input, startat);

            return(new MatchCollection(m));
        }
Beispiel #20
0
        public static void Main(string[] args)
        {
            {
                #region Snippet_1a
                // Create localization source
                var source = new Dictionary <string, string> {
                    { "Culture:en:Type:MyController:Key:hello", "Hello World!" }
                };
                // Create asset
                IAsset asset = new StringAsset(source, LineFormat.Parameters);
                // Create culture policy
                ICulturePolicy culturePolicy = new CulturePolicy();
                // Create root
                ILineRoot root = new LineRoot(asset, culturePolicy);
                #endregion Snippet_1a

                #region Snippet_1b
                // Construct key
                ILine key = root.Type("MyController").Key("Hello");
                #endregion Snippet_1b

                #region Snippet_1c
                // Set active culture for this root
                (root.FindCulturePolicy() as ICulturePolicyAssignable).SetCultures("en", "");
                // Provide string
                string str = key.ToString();
                #endregion Snippet_1c
            }

            {
                // Create localization source
                var source = new Dictionary <string, string> {
                    { "Culture:en:Section:Section:Key:Key", "Hello World!" }
                };
                // Create asset
                IAsset asset = new StringAsset(source, LineFormat.Parameters);
                #region Snippet_5x
                // Create reference
                ILine key = LineAppender.NonResolving.Section("Section").Key("Key");
                // Retreieve with reference
                IString str = asset.GetLine(key).GetString();
                #endregion Snippet_5x
            }

            {
                #region Snippet_2a
                // Create key from global root
                ILine key = LineRoot.Global.Type("MyController").Key("Hello");
                #endregion Snippet_2a

                #region Snippet_2b
                // Create localization source
                var source = new Dictionary <string, string> {
                    { "Culture:en:Type:MyController:Key:hello", "Hello World!" }
                };
                // Create asset
                IAsset asset = new StringAsset(source, LineFormat.Parameters);
                // Assets are added to global static builder. It must be (re-)built after adding.
                LineRoot.Builder.AddAsset(asset).Build();
                #endregion Snippet_2b

                #region Snippet_2c
                // If ran in multi-threaded initialization, lock to LineRoot.Builder.
                lock (LineRoot.Builder) LineRoot.Builder.AddAsset(asset).Build();
                #endregion Snippet_2c

                #region Snippet_2d
                // StringLocalizerRoot is root for IStringLocalizer interoperability
                IStringLocalizerFactory stringLocalizerFactory = StringLocalizerRoot.Global;
                #endregion Snippet_2d

                #region Snippet_2e
                // LineRoot and StringLocalizerRoot are interchangeable. They share the same asset(s).
                LineRoot.Builder.AddAsset(asset).Build();
                IStringLocalizer <MyController> stringLocalizer = StringLocalizerRoot.Global.Type <MyController>().AsStringLocalizer <MyController>();
                #endregion Snippet_2e

                #region Snippet_2f
                // Dynamic instance is acquired with LineRoot.GlobalDynamic
                dynamic key_ = LineRoot.GlobalDynamic.Section("Section").Key("Key");
                #endregion Snippet_2f
            }
        }
Beispiel #21
0
        // replace methods

        public IString Replace(IString input, MatchEvaluator evaluator)
        {
            return(Replace(input, evaluator, Int32.MaxValue, default_startat(input)));
        }
Beispiel #22
0
        private static void NoAllocationWithForeach <TIndex, TEnumerator, TIndexEnumerable, TIndexEnumerator>(IString <TIndex, TEnumerator, TIndexEnumerable, TIndexEnumerator> s, int n)
            where TIndex : struct
            where TEnumerator : struct, IEnumerator <CodePoint>
            where TIndexEnumerator : struct, IEnumerator <TIndex>
            where TIndexEnumerable : struct, IIndexEnumerable <TIndex, TIndexEnumerator>
        {
            var start = GC.GetTotalMemory(false);

            for (int i = 0; i < n; i++)
            {
                foreach (var x in s)
                {
                    ;
                }
            }

            for (int i = 0; i < n; i++)
            {
                foreach (var x in s.Indexes)
                {
                    var c = s[x];
                }
            }

            var end = GC.GetTotalMemory(false);

            Assert.AreEqual(start, end);
        }
Beispiel #23
0
 public IString Replace(IString input, MatchEvaluator evaluator, int count)
 {
     return(Replace(input, evaluator, count, default_startat(input)));
 }
        // This function acquires and saves 10 images from a device.
        static int AcquireImages(IManagedCamera cam, INodeMap nodeMap, INodeMap nodeMapTLDevice)
        {
            int result = 0;

            Console.WriteLine("\n*** IMAGE ACQUISITION ***\n");

            try {
                //
                // Set acquisition mode to continuous
                //
                // *** NOTES ***
                // Because the example acquires and saves 10 images, setting
                // acquisition mode to continuous lets the example finish. If
                // set to single frame or multiframe (at a lower number of
                // images), the example would just hang. This is because the
                // example has been written to acquire 10 images while the
                // camera would have been programmed to retrieve less than that.
                //
                // Setting the value of an enumeration node is slightly more
                // complicated than other node types. Two nodes are required:
                // first, the enumeration node is retrieved from the nodemap and
                // second, the entry node is retrieved from the enumeration node.
                // The symbolic of the entry node is then set as the new value
                // of the enumeration node.
                //
                // Notice that both the enumeration and entry nodes are checked
                // for availability and readability/writability. Enumeration
                // nodes are generally readable and writable whereas entry
                // nodes are only ever readable.
                //
                // Retrieve enumeration node from nodemap
                IEnum iAcquisitionMode = nodeMap.GetNode <IEnum>("AcquisitionMode");
                if (iAcquisitionMode == null || !iAcquisitionMode.IsWritable)
                {
                    Console.WriteLine("Unable to set acquisition mode to continuous (node retrieval). Aborting...\n");
                    return(-1);
                }

                // Retrieve entry node from enumeration node
                IEnumEntry iAcquisitionModeContinuous = iAcquisitionMode.GetEntryByName("Continuous");
                if (iAcquisitionModeContinuous == null || !iAcquisitionMode.IsReadable)
                {
                    Console.WriteLine("Unable to set acquisition mode to continuous (enum entry retrieval). Aborting...\n");
                    return(-1);
                }

                // Set symbolic from entry node as new value for enumeration node
                iAcquisitionMode.Value = iAcquisitionModeContinuous.Symbolic;

                Console.WriteLine("Acquisition mode set to continuous...");

#if DEBUG
                Console.WriteLine("\n\n*** DEBUG ***\n\n");
                // If using a GEV camera and debugging, should disable heartbeat first to prevent further issues

                if (DisableHeartbeat(cam, nodeMap, nodeMapTLDevice) != 0)
                {
                    return(-1);
                }

                Console.WriteLine("\n\n*** END OF DEBUG ***\n\n");
#endif
                //
                // Begin acquiring images
                //
                // *** NOTES ***
                // What happens when the camera begins acquiring images depends
                // on which acquisition mode has been set. Single frame captures
                // only a single image, multi frame catures a set number of
                // images, and continuous captures a continuous stream of images.
                // Because the example calls for the retrieval of 10 images,
                // continuous mode has been set for the example.
                //
                // *** LATER ***
                // Image acquisition must be ended when no more images are needed.
                //
                cam.BeginAcquisition();

                Console.WriteLine("Acquiring images...");

                //
                // Retrieve device serial number for filename
                //
                // *** NOTES ***
                // The device serial number is retrieved in order to keep
                // different cameras from overwriting each other's images.
                // Grabbing image IDs and frame IDs make good alternatives for
                // this purpose.
                //
                String deviceSerialNumber = "";

                IString iDeviceSerialNumber = nodeMapTLDevice.GetNode <IString>("DeviceSerialNumber");
                if (iDeviceSerialNumber != null && iDeviceSerialNumber.IsReadable)
                {
                    deviceSerialNumber = iDeviceSerialNumber.Value;

                    Console.WriteLine("Device serial number retrieved as {0}...", deviceSerialNumber);
                }
                Console.WriteLine();

                // Retrieve, convert, and save images
                const int NumImages = 10;

                for (int imageCnt = 0; imageCnt < NumImages; imageCnt++)
                {
                    try {
                        //
                        // Retrieve next received image
                        //
                        // *** NOTES ***
                        // Capturing an image houses images on the camera buffer.
                        // Trying to capture an image that does not exist will
                        // hang the camera.
                        //
                        // Using-statements help ensure that images are released.
                        // If too many images remain unreleased, the buffer will
                        // fill, causing the camera to hang. Images can also be
                        // released manually by calling Release().
                        //
                        using (IManagedImage rawImage = cam.GetNextImage()) {
                            //
                            // Ensure image completion
                            //
                            // *** NOTES ***
                            // Images can easily be checked for completion. This
                            // should be done whenever a complete image is
                            // expected or required. Alternatively, check image
                            // status for a little more insight into what
                            // happened.
                            //
                            if (rawImage.IsIncomplete)
                            {
                                Console.WriteLine("Image incomplete with image status {0}...", rawImage.ImageStatus);
                            }
                            else
                            {
                                //
                                // Print image information; width and height
                                // recorded in pixels
                                //
                                // *** NOTES ***
                                // Images have quite a bit of available metadata
                                // including CRC, image status, and offset
                                // values to name a few.
                                //
                                uint width = rawImage.Width;

                                uint height = rawImage.Height;

                                Console.WriteLine("Grabbed image {0}, width = {1}, height = {1}", imageCnt, width, height);

                                //
                                // Convert image to mono 8
                                //
                                // *** NOTES ***
                                // Images can be converted between pixel formats
                                // by using the appropriate enumeration value.
                                // Unlike the original image, the converted one
                                // does not need to be released as it does not
                                // affect the camera buffer.
                                //
                                // Using statements are a great way to ensure code
                                // stays clean and avoids memory leaks.
                                // leaks.
                                //
                                using (IManagedImage convertedImage = rawImage.Convert(PixelFormatEnums.Mono8)) {
                                    // Create a unique filename
                                    String filename = "Acquisition-CSharp-";
                                    if (deviceSerialNumber != "")
                                    {
                                        filename = filename + deviceSerialNumber + "-";
                                    }
                                    filename = filename + imageCnt + ".jpg";

                                    //
                                    // Save image
                                    //
                                    // *** NOTES ***
                                    // The standard practice of the examples is
                                    // to use device serial numbers to keep
                                    // images of one device from overwriting
                                    // those of another.
                                    //
                                    convertedImage.Save(filename);

                                    Console.WriteLine("Image saved at {0}\n", filename);
                                }
                            }
                        }
                    } catch (SpinnakerException ex) {
                        Console.WriteLine("Error: {0}", ex.Message);
                        result = -1;
                    }
                }

                //
                // End acquisition
                //
                // *** NOTES ***
                // Ending acquisition appropriately helps ensure that devices
                // clean up properly and do not need to be power-cycled to
                // maintain integrity.
                //
                cam.EndAcquisition();
            } catch (SpinnakerException ex) {
                Console.WriteLine("Error: {0}", ex.Message);
                result = -1;
            }

            return(result);
        }
Beispiel #25
0
 public IString Replace(IString input, string replacement)
 {
     return(Replace(input, replacement, Int32.MaxValue, default_startat(input)));
 }
 public StringHelperTests()
 {
     sut = new StringHelper();
 }
Beispiel #27
0
 public IString Replace(IString input, string replacement, int count)
 {
     return(Replace(input, replacement, count, default_startat(input)));
 }
Beispiel #28
0
 /// <summary>
 /// Appends a new string to the end of this builder's current content.
 /// </summary>
 /// <param name="s">The string to append.</param>
 public void Append(IString s) => Append((ColoredMultistring)s);
Beispiel #29
0
        // split methods

        public string [] Split(IString input)
        {
            return(Split(input, Int32.MaxValue, default_startat(input)));
        }
Beispiel #30
0
 // internal
 internal Group(IString text, int index, int length, int n_caps) : base(text, index, length)
 {
     success  = true;
     captures = new CaptureCollection(n_caps);
     captures.SetValue(this, n_caps - 1);
 }
Beispiel #31
0
 public string [] Split(IString input, int count)
 {
     return(Split(input, count, default_startat(input)));
 }
Beispiel #32
0
        // This function queries an interface for its cameras and then prints
        // out device information.
        int QueryInterface(IManagedInterface managedInterface)
        {
            int result = 0;

            try {
                //
                // Retrieve TL nodemap from interface
                //
                // *** NOTES ***
                // Each interface has a nodemap that can be retrieved in order
                // to access information about the interface itself, any devices
                // connected, or addressing information if applicable.
                //
                INodeMap nodeMapInterface = managedInterface.GetTLNodeMap();

                //
                // Print interface display name
                //
                // *** NOTES ***
                // Grabbing node information requires first retrieving the node
                // and then retrieving its information. There are two things to
                // keep in mind. First, a node is distinguished by type, which
                // is related to its value's data type. Second, nodes should be
                // checked for availability and readability/writability prior to
                // making an attempt to read from or write to them.
                //
                IString iInterfaceDisplayName = nodeMapInterface.GetNode <IString>("InterfaceDisplayName");

                if (iInterfaceDisplayName != null && iInterfaceDisplayName.IsReadable)
                {
                    string interfaceDisplayName = iInterfaceDisplayName.Value;

                    Console.WriteLine("{0}", interfaceDisplayName);
                }
                else
                {
                    Console.WriteLine("Interface display name not readable");
                }

                //
                // Update list of cameras on the interface
                //
                // *** NOTES ***
                // Updating the cameras on each interface is especially important
                // if there has been any device arrivals or removals since the
                // last time UpdateCameras() was called.
                //
                managedInterface.UpdateCameras();

                //
                // Retrieve list of cameras from the interface
                //
                // *** NOTES ***
                // Camera lists can be retrieved from an interface or the system
                // object. Camera lists retrieved from an interface, such as this
                // one, only return cameras attached on that specific interface
                // while camera lists retrieved from system returns all cameras
                // on all interfaces.
                //
                // *** LATER ***
                // Camera lists must be cleared manually. This must be done
                // prior to releasing the system and while the camera list is
                // still in scope.
                //
                List <IManagedCamera> camList = managedInterface.GetCameras();

                // Return if no cameras detected
                if (camList.Count == 0)
                {
                    Console.WriteLine("\tNo devices detected.\n");
                    return(0);
                }

                // Print device vendor and model name for each camera on the
                // interface
                for (int i = 0; i < camList.Count; i++)
                {
                    //
                    // Select camera
                    //
                    // *** NOTES ***
                    // Each camera is retrieved from a camera list with an index.
                    // If the index is out of range, an exception is thrown.
                    //
                    IManagedCamera cam = camList[i];

                    // Retrieve TL device nodemap; please see NodeMapInfo_CSharp
                    // example for additional information on TL device nodemaps
                    INodeMap nodeMapTLDevice = cam.GetTLDeviceNodeMap();

                    Console.Write("\tDevice {0} ", i);

                    // Print device vendor name and device model name
                    IString iDeviceVendorName = nodeMapTLDevice.GetNode <IString>("DeviceVendorName");

                    if (iDeviceVendorName != null && iDeviceVendorName.IsReadable)
                    {
                        String deviceVendorName = iDeviceVendorName.Value;

                        Console.Write("{0} ", deviceVendorName);
                    }

                    IString iDeviceModelName = nodeMapTLDevice.GetNode <IString>("DeviceModelName");

                    if (iDeviceModelName != null && iDeviceModelName.IsReadable)
                    {
                        String deviceModelName = iDeviceModelName.Value;

                        Console.WriteLine("{0}\n", deviceModelName);
                    }

                    // Dispose of managed camera
                    cam.Dispose();

                    //
                    // Clear camera list before losing scope
                    //
                    // *** NOTES ***
                    // If a camera list (or an interface list) is not cleaned up
                    // manually, the system will do so when the system is
                    // released.
                    //
                    camList.Clear();
                }
            } catch (SpinnakerException ex) {
                Console.WriteLine("Error " + ex.Message);
                result = -1;
            }

            return(result);
        }
Beispiel #33
0
        public static void Main(string[] args)
        {
            {
                List <ILine> lines = new List <ILine>
                {
                    LineAppender.Default.Type("ILineFactory_Examples").Key("Hello").Text("Hello World"),
                };
                IAsset asset = new StringAsset().Add(lines);
                #region Snippet_0
                ILine   key = LineAppender.NonResolving.Type("ILineFactory_Examples").Key("Hello");
                IString str = asset.GetLine(key).GetString();
                #endregion Snippet_0
            }
            {
                #region Snippet_1
                ILine localization = LineAppender.Default
                                     .PluralRules("[Category=cardinal,Case=one]n=1[Category=cardinal,Case=other]true")
                                     .Assembly("docs")
                                     .Culture("en")
                                     .Type <ILineFactory_Examples>();

                List <ILine> lines = new List <ILine>
                {
                    localization.Key("OK").Text("Successful"),
                    localization.Key("Error").Format("Failed (ErrorCode={0})")
                };

                IAsset asset = new StringAsset().Add(lines);
                #endregion Snippet_1
            }
            {
                #region Snippet_2
                IStringLocalizer localizer =
                    LineRoot.Global.Type("Hello").SetAppender(StringLocalizerAppender.Default).Key("Ok")
                    as IStringLocalizer;
                #endregion Snippet_2
            }
            {
                #region Snippet_3a
                ILine line = LineRoot.Global.AddAppender(new MyAppender()).Key("Ok");
                #endregion Snippet_3a
            }
            {
                #region Snippet_4
                #endregion Snippet_4
            }
            {
                #region Snippet_5
                #endregion Snippet_5
            }
            {
                #region Snippet_6
                #endregion Snippet_6
            }
            {
                #region Snippet_7
                #endregion Snippet_7
            }
            {
                #region Snippet_8
                #endregion Snippet_8
            }
        }
        /// <summary>
        /// Read json token stream into <paramref name="node"/>
        /// </summary>
        /// <param name="json"></param>
        /// <param name="node">parent node to under which add nodes</param>
        /// <param name="lineFormat">unused</param>
        /// <param name="correspondenceContext">(optional) place to update correspondence. If set <paramref name="json"/> must implement <see cref="JTokenReader"/>.</param>
        /// <returns></returns>
        public ILineTree ReadJsonIntoTree(JsonReader json, ILineTree node, ILineFormat lineFormat, JsonCorrespondence correspondenceContext)
        {
            ILineFactory tmp;
            ILineFormat  _lineFormat = lineFormat.TryGetLineFactory(out tmp) && tmp != LineFactory ? new LineFormat(" :\\", false, " :\\", false, tmp, null) : this.lineFormat;

            ILineTree         current     = node;
            Stack <ILineTree> stack       = new Stack <ILineTree>();
            JTokenReader      tokenReader = json as JTokenReader;
            bool updateCorrespondence     = correspondenceContext != null && tokenReader != null;

            while (json.Read())
            {
                switch (json.TokenType)
                {
                case JsonToken.StartObject:
                    stack.Push(current);
                    if (updateCorrespondence)
                    {
                        correspondenceContext.Nodes.Put(current, tokenReader.CurrentToken);
                    }
                    break;

                case JsonToken.EndObject:
                    current = stack.Pop();
                    break;

                case JsonToken.PropertyName:
                    ILine key = null;
                    if (_lineFormat.TryParse(json.Value?.ToString(), out key))
                    {
                        current = key == null?stack.Peek() : stack.Peek()?.Create(key);

                        if (current != null && updateCorrespondence && !correspondenceContext.Nodes.ContainsLeft(current))
                        {
                            correspondenceContext.Nodes.Put(current, tokenReader.CurrentToken);
                        }
                    }
                    else
                    {
                        current = null;
                    }
                    break;

                case JsonToken.Raw:
                case JsonToken.Date:
                case JsonToken.String:
                case JsonToken.Boolean:
                case JsonToken.Float:
                case JsonToken.Integer:
                    if (current != null)
                    {
                        string value = json.Value?.ToString();
                        if (value != null)
                        {
                            int           ix = current.Values.Count;
                            IStringFormat stringFormat;
                            if (current.TryGetStringFormat(resolver, out stringFormat))
                            {
                                // Append FormatString
                                IString     valueString = stringFormat.Parse(value);
                                ILineString lineValue   = LineFactory.Create <ILineString, IString>(null, valueString);
                                current.Values.Add(lineValue);
                                if (updateCorrespondence)
                                {
                                    correspondenceContext.Values[new LineTreeValue(current, lineValue, ix)] = (JValue)tokenReader.CurrentToken;
                                }
                            }
                            else
                            {
                                // Append Hint
                                ILineHint lineValue = LineFactory.Create <ILineHint, string, string>(null, "String", value);
                                current.Values.Add(lineValue);
                                if (updateCorrespondence)
                                {
                                    correspondenceContext.Values[new LineTreeValue(current, lineValue, ix)] = (JValue)tokenReader.CurrentToken;
                                }
                            }
                        }
                    }
                    break;

                case JsonToken.StartArray:
                    if (updateCorrespondence)
                    {
                        correspondenceContext.Nodes.Put(current, tokenReader.CurrentToken);
                    }
                    break;

                case JsonToken.EndArray:
                    break;
                }
            }
            return(node);
        }
 /// <summary>
 /// ������
 /// </summary>
 /// <param name="S">��β��Ҫ���ӵĴ�</param>
 /// <returns>���Ӻ�õ����´�</returns>
 public IString Concat(IString S)
 {
     if (S == null)
         throw new Exception("�����ַ���Ϊnull.");
     return Insert(Length, S);
 }