public override System.Windows.Data.BindingBase Save()
        {
            if (channels.Count > 0)
            {
                System.Windows.Data.MultiBinding multiBind = new MultiBinding();
                foreach (IChannel channel in channels)
                {
                    System.Windows.Data.Binding bind = new System.Windows.Data.Binding("Value");
                    ChannelDataProvider         cdp  = new ChannelDataProvider();
                    cdp.ChannelName    = channel.PluginId + "." + channel.Name;
                    bind.Source        = cdp;
                    bind.FallbackValue = 0;
                    bind.Converter     = new Kent.Boogaart.Converters.TypeConverter(typeof(Double), typeof(Double));
                    multiBind.Bindings.Add(bind);
                }
                multiBind.Mode = BindingMode.TwoWay;
                ScriptConverter ec = new ScriptConverter(expressionEdit.Text);

                multiBind.Converter = ec;

                DependencyObject   depObj;
                DependencyProperty depProp;
                if (Property.GetWpfObjects(out depObj, out depProp))
                {
                    multiBind.FallbackValue = depObj.GetValue(depProp);
                }
                return(multiBind);
            }
            else
            {
                return(base.Save());
            }
        }
Esempio n. 2
0
        public void TestGetTagInvalidEnumValue()
        {
            ScriptType type = (ScriptType)99;
            Action     a    = () => ScriptConverter.GetTag(type);

            a.Should().Throw <InvalidOperationException>().WithMessage("Unable to find a tag for*");
        }
Esempio n. 3
0
 public ScriptConversion(string outputDirectory)
 {
     _outputDirectory = outputDirectory;
     workspace        = new AdhocWorkspace();
     project          = workspace.AddProject(ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Default, "Scripts",
                                                                "Scripts", LanguageNames.CSharp));
     _typings  = new Typings();
     converter = new ScriptConverter(_typings);
 }
                // -----------------
                override protected void OnDrawGUI(float indent)
                {
                    ScriptConverter.StartTreeViewElemHorizontal(this.view, this);

                    //EditorGUILayout.BeginHorizontal((this.view.selectedElem == this) ? CFEditorStyles.Inst.treeViewElemSelBG : CFEditorStyles.Inst.treeViewElemBG,
                    //	GUILayout.ExpandWidth(true));

                    GUILayout.Space(indent);

                    int enabledState = CFGUI.TriState("", "Restore this script.",
                                                      (this.enabled ? 1 : 0), EditorStyles.toggle, EditorStyles.toggle, GUILayout.Width(16)); //CFEditorStyles.Inst.checkbox, CFEditorStyles.Inst.checkbox );

                    if (enabledState != (this.enabled ? 1 : 0))
                    {
                        this.SetState((int)ElemStateId.Enabled, enabledState);
                    }

                    GUILayout.Space(indent);



                    GUILayout.Box(GUIContent.none, ((this.lang == ConvertedScript.Lang.CS) ? CFEditorStyles.Inst.iconScriptCS : CFEditorStyles.Inst.iconScriptJS));

                    //Color initialBGColor = GUI.backgroundColor;
                    //GUI.backgroundColor = this.bgColor;

                    if (GUILayout.Button(this.name, CFEditorStyles.Inst.treeViewElemTranspLabel, GUILayout.ExpandWidth(true)))
                    {
                        //Event c = Event.current;
//if (Event.current != null) Debug.Log("Event : key:" + c.keyCode + " button: " + c.button + " clicks: " + c.clickCount);
                        this.view.Select(this);
                    }

                    //GUI.backgroundColor = initialBGColor;

                    if (GUILayout.Button(new GUIContent("B", CFEditorStyles.Inst.magnifiyingGlassTex, "Open backup file."), GUILayout.Width(30), GUILayout.Height(16)))
                    {
                        this.ViewBackupFile();
                    }

                    if (GUILayout.Button(new GUIContent("C", CFEditorStyles.Inst.magnifiyingGlassTex, "Open current file."), GUILayout.Width(30), GUILayout.Height(16)))
                    {
                        this.ViewCurrentFile();
                    }



                    EditorGUILayout.EndHorizontal();
                }
Esempio n. 5
0
        private void OperationList_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                IEnumerable <IOperation> newItems = e.NewItems.Cast <IOperation>();

                ScriptString += ScriptConverter.GetString(newItems);
                ScriptHex    += ScriptConverter.GetHex(newItems);
            }
            else if (e.Action == NotifyCollectionChangedAction.Reset)
            {
                ScriptString = string.Empty;
                ScriptHex    = string.Empty;
            }

            // Raise for all actions: add, remove, change,...
            RunCommand.RaiseCanExecuteChanged();
        }
                // ----------------
                override protected void OnDrawGUI(float indent)
                {
                    ScriptConverter.StartTreeViewElemHorizontal(this.view, this);

                    //EditorGUILayout.BeginHorizontal((this.view.selectedElem == this) ? CFEditorStyles.Inst.treeViewElemSelBG : CFEditorStyles.Inst.treeViewElemBG,
                    //	GUILayout.ExpandWidth(true));

                    GUILayout.Space(indent);

                    int enabledState = CFGUI.TriState("", "Restore entire folder.",
                                                      (this.enableState), EditorStyles.toggle, EditorStyles.toggle, GUILayout.Width(16)); //, CFEditorStyles.Inst.checkbox, CFEditorStyles.Inst.checkbox );

                    if (enabledState != this.enableState)
                    {
                        this.SetState((int)ElemStateId.Enabled, enabledState);
                    }


                    //GUILayout.Space(indent);


                    //this.isFoldedOut = EditorGUILayout.Toggle(this.isFoldedOut, CFEditorStyles.Inst.foldout, GUILayout.Width(16));

                    GUILayout.Box(GUIContent.none, CFEditorStyles.Inst.iconFolder);

                    Color initialBGColor = GUI.backgroundColor;

                    GUI.backgroundColor = new Color(1, 1, 1, 0);  //this.bgColor;

                    if (GUILayout.Button(this.name, CFEditorStyles.Inst.treeViewElemTranspLabel, GUILayout.ExpandWidth(true)))
                    {
                        this.view.Select(this);
                    }

                    GUI.backgroundColor = initialBGColor;


                    EditorGUILayout.EndHorizontal();
                }
Esempio n. 7
0
        static void Main(string[] args)
        {
            List <string> paths       = new List <string>();
            List <string> inc         = new List <string>();
            List <string> @ref        = new List <string>();
            string        bin         = "a.exe";
            string        @class      = "Script";
            string        @base       = "System.Object";
            string        option      = "";
            bool          nocsc       = false;
            bool          classLib    = false;
            bool          pythonStyle = false;

            char prefix = '#';

            foreach (var item in args)
            {
                if (item == "/?")
                {
                    Console.WriteLine("cssc [/class:<classname>] [/ref:<file>] [/bin:<file>] [/base:<basename>] [/optimize] [/unsafe] [/win32icon:<file>] [/include:<dir>] [/nocsc] [/target:library] [/?] <src>");
                    Console.WriteLine();
                    Console.WriteLine("{0, -20}依存ファイルを指定します。", "/ref:<file>");
                    Console.WriteLine("{0, -20}出力ファイルを指定します。", "/bin:<file>");
                    Console.WriteLine("{0, -20}基底クラスを指定します。", "/base:<basename>");
                    Console.WriteLine("{0, -20}クラス名を指定します。", "/class:<classname>");
                    Console.WriteLine("{0, -20}インクルードファイルのディレクトリを指定します。", "/include:<dir>");
                    Console.WriteLine("{0, -20}入力ファイルを指定します。", "<src>");
                    Console.WriteLine("{0, -20}最適化を行います。", "/optimize");
                    Console.WriteLine("{0, -20}アンセーフコードを許可します。", "/unsafe");
                    Console.WriteLine("{0, -20}アイコンファイルを指定します。", "/win32icon:<file>");
                    Console.WriteLine("{0, -20}アセンブリの生成を行いません。", "/nocsc");
                    Console.WriteLine("{0, -20}クラスライブラリを出力します。", "/target:library");
                    Console.WriteLine("{0, -20}インデントでスコープを定義します。", "/scope:python");
                    Console.WriteLine();
                    Console.WriteLine("*ソースファイルが一つも指定されていない場合、自動でソースファイルを検索します。");
                    Console.WriteLine();
                }

                var match = Regex.Match(item, @"/(?<name>\w+)(:(?<value>.*))?");
                if (match.Success)
                {
                    var  name     = match.Groups["name"].Value;
                    bool hasValue = (match.Groups.Count > 1);
                    var  value    = hasValue ? match.Groups["value"].Value : null;

                    switch (name)
                    {
                    case "ref":
                        @ref.Add(value);
                        break;

                    case "bin":
                        bin = value;
                        break;

                    case "base":
                        @base = value;
                        break;

                    case "class":
                        @class = value;
                        break;

                    case "include":
                        inc.Add(value);
                        break;

                    case "optimize":
                        option += " /optimize+";
                        break;

                    case "unsafe":
                        option += " /unsafe";
                        break;

                    case "win32icon":
                        option += " /win32icon:" + value;
                        break;

                    case "nocsc":
                        nocsc = true;
                        break;

                    case "target":
                        if (value == "library")
                        {
                            classLib = true;
                        }
                        break;

                    case "scope":
                        if (value == "python")
                        {
                            pythonStyle = true;
                        }
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    paths.Add(item);
                }
            }

            if (paths.Count == 0)
            {
                Console.WriteLine("入力ファイルを自動で検索します。");
                foreach (var path in Directory.GetFiles(Environment.CurrentDirectory, "*.cs", SearchOption.AllDirectories))
                {
                    var file = Path.GetFileName(path);
                    if (!file.StartsWith(prefix.ToString()) && (char.IsLower(file.First())))
                    {
                        paths.Add(path);
                    }
                }
                foreach (var path in paths)
                {
                    Console.WriteLine("+ " + path);
                }
            }

            // Auto add include directory.
            foreach (var path in paths)
            {
                inc.Add(Path.GetDirectoryName(path));
            }

            try
            {
                // Not preprocessed C#/Script -> C#/Script
                var processor1 = new ScriptPreprocessor();
                var params1    = new ScriptPreprocessorParameters(inc.ToArray());
                var results1   = processor1.PreprocessFromFile(params1, paths.ToArray());

                // C#/Script -> C#
                var processor2 = new ScriptConverter();
                var params2    = new ScriptConverterParameters(@class, @base, !classLib)
                {
                    PythonScopeStyle = pythonStyle
                };
                var results2 = processor2.Convert(params2, results1.OutputSources);

                // (Save intermediate code.)
                List <string> csSourceFiles = new List <string>();
                for (int i = 0; i < results2.OutputSources.Length; i++)
                {
                    var dir  = Path.GetDirectoryName(paths[i]);
                    var file = prefix + Path.GetFileName(paths[i]);
                    var path = Path.Combine(dir, file);
                    using (var stream = new StreamWriter(path))
                    {
                        stream.Write(results2.OutputSources[i]);
                    }
                    csSourceFiles.Add(path);
                }

                if (nocsc)
                {
                    goto Finish;
                }

                // C# -> Assembly
                var processor3 = CodeDomProvider.CreateProvider("C#");
                var params3    = new CompilerParameters()
                {
                    GenerateExecutable      = (Path.GetExtension(bin) == ".exe"),
                    GenerateInMemory        = false,
                    IncludeDebugInformation = false,
                    OutputAssembly          = bin,
                    CompilerOptions         = option
                };
                params3.ReferencedAssemblies.AddRange(results1.ReferencedAssemblies.ToArray());
                params3.ReferencedAssemblies.AddRange(@ref.ToArray());
                var results3 = processor3.CompileAssemblyFromFile(params3, csSourceFiles.ToArray());
                processor3.Dispose();
                if (results3.Errors.HasErrors)
                {
                    var results = results3;

                    // Modify line number and columns.
                    foreach (CompilerError error in results.Errors)
                    {
                        if (File.Exists(error.FileName))
                        {
                            string errorSource;
                            using (var reader = new StreamReader(error.FileName))
                            {
                                errorSource = reader.ReadToEnd().Split('\n')[error.Line - 1];
                            }

                            var original = error.FileName.Replace("#", "");
                            if (File.Exists(original))
                            {
                                using (var reader = new StreamReader(original))
                                {
                                    error.Line = getline(reader.ReadToEnd(), errorSource);
                                }
                            }
                        }
                    }

                    foreach (CompilerError error in results.Errors)
                    {
                        error.FileName = error.FileName.Replace("#", "");
                    }

                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine("<!-- コンパイル エラー -->");
                    foreach (CompilerError error in results.Errors)
                    {
                        if (error.IsWarning)
                        {
                            Console.ForegroundColor = ConsoleColor.DarkYellow;
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.DarkRed;
                        }
                        Console.WriteLine(error.ToString());
                    }
                    return;
                }

Finish:
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("コンパイルが成功しました。");
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("コンパイル中に例外が発生しました。");
                Console.WriteLine(e);
            }
            finally
            {
                Console.ForegroundColor = ConsoleColor.White;
            }
        }
Esempio n. 8
0
        public void TestGetStringValueSub()
        {
            ScriptType type = ScriptType.Sub;

            ScriptConverter.GetStringValue(type).Should().Be("sub");
        }
Esempio n. 9
0
 public void TestGetTagSub()
 {
     ScriptConverter.GetTag(ScriptType.Sub).Should().Be("sub");
 }
Esempio n. 10
0
 public void TestGetTagSuper()
 {
     ScriptConverter.GetTag(ScriptType.Super).Should().Be("sup");
 }
Esempio n. 11
0
 public void TestGetEnumValueSuper()
 {
     ScriptConverter.GetEnumValue("super").Should().Be(ScriptType.Super);
 }
Esempio n. 12
0
 public void TestGetEnumValueDuffValue()
 {
     ScriptConverter.GetEnumValue("rubbish").Should().Be(null);
 }
Esempio n. 13
0
        public void TestGetStringValueNullableValue()
        {
            ScriptType?type = ScriptType.Super;

            ScriptConverter.GetStringValue(type).Should().Be("super");
        }
Esempio n. 14
0
        public void TestGetStringValueNullableNull()
        {
            ScriptType?type = null;

            ScriptConverter.GetStringValue(type).Should().Be("");
        }
Esempio n. 15
0
        public void TestGetStringValueInvalidEnumValue()
        {
            ScriptType type = (ScriptType)99;

            ScriptConverter.GetStringValue(type).Should().Be("");
        }
Esempio n. 16
0
        private void Run()
        {
            var source = this.Scintilla.Text;

            this.ErrorView.Clear();

            this.NotifyProgress(0);

            this.CommandNumber++;

            ScriptPreprocessorResults results1 = null;

            #region Not preprocessed C#/Script -> C#/Script
            {
                var params1 = new ScriptPreprocessorParameters(Path.GetDirectoryName(OpenFilePath));
                try
                {
                    results1 = new ScriptPreprocessor().Preprocess(params1, source);
                }
                catch (CompilerErrorException e)
                {
                    if (e.Errors.Count > 0)
                    {
                        foreach (CompilerError error in e.Errors)
                        {
                            this.ErrorView.Add(error);
                        }
                        this.NotifyMessage("プリプロセスエラーが発生しました。");
                        this.NotifyProgress(0);
                        return;
                    }
                }
                this.NotifyProgress(25);
            }
            #endregion

            ScriptConverterResults results2;

            #region C#/Script -> C#
            {
                string baseclass = Assembly.GetEntryAssembly().GetType("GameScript") != null ? "GameScript" : "object";
                var    params2   = new ScriptConverterParameters("_Command" + this.CommandNumber, baseclass, false)
                {
                    BatchScriptStyle = true
                };
                results2 = new ScriptConverter().Convert(params2, results1.OutputSources);

                this.NotifyProgress(50);
            }
            #endregion

            var source2 = results2.OutputSources[0];

            CompilerResults results3;

            #region C# -> Assembly
            {
                var compiler = CodeDomProvider.CreateProvider("C#");
                var params3  = new CompilerParameters()
                {
                    GenerateExecutable      = false,
                    GenerateInMemory        = true,
                    IncludeDebugInformation = false,
                };
                params3.ReferencedAssemblies.AddRange(results1.ReferencedAssemblies.ToArray());
                params3.ReferencedAssemblies.AddRange(Directory.GetFiles(Application.StartupPath, "*.dll"));
                params3.ReferencedAssemblies.AddRange(Directory.GetFiles(Application.StartupPath, "*.exe"));
                params3.CompilerOptions += " /unsafe";
                params3.CompilerOptions += " /optimize+";

                results3 = compiler.CompileAssemblyFromSource(params3, source2);
                compiler.Dispose();
                if (results3.Errors.HasErrors)
                {
                    string[] splitedSource2 = source2.Split('\n');

                    foreach (CompilerError error in results3.Errors)
                    {
                        int lineOfSource2 = error.Line - 1;

                        if (0 <= lineOfSource2 && lineOfSource2 < splitedSource2.Length)
                        {
                            string errorText = splitedSource2[lineOfSource2];
                            error.Line = getline(source, errorText);
                        }

                        this.ErrorView.Add(error);
                    }
                    this.NotifyMessage("コンパイルエラーが発生しました。");
                    this.NotifyProgress(0);
                    return;
                }
                this.NotifyProgress(100);
            }
            #endregion

            #region Run script
            {
                var asm  = results3.CompiledAssembly;
                var type = asm.GetType("_Command" + this.CommandNumber);
                type.GetMethod("run").Invoke(null, null);
                this.NotifyMessage("スクリプトの実行が完了しました。");
            }
            #endregion
        }