コード例 #1
0
        public bool GetSynchronizedMark()
        {
            string xmlFilePath = metadata.SourceXmlPath;

            if (String.IsNullOrEmpty(xmlFilePath))
            {
                // assume it's Imported and not synced
                return(false);
            }
            string baseFilePath = Path.Combine(
                Path.GetDirectoryName(xmlFilePath),
                Path.GetFileNameWithoutExtension(xmlFilePath));
            string metadataFilePath =
                String.Format(vtsagentFormat, baseFilePath);

            if (!File.Exists(metadataFilePath))
            {
                return(false);
            }
            using (FileStream metadataFile = new FileStream(metadataFilePath,
                                                            FileMode.Open,
                                                            FileAccess.Read,
                                                            FileShare.ReadWrite))
            {
                PsaMetadataPersistencyObject po =
                    new PsaMetadataPersistencyObject(metadataFile);
                return(po.IsSynchronized());
            }
        }
コード例 #2
0
        private void SetHiddenMark(bool mark)
        {
            string metadataFilePath = GetMetadataFilepath();

            if (String.IsNullOrEmpty(metadataFilePath))
            {
                return; // possibly imported data
            }
            using (FileStream file = new FileStream(metadataFilePath,
                                                    FileMode.OpenOrCreate,
                                                    FileAccess.ReadWrite,
                                                    FileShare.None))
            {
                PsaMetadataPersistencyObject po = new PsaMetadataPersistencyObject(file);
                po.IsHidden = mark;
            }
        }
コード例 #3
0
        public void PersistSynchronizedMark(bool isSynchronized)
        {
            string xmlFilePath = metadata.SourceXmlPath;

            if (String.IsNullOrEmpty(xmlFilePath))
            {
                // assume it's imported and has been synced to a server.
                return;
            }
            string baseFilePath = Path.Combine(
                Path.GetDirectoryName(xmlFilePath),
                Path.GetFileNameWithoutExtension(xmlFilePath));
            string metadataFilePath =
                String.Format(vtsagentFormat, baseFilePath);

            using (FileStream metadataFile =
                       File.Open(metadataFilePath, FileMode.OpenOrCreate))
            {
                PsaMetadataPersistencyObject po =
                    new PsaMetadataPersistencyObject(metadataFile);
                po.MarkAsSynchronized(isSynchronized);
                metadataFile.Close();
            }
        }
コード例 #4
0
        private void PersistLexiaMileage(int newMileage)
        {
            if (md.Subtype == PsaConnectorSubtype.Trace)
            {
                using (FileStream stream = new FileStream(
                           md.SourceXmlPath, FileMode.Open))
                {
                    int currentMileage = 0;

                    XDocument xDoc = XDocument.Load(stream);
                    IEnumerable <XElement> chapter1s = xDoc.Root.Elements(chapitre)
                                                       .Where(e => e.Attribute(code).Value == oo1);
                    foreach (XElement ch1 in chapter1s)
                    {
                        XElement infoOutil = ch1.Element(infoOutilString);
                        if (infoOutil != null)
                        {
                            XAttribute attr = infoOutil.Attribute(
                                kilometrage);
                            if (attr != null && !String.IsNullOrEmpty(attr.Value))
                            {
                                int result = 0;
                                Int32.TryParse(attr.Value,
                                               NumberStyles.Integer,
                                               CultureInfo.InvariantCulture, out result);
                                currentMileage = result;
                                break;
                            }
                        }
                    }
                    if (currentMileage != 0 && currentMileage >= newMileage)
                    {
                        return;
                    }
                    if (chapter1s.Count() != 0)
                    {
                        XElement infoOutil = chapter1s.First().
                                             Element(infoOutilString);
                        if (infoOutil != null)
                        {
                            XAttribute attr = infoOutil.Attribute(
                                kilometrage);
                            if (attr != null)
                            {
                                attr.Value = newMileage.ToString();
                                xDoc.Root.Elements(chapitre).Where(
                                    e => e.Attribute(code).Value == oo1).
                                FirstOrDefault().Element(infoOutilString).
                                Attribute(kilometrage).Value =
                                    newMileage.ToString();
                                stream.Position = 0;
                                xDoc.Save(stream);
                            }
                        }
                    }
                }
            }
            else if (md.Subtype == PsaConnectorSubtype.Graph)
            {
                string xmlFilePath  = md.SourceXmlPath;
                string baseFilePath = Path.Combine(
                    Path.GetDirectoryName(xmlFilePath),
                    Path.GetFileNameWithoutExtension(xmlFilePath));
                string metadataFilePath =
                    String.Format(vtsagentFormat, baseFilePath);
                FileStream metadataFile =
                    File.Open(metadataFilePath, FileMode.OpenOrCreate);
                PsaMetadataPersistencyObject po =
                    new PsaMetadataPersistencyObject(metadataFile);
                po.SetMileage(newMileage);
                metadataFile.Close();
            }
            else
            {
                throw new NotImplementedException();
            }
        }