コード例 #1
0
        public void SaveFolderState(string deviceId, SyncKey syncKey, StateObjects.FolderHierarchyState folderState)
        {
            var folderPath = String.Format("{0}\\folders", deviceId);

            folderPath = Path.Combine(rootFolder, folderPath);

            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }

            var filePath = String.Format("fld-{0}.xml", syncKey);

            filePath = Path.Combine(folderPath, filePath);

            var dsFolderState = new DataSet();

            var xmlSerializer = new XmlSerializer(folderState.GetType());
            var writer        = new StringWriter();

            xmlSerializer.Serialize(writer, folderState);
            var reader = new StringReader(writer.ToString());

            dsFolderState.ReadXml(reader);

            dsFolderState.WriteXml(filePath);

            if (DeleteOldData)
            {
                foreach (var oldFilePath in from oldFilePath in Directory.GetFiles(folderPath) let oldFileName = Path.GetFileName(oldFilePath) where oldFileName != null && oldFileName.StartsWith("fld-") && oldFileName != Path.GetFileName(filePath) select oldFilePath)
                {
                    File.Delete(oldFilePath);
                }
            }
        }
コード例 #2
0
ファイル: SyncKey.cs プロジェクト: liaodong/ActiveSync
        public static bool TryParse(string syncKey, out SyncKey syncKeyObject)
        {
            try
            {
                var syncKeyTemp = (SyncKey)syncKey;
                syncKeyObject = syncKeyTemp;

                return(syncKeyTemp != null);
            }
            catch
            {
                syncKeyObject = null;
                return(false);
            }
        }
コード例 #3
0
        public FolderHierarchyState LoadFolderState(string deviceId, SyncKey syncKey)
        {
            var folderPath = String.Format("{0}\\folders", deviceId);

            folderPath = Path.Combine(rootFolder, folderPath);
            var filePath = String.Format("fld-{0}.xml", syncKey);

            filePath = Path.Combine(folderPath, filePath);

            if (!File.Exists(filePath))
            {
                return(null);
            }

            var serializer = new XmlSerializer(typeof(FolderHierarchyState));

            using (var reader = XmlReader.Create(filePath))
            {
                return((FolderHierarchyState)serializer.Deserialize(reader));
            }
        }
コード例 #4
0
        public void SaveCollectionState(string deviceId, SyncKey syncKey, CollectionState collectionState)
        {
            FileStateMachine.LastSyncKey = syncKey;
            var folderPath = String.Format("{0}\\collections", deviceId);

            folderPath = Path.Combine(rootFolder, folderPath);

            var collectionPrefix = "coll-" + collectionState.FolderId;
            var filePath         = String.Format("{0}-{1}.xml", collectionPrefix, syncKey);

            filePath = Path.Combine(folderPath, filePath);

            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }

            var dsCollectionState = new DataSet();
            var xmlSerializer     = new XmlSerializer(collectionState.GetType());
            var writer            = new StringWriter();

            xmlSerializer.Serialize(writer, collectionState);
            var reader = new StringReader(writer.ToString());

            dsCollectionState.ReadXml(reader);

            dsCollectionState.Tables[0].TableName = "CollectionState";
            dsCollectionState.DataSetName         = "CollectionStates";

            dsCollectionState.WriteXml(filePath);


            if (DeleteOldData)
            {
                foreach (var oldFilePath in from oldFilePath in Directory.GetFiles(folderPath) let oldFileName = Path.GetFileName(oldFilePath) where oldFileName != null && oldFileName.StartsWith(collectionPrefix) && oldFileName != Path.GetFileName(filePath) select oldFilePath)
                {
                    File.Delete(oldFilePath);
                }
            }
        }
コード例 #5
0
        public CollectionState LoadCollectionState(string deviceId, SyncKey syncKey, string folderId)
        {
            var folderPath = String.Format("{0}\\collections", deviceId);

            folderPath = Path.Combine(rootFolder, folderPath);

            var filePath = String.Format("coll-{0}-{1}.xml", folderId, syncKey);

            filePath = Path.Combine(folderPath, filePath);

            if (!File.Exists(filePath))
            {
                return(null);
            }

            var serializer = new XmlSerializer(typeof(CollectionState));

            using (var reader = XmlReader.Create(filePath))
            {
                return((CollectionState)serializer.Deserialize(reader));
            }
        }
コード例 #6
0
        /// <summary>
        /// The SyncKey element is a required child element of the Collection element in Sync command requests and responses that contains a value that is used by the server to mark the synchronization state of a collection.
        /// A synchronization key of value 0 (zero) initializes the synchronization state on the server and causes a full synchronization of the collection. The server sends a response that includes a new synchronization key value. The client MUST store this synchronization key value until the client requires the key value for the next synchronization request for that collection. When the client uses this synchronization key value to do the next synchronization of the collection, the client sends this synchronization key value to the server in a Sync request. If the synchronization is successful, the server responds by sending all objects in the collection. The response includes a new synchronization key value that the client MUST use on the next synchronization of the collection.
        /// </summary>
        /// <returns></returns>
        public string GetNewSyncKey(string synckey)
        {
            SyncKey synckeyObject;

            if (string.IsNullOrWhiteSpace(synckey) || synckey == "0")
            {
                //First Initilize of Sync Key
                synckeyObject = new SyncKey
                {
                    Key     = GenerateNewUniqueKey(),
                    Counter = 0
                };
            }
            else
            {
                synckeyObject = (SyncKey)synckey;
            }

            synckeyObject.Counter += 1;

            return(synckeyObject.ToString());
        }
コード例 #7
0
 public void SaveCollectionState(SyncKey syncKey, CollectionState collectionState)
 {
     StateMachine.SaveCollectionState(UserDevice.DeviceId, syncKey, collectionState);
 }
コード例 #8
0
 public void SaveFolderState(SyncKey syncKey, FolderHierarchyState folderState)
 {
     StateMachine.SaveFolderState(UserDevice.DeviceId, syncKey, folderState);
 }
コード例 #9
0
 public CollectionState LoadCollectionState(SyncKey syncKey, string folderId)
 {
     return(StateMachine.LoadCollectionState(UserDevice.DeviceId, syncKey, folderId));
 }
コード例 #10
0
 public FolderHierarchyState LoadFolderState(SyncKey syncKey)
 {
     return(StateMachine.LoadFolderState(UserDevice.DeviceId, syncKey));
 }