Ejemplo n.º 1
0
        private bool SynchronizePathInfoData(PathAccess pathFile, IServiceAddress rootServer)
        {
            // Get the last entry,
            PathRecordEntry lastEntry = pathFile.GetLastEntry();

            long uid;
            DataAddress daddr;

            if (lastEntry == null) {
                uid = 0;
                daddr = null;
            } else {
                uid = lastEntry.Uid;
                daddr = lastEntry.Address;
            }

            while (true) {
                // Fetch a bundle for the path from the root server,
                MessageStream outputStream = new MessageStream();
                outputStream.AddMessage(new Message("internalFetchPathDataBundle", pathFile.PathName, uid, daddr));

                // Send the command
                IMessageProcessor processor = connector.Connect(rootServer, ServiceType.Root);
                IEnumerable<Message> result = processor.Process(outputStream);

                long[] uids = null;
                DataAddress[] dataAddrs = null;

                foreach (Message m in result) {
                    if (m.HasError) {
                        // If it's a connection fault, report the error and return false
                        if (ReplicatedValueStore.IsConnectionFault(m)) {
                            serviceTracker.ReportServiceDownClientReport(rootServer, ServiceType.Root);
                            return false;
                        }

                        throw new ApplicationException(m.ErrorMessage);
                    }

                    uids = (long[]) m.Arguments[0].Value;
                    dataAddrs = (DataAddress[]) m.Arguments[1].Value;
                }

                // If it's empty, we reached the end so return,
                if (uids == null || uids.Length == 0) {
                    break;
                }

                // Insert the data
                pathFile.AddPathDataEntries(uids, dataAddrs);

                // The last,
                uid = uids[uids.Length - 1];
                daddr = dataAddrs[dataAddrs.Length - 1];

            }

            return true;
        }