/// <summary>
        /// Uploads the document request did finish with json.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="json">The json.</param>
        public void UploadDocumentRequestDidFinishWithJSON(UploadDocumentServerOperation request, Dictionary <string, object> json)
        {
            List <object> jsonArray = json.Values.ToList();
            string        d1        = jsonArray[0] as string;
            List <object> syncInfos = jsonArray[2] as List <object>;

            UPCRMRecordSync.SyncRecordSetDefinitions(syncInfos);
            ResourceManager resourceManager = SmartbookResourceManager.DefaultResourceManager;
            Uri             url             = ServerSession.CurrentSession.DocumentRequestUrlForRecordIdentification(d1, request.FileName);
            string          localUrl        = resourceManager.LocalPathForResourceAtUrl(url, resourceManager.LocalPathForTransientResources, request.FileName);

            SimpleIoc.Default.GetInstance <IPlatformService>().StorageProvider.SaveFile(localUrl, request.Data);
            this.ReportSuccessfulSync();
            this.OfflineRequestDelegate?.OfflineRequestDidFinishWithResult(this, d1, true, null, json);
        }
Пример #2
0
        /// <summary>
        /// Processes the json response.
        /// </summary>
        /// <param name="json">The json.</param>
        /// <param name="remoteData">The remote data.</param>
        public override void ProcessJsonResponse(Dictionary <string, object> json, RemoteData remoteData)
        {
            object statusInfo = json.ValueOrDefault("StatusInfo");

            if (statusInfo != null)
            {
                this.ProcessErrorWithRemoteData(this.ErrorFromStatusInfo(statusInfo), remoteData);
                return;
            }

            List <string> changedRecords = null;
            List <string> messages       = json.ValueOrDefault("Messages") as List <string>;

            List <Dictionary <string, object> > changedRecordsFromServer = json.ValueOrDefault("ChangedRecords") as List <Dictionary <string, object> >;

            if (changedRecordsFromServer?.Count > 0)
            {
                changedRecords = new List <string>(changedRecordsFromServer.Count);
                foreach (Dictionary <string, object> record in changedRecordsFromServer)
                {
                    string recordIdentification;
                    object recordPart = record["RecordId"];
                    if (recordPart is long)
                    {
                        recordIdentification = StringExtensions.InfoAreaIdNumberRecordId((string)record["InfoAreaId"], (long)recordPart);
                    }
                    else
                    {
                        recordIdentification = StringExtensions.InfoAreaIdRecordId((string)record["InfoAreaId"], recordPart.ToString());
                    }

                    changedRecords.Add(recordIdentification);
                }
            }

            List <object> changedRecordData = json.ValueOrDefault("ChangedRecordsData") as List <object>;

            UPCRMRecordSync.SyncRecordSetDefinitions(changedRecordData);
            UPExecuteWorkflowResult executeWorkflowResult = new UPExecuteWorkflowResult(changedRecords, messages);

            this.TheDelegate.ExecuteWorkflowRequestDidFinishWithResult(this, executeWorkflowResult);
        }
Пример #3
0
        /// <summary>
        /// Synchronizes the with data dictionary.
        /// </summary>
        /// <param name="dataDict">
        /// The data dictionary.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        public int SyncWithDataObject(DataModelSyncDeserializer dataDict)
        {
            bool isEnterprise = false;
            var  licenseDef   = dataDict.licenseInfo;

            if (licenseDef != null)
            {
                // DDLogCRequest("Import LICENSEINFO");
                this.Logger.LogDebug("Import LICENSEINFO", LogFlag.LogRequests);
                Dictionary <string, object> licenseDefDictionary = licenseDef.ToDictionary();
                isEnterprise = bool.Parse(licenseDefDictionary.ValueOrDefault("IsEnterpriseVersion").ToString());
#if PORTING
                NSUserDefaults.StandardUserDefaults().SetBoolForKey(isEnterprise.BoolValue, "System.isEnterprise");
                NSUserDefaults.StandardUserDefaults().Synchronize();
#endif
            }

            var recordDef = dataDict.records;

            if (recordDef != null)
            {
                // DDLogCRequest("Import RECORDS");
                this.Logger.LogDebug("Import RECORDS", LogFlag.LogRequests);
                var recordSyncResult =
                    UPCRMRecordSync.SyncRecordSetDefinitionsCrmDataStore(recordDef, this.DataStore, isEnterprise);
                if (recordSyncResult.Successful)
                {
                    this.RecordCount += recordSyncResult.RecordCount;
                }
                else
                {
                    return(recordSyncResult.ReturnCode);
                }
            }

            return(0);
        }
Пример #4
0
        /// <summary>
        /// Synchronizes the with data dictionary.
        /// </summary>
        /// <param name="dataDict">
        /// The data dictionary.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        public int SyncWithDataDictionary(Dictionary <string, object> dataDict)
        {
            var fullSync     = false;
            var dataModelDef = dataDict.ValueOrDefault("dataModel") as JObject;

            if (dataModelDef != null)
            {
                // DDLogCRequest("Import DATAMODEL");
                this.Logger.LogDebug("Import DATAMODEL", LogFlag.LogRequests);
                var dataModelSync = new UPSyncDataModel(this.DataStore);

                dataModelSync.SyncWithDataModelDefinition(dataModelDef.ToObject <Dictionary <string, object> >());

                fullSync = true;
            }

            var            catalogDef  = dataDict.ValueOrDefault("fixedCatalogs") as JArray;
            UPSyncCatalogs catalogSync = null;

            if (catalogDef != null)
            {
                // DDLogCRequest("Import FIXED CATALOGS");
                this.Logger.LogDebug("Import FIXED CATALOGS", LogFlag.LogRequests);
                catalogSync = new UPSyncCatalogs(this.DataStore);
                catalogSync.SyncFixedCatalogs(catalogDef.ToObject <List <object> >());
            }

            catalogDef = dataDict.ValueOrDefault("variableCatalogs") as JArray;
            if (catalogDef != null)
            {
                // DDLogCRequest("Import VARIABLE CATALOGS");
                this.Logger.LogDebug("Import VARIABLE CATALOGS", LogFlag.LogRequests);
                if (catalogSync == null)
                {
                    catalogSync = new UPSyncCatalogs(this.DataStore);
                }

                catalogSync.SyncVariableCatalogs(catalogDef.ToObject <List <object> >());
            }

            var configurationDef = dataDict.ValueOrDefault("configuration") as JObject;

            if (configurationDef != null)
            {
                // DDLogCRequest("Import CONFIGURATION");
                this.Logger.LogDebug("Import CONFIGURATION", LogFlag.LogRequests);
                var configurationSync = new UPSyncConfiguration(this.ConfigStore);
                configurationSync.SyncWithConfigurationDefinition(configurationDef.ToObject <Dictionary <string, object> >());

                if (fullSync)
                {
                    var v = this.ConfigStore.ConfigValue("System.iOSServerTimeZone");
                    if (!string.IsNullOrEmpty(v))
                    {
                        this.DataStore.SetTimeZoneUtcDifference(v, 0);
                    }
                }
            }

            bool isEnterprise = false;
            var  licenseDef   = dataDict.ValueOrDefault("licenseInfo") as JObject;

            if (licenseDef != null)
            {
                // DDLogCRequest("Import LICENSEINFO");
                this.Logger.LogDebug("Import LICENSEINFO", LogFlag.LogRequests);
                Dictionary <string, object> licenseDefDictionary = licenseDef.ToObject <Dictionary <string, object> >();
                isEnterprise = bool.Parse(licenseDefDictionary.ValueOrDefault("IsEnterpriseVersion").ToString());
#if PORTING
                NSUserDefaults.StandardUserDefaults().SetBoolForKey(isEnterprise.BoolValue, "System.isEnterprise");
                NSUserDefaults.StandardUserDefaults().Synchronize();
#endif
            }

            var recordDef = dataDict.ValueOrDefault("records") as JArray;

            if (recordDef != null)
            {
                // DDLogCRequest("Import RECORDS");
                this.Logger.LogDebug("Import RECORDS", LogFlag.LogRequests);
                var recordSyncResult =
                    UPCRMRecordSync.SyncRecordSetDefinitionsCrmDataStore(recordDef.ToObject <List <object> >(), this.DataStore, isEnterprise);
                if (recordSyncResult.Successful)
                {
                    this.RecordCount += recordSyncResult.RecordCount;
                }
                else
                {
                    return(recordSyncResult.ReturnCode);
                }
            }

            var queryDef = dataDict.ValueOrDefault("queries");
            if (queryDef != null)
            {
                var querySync = new UPSyncQuery(this.DataStore);
                querySync.SyncWithQueryDefinition((List <object>)queryDef);
            }

            return(0);
        }