/// <summary>
        /// Dependents the requests deep.
        /// </summary>
        /// <returns></returns>
        public Dictionary <int, UPOfflineRequest> DependentRequestsDeep()
        {
            List <int> dependentRequestNumbers = this.DependentRequestNumbers();

            if (dependentRequestNumbers == null || dependentRequestNumbers.Count == 0)
            {
                return(null);
            }

            Dictionary <int, UPOfflineRequest> dependentRequestNumberDictionary = new Dictionary <int, UPOfflineRequest>();
            IOfflineStorage offlineStorage = this.Storage;

            foreach (int cur in dependentRequestNumbers)
            {
                if (!dependentRequestNumberDictionary.ContainsKey(cur))
                {
                    UPOfflineRequest childRequest = offlineStorage.RequestWithNr(cur);
                    if (childRequest != null)
                    {
                        dependentRequestNumberDictionary.SetObjectForKey(childRequest, cur);
                        Dictionary <int, UPOfflineRequest> subdep = childRequest.DependentRequestsDeep();
                        foreach (int sub in subdep.Keys)
                        {
                            if (!dependentRequestNumberDictionary.ContainsKey(sub))
                            {
                                dependentRequestNumberDictionary.SetObjectForKey(subdep[sub], sub);
                            }
                        }
                    }
                }
            }

            return(dependentRequestNumberDictionary);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Builds the pages from view reference.
        /// </summary>
        public override void BuildPagesFromViewReference()
        {
            SyncConflictsPageModelController pageModelController = new SyncConflictsPageModelController();
            UPMOrganizer syncConflictOrganizer = new UPMOrganizer(StringIdentifier.IdentifierWithStringId("SyncConflictsOrganizer"))
            {
                ExpandFound  = true,
                SubtitleText = LocalizedString.TextSyncConflictsTitle
            };

            this.ShouldShowTabsForSingleTab = false;
            UPMOrganizerAction retryAction       = new UPMOrganizerAction(StringIdentifier.IdentifierWithStringId("action.retry"));
            UPMOrganizerAction reportErrorAction = new UPMOrganizerAction(StringIdentifier.IdentifierWithStringId("action.report"));
            string             retryText         = LocalizedString.Localize(LocalizationKeys.TextGroupBasic, LocalizationKeys.KeyBasicSyncConflictsRetryAll, "Retry All");

            retryAction.LabelText = retryText;
            retryAction.IconName  = "Icon:Record";
            retryAction.SetTargetAction(this, this.RetryAll);
            this.AddOrganizerHeaderActionItem(retryAction);
            IOfflineStorage offlineStorage = UPOfflineStorage.DefaultStorage;

            if (!string.IsNullOrEmpty(ConfigurationUnitStore.DefaultStore.ConfigValue("Sync.ConflictEmailAddress")) &&
                offlineStorage.ConflictRequests?.Count > 1 &&
                !string.IsNullOrEmpty(offlineStorage.OfflineRequestXml()))
            {
                string sendRequestXmlText = LocalizedString.Localize(LocalizationKeys.TextGroupBasic, LocalizationKeys.KeyBasicSyncConflictsReportAllErrors, "Report all errors");
                reportErrorAction.LabelText = sendRequestXmlText;
                reportErrorAction.SetTargetAction(this, this.ReportAllErrors);
                this.AddOrganizerHeaderActionItem(reportErrorAction);
            }

            this.AddPageModelController(pageModelController);
            syncConflictOrganizer.AddPage(pageModelController.Page);
            this.TopLevelElement = syncConflictOrganizer;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Constructs a TCAPI object with no asynchronous support.
 /// </summary>
 /// <param name="endpoint">The endpoint for the TCAPI</param>
 /// <param name="authentification">The authentification object</param>
 public TCAPI(Uri endpoint, IAuthenticationConfiguration authentification)
 {
     this.endpoint = endpoint;
     this.Authentification = authentification;
     this.tcapiCallback = null;
     this.offlineStorage = null;
     this.version = DetermineVersioning();
 }
        /// <summary>
        /// Saves the request.
        /// </summary>
        /// <param name="database">The database.</param>
        /// <param name="type">The type.</param>
        /// <param name="followUpRequestId">The follow up request identifier.</param>
        /// <returns></returns>
        int SaveRequest(IDatabase database, string type, int followUpRequestId)
        {
            DatabaseStatement statement = new DatabaseStatement(database);
            IOfflineStorage   storage   = this.Storage;
            int requestId = this.RequestNr < 0 ? (this.ReservedRequestNr <= 0 ? storage.NextId : this.ReservedRequestNr) : this.RequestNr;

            string sql = @"INSERT INTO requests (requestnr, syncdate, requesttype, json, processtype, draft, titleLine, detailsLine, imageName, 
                           error, serverRequestNumber, followuproot, translationkey, relatedinfo, baseError, appversion) 
                           VALUES (?,datetime('now'),?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

            if (statement.Prepare(sql))
            {
                storage.ClearCachedRequestNumbers();
                statement.Bind(1, requestId);
                statement.Bind(2, this.RequestType.ToString()); // TODO Verify, values are going correctly
                statement.Bind(3, this.Json);
                statement.Bind(4, this.ProcessType.ToString());
                statement.Bind(5, 0);
                statement.Bind(6, this.titleLine);
                statement.Bind(7, this.detailsLine);
                statement.Bind(8, this.imageName);

                if (!string.IsNullOrEmpty(type))
                {
                    statement.Bind(9, type);
                }
                else if (this.blockExecution)
                {
                    statement.Bind(9, Constants.OFFLINEREQUEST_BLOCKED_TEXT);
                }
                else
                {
                    statement.Bind(9, null);
                }

                statement.Bind(10, this.ServerRequestNumber);
                statement.Bind(11, followUpRequestId >= 0 ? (object)followUpRequestId : null);
                statement.Bind(12, !string.IsNullOrEmpty(this.ErrorTranslationKey) ? this.ErrorTranslationKey : null);

                statement.Bind(13, this.RelatedInfoDictionary != null ? StringExtensions.StringFromObject(this.RelatedInfoDictionary) : null);

                statement.Bind(14, this.BaseErrorCode != 0 ? (object)this.BaseErrorCode : null);

                this.ApplicationVersion = Constants.CRMPAD_CLIENTVERSION;
                statement.Bind(15, this.ApplicationVersion);

                if (statement.Execute() == 0)
                {
                    return(requestId);
                }
            }

            return(-1);
        }
        /// <summary>
        /// Stores the request with offline records.
        /// </summary>
        /// <param name="_offlineRecords">The offline records.</param>
        /// <param name="rootRecord">The root record.</param>
        /// <returns>0, if successfull</returns>
        private int StoreRequestWithOfflineRecords(List <UPCRMRecord> _offlineRecords, UPCRMRecord rootRecord)
        {
            IOfflineStorage storage = this.Storage;

            storage.Database.BeginTransaction();

            if (this.RequestNr == -1)
            {
                if (!this.CreateRequest(storage.Database))
                {
                    storage.Database.Rollback();
                    return(1);
                }
            }

            int ret = storage.SaveDocumentUpload(this.Data, this.RequestNr, this.FileName, this.MimeType, this.RecordIdentification, this.FieldId, storage.Database);

            if (ret == 0 && _offlineRecords != null)
            {
                int  nextRecordNr           = 1;
                bool documentKeyFieldFilled = this.FieldId < 0;
                foreach (UPCRMRecord record in _offlineRecords)
                {
                    ret = storage.SaveRecord(record, this.RequestNr, nextRecordNr++, storage.Database);
                    if (ret != 0)
                    {
                        break;
                    }

                    if (rootRecord != null && !documentKeyFieldFilled && record.InfoAreaId == "D1")
                    {
                        documentKeyFieldFilled = true;
                        string documentKey = $"new:{record.RecordIdentification}";
                        rootRecord.AddValue(new UPCRMFieldValue(documentKey, rootRecord.InfoAreaId, this.FieldId, true));
                    }
                }
            }

            if (ret == 0)
            {
                storage.Database.Commit();
            }
            else
            {
                storage.Database.Rollback();
            }

            return(ret);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Updateds the element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns>
        /// The <see cref="UPMElement" />.
        /// </returns>
        public override UPMElement UpdatedElement(UPMElement element)
        {
            UPMSyncConflictsPage page = new UPMSyncConflictsPage(StringIdentifier.IdentifierWithStringId("SyncConflictsPage"));

            page.SyncConflictEmail = ConfigurationUnitStore.DefaultStore.ConfigValue("Sync.ConflictEmailAddress");
            IOfflineStorage offlineStorage  = UPOfflineStorage.DefaultStorage;
            var             offlineRequests = this.ShowAllOfflineRequests ? offlineStorage.OfflineRequests : offlineStorage.ConflictRequests;

            if (offlineRequests == null || offlineRequests.Count == 0)
            {
                this.AddNoConflictsFoundPage(page);
                return(page);
            }

            foreach (UPOfflineRequest request in offlineRequests)
            {
                IIdentifier identifier;
                if (!string.IsNullOrEmpty(request.IdentifyingRecordIdentification))
                {
                    identifier = new RecordIdentifier(request.IdentifyingRecordIdentification);
                }
                else
                {
                    identifier = StringIdentifier.IdentifierWithStringId($"request_{request.RequestNr}");
                }

                UPMSyncConflictWithContext syncConflict = new UPMSyncConflictWithContext(identifier);
                request.LoadFromOfflineStorage();
                syncConflict.OfflineRequest = request;
                syncConflict.CanBeFixed     = request.FixableByUser;
                syncConflict.CanBeReported  = !string.IsNullOrEmpty(page.SyncConflictEmail) && syncConflict.OfflineRequest.HasXml;
                if (!string.IsNullOrEmpty(request.ImageName))
                {
                    //SyncConflict.Icon = UIImage.ImageNamed(request.ImageName);    // CRM-5007
                }

                UPMStringField titleLineField = new UPMStringField(null);
                titleLineField.StringValue = request.TitleLine;
                syncConflict.MainField     = titleLineField;
                string detailsLine = request.DetailsLine;
                if (!string.IsNullOrEmpty(detailsLine))
                {
                    UPMStringField detailsLineField = new UPMStringField(null);
                    detailsLineField.StringValue = detailsLine;
                    syncConflict.DetailField     = detailsLineField;
                }

                if (!this.ShowAllOfflineRequests)
                {
                    UPMErrorStatus error = UPMErrorStatus.ErrorStatusWithMessageDetails(request.Error, request.Response);
                    syncConflict.AddStatus(error);
                }

                List <UPOfflineRequest> dependingRequests = request.DependentRequests;
                if (dependingRequests != null)
                {
                    foreach (UPOfflineRequest dependentRequest in dependingRequests)
                    {
                        string        description = $"{dependentRequest.TitleLine}-{dependentRequest.DetailsLine}";
                        UPMWarnStatus warning     = UPMWarnStatus.WarnStatusWithMessageDetails(description, null);
                        syncConflict.AddStatus(warning);
                    }
                }

                page.AddSyncConflict(syncConflict);
            }

            if (this.oldNumberOfConflicts >= 0 && this.oldNumberOfConflicts != offlineRequests.Count)
            {
                Messenger.Default.Send(SyncManagerMessage.Create(SyncManagerMessageKey.NumberOfConflictsChanged));
            }

            this.oldNumberOfConflicts = offlineRequests.Count;
            return(page);
        }
Ejemplo n.º 7
0
 public TCAPI(Uri endpoint, IAuthenticationConfiguration authentification, ITCAPICallback tcapiCallback, IOfflineStorage offlineStorage, int statementPostInterval, int maxBatchSize, TCAPIVersion version)
     : this(endpoint, authentification, tcapiCallback, offlineStorage, statementPostInterval, maxBatchSize)
 {
     this.version = version;
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Construct a TCAPI object with asynchronous support.
        /// </summary>
        /// <param name="endpoint">The LRS endpoint</param>
        /// <param name="authentification">Authentification object</param>
        /// <param name="tcapiCallback">Asynchornous callback object</param>
        /// <param name="offlineStorage">Offline Storage object</param>
        /// <param name="statementPostInterval">Interval for asynchronous operations to take place, in milliseconds</param>
        public TCAPI(Uri endpoint, IAuthenticationConfiguration authentification, ITCAPICallback tcapiCallback, IOfflineStorage offlineStorage, int statementPostInterval, int maxBatchSize)
        {
            this.endpoint = endpoint;
            this.authentification = authentification;
            this.tcapiCallback = tcapiCallback;
            this.offlineStorage = offlineStorage;
            this.statementPostInterval = statementPostInterval;
            this.maxBatchSize = maxBatchSize;

            this.asyncPostCallback = new AsyncPostCallback(this.PostSuccess, this.PostFailed, this.PostConnectionFailed);
            this.isAsyncFlushing = false;

            asyncPostTimer = new Timer();
            asyncPostTimer.Elapsed += new ElapsedEventHandler(AsyncPostTimerElapsed);
            asyncPostTimer.Interval = this.statementPostInterval;
            asyncPostTimer.Enabled = this.statementPostInterval > 0;
            asyncPostTimer.AutoReset = true;
            this.version = DetermineVersioning();
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Construct a TCAPI object with asynchronous support and a default maxBatchSize of 10.
 /// </summary>
 /// <param name="endpoint">The LRS endpoint</param>
 /// <param name="authentification">Authentification object</param>
 /// <param name="tcapiCallback">Asynchornous callback object</param>
 /// <param name="offlineStorage">Offline Storage object</param>
 /// <param name="statementPostInterval">Interval for asynchronous operations to take place, in seconds</param>
 public TCAPI(Uri endpoint, IAuthenticationConfiguration authentification, ITCAPICallback tcapiCallback, IOfflineStorage offlineStorage, int statementPostInterval)
     : this(endpoint, authentification, tcapiCallback, offlineStorage, statementPostInterval, 10)
 {
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Construct a TCAPI object with asynchronous support with a default post interval of 500ms and a default maxBatchSize of 10.
 /// </summary>
 /// <param name="endpoint">The LRS endpoint</param>
 /// <param name="authentification">Authentification object</param>
 /// <param name="tcapiCallback">Asynchornous callback object</param>
 /// <param name="offlineStorage">Offline Storage object</param>
 public TCAPI(Uri endpoint, IAuthenticationConfiguration authentification, ITCAPICallback tcapiCallback, IOfflineStorage offlineStorage)
     : this(endpoint, authentification, tcapiCallback, offlineStorage, 500, 10)
 {
 }
Ejemplo n.º 11
0
 public void ResetStorage(string id, IOfflineStorage storage)
 {
     if (!_storageCache.ContainsKey(id))
     {
         _storageCache.Add(id, storage);
     }
     else
     {
         _storageCache[id] = storage;
     }
 }
Ejemplo n.º 12
0
 /// <summary>
 /// 注册一个新的图层。
 /// </summary>
 /// <param name="id"></param>
 /// <param name="storage"></param>
 public void Register(string id, IOfflineStorage storage, Func<Tile, Task<Tile>> howToDownload)
 {
     _tilesBuffer.Register(id);
     _executantPool.Register(id);
     if (!_storageCache.ContainsKey(id) && storage != null)
     {
         _storageCache.Add(id, storage);
     }
     if (!_howToDownload.ContainsKey(id))
     {
         _howToDownload.Add(id, howToDownload);
     }
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Construct a TCAPI object with asynchronous support.
 /// </summary>
 /// <param name="endpoint">The LRS endpoint</param>
 /// <param name="authentification">Authentification object</param>
 /// <param name="tcapiCallback">Asynchornous callback object</param>
 /// <param name="offlineStorage">Offline Storage object</param>
 /// <param name="statementPostInterval">Interval for asynchronous operations to take place, in milliseconds</param>
 public TCAPI(Uri endpoint, IAuthenticationConfiguration authentification, ITCAPICallback tcapiCallback, IOfflineStorage offlineStorage, int statementPostInterval, int maxBatchSize)
     : this(endpoint, authentification, tcapiCallback, offlineStorage, statementPostInterval, maxBatchSize, DetermineVersioning(endpoint, authentification, TCAPIVersion.TinCan090))
 {
 }