예제 #1
0
        private static Aindicator Serialize(string path, string nameClass, string name, bool canDelete)
        {
            try
            {
                Aindicator result = null;

                string fileStr = ReadFile(path);

                CSharpCodeProvider prov = new CSharpCodeProvider();

                var assemblies = AppDomain.CurrentDomain.GetAssemblies();

                var res = Array.ConvertAll <Assembly, string>(assemblies, (x) =>
                {
                    if (!x.IsDynamic)
                    {
                        return(x.Location);
                    }

                    return(null);
                });

                CompilerParameters cp = new CompilerParameters(res);

                cp.IncludeDebugInformation = true;

                cp.GenerateInMemory    = true;
                cp.TempFiles.KeepFiles = false;

                CompilerResults results = prov.CompileAssemblyFromSource(cp, fileStr);

                if (results.Errors != null && results.Errors.Count != 0)
                {
                    string errorString = "Error! Indicator script runTime compilation problem! \n";
                    errorString += "Path to indicator: " + path + " \n";

                    int errorNum = 1;

                    foreach (var error in results.Errors)
                    {
                        errorString += "Error Number: " + errorNum + " \n";
                        errorString += error.ToString() + "\n";
                        errorNum++;
                    }

                    throw new Exception(errorString);
                }

                result = (Aindicator)results.CompiledAssembly.CreateInstance(results.CompiledAssembly.DefinedTypes.ElementAt(0).FullName);

                cp.TempFiles.Delete();

                return(result);
            }
            catch (Exception e)
            {
                throw new Exception(e.ToString());
            }
        }
예제 #2
0
        public static Aindicator CreateIndicatorByName(string nameClass, string name, bool canDelete)
        {
            Aindicator Indicator = null;

            /* if (nameClass == "FBD")
             * {
             *   Indicator = new FBD();
             * }*/

            try
            {
                if (Indicator == null)
                {
                    List <string> fullPaths = GetFullNamesFromFolder(@"Custom\Indicators\Scripts");

                    string longNameClass  = nameClass + ".txt";
                    string longNameClass2 = nameClass + ".cs";

                    string myPath = "";

                    for (int i = 0; i < fullPaths.Count; i++)
                    {
                        string nameInFile = fullPaths[i].Split('\\')[fullPaths[i].Split('\\').Length - 1];

                        if (nameInFile == longNameClass ||
                            nameInFile == longNameClass2)
                        {
                            myPath = fullPaths[i];
                            break;
                        }
                    }

                    if (myPath == "")
                    {
                        MessageBox.Show("Error! Indicator with name " + nameClass + "not found");
                        return(null);
                    }

                    Indicator = Serialize(myPath, nameClass, name, canDelete);
                }

                Indicator.Init(name);
                Indicator.CanDelete = canDelete;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }

            return(Indicator);
        }
예제 #3
0
        public AIndicatorUi(Aindicator indicator)
        {
            InitializeComponent();
            Title      = indicator.GetType().Name + " " + OsLocalization.Charts.Label1;
            _indicator = indicator;

            CreateGridParam();
            UpdateGridParam();

            CreateGridVisual();
            UpdateGridVisual();

            CreateGridIndicators();
            UpdateGridIndicators();

            TabItemParam.Header      = OsLocalization.Charts.Label2;
            TabItemVisual.Header     = OsLocalization.Charts.Label3;
            TabItemIncludeInd.Header = OsLocalization.Charts.Label4;
            ButtonAccept.Content     = OsLocalization.Charts.LabelButtonIndicatorAccept;
            ButtonDefault.Content    = OsLocalization.Charts.Label5;
        }
예제 #4
0
        public static Aindicator CreateIndicatorByName(string nameClass, string name, bool canDelete)
        {
            Aindicator Indicator = null;

            /* if (nameClass == "Ssma")
             * {
             *   Indicator = new Ssma();
             * }*/

            if (Indicator == null)
            {
                List <string> fullPaths = GetFullNamesFromFolder(@"Custom\Indicators");

                string longNameClass  = nameClass + ".txt";
                string longNameClass2 = nameClass + ".cs";

                string myPath = "";

                for (int i = 0; i < fullPaths.Count; i++)
                {
                    if (fullPaths[i].EndsWith(longNameClass) ||
                        fullPaths[i].EndsWith(longNameClass2))
                    {
                        myPath = fullPaths[i];
                        break;
                    }
                }

                Indicator = Serialize(myPath, nameClass, name, canDelete);
            }

            Indicator.CanDelete = canDelete;
            Indicator.Init(name);

            return(Indicator);
        }
예제 #5
0
        private static Aindicator Serialize(string path, string nameClass, string name, bool canDelete)
        {
            // 1 пробуем клонировать из ранее сериализованных объектов. Это быстрее чем подымать из файла

            for (int i = 0; i < _serializedInd.Count; i++)
            {
                if (_serializedInd[i].GetType().Name == nameClass)
                {
                    object[]   param    = new object[] { name };
                    Aindicator newPanel = (Aindicator)Activator.CreateInstance(_serializedInd[i].GetType());
                    newPanel.Init(name);
                    newPanel.CanDelete = canDelete;
                    return(newPanel);
                }
            }

            // сериализуем из файла

            try
            {
                if (linksToDll == null)
                {
                    var assemblies = AppDomain.CurrentDomain.GetAssemblies();

                    var res = Array.ConvertAll <Assembly, string>(assemblies, (x) =>
                    {
                        if (!x.IsDynamic)
                        {
                            return(x.Location);
                        }

                        return(null);
                    });

                    for (int i = 0; i < res.Length; i++)
                    {
                        if (string.IsNullOrEmpty(res[i]))
                        {
                            List <string> list = res.ToList();
                            list.RemoveAt(i);
                            res = list.ToArray();
                            i--;
                        }
                        else if (res[i].Contains("System.Runtime.Serialization") ||
                                 i > 24)
                        {
                            List <string> list = res.ToList();
                            list.RemoveAt(i);
                            res = list.ToArray();
                            i--;
                        }
                    }

                    string dllPath = AppDomain.CurrentDomain.BaseDirectory + "System.Runtime.Serialization.dll";

                    List <string> listRes = res.ToList();
                    listRes.Add(dllPath);
                    res = listRes.ToArray();

                    linksToDll = res;
                }

                List <string> dllsToCompiler = linksToDll.ToList();

                List <string> dllsFromPath = GetDllsPathFromFolder(path);

                if (dllsFromPath != null && dllsFromPath.Count != 0)
                {
                    for (int i = 0; i < dllsFromPath.Count; i++)
                    {
                        string dll = dllsFromPath[i].Split('\\')[dllsFromPath[i].Split('\\').Length - 1];

                        if (dllsToCompiler.Find(d => d.Contains(dll)) == null)
                        {
                            dllsToCompiler.Add(dllsFromPath[i]);
                        }
                    }
                }


                CompilerParameters cp = new CompilerParameters(dllsToCompiler.ToArray());
                cp.IncludeDebugInformation = true;
                cp.GenerateInMemory        = true;

                string folderCur = AppDomain.CurrentDomain.BaseDirectory + "Engine\\Temp";

                if (Directory.Exists(folderCur) == false)
                {
                    Directory.CreateDirectory(folderCur);
                }

                folderCur += "\\Indicators";

                if (Directory.Exists(folderCur) == false)
                {
                    Directory.CreateDirectory(folderCur);
                }

                if (_isFirstTime)
                {
                    _isFirstTime = false;

                    string[] files = Directory.GetFiles(folderCur);

                    for (int i = 0; i < files.Length; i++)
                    {
                        try
                        {
                            File.Delete(files[i]);
                        }
                        catch
                        {
                            // ignore
                        }
                    }
                }

                cp.TempFiles = new TempFileCollection(folderCur, false);

                Aindicator result = null;

                string fileStr = ReadFile(path);

                CSharpCodeProvider prov = new CSharpCodeProvider();

                CompilerResults results = prov.CompileAssemblyFromSource(cp, fileStr);

                if (results.Errors != null && results.Errors.Count != 0)
                {
                    string errorString = "Error! Indicator script runTime compilation problem! \n";
                    errorString += "Path to indicator: " + path + " \n";

                    int errorNum = 1;

                    foreach (var error in results.Errors)
                    {
                        errorString += "Error Number: " + errorNum + " \n";
                        errorString += error.ToString() + "\n";
                        errorNum++;
                    }

                    throw new Exception(errorString);
                }

                result = (Aindicator)results.CompiledAssembly.CreateInstance(results.CompiledAssembly.DefinedTypes.ElementAt(0).FullName);

                cp.TempFiles.Delete();

                bool isInArray = false;

                for (int i = 0; i < _serializedInd.Count; i++)
                {
                    if (_serializedInd[i].GetType().Name == nameClass)
                    {
                        isInArray = true;
                        break;
                    }
                }

                if (isInArray == false)
                {
                    _serializedInd.Add(result);
                }

                return(result);
            }
            catch (Exception e)
            {
                throw new Exception(e.ToString());
            }
        }
예제 #6
0
 public void ProcessIndicator(string indicatorName, Aindicator indicator)
 {
     IncludeIndicators.Add(indicator);
     IncludeIndicatorsName.Add(indicatorName);
 }