private void ExportSectionsAndMeters(IBaseSerializer baseSerializer, string documentsPath, OperationData operationData)
        {
            var deviceElementUses        = GetAllDeviceElementUses(operationData);
            var deviceElementUseFileName = string.Format(DatacardConstants.SectionFile, operationData.Id.ReferenceId);
            var deviceElementUseFilePath = Path.Combine(documentsPath, deviceElementUseFileName);

            var workingData         = deviceElementUses.SelectMany(deviceElementUse => deviceElementUse.Value.SelectMany(x => x.GetWorkingDatas()));
            var workingDataFileName = string.Format(DatacardConstants.WorkingDataFile, operationData.Id.ReferenceId);
            var workingDataFilePath = Path.Combine(documentsPath, workingDataFileName);

            baseSerializer.Serialize(deviceElementUses, deviceElementUseFilePath);
            baseSerializer.Serialize(workingData, workingDataFilePath);
        }
        private void WriteObject <T>(IBaseSerializer baseSerializer, string documentsPath, T obj, int referenceId, string fileNameFormat)
        {
            var fileName = String.Format(fileNameFormat, referenceId);
            var filePath = Path.Combine(documentsPath, fileName);

            baseSerializer.Serialize(obj, filePath);
        }
        public void Serialize(IBaseSerializer baseSerializer, IEnumerable <ReferenceLayer> referenceLayers, string path)
        {
            if (referenceLayers == null)
            {
                return;
            }

            var serializableReferenceLayers = referenceLayers.Select(x => _protobufReferenceLayerConverter.ConvertToSerializableReferenceLayer(x)).ToList();

            baseSerializer.Serialize(serializableReferenceLayers, Path.Combine(path, DatacardConstants.ReferenceLayersFile));
        }
Esempio n. 4
0
    public void Serialize(IBaseSerializer baseSerializer, T content, string dataPath)
    {
      if (content == null)
      {
        return;
      }

      var filePath = Path.Combine(dataPath, _fileName);

      baseSerializer.Serialize(content, filePath);
    }
Esempio n. 5
0
        private void ButtonSave_Click(object sender, EventArgs e)
        {
            Control textboxFileName    = Controls.Find("textboxFileName", true)[0];
            Control comboboxSerializer = Controls.Find("comboboxSerializer", true)[0];
            Control comboboxPlugin     = Controls.Find("comboboxPlugin", true)[0];

            if ((textboxFileName.Text.Length == 0) || (comboboxSerializer.Text.Length == 0))
            {
                MessageBox.Show("Incorrect data!");
                return;
            }
            Type            serializerType = Data.serializerTypes.First(t => (t.GetCustomAttribute(typeof(DescriptionAttribute)) as DescriptionAttribute).Description == comboboxSerializer.Text);
            IBaseSerializer serializer     = Data.serializers.First(s => s.GetType() == serializerType);
            string          fileName       = textboxFileName.Text + "." + serializer.GetExtention();

            using (Stream outputStream = new MemoryStream())
            {
                serializer.Serialize(outputStream, Data.objects);
                if (comboboxPlugin.Text.Length == 0)
                {
                    using (FileStream fileStream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write))
                    {
                        outputStream.Seek(0, SeekOrigin.Begin);
                        byte[] bytes = new byte[outputStream.Length];
                        outputStream.Read(bytes, 0, (int)outputStream.Length);
                        fileStream.Write(bytes, 0, bytes.Length);
                    }
                }
                else
                {
                    Type    pluginType = Data.pluginTypes.First(t => (t.GetCustomAttribute(typeof(DescriptionAttribute)) as DescriptionAttribute).Description == comboboxPlugin.Text);
                    IPlugin plugin     = Data.plugins.First(p => p.GetType() == pluginType);
                    fileName += "." + plugin.GetExt();
                    plugin.Archive(fileName, outputStream);
                }
            }
            MessageBox.Show("Data has successfully saved!");
            Dispose();
        }
 public void GivenSerializerWhenSerializeCalledWithNullThenShouldReturnNull(IBaseSerializer serializer)
 {
     Assert.Null(serializer.Serialize(null, null));
 }