Пример #1
0
        public static IStaticData GetStaticData(ISerializator serializator, string staticData)
        {
            var data = serializator.Deserialize <Internal_StaticData>(staticData);

            data.PostSerialize();
            return(data);
        }
Пример #2
0
        private static bool TryGetSerializator(TypeInfo type, out ISerializator serializator)
        {
            if (type.IsGenericType)
            {
                type = type.GetGenericTypeDefinition().GetTypeInfo();
            }

            if (type.Equals(typeof(object).GetTypeInfo()))
            {
                type = typeof(IObject).GetTypeInfo();
            }

            if (SerializatorsMap.TryGetValue(type, out var foundSerializator))
            {
                serializator = foundSerializator;

                return(true);
            }

            serializator = Serializators.SingleOrDefault(s => Equals(s.SupportedType, type)) ?? Serializators.FirstOrDefault(s => s.SupportedType.IsAssignableFrom(type));

            if (serializator != null)
            {
                SerializatorsMap[type] = serializator;
                return(true);
            }

            return(false);
        }
Пример #3
0
        public bool LoadShapeList(string filePath, ref string errorMessage)
        {
            try
            {
                string formatName = Path.GetExtension(filePath);
                if (formatName.Length > 1)
                {
                    formatName = formatName.Substring(1);
                }

                SerializationFormat serializationFormat = SerializationFormat.Binary;
                if (Functionality.GetSerializationFormatByName(formatName, ref serializationFormat))
                {
                    ISerializator serializator = SerializationManager.getInstance().GetSerializatorForFormat(serializationFormat);

                    if (null != serializator)
                    {
                        using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
                        {
                            //plugins work routine
                            var bytes = Utils.ReadStream(fileStream);
                            for (int i = Settings.OrderedAppliedPluginsList.Count - 1; i >= 0; i--)
                            {
                                bytes = Settings.OrderedAppliedPluginsList[i].ProcessDataOnLoad(filePath, serializationFormat, bytes);
                            }

                            //shapes deserealization
                            using (MemoryStream memoryStream = new MemoryStream(bytes))
                            {
                                ListOfShapes loadedShapeList = serializator.Deserialize <ListOfShapes>(memoryStream);

                                if (null != loadedShapeList)
                                {
                                    foreach (Shape shape in loadedShapeList.Shapes)
                                    {
                                        ListOfShapes.AddShape(shape);
                                    }

                                    return(true);
                                }
                            }
                        }
                    }
                }

                return(false);
            }
            catch (Exception e)
            {
                errorMessage = e.Message;
                return(false);
            }
        }
Пример #4
0
 public void SerializeEntities(ISerializator <List <IEntity> > serializator, List <IEntity> entities, IDisposable writer)
 {
     if (entities.Count > 0)
     {
         using (writer)
         {
             serializator.Serialize(writer, entities);
         }
     }
     else
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine($"No entity to serialize found!");
         Console.ForegroundColor = ConsoleColor.White;
     }
 }
Пример #5
0
        public MainWindow()
        {
            InitializeComponent();

            // For tests only.
            //_serializator = new SerializatorStub();
            //_scrapper = new OddsScrapperStub();

            // Uncomment for production.
            _serializator = new Serializator();
            _scrapper     = new OddsScrapper();

            _scrapper.ProgressReportedEvent += ProgressReportedEvent;

            //Oddslist = _scrapper.OddValues;
            OddsValuesList = new ObservableCollection <OddSerializationModel>();
        }
Пример #6
0
        public bool SaveShapeList(SerializationFormat serializationFormat, string dirPath, ref string filePath)
        {
            string extension = serializationFormat.ToString();
            var    shapeFilesOfSelectedFormat = new HashSet <string>(Directory.GetFiles(dirPath, "*." + extension));

            int i = 0;

            do
            {
                filePath = dirPath + "\\" + "shape_" + i + "." + serializationFormat.ToString();
                i++;
            } while (shapeFilesOfSelectedFormat.Contains(filePath));

            ISerializator serializator = SerializationManager.getInstance().GetSerializatorForFormat(serializationFormat);

            if (null != serializator)
            {
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    serializator.Serialize(memoryStream, ListOfShapes);

                    //plugins work routine
                    var dataToSave = Utils.ReadStream(memoryStream);
                    foreach (Plugin plugin in Settings.OrderedAppliedPluginsList)
                    {
                        dataToSave = plugin.ProcessDataOnSave(filePath, serializationFormat, dataToSave);
                    }

                    //save data to file
                    using (FileStream fileStream = new FileStream(filePath, FileMode.OpenOrCreate))
                    {
                        fileStream.Write(dataToSave, 0, dataToSave.Length);
                    }
                }

                return(true);
            }

            return(false);
        }
Пример #7
0
        public void Init(Vector3 startPosition, IEnumerable <IPoolable> Pooalables, float size)
        {
            activated = false;
            this.startCenterPosition = startPosition;
            this.size   = size;
            enterTriger = gameObject.AddComponent <BoxCollider>();
            enterTriger.transform.position = this.startCenterPosition;
            enterTriger.size      = new Vector3(TrackAbstract.GetInstance().LineWidth *10f, 40f, 1f);
            enterTriger.isTrigger = true;

            var trigerScript = gameObject.AddComponent <EnterTrackChunkStartTrigger>();

            trigerScript.chunk = this;
            bounds             = new Bounds(startPosition + new Vector3(0f, 5f, size / 2f), new Vector3(100f, 20f, size));

            foreach (IPoolable poolable in Pooalables)
            {
                if (bounds.Contains(poolable.GetGameObject.transform.position))
                {
                    try
                    {
                        ISerializator serializator = (ISerializator)gameObject.AddComponent(SerializatorTypes.SerializatorFor(poolable.GetType().Name));
                        if (serializator == null)
                        {
                            Debug.LogWarning(poolable.GetType().Name + "Serializator not found");
                        }
                        else
                        {
                            serializator.Serialize(poolable);
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.LogException(e);
                        Debug.LogError(poolable);
                    }
                }
            }
        }
Пример #8
0
 public static string CreateDefaultStatic(ISerializator serializator)
 {
     return(null);
     //return serializator.Serialize(new Internal_StaticData());
 }
Пример #9
0
 public Form1(ISerializator serializator)
 {
     this.serializator   = serializator;
     folderBrowserDialog = new FolderBrowserDialog();
     InitializeComponent();
 }
 public SerializingController(ISerializator serializator)
 {
     this.serializator = serializator;
 }
Пример #11
0
 public void Serialize(ISerializator <PhoneBook> serializer, IWriter writer)
 {
     serializer.Serialize(writer as FileWriter, this);
 }
Пример #12
0
 public static string CreateDefaultState(ISerializator serializator)
 {
     return(serializator.Serialize(new Internal_StateData()));
 }
Пример #13
0
 public static IServerLogicContext Create(ISerializator serializator, IMigrationsExternalAPI api)
 {
     return(null);
     //return new InternalContext(serializator, api);
 }
Пример #14
0
 public static IClientLogicContext Create(ISerializator serializator, ICommandStorage commandStorage, ITestExternalAPI api)
 {
     return(null);
     //return new InternalContext(serializator, commandStorage, api);
 }
Пример #15
0
 public SerializationEventArgs( ISerializator key, RegistrySerialization storage )
 {
   m_key = key;
   m_storage = storage;
 }
 private void RegisterSerializator(ISerializator serializator)
 {
     serialozators[serializator.OutputFormat()] = serializator;
 }
Пример #17
0
 public SerializationEventArgs(ISerializator key, RegistrySerialization storage)
 {
     m_key     = key;
     m_storage = storage;
 }
 public TestCommandStorage(ISerializator serializator)
 {
     _serializator = serializator;
 }
Пример #19
0
 public void SerializeBook(ISerializator <PhoneBook <IEntity> > serializer, IWriter writer, PhoneBook <IEntity> book)
 {
     serializer.Serialize(writer as FileWriter, book);
 }