/* ** Concordance Programming Language ** ** replicate_daemon.cpl ** This script is designed to replicate and reindex databases ** found in a .txt file. The program will evaluate one line at a ** time. The format of each line of the file should be: ** "full\path\to\publisher_database.dcb", "full\path\to\subscriber_database.dcb" ** ** You may incorporate this program into your own programs ** ONLY if you incorporate the following copyright notice: ** ** Copyright (c) 2004 Dataflight Software, Inc. ** ALL RIGHTS RESERVED. ** 2337 Roscomare Road, Suite 11 ** Bel Air, CA 90077 ** ** Unauthorized distribution, adaptation or use may be ** subject to civil and criminal penalties. ** ****************************************************************** ** ** replicate() function Summary ** int replicate( int publisher; ** text subscriber; ** text synchMethod; ** int appendToPublisher; ** int appendToSubscriber; ** text deletionTag; ** int copyDeletionMarks; ** int restoreDeletedDocs; ** text collisionTag; ** int copyAttachments); ** ** Description ** Sychronizes two database. The databases must be from the same replication set, for instance they were created from the same databases using createReplica(). Security, record edits, deletions, and tags are replicated. Replication does not reindex or pack the databases. ** ** Concordance will attempt to open the subscriber database in shared, multi-user mode. This enables laptop clients to synchronize with the network database even if they are running a single user. However, if the single user program already has the database open on the File menu, the shared open will fail. The example program takes this into account by closing any open database handles. ** ** replicate() can synchronize all fields or just selected fields. Use the db.order[i] value to select fields for replication. Only selected fields are replicated. See the example for more information. ** ** Any records in collision are tagged with the collisionTag. A collision occurs when the same field in the same record in both databases has been edited. Concordance will not overwrite either edit, but will flag the records as being in collision. See the resolve() function for information on scripting collision resolution. ** ** Parameter Type Function ** publisher int Handle of publisher database. ** subscriber text Full path and file anme of subscriber database. ** synchMethod text Specify one of the three following options for synchronization: "Synchronize" for full bi-directional synchronize between databases. "POverwrites" for the publisher to overwrite the subscriber when differences are detected, regardless of which database has the most up-to-date information. "Soverwrites" for the subscriber to overwrite the publisher when differences are detected. ** appendToPublisher int Pass any nonzero value to allow appending of new records to the publisher from the subscriber. Use zero to prevent appending of new records to the publisher database. This is a Boolean value. ** appendToSubscriber int Pass any nonzero value to allow appending of new records to the subscriber from the publisher. Use zero to prevent appending of new records to the subscriber database. ** deletionTag text The optional tag is applied to records when the flag marking a record for deletion is copied from one database to another. Use "" if you do not want to tag these records. ** copyDeletionMarks int Use any nonzero value to allow replication to copy deletion flags. This flag indicates that a record should be deleted during the next database pack. It does not delete the record during replication. ** restoreDeletedDocs int Use any nonzero value to restore deleted records. This restores the record if it exists in one database but has been deleted from the other. Note that it may be restored and still flagged for deletion. ** collisionTag text This tag is applied to records in each database when a collision occurs. Use this tag after replication to resolve collisions via the resolve() function. Use "" if you don’t need to track collisions. ** copyAttachments int This optional parameter copies attachments if set to TRUE. ** Return Value ** A zero indicates success. Any nonzero value indicates failure. Failure can occur if the subscriber database cannot be opened, if the databases are not from the same replication set, if the replication fields are not present or are not both system and key fields. ** ** See also ** createReplica(), resolve() ** *********************************************************************/ main() { int dbPublisher, dbSubscriber, fhLog, nStart, nEnd; text pszLogFile, pszPublisher, pszSubscriber; char szBuffer[2048]; /* Get the file name to the log file */ if (getfile("Open log file", "*.TXT", pszLogFile) == CR) { /* Open the log file */ if ((fhLog = open(pszLogFile, "r")) <> EOF) { /* Read one line at a time */ while (readln(fhLog, szBuffer) <> EOF) { /* Reset the publisher and subscriber */ pszPublisher = ""; pszSubscriber = ""; /* Look for the first quote */ if ((nStart = match(szBuffer, chr(34), 1)) <> 0) { /* Look for the ending quote */ if ((nEnd = match(szBuffer, chr(34), nStart + 1)) <> 0) { pszPublisher = trim(substr(szBuffer, nStart + 1, nEnd - nStart - 1)); /* Get the next first quote */ if ((nStart = match(szBuffer, chr(34), nEnd + 1)) <> 0) { /* Get the ending quote */ if ((nEnd = match(szBuffer, chr(34), nStart + 1)) <> 0) pszSubscriber = trim(substr(szBuffer, nStart + 1, nEnd - nStart - 1)); } } } else { /* Assume no quotes */ nStart = 1; if ((nEnd = match(szBuffer, ",", nStart)) <> 0) { pszPublisher = trim(substr(szBuffer, 1, nEnd - nStart)); pszSubscriber = trim(substr(szBuffer, nEnd + 1)); } } if ((pszPublisher <> "") and (pszSubscriber <> "")) { /* Open the publisher database */ if ((dbPublisher = opendb(pszPublisher)) <> EOF) { /* Replicate */ replicate(dbPublisher, pszSubscriber, "Synchronize", TRUE, TRUE, "mark for deletion", TRUE, TRUE, "mark for collision", TRUE); /* Reindex the publisher */ reindex(dbPublisher); /* Close the publisher */ close(dbPublisher); /* Open and reindex the subscriber */ if ((dbSubscriber = opendb(pszSubscriber)) <> EOF) { reindex(dbSubscriber); closedb(dbSubscriber); } } } } /* Close the log file */ close(fhLog); } } }