/// <summary>
		/// The registered application calls the Progress method to update the progress 
		/// information and determine whether the operation should continue.
		/// </summary>
		/// <param name="pItemID">[in] The item identifier for an item that is being updated.</param>
		/// <param name="lpSyncProgressItem">[in] A pointer to a SYNCMGRPROGRESSITEM structure that contains the updated progress information.</param>
		public int Progress(ref Guid pItemID, ref SyncMgrProgressItem lpSyncProgressItem)
		{
			string statusText = "";
			if (0 != (lpSyncProgressItem.mask & (int) StatusType.StatusText))
			{
				statusText = lpSyncProgressItem.lpcStatusText;
			}

			SyncState syncState = SyncState.NotAvailable;
			if (0 != (lpSyncProgressItem.mask & (int) StatusType.StatusType))
			{
				switch (lpSyncProgressItem.dwStatusType)
				{
					case (int) SyncMgrStatus.Updating:
						syncState = SyncState.Updating;
						break;
					case (int) SyncMgrStatus.Succeeded:
						syncState = SyncState.Succeeded;
						break;
					case (int) SyncMgrStatus.Failed:
						syncState = SyncState.Failed;
						break;
				}
			}

			int progressValue = 0;
			int maxValue = 0;
			if ((0 != (lpSyncProgressItem.mask & (int) StatusType.ProgValue))
				&& (0 != (lpSyncProgressItem.mask & (int) StatusType.MaxValue)))
			{
				progressValue = lpSyncProgressItem.iProgValue;
				maxValue = lpSyncProgressItem.iMaxValue;
			}

			if (fileSync != null)
			{
				fileSync.StatusUpdate(syncState, statusText, progressValue, maxValue);
			}

			int retval = 0;
			if (fileSync.UpdateWasCanceled)
			{
				retval = 0x40203;  // S_SYNCMGR_CANCELITEM
			}
			return retval;
		}
Esempio n. 2
0
        public int Synchronize(IntPtr hWndParent)
        {
            bool succeeded = true;

            if (syncMgrSynchronizeCallback == null)
            {
                unchecked
                {
                    return (int) 0x80004005;  // E_FAIL
                }
            }

            
            // CALCULATE WHAT AND HOW MUCH TO SYNC

            SyncMgrProgressItem syncMgrProgressItem = new SyncMgrProgressItem();
            syncMgrProgressItem.cbSize = Marshal.SizeOf(typeof(SyncMgrProgressItem));
            syncMgrProgressItem.mask = (int) 
                (StatusType.StatusText 
                | StatusType.StatusType
                | StatusType.ProgValue
                | StatusType.MaxValue);
            syncMgrProgressItem.dwStatusType = (int) SyncMgrStatus.Updating;
            syncMgrProgressItem.iMaxValue = 59; // FETCH1.COUNT + FETCH2.COUNT

            int progvalue = 1;
            IList<string> items = new List<string>();


            foreach (string clientFilename in items)
            {
                syncMgrProgressItem.lpcStatusText = "Deleting file " + clientFilename;
                syncMgrProgressItem.iProgValue = progvalue++;
                int callbackRetval = syncMgrSynchronizeCallback.Progress(ref itemId, ref syncMgrProgressItem);
                if (callbackRetval != 0)
                {
                    // The user has canceled the update; send "skipped" progress.
                    syncMgrProgressItem.dwStatusType = (int) SyncMgrStatus.Skipped;
                    syncMgrSynchronizeCallback.Progress(ref itemId, ref syncMgrProgressItem);

                    unchecked
                    {
                        return (int) 0x80004005;  // E_FAIL
                    }
                }

                Thread.Sleep(500);
            }

            // SET LAST UPDATED

            int retval = 0;  // S_OK
            if (succeeded)
            {
                syncMgrProgressItem.dwStatusType = (int) SyncMgrStatus.Succeeded;
            }
            else
            {
                syncMgrProgressItem.dwStatusType = (int) SyncMgrStatus.Failed;
                unchecked
                {
                    retval = (int) 0x80004005;  // E_FAIL
                }
            }
            syncMgrSynchronizeCallback.Progress(ref itemId, ref syncMgrProgressItem);
            
            if (succeeded)
            {
                syncMgrSynchronizeCallback.SynchronizeCompleted(0);
            }

            return retval;
        }