示例#1
0
        MetaClass CreateMetaClass(System.Type type)
        {
            var cname = RttiHelper.GetTypeSaveString(type);

            var klass = new MetaClass();

            klass.MetaType = type;
            var csIdx    = cname.IndexOf('|');
            var fileName = cname;

            if (csIdx >= 0)
            {
                fileName = cname.Substring(csIdx + 1);
            }
            klass.ClassName = RName.GetRName(MetaDirectory.Name + "/" + fileName);

            MetaData curVer = new MetaData();

            curVer.BuildMetaData(type);

            Hash64 hash = klass.GetFolderHash();
            string dir  = klass.ClassName.GetDirectory() + hash.ToString();

            if (EngineNS.CEngine.Instance.FileManager.DirectoryExists(dir))
            {
                bool hasRedirection = false;
                klass.LoadXnd(out hasRedirection);
#if PWindow
                //if (hasRedirection)
                //    klass.Save2Xnd(false);
#endif
                MetaData data = klass.FindMetaData(curVer.MetaHash);
                if (data == null)
                {
                    klass.RegMetaData(curVer.MetaHash, curVer);
                    var xnd = IO.XndHolder.NewXNDHolder();
                    curVer.Save2Xnd(xnd.Node);
                    IO.XndHolder.SaveXND(dir + "/" + curVer.MetaHash + ".MetaData", xnd);
                }
            }
            else
            {
                CEngine.Instance.FileManager.CreateDirectory(dir);

                var sw = new System.IO.StreamWriter(dir + "/typename.txt", false);
                sw.WriteLine(cname);
                sw.Close();

                klass.RegMetaData(curVer.MetaHash, curVer);
                var xnd = IO.XndHolder.NewXNDHolder();
                curVer.Save2Xnd(xnd.Node);
                IO.XndHolder.SaveXND(dir + "/" + curVer.MetaHash + ".MetaData", xnd);
            }

            klass.CurrentVersion = curVer;
            Klasses.Add(cname, klass);

            return(klass);
        }
示例#2
0
        private void Copy(Avdeling copyFrom, TimeplanEntities db)
        {
            Navn = copyFrom.Navn;
            fk_AvdelingslederAnsattId = copyFrom.AvdelingsLeder.Id;

            Klasses.Clear();
            foreach (var klasse in copyFrom.Klasses)
            {
                Klasses.Add(Klasse.GetById(klasse.Id, db));
            }

            Ansatts.Clear();
            foreach (var ansatt in copyFrom.Ansatts)
            {
                Ansatts.Add(Ansatt.GetById(ansatt.Id, db));
            }
        }
示例#3
0
        private void Load()
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Title            = "Open Diagram";
            dialog.Filter           = "Diagram files (*.dia)|*.dia";
            dialog.RestoreDirectory = true;

            if ((bool)dialog.ShowDialog())
            {
                // Load data from file
                IFormatter formatter = new BinaryFormatter();
                FileStream s         = new FileStream(dialog.FileName, FileMode.Open);

                try
                {
                    ObservableCollection <Klass> t = (ObservableCollection <Klass>)formatter.Deserialize(s);
                    // Clear existing Klasses and Relations
                    Klasses.Clear();
                    Relations.Clear();

                    // Add loaded data
                    foreach (Klass k in t)
                    {
                        // Add Klass
                        Klasses.Add(k);

                        // Add Relations
                        foreach (Relation r in k.Relations)
                        {
                            if (!Relations.Contains(r))
                            {
                                Relations.Add(r);
                            }
                        }
                    }

                    _filepath = dialog.FileName;
                }
                catch (Exception)
                {
                    MessageBox.Show("Please choose a valid Diagram file.");
                }
            }
        }
示例#4
0
        public void Update(string navn, int avdelingsLederId, IList <int> ansatteIds, IList <int> klasserIds)
        {
            if (Navn != navn)
            {
                Navn      = navn;
                IsChanged = true;
            }

            if (AvdelingsLeder == null || AvdelingsLeder.Id != avdelingsLederId)
            {
                AvdelingsLeder = Ansatt.GetById(avdelingsLederId);
                IsChanged      = true;
            }

            var klasserIdsOld = Klasses.OrderBy(klasse => klasse.Id).Select(klasse => klasse.Id).ToList();

            if (klasserIdsOld.Count != klasserIds.Count ||
                klasserIdsOld.SequenceEqual(klasserIds.OrderBy(i => i)) == false)
            {
                Klasses.Clear();
                foreach (var klasseId in klasserIds)
                {
                    Klasses.Add(Klasse.GetById(klasseId));
                }
                IsChanged = true;
            }

            var ansattIdsOld = Ansatts.OrderBy(ansatt => ansatt.Id).Select(ansatt => ansatt.Id).ToList();

            if (ansattIdsOld.Count != ansatteIds.Count ||
                ansattIdsOld.SequenceEqual(ansatteIds.OrderBy(i => i)) == false)
            {
                Ansatts.Clear();
                foreach (var ansattId in ansatteIds)
                {
                    Ansatts.Add(Ansatt.GetById(ansattId));
                }
                IsChanged = true;
            }
        }
示例#5
0
        public void LoadMetaClasses()
        {
            var t1   = Support.Time.HighPrecision_GetTickCount();
            var dirs = CEngine.Instance.FileManager.GetDirectories(MetaDirectory.Address);

            if (dirs == null)
            {
                Profiler.Log.WriteLine(Profiler.ELogTag.Error, "MetaData", $"MetaDirectory.Address is null:{MetaDirectory.Address}");
                return;
            }
            foreach (var i in dirs)
            {
                if (false == CEngine.Instance.FileManager.FileExists(i + "/typename.txt"))
                {
                    continue;
                }

                //System.IO.StreamReader sr = new System.IO.StreamReader(i + "/typename.txt", System.Text.Encoding.ASCII);
                //string className = sr.ReadLine();
                //sr.Close();

                byte[] bytes     = IO.FileManager.ReadFile(i + "/typename.txt");
                string className = System.Text.Encoding.ASCII.GetString(bytes);
                className = className.Replace("\r\n", "");

                ///////////////////////////////////////////////////////////////////
                //if (className.Contains("enginecore"))
                //{
                //    using (var sw = new System.IO.StreamWriter(i + "/typename.txt", false, System.Text.Encoding.ASCII))
                //    {
                //        className = className.Replace("enginecore", "EngineCore");
                //        sw.WriteLine(className);
                //    }
                //}
                //if (className.Contains("Common|EngineCore"))
                //{
                //    using (var sw = new System.IO.StreamWriter(i + "/typename.txt", false, System.Text.Encoding.ASCII))
                //    {
                //        className = className.Replace("Common|EngineCore", "Client|EngineCore");
                //        sw.WriteLine(className);
                //    }
                //}
                ///////////////////////////////////////////////////////////////////
                bool isRedirection;
                var  type = RttiHelper.GetTypeFromSaveString(className, out isRedirection);
                if (type == null)
                {
                    continue;
                }

                if (CIPlatform.Instance.PlayMode != CIPlatform.enPlayMode.Game)
                {
                    var noUsedFile = i + "/" + type.FullName + ".noused";
                    if (CEngine.Instance.FileManager.FileExists(noUsedFile) == false)
                    {
                        CEngine.Instance.FileManager.CreateFile(noUsedFile);
                    }
                }

                MetaClass klass = new MetaClass();
                klass.MetaType = type;
                var csIdx   = className.IndexOf('|');
                var fileStr = className;
                if (csIdx >= 0)
                {
                    fileStr = className.Substring(csIdx + 1);
                }
                klass.ClassName = RName.GetRName(MetaDirectory.Name + "/" + fileStr);
                bool hasRedirection = false;
                klass.LoadXnd(out hasRedirection);
#if PWindow
                //if (hasRedirection)
                //    klass.Save2Xnd(false);
#endif

                // 重定向后由于原来的类型已不存在,不再进行当前版本的处理
                if (!isRedirection)
                {
                    MetaData curVer = new MetaData();
                    curVer.BuildMetaData(type);

                    MetaData data = klass.FindMetaData(curVer.MetaHash);
                    if (data == null)
                    {
                        klass.RegMetaData(curVer.MetaHash, curVer);

#if PWindow
                        var xnd = IO.XndHolder.NewXNDHolder();
                        curVer.Save2Xnd(xnd.Node);
                        var hash = klass.GetFolderHash();
                        var file = klass.ClassName.GetRootFolder() + "MetaClasses/" + hash.ToString() + "/" + curVer.MetaHash + ".MetaData";
                        IO.XndHolder.SaveXND(file, xnd);
                        klass.CurrentVersion = curVer;
#endif
                    }
                    else
                    {
                        klass.CurrentVersion = data;
                    }
                }

                Klasses.Add(className, klass);
            }

            var t2 = Support.Time.HighPrecision_GetTickCount();
            Profiler.Log.WriteLine(Profiler.ELogTag.Info, "MetaData", $"LoadMetaClasses Time:{t2-t1}");
            //MetaDatas.Clear();
            //foreach (var i in Klasses)
            //{
            //    foreach (var j in i.Value.Metas)
            //    {
            //        MetaDatas.Add(j.Key, j.Value);
            //    }
            //}
        }