/// <summary>
 /// Initializes a new instance of the <see cref="UPOfflineRequest"/> class.
 /// </summary>
 /// <param name="_requestMode">The request mode.</param>
 /// <param name="jsonString">The json string.</param>
 public UPOfflineRequest(UPOfflineRequestMode _requestMode, string jsonString)
 {
     this.RequestNr           = -1;
     this.requestMode         = _requestMode;
     this.Json                = jsonString;
     this.ServerRequestNumber = -1;
     this.ApplicationRequest  = true;
     this.Session             = ServerSession.CurrentSession;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="UPCRMFavorites"/> class.
 /// </summary>
 /// <param name="offlineRequestMode">The offline request mode.</param>
 /// <param name="theDelegate">The delegate.</param>
 public UPCRMFavorites(UPOfflineRequestMode offlineRequestMode, UPCRMFavoritesDelegate theDelegate)
 {
     this.OfflineRequestMode = offlineRequestMode;
     this.TheDelegate        = theDelegate;
     this.RepFilter          = ConfigurationUnitStore.DefaultStore.FilterByName(Constants.FAVORITES_FILTERNAME);
     this.RepFilter          = this.RepFilter?.FilterByApplyingReplacements(UPConditionValueReplacement.DefaultParameters);
     this.TemplateFilter     = ConfigurationUnitStore.DefaultStore.FilterByName(Constants.FAVORITES_TEMPLATEFILTERNAME);
     this.TemplateFilter     = this.TemplateFilter?.FilterByApplyingReplacements(UPConditionValueReplacement.DefaultParameters);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="UPOfflineRequest"/> class.
        /// </summary>
        /// <param name="_requestMode">The request mode.</param>
        /// <param name="viewReference">The view reference.</param>
        public UPOfflineRequest(UPOfflineRequestMode _requestMode, ViewReference viewReference)
            : this(_requestMode, viewReference.Serialized())
        {
            string errorTranslation = viewReference.ContextValueForKey("ErrorTranslation");

            if (!string.IsNullOrEmpty(errorTranslation))
            {
                this.ErrorTranslationKey = errorTranslation;
            }
        }
        /// <summary>
        /// Starts the request the delegate.
        /// </summary>
        /// <param name="requestMode">The request mode.</param>
        /// <param name="_theDelegate">The delegate.</param>
        /// <returns>True, if success</returns>
        public override bool StartRequest(UPOfflineRequestMode requestMode, UPOfflineRequestDelegate _theDelegate)
        {
            this.OfflineRequestDelegate = _theDelegate;
            string maxUploadFileSize = this.Configuration.ConfigValueDefaultValue("Sync.DocumentUploadMaxSize", null);
            bool   canUploadDocument = true;

            if (!string.IsNullOrEmpty(maxUploadFileSize))
            {
                int configMaxSize = Convert.ToInt32(maxUploadFileSize) * 1024;
                if (configMaxSize < 0 || this.Data.Length > configMaxSize)
                {
                    canUploadDocument = false;
                }
            }

            if (canUploadDocument)
            {
                IDatabase database = this.Storage.Database;
                if (this.RequestMode == UPOfflineRequestMode.Offline)
                {
                    this.StoreRequest(database);
                    this.OfflineRequestDelegate?.OfflineRequestDidFinishWithResult(this, null, false, null, null);
                    return(true);
                }

                if (ServerSession.CurrentSession.ConnectionWatchDog.LastServerReachabilityStatus == ReachabilityStatus.ReachableViaWiFi ||
                    (!this.NeedsWLANForSync && ServerSession.CurrentSession.ConnectionWatchDog.LastServerReachabilityStatus == ReachabilityStatus.ReachableViaWWAN))
                {
                    if (this.StoreBeforeRequest)
                    {
                        this.StoreRequest(database);
                    }

                    UploadDocument document = new UploadDataDocument(this.Data, this.FileName, this.MimeType);
                    this.UploadServerOperation = new UploadDocumentServerOperation(document, this.RecordIdentification, this.FieldId, this.NoD3Link, this);
                    ServerSession.CurrentSession.ExecuteRequest(this.UploadServerOperation);
                    return(true);
                }

                if (requestMode == UPOfflineRequestMode.OnlineOnly)
                {
                    return(false);
                }

                this.StoreRequest(database);
                this.OfflineRequestDelegate?.OfflineRequestDidFinishWithResult(this, null, false, null, null);
                return(true);
            }

            Exception error = new Exception("Document can not be uploaded as the size exceeds the maximum limit");

            this.OfflineRequestDelegate?.OfflineRequestDidFailWithError(this, null, null, error);
            return(false);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="UPOfflineRequest"/> class.
 /// </summary>
 /// <param name="requestNr">The request number</param>
 public UPOfflineRequest(int requestNr)
     : this()
 {
     this.RequestNr           = requestNr;
     this.ServerRequestNumber = -1;
     if (requestNr >= 0)
     {
         this.requestMode = UPOfflineRequestMode.OnlineOnly;
     }
     else
     {
         this.requestMode        = UPOfflineRequestMode.OnlineConfirm;
         this.ApplicationRequest = true;
     }
 }
        /// <summary>
        /// Approves the specified dummy.
        /// </summary>
        /// <param name="dummy">The dummy.</param>
        public void Approve(object dummy)
        {
            if (this.disableSigning)
            {
                return;
            }

            string recordIdentification = this.buttonViewReference.ContextValueForKey("RecordId");
            string filterName           = this.buttonViewReference.ContextValueForKey("TemplateFilter");

            if (string.IsNullOrEmpty(recordIdentification))
            {
                this.ParentOrganizerModelController.HandleOrganizerActionError(
                    LocalizedString.TextErrorConfiguration, string.Format(LocalizedString.TextErrorParameterEmpty, "RecordId"), true);
                return;
            }

            UPConfigFilter filter = ConfigurationUnitStore.DefaultStore.FilterByName(filterName);

            if (filter == null)
            {
                this.HandlePageErrorDetails(LocalizedString.TextErrorConfiguration, string.Format(LocalizedString.TextErrorFilterMissing, filterName));
                return;
            }

            filter = filter.FilterByApplyingValueDictionaryDefaults(this.FieldValueDictionary, true);
            UPCRMRecord record = new UPCRMRecord(recordIdentification);

            record.ApplyValuesFromTemplateFilter(filter);
            UPOfflineEditRecordRequest request = new UPOfflineEditRecordRequest(0);

            this.buttonRequest = request;
            string requestOptionString       = this.buttonViewReference.ContextValueForKey("RequestOption");
            UPOfflineRequestMode requestMode = UPOfflineRequest.RequestModeFromString(requestOptionString, UPOfflineRequestMode.OnlineConfirm);

            if (request.StartRequest(requestMode, new List <UPCRMRecord> {
                record
            }, this) == false)
            {
                this.buttonRequest = null;
            }
            else
            {
                this.ShouldWaitForPendingChanges = true;
            }
        }
        private void PerformUploadReportPdfWithRecords(List <UPCRMRecord> records)
        {
            if (records.Count > 0)
            {
                string requestOptionString             = this.buttonViewReference.ContextValueForKey("RequestOption");
                UPOfflineRequestMode       requestMode = UPOfflineRequest.RequestModeFromString(requestOptionString, UPOfflineRequestMode.OnlineConfirm);
                UPOfflineEditRecordRequest request     = new UPOfflineEditRecordRequest(requestMode, null);
                this.buttonRequest = request;
                foreach (UPCRMRecord record in records)
                {
                    request.AddRecord(record);
                }

                this.multiRequest.AddRequest(request);
            }

            this.multiRequest.Start();
        }
        /// <summary>
        /// Requests the mode from string the default.
        /// </summary>
        /// <param name="requestMode">The request mode.</param>
        /// <param name="mode">The mode.</param>
        /// <returns></returns>
        public static UPOfflineRequestMode RequestModeFromString(string requestMode, UPOfflineRequestMode mode)
        {
            switch (requestMode)
            {
            case "Offline":
                return(UPOfflineRequestMode.Offline);

            case "Online":
                return(UPOfflineRequestMode.OnlineOnly);

            case "Best":
                return(UPOfflineRequestMode.OnlineConfirm);

            case "Fastest":
                return(UPOfflineRequestMode.OnlineNoConfirm);
            }

            return(mode);
        }
Beispiel #9
0
        /// <summary>
        /// Executes this instance.
        /// </summary>
        public override void Execute()
        {
            string requestModeString = this.ViewReference.ContextValueForKey("RequestMode");

            if (!ServerSession.CurrentSession.UserChoiceOffline && ServerSession.CurrentSession.ConnectedToServer)
            {
                this.RequestMode = UPOfflineRequest.RequestModeFromString(requestModeString, UPOfflineRequestMode.OnlineOnly);
            }
            else
            {
                this.RequestMode = UPOfflineRequest.RequestModeFromString(requestModeString, UPOfflineRequestMode.Offline);
            }

            this.RecordIdentification = this.ViewReference.ContextValueForKey("RecordId");
            string filterName = this.ViewReference.ContextValueForKey("TemplateFilter");

            if (string.IsNullOrEmpty(this.RecordIdentification))
            {
                this.ModelController.HandleOrganizerActionError(LocalizedString.TextErrorConfiguration, string.Format(LocalizedString.TextErrorParameterEmpty, "RecordId"), true);
                return;
            }

            this.TemplateFilter = ConfigurationUnitStore.DefaultStore.FilterByName(filterName);
            if (this.TemplateFilter == null && string.IsNullOrEmpty(this.ViewReference.ContextValueForKey("LinkRecordId")))
            {
                this.ModelController.HandleOrganizerActionError(LocalizedString.TextErrorConfiguration, string.Format(LocalizedString.TextErrorFilterMissing, filterName), true);
                return;
            }

            if (this.TemplateFilter?.NeedsLocation ?? false)
            {
                SimpleIoc.Default.GetInstance <ILocationService>().GetCurrentLocation(this);
                return;
            }

            this.ContinueTemplateFilterGeoChecked();
        }
Beispiel #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UPOfflineEditRecordRequest"/> class.
 /// </summary>
 /// <param name="requestMode">The request mode.</param>
 /// <param name="viewReference">The view reference.</param>
 public UPOfflineEditRecordRequest(UPOfflineRequestMode requestMode, ViewReference viewReference)
     : base(requestMode, viewReference)
 {
 }
Beispiel #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UPOfflineQuestionnaireRequest"/> class.
 /// </summary>
 /// <param name="requestMode">The request mode.</param>
 /// <param name="viewReference">The view reference.</param>
 public UPOfflineQuestionnaireRequest(UPOfflineRequestMode requestMode, ViewReference viewReference)
     : base(requestMode, viewReference)
 {
 }
 /// <summary>
 /// Starts the request.
 /// </summary>
 /// <param name="requestMode">The request mode.</param>
 /// <param name="theDelegate">The delegate.</param>
 /// <returns></returns>
 public virtual bool StartRequest(UPOfflineRequestMode requestMode, UPOfflineRequestDelegate theDelegate)
 {
     return(false);
 }
Beispiel #13
0
        private void ContinueRecordDoesNotExist()
        {
            string requestModeString         = this.ViewReference.ContextValueForKey("RequestMode");
            UPOfflineRequestMode requestMode = UPOfflineRequest.RequestModeFromString(requestModeString, UPOfflineRequestMode.OnlineOnly);
            string filterName   = this.ViewReference.ContextValueForKey("TemplateFilter");
            string infoAreaId   = this.ViewReference.ContextValueForKey("InfoAreaId");
            string linkIdString = this.ViewReference.ContextValueForKey("LinkId");

            if (string.IsNullOrEmpty(infoAreaId))
            {
                this.ModelController.HandleOrganizerActionError(LocalizedString.TextErrorConfiguration, string.Format(LocalizedString.TextErrorParameterEmpty, "InfoAreaId"), true);
                return;
            }

            int  linkId = -1;
            bool noLink = false;

            if (!string.IsNullOrEmpty(linkIdString))
            {
                if (linkIdString == "NoLink")
                {
                    noLink = true;
                }

                linkId = Convert.ToInt32(linkIdString);
            }

            UPConfigFilter filter = ConfigurationUnitStore.DefaultStore.FilterByName(filterName);

            if (filter == null)
            {
                this.ModelController.HandleOrganizerActionError(LocalizedString.TextErrorConfiguration, string.Format(LocalizedString.TextErrorFilterMissing, filterName), true);
                return;
            }

            filter      = filter.FilterByApplyingValueDictionaryDefaults(this.sourceCopyFields, true);
            this.record = UPCRMRecord.CreateNew(infoAreaId);
            if (!noLink && !string.IsNullOrEmpty(this.LinkRecordIdentification))
            {
                this.record.AddLink(new UPCRMLink(this.LinkRecordIdentification, linkId));
            }

            this.record.ApplyValuesFromTemplateFilter(filter);
            UPOfflineEditRecordRequest request = new UPOfflineEditRecordRequest(0);
            string optionsString = this.ViewReference.ContextValueForKey("Options");

            if (!string.IsNullOrEmpty(optionsString))
            {
                Dictionary <string, object> options = optionsString.JsonDictionaryFromString();
                if (Convert.ToInt32(options["ComputeLinks"]) != 0)
                {
                    request.AlwaysSetImplicitLinks = true;
                }
            }

            List <UPCRMRecord> recordArray = new List <UPCRMRecord> {
                this.record
            };
            string syncParentInfoAreaIdString = this.ViewReference.ContextValueForKey("SyncParentInfoAreaIds");

            if (!string.IsNullOrEmpty(syncParentInfoAreaIdString))
            {
                var syncParentInfoAreaIds = syncParentInfoAreaIdString.Split(',');
                foreach (string syncParentInfoAreaId in syncParentInfoAreaIds)
                {
                    var infoAreaIdParts = syncParentInfoAreaId.Split(':');
                    if (infoAreaIdParts.Length == 1)
                    {
                        recordArray.Add(new UPCRMRecord(syncParentInfoAreaId, new UPCRMLink(this.record, -1)));
                    }
                    else if (infoAreaIdParts.Length > 1)
                    {
                        recordArray.Add(new UPCRMRecord(infoAreaIdParts[0], new UPCRMLink(this.record, Convert.ToInt32(infoAreaIdParts[1]))));
                    }
                }
            }

            if (this.ModelController.SetOfflineRequest(request, true))
            {
                if (request.StartRequest(requestMode, recordArray, this) == false)
                {
                    this.ModelController.SetOfflineRequest(null, true);
                    return;
                }
            }
            else
            {
                this.ModelController.HandleOrganizerActionError(LocalizedString.TextErrorActionNotPossible, LocalizedString.TextErrorActionPending, true);
            }
        }