예제 #1
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);
            }
        }
예제 #2
0
 private void Init()
 {
     Settings     = new Settings();
     ListOfShapes = new ListOfShapes();
 }