Esempio n. 1
0
        public static void reload(ConvertedClass target, string fp)
        {
            int    uniqueFN = -1;
            Random r        = new Random();

            while (File.Exists("Temp/" + uniqueFN.ToString()) || uniqueFN == -1)
            {
                uniqueFN = r.Next(0, 255635).GetHashCode();
            }

            string path = "Temp/" + uniqueFN.ToString();

            File.Copy(fp, path);
            List <ConvertedClass> freshRead = readClass(path);

            Console.WriteLine("RELOADING");

            foreach (ConvertedClass fcc in freshRead)
            {
                //TODO: Catch class being removed
                //Console.WriteLine("reread {0}", fcc.name);
                if (fcc.name == target.name)
                {
                    target.diff(fcc);
                }
            }
        }
Esempio n. 2
0
        public static void registerFileWatch(string filePath, ConvertedClass cc)
        {
            if (filePath == null || fileWatchers.ContainsKey(filePath))
            {
                return;
            }

            Console.WriteLine("registering " + filePath);

            FileSystemWatcher fsw = new FileSystemWatcher();

            fsw.Path   = System.IO.Path.GetDirectoryName(filePath);
            fsw.Filter = System.IO.Path.GetFileName(filePath);

            fsw.EnableRaisingEvents = true;

            fileWatchers.Add(filePath, new ccFileWrapper(cc, fsw));
            //        this.textboxlink.Dispatcher.Invoke(DispatcherPriority.Normal,
            // new Action(() => { textBoxValue = this.textboxlink.Text; }));



            fsw.Changed += (object sender, FileSystemEventArgs e) => {
                setupSingleton.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { SetupWizard.reload(cc, filePath); }));
            };
        }
Esempio n. 3
0
        public void diff(ConvertedClass target)
        {
            Dictionary <string, fieldHelper> myPairs     = fields.ToDictionary(x => x.Name, x => x);
            Dictionary <string, fieldHelper> targetPairs = target.fields.ToDictionary(x => x.Name, x => x);

            for (int i = 0; i < fields.Count; i++)
            {
                fieldHelper fh = fields[i];
                if (targetPairs.ContainsKey(fh.Name))
                {
                    //Console.WriteLine("paired {0}", fh.Name);
                }
                else
                {
                    //Console.WriteLine("{0} not found", fh.Name);
                    fields.Remove(fh);
                    i--;
                }
            }

            foreach (fieldHelper fh in target.fields)
            {
                if (!myPairs.ContainsKey(fh.Name))
                {
                    //Console.WriteLine("NEW {0}", fh.Name);
                    fields.Add(fh);
                }
            }

            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("fields"));
            }
        }
Esempio n. 4
0
        public static List <ConvertedClass> readClass(string p)
        {
            string s = File.ReadAllText(p);

            List <ConvertedClass> toReturn = new List <ConvertedClass>();
            var syntaxTree = CSharpSyntaxTree.ParseText(s);

            var classes = syntaxTree.GetRoot().DescendantNodes().OfType <ClassDeclarationSyntax>();

            foreach (ClassDeclarationSyntax c in classes)
            {
                string[] identifierNames = c.DescendantNodes()
                                           .OfType <PropertyDeclarationSyntax>().Select(v => v.Identifier.Text)
                                           .ToArray();

                object[] identifierTypes = c.DescendantNodes()
                                           .OfType <PropertyDeclarationSyntax>().Select(v => v.Type)
                                           .ToArray();
                //Console.WriteLine(c.BaseList.ToString());
                loadedClasses.Add(c.Identifier.ToString());

                ConvertedClass cc = new ConvertedClass();

                if (c.BaseList != null)
                {
                    string clean = c.BaseList.ToString();
                    clean = clean.Replace(" ", "");
                    clean = clean.Replace(":", "");
                    Console.WriteLine("adding " + clean);
                    cc.dependencies.Add(clean);
                }
                cc.name = c.Identifier.ToString();


                for (int i = 0; i < identifierNames.Count(); i++)
                {
                    string tS = "";
                    tS = identifierTypes[i].ToString();
                    TypeSyntax t = identifierTypes[i] as TypeSyntax;
                    bool       l = false;
                    if (t.GetFirstToken().ToString() == "List")
                    {
                        tS = t.GetFirstToken().GetNextToken().GetNextToken().ToString();
                        l  = true;
                        Console.WriteLine("DEFINITELY A LIST");
                    }

                    cc.fields.Add(new fieldHelper(identifierNames[i], tS, l));
                }

                cc.linkedFilePath = p;

                cc.registerWatcher();

                toReturn.Add(cc);
            }

            return(toReturn);
        }
Esempio n. 5
0
        private void LoadedScripts_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Binding items = new Binding();

            items.Source = inspectedClasses[loadedScripts.SelectedIndex];
            Misc.WizardHierarchyConverter whc = new FlatBase.Misc.WizardHierarchyConverter();
            whc.setCC(inspectedClasses[loadedScripts.SelectedIndex]);
            items.Converter           = whc;
            items.Path                = new PropertyPath("fields");
            items.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;


            inspector.SetBinding(ListView.ItemsSourceProperty, items);
            curClass = inspectedClasses[loadedScripts.SelectedIndex];

            buildView();
        }
Esempio n. 6
0
 public ccFileWrapper(ConvertedClass cc, FileSystemWatcher fsw)
 {
     linkedCC  = cc;
     linkedFSW = fsw;
 }