Beispiel #1
0
        /// <summary>
        /// This MUST be overridden for any custom service properties to be copied over when instances of the service are created
        /// </summary>
        /// <param name="ninjaScript"></param>
        public override void CopyTo(NinjaScript ninjaScript)
        {
            base.CopyTo(ninjaScript);

            // Recompiling NinjaTrader.Custom after a Share service has been added will cause the Type to change.
            //  Use reflection to set the appropriate properties, rather than casting ninjaScript to Mail.
            PropertyInfo[] props = ninjaScript.GetType().GetProperties();
            foreach (PropertyInfo pi in props)
            {
                if (pi.Name == "Email")
                {
                    pi.SetValue(ninjaScript, Email);
                }
                else if (pi.Name == "MmsAddress")
                {
                    pi.SetValue(ninjaScript, MmsAddress);
                }
                else if (pi.Name == "PhoneNumber")
                {
                    pi.SetValue(ninjaScript, PhoneNumber);
                }
                else if (pi.Name == "SmsAddress")
                {
                    pi.SetValue(ninjaScript, SmsAddress);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// This MUST be overridden for any custom service properties to be copied over when instances of the service are created
        /// </summary>
        /// <param name="ninjaScript"></param>
        public override void CopyTo(NinjaScript ninjaScript)
        {
            base.CopyTo(ninjaScript);

            // Recompiling NinjaTrader.Custom after a Share service has been added will cause the Type to change.
            //  Use reflection to set the appropriate properties, rather than casting ninjaScript to Twitter.
            PropertyInfo[] props = ninjaScript.GetType().GetProperties();
            foreach (PropertyInfo pi in props)
            {
                if (pi.Name == "LastTimeConfigured")
                {
                    pi.SetValue(ninjaScript, LastTimeConfigured);
                }
                else if (pi.Name == "OAuth_Token")
                {
                    pi.SetValue(ninjaScript, OAuth_Token);
                }
                else if (pi.Name == "OAuth_Token_Secret")
                {
                    pi.SetValue(ninjaScript, OAuth_Token_Secret);
                }
                else if (pi.Name == "UserName")
                {
                    pi.SetValue(ninjaScript, UserName);
                }
            }
        }
Beispiel #3
0
        public override void CopyTo(NinjaScript ninjaScript)
        {
            base.CopyTo(ninjaScript);

            Type newInstType = ninjaScript.GetType();

            System.Reflection.PropertyInfo gannAnglePropertyInfo = newInstType.GetProperty("GannAngles");
            if (gannAnglePropertyInfo == null)
            {
                return;
            }

            IList newInstGannAngles = gannAnglePropertyInfo.GetValue(ninjaScript) as IList;

            if (newInstGannAngles == null)
            {
                return;
            }

            // Since new instance could be past set defaults, clear any existing
            newInstGannAngles.Clear();
            foreach (GannAngle oldGannAngle in GannAngles)
            {
                try
                {
                    // Clone from the new assembly here to prevent losing existing GannAngles on compile
                    object newInstance = oldGannAngle.AssemblyClone(Core.Globals.AssemblyRegistry.GetType(typeof(GannAngle).FullName));

                    if (newInstance == null)
                    {
                        continue;
                    }

                    newInstGannAngles.Add(newInstance);
                }
                catch (ArgumentException)
                {
                    // In compiled assembly case, Add call will fail for different assemblies so do normal clone instead
                    object newInstance = oldGannAngle.Clone();

                    if (newInstance == null)
                    {
                        continue;
                    }

                    // Make sure to update our stroke to a new instance so we dont try to use the old one
                    IStrokeProvider strokeProvider = newInstance as IStrokeProvider;
                    if (strokeProvider != null)
                    {
                        Stroke oldStroke = strokeProvider.Stroke;
                        strokeProvider.Stroke = new Stroke();
                        oldStroke.CopyTo(strokeProvider.Stroke);
                    }

                    newInstGannAngles.Add(newInstance);
                }
                catch { }
            }
        }
Beispiel #4
0
        public void TestSetValueWithIndex()
        {
            NinjaScript ns1 = new NinjaScript {
                Name = "Test"
            };

            var    pi  = ns1.GetType().GetProperty("Name");
            string val = (string)pi.GetValue(ns1, null);

            pi.SetValue(ns1, val + "1", null);

            Assert.AreEqual("Test1", ns1.Name);
        }
Beispiel #5
0
        /// <summary>
        /// This MUST be overridden for any custom service properties to be copied over when instances of the service are created
        /// </summary>
        /// <param name="ninjaScript"></param>
        public override void CopyTo(NinjaScript ninjaScript)
        {
            base.CopyTo(ninjaScript);

            // Recompiling NinjaTrader.Custom after a Share service has been added will cause the Type to change.
            //  Use reflection to set the appropriate properties, rather than casting ninjaScript to Mail.
            PropertyInfo[] props = ninjaScript.GetType().GetProperties();
            foreach (PropertyInfo pi in props)
            {
                if (pi.Name == "FromMailAddress")
                {
                    pi.SetValue(ninjaScript, FromMailAddress);
                }
                if (pi.Name == "SenderDisplayName")
                {
                    pi.SetValue(ninjaScript, SenderDisplayName);
                }
                else if (pi.Name == "IsBodyHtml")
                {
                    pi.SetValue(ninjaScript, IsBodyHtml);
                }
                else if (pi.Name == "Password")
                {
                    pi.SetValue(ninjaScript, Password);
                }
                else if (pi.Name == "Port")
                {
                    pi.SetValue(ninjaScript, Port);
                }
                else if (pi.Name == "Server")
                {
                    pi.SetValue(ninjaScript, Server);
                }
                else if (pi.Name == "Subject")
                {
                    pi.SetValue(ninjaScript, Subject);
                }
                else if (pi.Name == "ToMailAddress")
                {
                    pi.SetValue(ninjaScript, ToMailAddress);
                }
                else if (pi.Name == "UserName")
                {
                    pi.SetValue(ninjaScript, UserName);
                }
                else if (pi.Name == "UseSSL")
                {
                    pi.SetValue(ninjaScript, UseSSL);
                }
            }
        }
Beispiel #6
0
        public override void CopyTo(NinjaScript ninjaScript)
        {
            base.CopyTo(ninjaScript);

            Type         newInstType         = ninjaScript.GetType();
            PropertyInfo segmentPropertyInfo = newInstType.GetProperty("PathToolSegments");

            if (segmentPropertyInfo == null)
            {
                return;
            }

            IList newInstPathToolSegments = segmentPropertyInfo.GetValue(ninjaScript) as IList;

            if (newInstPathToolSegments == null)
            {
                return;
            }

            // Since new instance could be past set defaults, clear any existing
            newInstPathToolSegments.Clear();

            foreach (PathToolSegment oldPathToolSegment in PathToolSegments)
            {
                try
                {
                    object newInstance = oldPathToolSegment.AssemblyClone(Core.Globals.AssemblyRegistry.GetType(typeof(PathToolSegment).FullName));

                    if (newInstance == null)
                    {
                        continue;
                    }

                    newInstPathToolSegments.Add(newInstance);
                }
                catch (ArgumentException)
                {
                    // In compiled assembly case, Add call will fail for different assemblies so do normal clone instead
                    object newInstance = oldPathToolSegment.Clone();

                    if (newInstance == null)
                    {
                        continue;
                    }

                    newInstPathToolSegments.Add(newInstance);
                }
                catch { }
            }
        }
Beispiel #7
0
        public override void CopyTo(NinjaScript ninjaScript)
        {
            base.CopyTo(ninjaScript);

            /* Handle price levels updating.
             * We can't use a cast here, because the incoming NS could be from a newer assembly,
             * so the cast would always fail. Dig it up using reflection. For the same reason,
             * we need to cast as something without specific type, List<PriceLevel> could fail, because
             * it could try to resovle PriceLevel to current assembly, when its holding a list of PriceLevels
             * from newer assembly as well. For this reason we cast to IList */
            Type         newInstType            = ninjaScript.GetType();
            PropertyInfo priceLevelPropertyInfo = newInstType.GetProperty("PriceLevels");

            if (priceLevelPropertyInfo == null)
            {
                return;
            }

            IList newInstPriceLevels = priceLevelPropertyInfo.GetValue(ninjaScript) as IList;

            if (newInstPriceLevels == null)
            {
                return;
            }

            // Since new instance could be past set defaults, clear any existing
            newInstPriceLevels.Clear();
            foreach (PriceLevel oldPriceLevel in PriceLevels)
            {
                try
                {
                    object newInstance = oldPriceLevel.AssemblyClone(Core.Globals.AssemblyRegistry.GetType(typeof(PriceLevel).FullName));
                    if (newInstance == null)
                    {
                        continue;
                    }

                    // Make sure to update our stroke to a new instance so we dont try to use the old one
                    IStrokeProvider strokeProvider = newInstance as IStrokeProvider;
                    if (strokeProvider != null)
                    {
                        Stroke oldStroke = strokeProvider.Stroke;
                        strokeProvider.Stroke = new Stroke();
                        oldStroke.CopyTo(strokeProvider.Stroke);
                    }
                    newInstPriceLevels.Add(newInstance);
                }
                catch { }
            }
        }
Beispiel #8
0
        public override void CopyTo(NinjaScript ninjaScript)
        {
            base.CopyTo(ninjaScript);

            Type newInstType = ninjaScript.GetType();

            System.Reflection.PropertyInfo gannAnglePropertyInfo = newInstType.GetProperty("GannAngles");
            if (gannAnglePropertyInfo == null)
            {
                return;
            }

            IList newInstGannAngles = gannAnglePropertyInfo.GetValue(ninjaScript) as IList;

            if (newInstGannAngles == null)
            {
                return;
            }

            // Since new instance could be past set defaults, clear any existing
            newInstGannAngles.Clear();
            foreach (GannAngle oldGannAngle in GannAngles)
            {
                try
                {
                    object newInstance = oldGannAngle.AssemblyClone(Core.Globals.AssemblyRegistry.GetType(typeof(GannAngle).FullName));
                    if (newInstance == null)
                    {
                        continue;
                    }

                    // Make sure to update our stroke to a new instance so we dont try to use the old one
                    IStrokeProvider strokeProvider = newInstance as IStrokeProvider;
                    if (strokeProvider != null)
                    {
                        Stroke oldStroke = strokeProvider.Stroke;
                        strokeProvider.Stroke = new Stroke();
                        oldStroke.CopyTo(strokeProvider.Stroke);
                    }
                    newInstGannAngles.Add(newInstance);
                }
                catch (Exception e) { NinjaTrader.Code.Output.Process(e.ToString(), PrintTo.OutputTab1); }
            }
        }
Beispiel #9
0
        public override void CopyTo(NinjaScript ninjaScript)
        {
            base.CopyTo(ninjaScript);
            Type newInstType = ninjaScript.GetType();

            // Loop through each Collection
            for (int i = 1; i <= 5; i++)
            {
                PropertyInfo noteTextPropertyInfo = newInstType.GetProperty("Note" + i + "Text");
                Collection <IndiChartNotes.StringWrapper> NoteText;

                switch (i)
                {
                case 1:
                    NoteText = new Collection <IndiChartNotes.StringWrapper>(Note1Text);
                    break;

                case 2:
                    NoteText = new Collection <IndiChartNotes.StringWrapper>(Note2Text);
                    break;

                case 3:
                    NoteText = new Collection <IndiChartNotes.StringWrapper>(Note3Text);
                    break;

                case 4:
                    NoteText = new Collection <IndiChartNotes.StringWrapper>(Note4Text);
                    break;

                case 5:
                    NoteText = new Collection <IndiChartNotes.StringWrapper>(Note5Text);
                    break;

                default:
                    NoteText = new Collection <IndiChartNotes.StringWrapper>(Note1Text);
                    break;
                }

                // Reflect Note from old assembly
                if (noteTextPropertyInfo != null)
                {
                    IList newInstNoteText = noteTextPropertyInfo.GetValue(ninjaScript) as IList;
                    if (newInstNoteText != null)
                    {
                        // Since new instance could be past set defaults, clear any existing
                        newInstNoteText.Clear();
                        foreach (IndiChartNotes.StringWrapper oldStringWrapper in NoteText)
                        {
                            try
                            {
                                object newInstance = oldStringWrapper.AssemblyClone(Core.Globals.AssemblyRegistry.GetType(typeof(IndiChartNotes.StringWrapper).FullName));
                                if (newInstance == null)
                                {
                                    continue;
                                }

                                newInstNoteText.Add(newInstance);
                            }
                            catch { }
                        }
                    }
                }
            }
        }