public virtual void Construct(UserProfileDataObject userProfile, bool includeDirtyObjectsOnly)
        {
            if (userProfile == null)
            {
                return;
            }

            this.PrimaryKey = userProfile.PrimaryKey;

            if (userProfile.ObjectsDataSet == null)
            {
                var dataset = ApplicationSettings.Container.Resolve <IObjectsDataSet>();
                dataset.AddObject(userProfile);
            }

            if (userProfile.ObjectsDataSet == null)
            {
                _logEngine.LogError("Unable to set a dataset to the Entity UserProfile", "Unable to set a dataset to the entity. Container may not be initialized", "UserProfileDataObject", null);
                throw new PulpException("Unexpected Error : Unable to set a dataset to the entity : UserProfile");
            }

            if (userProfile.InternalObjectId == null)
            {
                _logEngine.LogError("Unable to construct an object without InternalObjectId in UserProfileDataObject", "The Object you are trying to construct doesn't have an InternalObjectId", "UserProfileDataObject", null);
                throw new PulpException("Unexpected Error : Unable to construct an object without InternalObjectId in UserProfileDataObject");
            }
            this.InternalObjectId = (int)userProfile.InternalObjectId;
            this.ObjectsDataSet   = includeDirtyObjectsOnly ? userProfile.ObjectsDataSet.CloneDirtyObjects() : userProfile.ObjectsDataSet;
        }
        public virtual void Construct(PlaceToLocationDataObject placeToLocation, bool includeDirtyObjectsOnly)
        {
            if (placeToLocation == null)
            {
                return;
            }

            this.PrimaryKey = placeToLocation.PrimaryKeysCollection;

            if (placeToLocation.ObjectsDataSet == null)
            {
                var dataset = ApplicationSettings.Container.Resolve <IObjectsDataSet>();
                dataset.AddObject(placeToLocation);
            }

            if (placeToLocation.ObjectsDataSet == null)
            {
                _logEngine.LogError("Unable to set a dataset to the Entity PlaceToLocation", "Unable to set a dataset to the entity. Container may not be initialized", "PlaceToLocationDataObject", null);
                throw new PulpException("Unexpected Error : Unable to set a dataset to the entity : PlaceToLocation");
            }

            if (placeToLocation.InternalObjectId == null)
            {
                _logEngine.LogError("Unable to construct an object without InternalObjectId in PlaceToLocationDataObject", "The Object you are trying to construct doesn't have an InternalObjectId", "PlaceToLocationDataObject", null);
                throw new PulpException("Unexpected Error : Unable to construct an object without InternalObjectId in PlaceToLocationDataObject");
            }
            this.InternalObjectId = (int)placeToLocation.InternalObjectId;
            this.ObjectsDataSet   = includeDirtyObjectsOnly ? placeToLocation.ObjectsDataSet.CloneDirtyObjects() : placeToLocation.ObjectsDataSet;
        }
        public virtual GOUserDataObject LoadGOUser(Parameters parameters, bool skipSecurity = false)
        {
            if (this.ObjectsDataSet == null)
            {
                _logEngine.LogError("Unable to Load Related Data", "Unable to Load Related Data GOUser for the current entity. The DataObjects doesn't have an ObjectsDataSet", "UserProfileObjectsDataSet", null);
                throw new PulpException("Unable to Load Related Data. The current Data Object doesn't have an ObjectsDataSet");
            }

            var gOUser = (this.ObjectsDataSet as ObjectsDataSet).GOUserObjects == null ? null : (this.ObjectsDataSet as ObjectsDataSet).GOUserObjects.Where(item => item.Value.UserName == Uri).SingleOrDefault().Value;

            // If null relation => load the entity
            if (ReferenceEquals(gOUser, null) && !__gOUserCurrentLoading)
            {
                __gOUserCurrentLoading = true;
                var filterPredicate = "UserName == \"" + Uri + "\"";

                gOUser = ApplicationSettings.Container.Resolve <IDataProvider <GOUserDataObject> >().GetCollection(null, filterPredicate, parameters: parameters, skipSecurity: skipSecurity).SingleOrDefault();

                SetGOUserValue(gOUser, false, false);
                __gOUserCurrentLoading = false;
            }

            // Patch for what is most likely an internal dataset fault when the relation field is on PK side of a OneToOne relation
            // If we've got a gOUser, but relation field not set, encourage it to get set by removing and re-adding the gOUser
            if (gOUser != null && this.GOUser == null)
            {
                this.ObjectsDataSet.RemoveObject(gOUser);
                this.ObjectsDataSet.AddObject(gOUser);
            }

            // Return the object was added to our dataset, not the 'temporary' instance that was loaded via the Get()
            return(gOUser == null ? null : ObjectsDataSet.GetObject(gOUser));
        }
        private void GroupRoleItems_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
                case NotifyCollectionChangedAction.Add:
                    foreach (var item in e.NewItems)
                    {
						var relatedObj = item as GOGroupRoleDataObject;
						if (relatedObj == null)
						{
							_logEngine.LogError("Add Event throw an Exception", "Unable to get value of expected related Object : GOGroupRole", "GOGroupDataObject.GroupRoleItems_CollectionChanged", null);
							throw new PulpException("Unexpected Error : The Add Event of GOGroupDataObject throw an exception while trying to add GOGroupRoleDataObject : NullReference occured");
						}

						if (this.IsNew)
						{
							relatedObj._group_NewObjectId = this.InternalObjectId;
						}
						else
						{
							relatedObj.GOGroupName = this.Name;
						}
 
						if (relatedObj.IsNew && relatedObj.GOGroupName == default(System.String))
							relatedObj.GOGroupName = this.Name;
                    }
                    break;
                case NotifyCollectionChangedAction.Remove:
                    // foreach (var item in e.OldItems)
                    // {
                        //(item as GOGroupRoleDataObject).Group = null;
                    // }
                    break;
            }            
        }
		public virtual void Construct(GOGroupDataObject gOGroup, bool includeDirtyObjectsOnly)
		{
            if (gOGroup == null)
                return;

			this.PrimaryKey = gOGroup.PrimaryKey;
			
            if (gOGroup.ObjectsDataSet == null)
            {
                var dataset = ApplicationSettings.Container.Resolve<IObjectsDataSet>();
                dataset.AddObject(gOGroup);
            }

			if(gOGroup.ObjectsDataSet == null)
			{
				_logEngine.LogError("Unable to set a dataset to the Entity GOGroup", "Unable to set a dataset to the entity. Container may not be initialized", "GOGroupDataObject", null);
				throw new PulpException("Unexpected Error : Unable to set a dataset to the entity : GOGroup");
			}

			if(gOGroup.InternalObjectId == null)
			{
				_logEngine.LogError("Unable to construct an object without InternalObjectId in GOGroupDataObject", "The Object you are trying to construct doesn't have an InternalObjectId", "GOGroupDataObject", null);
				throw new PulpException("Unexpected Error : Unable to construct an object without InternalObjectId in GOGroupDataObject");
			}
			this.InternalObjectId = (int) gOGroup.InternalObjectId;
			this.ObjectsDataSet = includeDirtyObjectsOnly ? gOGroup.ObjectsDataSet.CloneDirtyObjects() : gOGroup.ObjectsDataSet;
		}
        private void PlaceToLocationItems_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                foreach (var item in e.NewItems)
                {
                    var relatedObj = item as PlaceToLocationDataObject;
                    if (relatedObj == null)
                    {
                        _logEngine.LogError("Add Event throw an Exception", "Unable to get value of expected related Object : PlaceToLocation", "PlaceDataObject.PlaceToLocationItems_CollectionChanged", null);
                        throw new PulpException("Unexpected Error : The Add Event of PlaceDataObject throw an exception while trying to add PlaceToLocationDataObject : NullReference occured");
                    }

                    if (this.IsNew)
                    {
                        relatedObj._place_NewObjectId = this.InternalObjectId;
                    }
                    else
                    {
                        relatedObj.PlaceURI = this.URI;
                    }

                    if (relatedObj.IsNew && relatedObj.PlaceURI == default(System.String))
                    {
                        relatedObj.PlaceURI = this.URI;
                    }
                }
                break;

            case NotifyCollectionChangedAction.Remove:
                // foreach (var item in e.OldItems)
                // {
                //(item as PlaceToLocationDataObject).Place = null;
                // }
                break;
            }
        }
        public override void AddObject(IDataObject objectToAdd, bool replaceIfExists)
        {
            var existingObject = GetObject(objectToAdd);

            if (!replaceIfExists && existingObject != null)
            {
                throw new PulpException("Object already exists");
            }

            int newInternalId;

            if (existingObject != null)
            {
                //RemoveObject(existingObject);
                if (existingObject.InternalObjectId == null)
                {
                    _logEngine.LogError("Error while trying to Add Object to the GOUserObjectsDataSet", "The object you are trying to add doesn't have an InternalObjectId", "GOUserObjectsDataSet", null);
                    throw new PulpException("Error while trying to add an object to the dataset without InternalObjectId");
                }
                newInternalId = (int)existingObject.InternalObjectId;
                objectToAdd.InternalObjectId = newInternalId;
                existingObject.CopyValuesFrom(objectToAdd, false);
            }
            else
            {
                newInternalId = GetNextNewInternalObjectId();
                objectToAdd.InternalObjectId = newInternalId;

                var completed = false;
                var count     = 0;
                while (!completed && count++ < 15)
                {
                    completed = GOUserObjects.TryAdd(newInternalId, (GOUserDataObject)objectToAdd);
                }
            }

            if (!objectToAdd.IsNew && existingObject == null)
            {
                //The following if should not be necessary...
                var completed = false;
                if (GOUserObjectInternalIds.ContainsKey(((GOUserDataObject)objectToAdd).PrimaryKey))
                {
                    int value;
                    var count2 = 0;
                    while (!completed && count2++ < 15)
                    {
                        completed = GOUserObjectInternalIds.TryRemove(((GOUserDataObject)objectToAdd).PrimaryKey, out value);
                    }
                }

                completed = false;
                var count = 0;
                while (!completed && count++ < 15)
                {
                    completed = GOUserObjectInternalIds.TryAdd(((GOUserDataObject)objectToAdd).PrimaryKey, newInternalId);
                }
            }
            // Update relations including platform as "many" side or "one" side , pk side for one to one relations
            if ((objectToAdd as GOUserDataObject) == null)
            {
                _logEngine.LogError("Unable to Add an object which is null", "Unable to add an object which is null", "GOUserDataObject", null);
                throw new PulpException("Unexpected Error: Unable to Add an object which is Null.");
            }


            // Update the UserProfile FK Index
            if ((objectToAdd as GOUserDataObject).UserName != null)
            {
                if (!UserProfile_FKIndex.ContainsKey((System.String)(objectToAdd as GOUserDataObject).UserName))
                {
                    var iscompleted = false;
                    var count2      = 0;
                    while (!iscompleted && count2++ < 15)
                    {
                        iscompleted = UserProfile_FKIndex.TryAdd((System.String)(objectToAdd as GOUserDataObject).UserName, new List <int>());
                    }
                }

                if (!UserProfile_FKIndex[(System.String)(objectToAdd as GOUserDataObject).UserName].Contains(newInternalId))
                {
                    UserProfile_FKIndex[(System.String)(objectToAdd as GOUserDataObject).UserName].Add(newInternalId);
                }

                UserProfileDataObject relatedUserProfile;
                if ((objectToAdd as GOUserDataObject)._userProfile_NewObjectId != null)
                {
                    relatedUserProfile = _rootObjectDataSet.GetObject(new UserProfileDataObject()
                    {
                        IsNew = true, InternalObjectId = (objectToAdd as GOUserDataObject)._userProfile_NewObjectId
                    });
                }
                else
                {
                    relatedUserProfile = _rootObjectDataSet.GetObject(new UserProfileDataObject((System.String)(objectToAdd as GOUserDataObject).UserName)
                    {
                        IsNew = false
                    });
                }

                if (relatedUserProfile != null && this.RootObjectDataSet.NotifyChanges)
                {
                    relatedUserProfile.NotifyPropertyChanged("GOUser", new SeenObjectCollection());
                }
            }
        }
        public virtual void SetLocationValue(LocationDataObject valueToSet, bool notifyChanges, bool dirtyHandlerOn)
        {
            LocationDataObject existing_location = null;

            if (!(this.LocationURI == null || ObjectsDataSet == null))
            {
                var key = this._location_NewObjectId == null ? new LocationDataObject(this.LocationURI)
                {
                    IsNew = false
                } : new LocationDataObject()
                {
                    IsNew = true, InternalObjectId = this._location_NewObjectId
                };
                existing_location = (LocationDataObject)ObjectsDataSet.GetObject(key);
            }

            if (ReferenceEquals(existing_location, valueToSet))
            {
                return;
            }
            // Give opportunity to change value before set
            OnBeforeSetRelationField("Location", valueToSet);

            // Setting the navigator desync the FK. The FK should be resync
            if (!ReferenceEquals(null, valueToSet))
            {
                if (ObjectsDataSet == null)
                {
                    _logEngine.LogError("Unable to set Relation Field", "Unable to set Relation Field, your entity doesn't have a DataSet.", "PlaceToLocationDataObject", null);
                    throw new PulpException("Unable to set Relation fields, your entity doesn't have a DataSet");
                }

                ObjectsDataSet.AddObjectIfDoesNotExist(valueToSet);

                if (valueToSet.IsNew)
                {
                    if (_location_NewObjectId != valueToSet.InternalObjectId)
                    {
                        _location_NewObjectId = valueToSet.InternalObjectId;
                        _locationURI          = valueToSet.URI;
                        OnPropertyChanged("LocationURI", notifyChanges, dirtyHandlerOn);
                    }
                }
                else
                {
                    if (_locationURI != valueToSet.URI)
                    {
                        _location_NewObjectId = null;

                        _locationURI = valueToSet.URI;
                        OnPropertyChanged("LocationURI", notifyChanges, dirtyHandlerOn);
                    }
                }
            }
            else
            {
                _locationURI = null;
                OnPropertyChanged("LocationURI", notifyChanges, dirtyHandlerOn);
            }
            if (!ReferenceEquals(existing_location, valueToSet))
            {
                OnPropertyChanged("Location", notifyChanges, dirtyHandlerOn);
            }
        }
        public virtual void SetGroupValue(GOGroupDataObject valueToSet, bool notifyChanges, bool dirtyHandlerOn)
        {
            GOGroupDataObject existing_group = null;

            if (!(this.GOGroupName == null || ObjectsDataSet == null))
            {
                var key = this._group_NewObjectId == null ? new GOGroupDataObject(this.GOGroupName)
                {
                    IsNew = false
                } : new GOGroupDataObject()
                {
                    IsNew = true, InternalObjectId = this._group_NewObjectId
                };
                existing_group = (GOGroupDataObject)ObjectsDataSet.GetObject(key);
            }

            if (ReferenceEquals(existing_group, valueToSet))
            {
                return;
            }
            // Give opportunity to change value before set
            OnBeforeSetRelationField("Group", valueToSet);

            // Setting the navigator desync the FK. The FK should be resync
            if (!ReferenceEquals(null, valueToSet))
            {
                if (ObjectsDataSet == null)
                {
                    _logEngine.LogError("Unable to set Relation Field", "Unable to set Relation Field, your entity doesn't have a DataSet.", "GOGroupRoleDataObject", null);
                    throw new PulpException("Unable to set Relation fields, your entity doesn't have a DataSet");
                }

                ObjectsDataSet.AddObjectIfDoesNotExist(valueToSet);

                if (valueToSet.IsNew)
                {
                    if (_group_NewObjectId != valueToSet.InternalObjectId)
                    {
                        _group_NewObjectId = valueToSet.InternalObjectId;
                        _gOGroupName       = valueToSet.Name;
                        OnPropertyChanged("GOGroupName", notifyChanges, dirtyHandlerOn);
                    }
                }
                else
                {
                    if (_gOGroupName != valueToSet.Name)
                    {
                        _group_NewObjectId = null;

                        _gOGroupName = valueToSet.Name;
                        OnPropertyChanged("GOGroupName", notifyChanges, dirtyHandlerOn);
                    }
                }
            }
            else
            {
                _gOGroupName = null;
                OnPropertyChanged("GOGroupName", notifyChanges, dirtyHandlerOn);
            }
            if (!ReferenceEquals(existing_group, valueToSet))
            {
                OnPropertyChanged("Group", notifyChanges, dirtyHandlerOn);
            }
        }
Exemplo n.º 10
0
        public override void AddObject(IDataObject objectToAdd, bool replaceIfExists)
        {
            var existingObject = GetObject(objectToAdd);

            if (!replaceIfExists && existingObject != null)
            {
                throw new PulpException("Object already exists");
            }

            int newInternalId;

            if (existingObject != null)
            {
                //RemoveObject(existingObject);
                if (existingObject.InternalObjectId == null)
                {
                    _logEngine.LogError("Error while trying to Add Object to the GORoleObjectsDataSet", "The object you are trying to add doesn't have an InternalObjectId", "GORoleObjectsDataSet", null);
                    throw new PulpException("Error while trying to add an object to the dataset without InternalObjectId");
                }
                newInternalId = (int)existingObject.InternalObjectId;
                objectToAdd.InternalObjectId = newInternalId;
                existingObject.CopyValuesFrom(objectToAdd, false);
            }
            else
            {
                newInternalId = GetNextNewInternalObjectId();
                objectToAdd.InternalObjectId = newInternalId;

                var completed = false;
                var count     = 0;
                while (!completed && count++ < 15)
                {
                    completed = GORoleObjects.TryAdd(newInternalId, (GORoleDataObject)objectToAdd);
                }
            }

            if (!objectToAdd.IsNew && existingObject == null)
            {
                //The following if should not be necessary...
                var completed = false;
                if (GORoleObjectInternalIds.ContainsKey(((GORoleDataObject)objectToAdd).PrimaryKey))
                {
                    int value;
                    var count2 = 0;
                    while (!completed && count2++ < 15)
                    {
                        completed = GORoleObjectInternalIds.TryRemove(((GORoleDataObject)objectToAdd).PrimaryKey, out value);
                    }
                }

                completed = false;
                var count = 0;
                while (!completed && count++ < 15)
                {
                    completed = GORoleObjectInternalIds.TryAdd(((GORoleDataObject)objectToAdd).PrimaryKey, newInternalId);
                }
            }
            // Update relations including platform as "many" side or "one" side , pk side for one to one relations
            if ((objectToAdd as GORoleDataObject) == null)
            {
                _logEngine.LogError("Unable to Add an object which is null", "Unable to add an object which is null", "GORoleDataObject", null);
                throw new PulpException("Unexpected Error: Unable to Add an object which is Null.");
            }
        }
        public override void DoProcessRequest(HttpContext context)
        {
            Exception error = null;

            try
            {
                // Set response headers
                context.Response.ContentType     = "application/json";
                context.Response.ContentEncoding = Encoding.UTF8;

                // Notify 'request begins' to extensions
                Extensions.OnRequestAction(new ApiExtensionResponseData {
                    action = context.Request.HttpMethod, context = "BEGIN", data = null
                });

                // Extract request parts via an ApiRequest wrapper
                ApiRequest request      = new ApiRequest(context);
                bool       isDatasetAPI = request.IsDatasetApi;
                string     methodName   = request.MethodName;

                // Enable GZip Compression if client support it
                AddGZipCompression(context, request.AcceptGZip);

                switch (context.Request.HttpMethod)
                {
                case "GET":
                case "POST":
                {
                    switch (methodName)
                    {
                    case "registerbyemail":
                    {
                        // Notify Extensions
                        {
                            var args = new Dictionary <string, string>()
                            {
                                { "email", context.Request["email"] },
                                { "password", "********" },
                            };

                            // Notify method call to extensions
                            Extensions.OnRequestAction(new ApiExtensionResponseData {
                                        action = "RegisterByEmail", context = "BEFORE_CALL", data = JsonConvert.SerializeObject(args)
                                    });
                        }

                        var result = JsonGOSecurityProviderService.RegisterByEmail(String.IsNullOrEmpty(context.Request["email"]) ? null : Convert.ToString(context.Request["email"]), String.IsNullOrEmpty(context.Request["password"]) ? null : Convert.ToString(context.Request["password"]));
                        // Seralise result
                        string json = JsonConvert.SerializeObject(result, GetSerializationSettings(false));
                        // Notify result to extensions
                        Extensions.OnRequestAction(new ApiExtensionResponseData {
                                    action = "RegisterByEmail", context = "JSON", data = json
                                });

                        WriteResponse(context, json);
                    }
                    break;

                    case "authorizenavigationto":
                    {
                        // Notify Extensions
                        {
                            var args = new Dictionary <string, string>()
                            {
                                { "nodeName", context.Request["nodeName"] },
                            };

                            // Notify method call to extensions
                            Extensions.OnRequestAction(new ApiExtensionResponseData {
                                        action = "AuthorizeNavigationTo", context = "BEFORE_CALL", data = JsonConvert.SerializeObject(args)
                                    });
                        }

                        var result = JsonGOSecurityProviderService.AuthorizeNavigationTo(String.IsNullOrEmpty(context.Request["nodeName"]) ? null : Convert.ToString(context.Request["nodeName"]));
                        // Seralise result
                        string json = JsonConvert.SerializeObject(result, GetSerializationSettings(false));
                        // Notify result to extensions
                        Extensions.OnRequestAction(new ApiExtensionResponseData {
                                    action = "AuthorizeNavigationTo", context = "JSON", data = json
                                });

                        WriteResponse(context, json);
                    }
                    break;

                    case "validateregistration":
                    {
                        // Notify Extensions
                        {
                            var args = new Dictionary <string, string>()
                            {
                                { "token", context.Request["token"] },
                            };

                            // Notify method call to extensions
                            Extensions.OnRequestAction(new ApiExtensionResponseData {
                                        action = "ValidateRegistration", context = "BEFORE_CALL", data = JsonConvert.SerializeObject(args)
                                    });
                        }

                        var result = JsonGOSecurityProviderService.ValidateRegistration(String.IsNullOrEmpty(context.Request["token"]) ? null : Convert.ToString(context.Request["token"]));
                        // Seralise result
                        string json = JsonConvert.SerializeObject(result, GetSerializationSettings(false));
                        // Notify result to extensions
                        Extensions.OnRequestAction(new ApiExtensionResponseData {
                                    action = "ValidateRegistration", context = "JSON", data = json
                                });

                        WriteResponse(context, json);
                    }
                    break;

                    case "logout":
                    {
                        // Notify Extensions
                        {
                            var args = new Dictionary <string, string>()
                            {
                                { "useCookies", context.Request["useCookies"] },
                            };

                            // Notify method call to extensions
                            Extensions.OnRequestAction(new ApiExtensionResponseData {
                                        action = "LogOut", context = "BEFORE_CALL", data = JsonConvert.SerializeObject(args)
                                    });
                        }

                        var result = JsonGOSecurityProviderService.LogOut(String.IsNullOrEmpty(context.Request["useCookies"]) ? false : Convert.ToBoolean(context.Request["useCookies"]));
                        // Seralise result
                        string json = JsonConvert.SerializeObject(result, GetSerializationSettings(false));
                        // Notify result to extensions
                        Extensions.OnRequestAction(new ApiExtensionResponseData {
                                    action = "LogOut", context = "JSON", data = json
                                });

                        WriteResponse(context, json);
                    }
                    break;

                    case "unregister":
                    {
                        // Notify Extensions
                        {
                            var args = new Dictionary <string, string>()
                            {
                                { "email", context.Request["email"] },
                            };

                            // Notify method call to extensions
                            Extensions.OnRequestAction(new ApiExtensionResponseData {
                                        action = "Unregister", context = "BEFORE_CALL", data = JsonConvert.SerializeObject(args)
                                    });
                        }

                        var result = JsonGOSecurityProviderService.Unregister(String.IsNullOrEmpty(context.Request["email"]) ? null : Convert.ToString(context.Request["email"]));
                        // Seralise result
                        string json = JsonConvert.SerializeObject(result, GetSerializationSettings(false));
                        // Notify result to extensions
                        Extensions.OnRequestAction(new ApiExtensionResponseData {
                                    action = "Unregister", context = "JSON", data = json
                                });

                        WriteResponse(context, json);
                    }
                    break;

                    case "authenticate":
                    {
                        // Notify Extensions
                        {
                            var args = new Dictionary <string, string>()
                            {
                                { "username", context.Request["username"] },
                                { "password", "********" },
                                { "useCookies", context.Request["useCookies"] },
                            };

                            // Notify method call to extensions
                            Extensions.OnRequestAction(new ApiExtensionResponseData {
                                        action = "Authenticate", context = "BEFORE_CALL", data = JsonConvert.SerializeObject(args)
                                    });
                        }

                        var result = JsonGOSecurityProviderService.Authenticate(String.IsNullOrEmpty(context.Request["username"]) ? null : Convert.ToString(context.Request["username"]), String.IsNullOrEmpty(context.Request["password"]) ? null : Convert.ToString(context.Request["password"]), String.IsNullOrEmpty(context.Request["useCookies"]) ? false : Convert.ToBoolean(context.Request["useCookies"]));

                        // Seralise result, if not already json encoded string
                        string json = result;

                        if (!IsJson(result))
                        {
                            json = JsonConvert.SerializeObject(result, GetSerializationSettings(false));
                        }

                        // Notify result to extensions
                        Extensions.OnRequestAction(new ApiExtensionResponseData {
                                    action = "Authenticate", context = "JSON", data = json
                                });

                        WriteResponse(context, json);
                    }
                    break;

                    case "registerfull":
                    {
                        // Notify Extensions
                        {
                            var args = new Dictionary <string, string>()
                            {
                                { "firstname", context.Request["firstname"] },
                                { "lastname", context.Request["lastname"] },
                                { "email", context.Request["email"] },
                                { "password", "********" },
                            };

                            // Notify method call to extensions
                            Extensions.OnRequestAction(new ApiExtensionResponseData {
                                        action = "RegisterFull", context = "BEFORE_CALL", data = JsonConvert.SerializeObject(args)
                                    });
                        }

                        var result = JsonGOSecurityProviderService.RegisterFull(String.IsNullOrEmpty(context.Request["firstname"]) ? null : Convert.ToString(context.Request["firstname"]), String.IsNullOrEmpty(context.Request["lastname"]) ? null : Convert.ToString(context.Request["lastname"]), String.IsNullOrEmpty(context.Request["email"]) ? null : Convert.ToString(context.Request["email"]), String.IsNullOrEmpty(context.Request["password"]) ? null : Convert.ToString(context.Request["password"]));
                        // Seralise result
                        string json = JsonConvert.SerializeObject(result, GetSerializationSettings(false));
                        // Notify result to extensions
                        Extensions.OnRequestAction(new ApiExtensionResponseData {
                                    action = "RegisterFull", context = "JSON", data = json
                                });

                        WriteResponse(context, json);
                    }
                    break;

                    case "resetpassword":
                    {
                        // Notify Extensions
                        {
                            var args = new Dictionary <string, string>()
                            {
                                { "password", "********" },
                                { "token", context.Request["token"] },
                            };

                            // Notify method call to extensions
                            Extensions.OnRequestAction(new ApiExtensionResponseData {
                                        action = "ResetPassword", context = "BEFORE_CALL", data = JsonConvert.SerializeObject(args)
                                    });
                        }

                        var result = JsonGOSecurityProviderService.ResetPassword(String.IsNullOrEmpty(context.Request["password"]) ? null : Convert.ToString(context.Request["password"]), String.IsNullOrEmpty(context.Request["token"]) ? null : Convert.ToString(context.Request["token"]));
                        // Seralise result
                        string json = JsonConvert.SerializeObject(result, GetSerializationSettings(false));
                        // Notify result to extensions
                        Extensions.OnRequestAction(new ApiExtensionResponseData {
                                    action = "ResetPassword", context = "JSON", data = json
                                });

                        WriteResponse(context, json);
                    }
                    break;

                    case "lostpassword":
                    {
                        // Notify Extensions
                        {
                            var args = new Dictionary <string, string>()
                            {
                                { "email", context.Request["email"] },
                            };

                            // Notify method call to extensions
                            Extensions.OnRequestAction(new ApiExtensionResponseData {
                                        action = "LostPassword", context = "BEFORE_CALL", data = JsonConvert.SerializeObject(args)
                                    });
                        }

                        var result = JsonGOSecurityProviderService.LostPassword(String.IsNullOrEmpty(context.Request["email"]) ? null : Convert.ToString(context.Request["email"]));
                        // Seralise result
                        string json = JsonConvert.SerializeObject(result, GetSerializationSettings(false));
                        // Notify result to extensions
                        Extensions.OnRequestAction(new ApiExtensionResponseData {
                                    action = "LostPassword", context = "JSON", data = json
                                });

                        WriteResponse(context, json);
                    }
                    break;

                    case "blockuser":
                    {
                        // Notify Extensions
                        {
                            var args = new Dictionary <string, string>()
                            {
                                { "email", context.Request["email"] },
                                { "block", context.Request["block"] },
                            };

                            // Notify method call to extensions
                            Extensions.OnRequestAction(new ApiExtensionResponseData {
                                        action = "BlockUser", context = "BEFORE_CALL", data = JsonConvert.SerializeObject(args)
                                    });
                        }

                        var result = JsonGOSecurityProviderService.BlockUser(String.IsNullOrEmpty(context.Request["email"]) ? null : Convert.ToString(context.Request["email"]), String.IsNullOrEmpty(context.Request["block"]) ? false : Convert.ToBoolean(context.Request["block"]));
                        // Seralise result
                        string json = JsonConvert.SerializeObject(result, GetSerializationSettings(false));
                        // Notify result to extensions
                        Extensions.OnRequestAction(new ApiExtensionResponseData {
                                    action = "BlockUser", context = "JSON", data = json
                                });

                        WriteResponse(context, json);
                    }
                    break;

                    case "register":
                    {
                        // Notify Extensions
                        {
                            var args = new Dictionary <string, string>()
                            {
                                { "username", context.Request["username"] },
                                { "email", context.Request["email"] },
                                { "password", "********" },
                            };

                            // Notify method call to extensions
                            Extensions.OnRequestAction(new ApiExtensionResponseData {
                                        action = "Register", context = "BEFORE_CALL", data = JsonConvert.SerializeObject(args)
                                    });
                        }

                        var result = JsonGOSecurityProviderService.Register(String.IsNullOrEmpty(context.Request["username"]) ? null : Convert.ToString(context.Request["username"]), String.IsNullOrEmpty(context.Request["email"]) ? null : Convert.ToString(context.Request["email"]), String.IsNullOrEmpty(context.Request["password"]) ? null : Convert.ToString(context.Request["password"]));
                        // Seralise result
                        string json = JsonConvert.SerializeObject(result, GetSerializationSettings(false));
                        // Notify result to extensions
                        Extensions.OnRequestAction(new ApiExtensionResponseData {
                                    action = "Register", context = "JSON", data = json
                                });

                        WriteResponse(context, json);
                    }
                    break;

                    case "keepalive":
                    {
                        // Notify Extensions
                        {
                            var args = new Dictionary <string, string>()
                            {
                            };

                            // Notify method call to extensions
                            Extensions.OnRequestAction(new ApiExtensionResponseData {
                                        action = "KeepAlive", context = "BEFORE_CALL", data = JsonConvert.SerializeObject(args)
                                    });
                        }

                        JsonGOSecurityProviderService.KeepAlive();
                        context.Response.StatusCode = (int)HttpStatusCode.NoContent;
                    }
                    break;

                    case "changepassword":
                    {
                        // Notify Extensions
                        {
                            var args = new Dictionary <string, string>()
                            {
                                { "userId", context.Request["userId"] },
                                { "oldPassword", context.Request["oldPassword"] },
                                { "newPassword", context.Request["newPassword"] },
                                { "useCookies", context.Request["useCookies"] },
                            };

                            // Notify method call to extensions
                            Extensions.OnRequestAction(new ApiExtensionResponseData {
                                        action = "ChangePassword", context = "BEFORE_CALL", data = JsonConvert.SerializeObject(args)
                                    });
                        }

                        var result = JsonGOSecurityProviderService.ChangePassword(String.IsNullOrEmpty(context.Request["userId"]) ? null : Convert.ToString(context.Request["userId"]), String.IsNullOrEmpty(context.Request["oldPassword"]) ? null : Convert.ToString(context.Request["oldPassword"]), String.IsNullOrEmpty(context.Request["newPassword"]) ? null : Convert.ToString(context.Request["newPassword"]), String.IsNullOrEmpty(context.Request["useCookies"]) ? false : Convert.ToBoolean(context.Request["useCookies"]));
                        // Seralise result
                        string json = JsonConvert.SerializeObject(result, GetSerializationSettings(false));
                        // Notify result to extensions
                        Extensions.OnRequestAction(new ApiExtensionResponseData {
                                    action = "ChangePassword", context = "JSON", data = json
                                });

                        WriteResponse(context, json);
                    }
                    break;

                    case "approveuser":
                    {
                        // Notify Extensions
                        {
                            var args = new Dictionary <string, string>()
                            {
                                { "email", context.Request["email"] },
                            };

                            // Notify method call to extensions
                            Extensions.OnRequestAction(new ApiExtensionResponseData {
                                        action = "ApproveUser", context = "BEFORE_CALL", data = JsonConvert.SerializeObject(args)
                                    });
                        }

                        var result = JsonGOSecurityProviderService.ApproveUser(String.IsNullOrEmpty(context.Request["email"]) ? null : Convert.ToString(context.Request["email"]));
                        // Seralise result
                        string json = JsonConvert.SerializeObject(result, GetSerializationSettings(false));
                        // Notify result to extensions
                        Extensions.OnRequestAction(new ApiExtensionResponseData {
                                    action = "ApproveUser", context = "JSON", data = json
                                });

                        WriteResponse(context, json);
                    }
                    break;

                    default:
                        _logEngine.LogError("Unknown json method: " + methodName, "Unknown json method: " + methodName, "JsonGOSecurityProviderServiceHandler", null);
                        throw new PulpException("Unknow json method: " + methodName);
                    }
                }
                break;

                case "OPTIONS":
                    return;

                default:
                    throw new InvalidOperationException("Invalid Verb " + context.Request.HttpMethod);
                }
            }
            catch (Exception exception)
            {
                error = exception;

                // Notify to extensions and re-throw
                Extensions.OnRequestAction(new ApiExtensionResponseData {
                    action = "EXCEPTION", context = exception.GetType().Name, data = exception.ToString(), error = true
                });
                throw;
            }
            finally
            {
                // Check no transaction left running
                DatabaseTransaction.AbortAnyOngoingTransaction(error);
            }
        }
Exemplo n.º 12
0
        public override void AddObject(IDataObject objectToAdd, bool replaceIfExists)
        {
            var existingObject = GetObject(objectToAdd);

            if (!replaceIfExists && existingObject != null)
            {
                throw new PulpException("Object already exists");
            }

            int newInternalId;

            if (existingObject != null)
            {
                //RemoveObject(existingObject);
                if (existingObject.InternalObjectId == null)
                {
                    _logEngine.LogError("Error while trying to Add Object to the PlaceToLocationObjectsDataSet", "The object you are trying to add doesn't have an InternalObjectId", "PlaceToLocationObjectsDataSet", null);
                    throw new PulpException("Error while trying to add an object to the dataset without InternalObjectId");
                }
                newInternalId = (int)existingObject.InternalObjectId;
                objectToAdd.InternalObjectId = newInternalId;
                existingObject.CopyValuesFrom(objectToAdd, false);
            }
            else
            {
                newInternalId = GetNextNewInternalObjectId();
                objectToAdd.InternalObjectId = newInternalId;

                var completed = false;
                var count     = 0;
                while (!completed && count++ < 15)
                {
                    completed = PlaceToLocationObjects.TryAdd(newInternalId, (PlaceToLocationDataObject)objectToAdd);
                }
            }

            if (!objectToAdd.IsNew && existingObject == null)
            {
                //The following if should not be necessary...
                var completed = false;
                if (PlaceToLocationObjectInternalIds.ContainsKey(((PlaceToLocationDataObject)objectToAdd).PrimaryKeysCollection))
                {
                    int value;
                    var count2 = 0;
                    while (!completed && count2++ < 15)
                    {
                        completed = PlaceToLocationObjectInternalIds.TryRemove(((PlaceToLocationDataObject)objectToAdd).PrimaryKeysCollection, out value);
                    }
                }

                completed = false;
                var count = 0;
                while (!completed && count++ < 15)
                {
                    completed = PlaceToLocationObjectInternalIds.TryAdd(((PlaceToLocationDataObject)objectToAdd).PrimaryKeysCollection, newInternalId);
                }
            }
            // Update relations including platform as "many" side or "one" side , pk side for one to one relations
            if ((objectToAdd as PlaceToLocationDataObject) == null)
            {
                _logEngine.LogError("Unable to Add an object which is null", "Unable to add an object which is null", "PlaceToLocationDataObject", null);
                throw new PulpException("Unexpected Error: Unable to Add an object which is Null.");
            }

            // Update the Location FK Index
            if ((objectToAdd as PlaceToLocationDataObject).LocationURI != null)
            {
                if (!Location_FKIndex.ContainsKey((objectToAdd as PlaceToLocationDataObject).LocationURI))
                {
                    var iscompleted = false;
                    var count2      = 0;
                    while (!iscompleted && count2++ < 15)
                    {
                        iscompleted = Location_FKIndex.TryAdd((objectToAdd as PlaceToLocationDataObject).LocationURI, new List <int>());
                    }
                }

                if (!Location_FKIndex[(objectToAdd as PlaceToLocationDataObject).LocationURI].Contains(newInternalId))
                {
                    Location_FKIndex[(objectToAdd as PlaceToLocationDataObject).LocationURI].Add(newInternalId);
                }

                LocationDataObject relatedLocation;
                if ((objectToAdd as PlaceToLocationDataObject)._location_NewObjectId != null)
                {
                    relatedLocation = _rootObjectDataSet.GetObject(new LocationDataObject()
                    {
                        IsNew = true, InternalObjectId = (objectToAdd as PlaceToLocationDataObject)._location_NewObjectId
                    });
                }
                else
                {
                    relatedLocation = _rootObjectDataSet.GetObject(new LocationDataObject((objectToAdd as PlaceToLocationDataObject).LocationURI)
                    {
                        IsNew = false
                    });
                }

                if (relatedLocation != null && this.RootObjectDataSet.NotifyChanges)
                {
                    relatedLocation.NotifyPropertyChanged("PlaceToLocationItems", new SeenObjectCollection());
                }
            }

            // Update the Place FK Index
            if ((objectToAdd as PlaceToLocationDataObject).PlaceURI != null)
            {
                if (!Place_FKIndex.ContainsKey((objectToAdd as PlaceToLocationDataObject).PlaceURI))
                {
                    var iscompleted = false;
                    var count2      = 0;
                    while (!iscompleted && count2++ < 15)
                    {
                        iscompleted = Place_FKIndex.TryAdd((objectToAdd as PlaceToLocationDataObject).PlaceURI, new List <int>());
                    }
                }

                if (!Place_FKIndex[(objectToAdd as PlaceToLocationDataObject).PlaceURI].Contains(newInternalId))
                {
                    Place_FKIndex[(objectToAdd as PlaceToLocationDataObject).PlaceURI].Add(newInternalId);
                }

                PlaceDataObject relatedPlace;
                if ((objectToAdd as PlaceToLocationDataObject)._place_NewObjectId != null)
                {
                    relatedPlace = _rootObjectDataSet.GetObject(new PlaceDataObject()
                    {
                        IsNew = true, InternalObjectId = (objectToAdd as PlaceToLocationDataObject)._place_NewObjectId
                    });
                }
                else
                {
                    relatedPlace = _rootObjectDataSet.GetObject(new PlaceDataObject((objectToAdd as PlaceToLocationDataObject).PlaceURI)
                    {
                        IsNew = false
                    });
                }

                if (relatedPlace != null && this.RootObjectDataSet.NotifyChanges)
                {
                    relatedPlace.NotifyPropertyChanged("PlaceToLocationItems", new SeenObjectCollection());
                }
            }
        }
        public override void DoProcessRequest(HttpContext context)
        {
            Exception error = null;

            try
            {
                // Set response headers
                context.Response.ContentType     = "application/json";
                context.Response.ContentEncoding = Encoding.UTF8;

                // Notify 'request begins' to extensions
                Extensions.OnRequestAction(new ApiExtensionResponseData {
                    action = context.Request.HttpMethod, context = "BEGIN", data = null
                });

                // Extract request parts via an ApiRequest wrapper
                ApiRequest request      = new ApiRequest(context);
                bool       isDatasetAPI = request.IsDatasetApi;
                string     methodName   = request.MethodName;

                // Enable GZip Compression if client support it
                AddGZipCompression(context, request.AcceptGZip);

                switch (context.Request.HttpMethod)
                {
                case "GET":
                case "POST":
                {
                    switch (methodName)
                    {
                    case "getembeddedreporturl":
                    {
                        // Notify Extensions
                        {
                            var args = new Dictionary <string, string>()
                            {
                                { "reportId", context.Request["reportId"] },
                                { "payload", context.Request["payload"] },
                            };

                            // Notify method call to extensions
                            Extensions.OnRequestAction(new ApiExtensionResponseData {
                                        action = "GetEmbeddedReportUrl", context = "BEFORE_CALL", data = JsonConvert.SerializeObject(args)
                                    });
                        }

                        var result = JsonGOReportsHelperService.GetEmbeddedReportUrl(String.IsNullOrEmpty(context.Request["reportId"]) ? Guid.Empty : Guid.Parse(context.Request["reportId"]), String.IsNullOrEmpty(context.Request["payload"]) ? null : Convert.ToString(context.Request["payload"]));

                        // Seralise result, if not already json encoded string
                        string json = result;

                        if (!IsJson(result))
                        {
                            json = JsonConvert.SerializeObject(result, GetSerializationSettings(false));
                        }

                        // Notify result to extensions
                        Extensions.OnRequestAction(new ApiExtensionResponseData {
                                    action = "GetEmbeddedReportUrl", context = "JSON", data = json
                                });

                        WriteResponse(context, json);
                    }
                    break;

                    default:
                        _logEngine.LogError("Unknown json method: " + methodName, "Unknown json method: " + methodName, "JsonGOReportsHelperServiceHandler", null);
                        throw new PulpException("Unknow json method: " + methodName);
                    }
                }
                break;

                case "OPTIONS":
                    return;

                default:
                    throw new InvalidOperationException("Invalid Verb " + context.Request.HttpMethod);
                }
            }
            catch (Exception exception)
            {
                error = exception;

                // Notify to extensions and re-throw
                Extensions.OnRequestAction(new ApiExtensionResponseData {
                    action = "EXCEPTION", context = exception.GetType().Name, data = exception.ToString(), error = true
                });
                throw;
            }
            finally
            {
                // Check no transaction left running
                DatabaseTransaction.AbortAnyOngoingTransaction(error);
            }
        }