Ejemplo n.º 1
0
        private static void ResetDataset(SubscriberDataset dataset, long endIndex)
        {
            if (endIndex > 0)
            {
                dataset.LastIndex = endIndex;
            }
            dataset.AbortedEndIndex    = null;
            dataset.AbortedTransaction = null;
            dataset.AbortedChangelogId = null;
            if (!string.IsNullOrEmpty(dataset.AbortedChangelogPath))
            {
                if (File.Exists(dataset.AbortedChangelogPath))
                {
                    File.Delete(dataset.AbortedChangelogPath);
                }

                var changelogDirectory = dataset.AbortedChangelogPath.Replace(".zip", "");

                if (Directory.Exists(changelogDirectory))
                {
                    Directory.Delete(changelogDirectory, true);
                }

                dataset.AbortedChangelogPath = null;
            }
            SubscriberDatasetManager.UpdateDataset(dataset);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Download changelog
        /// </summary>
        /// <param name="downloadUri"></param>
        /// <param name="dataset"></param>
        public bool DownloadChangelog(string downloadUri, SubscriberDataset dataset)
        {
            var webClient = new WebClient {
                Credentials = new NetworkCredential(dataset.UserName, dataset.Password)
            };

            webClient.DownloadFile(downloadUri, ChangelogFilename);
            if (File.Exists(ChangelogFilename))
            {
                string outPath = Path.GetDirectoryName(ChangelogFilename);
                UnpackZipFile(ChangelogFilename, outPath);

                // TODO: HS: Check if zip contains folder or file
                string baseFilename = ChangelogFilename.Replace(".zip", "");

                if (Directory.Exists(baseFilename))
                {
                    ChangelogFilename = baseFilename;
                    IsFolder          = true;
                }
                else
                {
                    string xmlFile = Path.ChangeExtension(ChangelogFilename, ".xml");
                    ChangelogFilename = xmlFile;
                }

                System.Diagnostics.Debug.WriteLine("client_DownloadFileCompleted: File downloaded");
                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
        private WebFeatureServiceReplicationPortClient buildClient(SubscriberDataset dataset)
        {
            var client = new WebFeatureServiceReplicationPortClient();

            client.ClientCredentials.UserName.UserName = dataset.UserName;
            client.ClientCredentials.UserName.Password = dataset.Password;
            client.Endpoint.Address = new System.ServiceModel.EndpointAddress(dataset.SynchronizationUrl);
            return(client);
        }
Ejemplo n.º 4
0
        private bool LoopChangeLog(IEnumerable <string> fileList, SubscriberDataset dataset, int datasetId,
                                   int progressCounter,
                                   string changelogFilename, long transactionStart)
        {
            var i = 0;

            var status = false;

            XElement changeLog = null;

            foreach (var fileName in fileList)
            {
                if (transactionStart > i)
                {
                    i++;
                    continue;
                }

                changeLog = XElement.Load(fileName);

                dataset.AbortedEndIndex    = GetAbortedEndIndex(changeLog);
                dataset.AbortedTransaction = i;
                if (File.Exists(changelogFilename))
                {
                    dataset.AbortedChangelogPath = changelogFilename;
                }
                else if (File.Exists(changelogFilename + ".zip"))
                {
                    dataset.AbortedChangelogPath = changelogFilename + ".zip";
                }
                else
                {
                    throw new FileNotFoundException("Changelogfile not found at either " + changelogFilename + " or " + changelogFilename + ".zip");
                }

                SubscriberDatasetManager.UpdateDataset(dataset);
                status = DoWfsTransaction(changeLog, datasetId, i + 1);
                if (!status)
                {
                    throw new Exception("WfsTransaction failed");
                }

                OnOrderProcessingChange((progressCounter + 1) * 100);
                ++progressCounter;
                i++;
            }

            if (changeLog != null)
            {
                ResetDataset(dataset, (long)changeLog.Attribute("endIndex"));
            }

            return(status);
        }
Ejemplo n.º 5
0
        private long performSynchronization(SubscriberDataset dataset, int datasetId)
        {
            //Check if previous transactions failed
            if (dataset.AbortedEndIndex != null)
            {
                var transactionStart = dataset.AbortedTransaction ?? 0;
                DoSyncronizationOffline(dataset.AbortedChangelogPath, datasetId, transactionStart);
                return(-1);
            }

            const int progressCounter = 0;
            string    changeLogId;

            long lastIndexProvider = 0;

            if (string.IsNullOrEmpty(dataset.AbortedChangelogId))
            {
                // Do lots of stuff
                var startIndex = dataset.LastIndex + 1;

                lastIndexProvider = PrepareForOrder(datasetId);

                if (lastIndexProvider == 0)
                {
                    return(-1);
                }

                OnOrderProcessingChange((progressCounter + 1) * 100 / 2);

                changeLogId = OrderChangelog(datasetId, startIndex);
            }
            else
            {
                changeLogId = dataset.AbortedChangelogId;
                OnNewSynchMilestoneReached("Found changelogId " + dataset.AbortedChangelogId +
                                           ". Querying for status.");
            }

            GetStatusForChangelogOnProvider(datasetId, changeLogId);

            DownloadController downloadController;
            var responseOk = GetChangelog(datasetId, changeLogId, out downloadController);

            if (!responseOk)
            {
                return(-1);
            }

            var fileList = GetChangelogFiles(downloadController.IsFolder,
                                             downloadController.ChangelogFilename);


            //Rewrite files according to mappingfile if given
            if (!string.IsNullOrEmpty(dataset.MappingFile))
            {
                fileList = ChangeLogMapper(fileList, datasetId);
            }

            LoopChangeLog(fileList, dataset, datasetId, progressCounter, downloadController.ChangelogFilename, 0);

            AcknowledgeChangelogDownloaded(datasetId, changeLogId);

            return(lastIndexProvider);
        }