Example #1
0
        private void CopySelection()
        {
            if (m_selectionList.Count == 0)
            {
                return;
            }

            // We're going to copy the selection by serializing it to a json string. Before we serialize it
            // though, we're going to exclude a few members from being serialized as they're owned by the
            // editor, and irrelevent when pasted.
            var jsonResolver = new IgnorableSerializerContractResolver();

            jsonResolver.Ignore(typeof(WWorld));
            jsonResolver.Ignore(typeof(WScene));
            jsonResolver.Ignore(typeof(WUndoStack));
            jsonResolver.Ignore(typeof(SimpleObjRenderer));

            var jsonSettings = new JsonSerializerSettings();

            jsonSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            jsonSettings.TypeNameHandling      = TypeNameHandling.Auto;
            jsonSettings.ContractResolver      = jsonResolver;
            jsonSettings.Converters.Add(new Vector2Converter());
            jsonSettings.Converters.Add(new Vector3Converter());
            jsonSettings.Converters.Add(new QuaternionConverter());


            string serializedSelectionList = JsonConvert.SerializeObject(m_selectionList, jsonSettings);

            Clipboard.SetText(serializedSelectionList);
        }
Example #2
0
        public void SaveRig(string filename)
        {
            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.Error = (serializer, err) =>
            {
                err.ErrorContext.Handled = true;
            };

            var jsonResolver = new IgnorableSerializerContractResolver();

            // ignore single property
            jsonResolver.Ignore(typeof(IrrlichtLime.Core.Matrix));
            jsonResolver.Ignore(typeof(Vector3Df), "SphericalCoordinateAngles");
            jsonResolver.Ignore(typeof(Vector3Df), "HorizontalAngle");
            jsonResolver.Ignore(typeof(Vector3Df), "LengthSQ");
            jsonResolver.Ignore(typeof(Vector3Df), "Length");

            settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            settings.ContractResolver      = jsonResolver;
            //open file stream
            using (StreamWriter file = File.CreateText(filename))
            {
                string meshSkeletonJson = JsonConvert.SerializeObject(meshSkeleton, Formatting.Indented, settings);
                file.Write(meshSkeletonJson);
            }
        }
Example #3
0
    public static T To <T>(this object obj)
    {
        if (obj == null)
        {
            return(default(T));
        }

        var jsonResolver = new IgnorableSerializerContractResolver();

        var settings = new JsonSerializerSettings
        {
            ReferenceLoopHandling      = ReferenceLoopHandling.Ignore,
            PreserveReferencesHandling = PreserveReferencesHandling.None,
            Formatting        = Newtonsoft.Json.Formatting.Indented,
            ContractResolver  = jsonResolver,
            NullValueHandling = NullValueHandling.Ignore,
            TypeNameHandling  = TypeNameHandling.None,
            Binder            = new EntityFrameworkSerializationBinder()
        };
        string json = JsonConvert.SerializeObject(obj, settings);

        T res = JsonConvert.DeserializeObject <T>(json);

        return(res);
    }
        /// <summary>
        /// Prevents a default instance of the <see cref="HidePropertiesContext"/> class from being created.
        /// </summary>
        private HidePropertiesContext()
        {
            this.Configuration = HidePropertiesConfig.Current;

            // Ignore rule.id
            this.contractResolver = new IgnorableSerializerContractResolver().Ignore <Rule>(rule => rule.Id);

            instance = this;
        }
Example #5
0
        public WZController(IWZFactory wzFactory)
        {
            _wzFactory = wzFactory;

            IgnorableSerializerContractResolver resolver = new IgnorableSerializerContractResolver();

            resolver.Ignore <MapleVersion>(a => a.Location);

            serializerSettings = new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                ContractResolver      = resolver,
                Formatting            = Formatting.Indented
            };
        }
Example #6
0
        public ItemController()
        {
            IgnorableSerializerContractResolver resolver = new IgnorableSerializerContractResolver();

            resolver.Ignore <ItemNameInfo>(a => a.Info);
            resolver.Ignore <ItemType>(a => a.HighItemId);
            resolver.Ignore <ItemType>(a => a.LowItemId);

            serializerSettings = new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                ContractResolver      = resolver,
                Formatting            = Formatting.Indented
            };
        }
Example #7
0
        /// <summary>
        /// Processes the input request
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private async Task <APIGatewayProxyResponse> ProcessRequestAsync(APIGatewayProxyRequest request)
        {
            APIGatewayProxyResponse response = new APIGatewayProxyResponse();

            // Retrieve DisplayEndpointID from request path-parameters
            string displayEndpointIdRequestPathName = "display-endpoint-id";

            if (request?.PathParameters?.ContainsKey(displayEndpointIdRequestPathName) ?? false)
            {
                // Try to parse the provided UserID from string to long
                try
                {
                    _displayEndpointID = Convert.ToInt64(request.PathParameters[displayEndpointIdRequestPathName]);
                }
                catch (Exception ex)
                {
                    Context.Logger.LogLine("DisplayEndpointID conversion ERROR: " + ex.Message);
                }
            }

            // Validate the DisplayEndpointID
            if (1 > (_displayEndpointID ?? 0))
            {
                // Respond error
                Error error = new Error((int)HttpStatusCode.BadRequest)
                {
                    Description  = "Invalid ID supplied",
                    ReasonPharse = "Bad Request"
                };
                response.StatusCode = error.Code;
                response.Body       = JsonConvert.SerializeObject(error);
                Context.Logger.LogLine(error.Description);
            }
            else
            {
                // Initialize DataClient
                Config.DataClientConfig dataClientConfig = new Config.DataClientConfig(Config.DataClientConfig.RdsDbInfrastructure.Aws);
                using (_dataClient = new DataClient(dataClientConfig))
                {
                    // Get the DisplayEndpoint if exists in DB
                    DisplayEndpoint displayEndpoint = await GetDisplayEndpointAsync();

                    if (displayEndpoint != null)
                    {
                        // Retrieve Notification for the DisplayEndpoint (if any)
                        Notification notification = await GetNotificationAsync(displayEndpoint);

                        // Exclude undesired properties from the returning json object
                        var jsonResolver = new IgnorableSerializerContractResolver();
                        jsonResolver.Ignore(typeof(Notification), new string[] { "ClientSpot", "LocationDeviceNotifications", "DisplayEndpointNotifications" });
                        jsonResolver.Ignore(typeof(Coupon), new string[] { "ClientSpot", "Notification" });

                        // Respond OK
                        response.StatusCode = (int)HttpStatusCode.OK;
                        response.Headers    = new Dictionary <string, string>()
                        {
                            { " Access-Control-Allow-Origin", "'*'" }
                        };
                        response.Body = JsonConvert.SerializeObject(notification, jsonResolver.GetSerializerSettings());
                    }
                    else
                    {
                        // Respond error
                        Error error = new Error((int)HttpStatusCode.NotFound)
                        {
                            Description  = "DisplayEndpoint not found",
                            ReasonPharse = "DisplayEndpoint Not Found"
                        };
                        response.StatusCode = error.Code;
                        response.Body       = JsonConvert.SerializeObject(error);
                        Context.Logger.LogLine(error.Description);
                    }
                }
            }

            return(response);
        }
Example #8
0
        /// <summary>
        /// Processes the input request
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private async Task <APIGatewayProxyResponse> ProcessRequestAsync(APIGatewayProxyRequest request)
        {
            APIGatewayProxyResponse response = new APIGatewayProxyResponse();

            // Initialize DataClient
            Config.DataClientConfig dataClientConfig = new Config.DataClientConfig(Config.DataClientConfig.RdsDbInfrastructure.Aws);
            using (_dataClient = new DataClient(dataClientConfig))
            {
                Location location           = null;
                string   locationSerialized = request?.Body;
                // Try to parse the provided json serialzed location into Location object
                try
                {
                    location = JsonConvert.DeserializeObject <Location>(locationSerialized);
                    location.LocatedAtTimestamp = location.LocatedAtTimestamp ?? DateTime.UtcNow;
                }
                catch (Exception ex)
                {
                    Context.Logger.LogLine("Location deserialization ERROR: " + ex.Message);
                }

                // Validate the Location
                if (!(location == null || location.Type == LocationDeviceType.None || string.IsNullOrEmpty(location.DeviceID)))
                {
                    // Check if corresponding LocationDevice exists in DB
                    _locationDevice = await GetLocationDeviceFromLocationAsync(location);

                    if (_locationDevice != null)
                    {
                        var notificationToReturn = await UpdateDisplayConcurrentListAsync();

                        // Exclude undesired properties from the returning json object
                        var jsonResolver = new IgnorableSerializerContractResolver();
                        jsonResolver.Ignore(typeof(Notification), new string[] { "ClientSpot", "LocationDeviceNotifications", "DisplayEndpointNotifications", "Coupons" });

                        // Respond OK
                        response.StatusCode = (int)HttpStatusCode.OK;
                        response.Headers    = new Dictionary <string, string>()
                        {
                            { "Access-Control-Allow-Origin", "'*'" }
                        };
                        response.Body = JsonConvert.SerializeObject(notificationToReturn, jsonResolver.GetSerializerSettings());
                    }
                    else
                    {
                        // Respond error
                        Error error = new Error((int)HttpStatusCode.NotFound)
                        {
                            Description  = "LocationDevice not found",
                            ReasonPharse = "LocationDevice Not Found"
                        };
                        response.StatusCode = error.Code;
                        response.Body       = JsonConvert.SerializeObject(error);
                        Context.Logger.LogLine(error.Description);
                    }
                }
                else
                {
                    // Respond error
                    Error error = new Error((int)HttpStatusCode.NotAcceptable)
                    {
                        Description  = "Invalid Location input",
                        ReasonPharse = "Not Acceptable Location"
                    };
                    response.StatusCode = error.Code;
                    response.Body       = JsonConvert.SerializeObject(error);
                    Context.Logger.LogLine(error.Description);
                }
            }

            return(response);
        }
Example #9
0
        /// <summary>
        /// Processes the input request
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private async Task <APIGatewayProxyResponse> ProcessRequestAsync(APIGatewayProxyRequest request)
        {
            APIGatewayProxyResponse response = new APIGatewayProxyResponse();

            // Retrieve UserID from request path-parameters
            string userIdRequestPathName = "user-id";

            if (request?.PathParameters?.ContainsKey(userIdRequestPathName) ?? false)
            {
                // Try to parse the provided UserID from string to long
                try
                {
                    _userID = Convert.ToInt64(request.PathParameters[userIdRequestPathName]);
                }
                catch (Exception ex)
                {
                    Context.Logger.LogLine("UserID conversion ERROR: " + ex.Message);
                }
            }

            // Validate the UserID
            if (1 > (_userID ?? 0))
            {
                // Respond error
                Error error = new Error((int)HttpStatusCode.BadRequest)
                {
                    Description  = "Invalid ID supplied",
                    ReasonPharse = "Bad Request"
                };
                response.StatusCode = error.Code;
                response.Body       = JsonConvert.SerializeObject(error);
                Context.Logger.LogLine(error.Description);
            }
            else
            {
                // Initialize DataClient
                Config.DataClientConfig dataClientConfig = new Config.DataClientConfig(Config.DataClientConfig.RdsDbInfrastructure.Aws);
                using (_dataClient = new DataClient(dataClientConfig))
                {
                    // Check if User exists in DB
                    if (await IsUserExistsAsync())
                    {
                        Location location           = null;
                        string   locationSerialized = request?.Body;
                        // Try to parse the provided json serialzed location into Location object
                        try
                        {
                            location = JsonConvert.DeserializeObject <Location>(locationSerialized);
                            location.LocatedAtTimestamp = location.LocatedAtTimestamp ?? DateTime.UtcNow;
                        }
                        catch (Exception ex)
                        {
                            Context.Logger.LogLine("Location deserialization ERROR: " + ex.Message);
                        }

                        // Validate the Location
                        if (!(location == null || location.Type == LocationDeviceType.None || string.IsNullOrEmpty(location.DeviceID)))
                        {
                            // Process the Location
                            await AddLocationAysnc(location);

                            // Retrieve Coupons for the User (if any)
                            List <Coupon> coupons = await GetCouponsAsync();

                            if (coupons != null)
                            {
                                // Exclude undesired properties from the returning json object
                                var jsonResolver = new IgnorableSerializerContractResolver();
                                jsonResolver.Ignore(typeof(Coupon), new string[] { "ClientSpot", "Notification" });

                                // Respond OK
                                response.StatusCode = (int)HttpStatusCode.OK;
                                response.Headers    = new Dictionary <string, string>()
                                {
                                    { "Access-Control-Allow-Origin", "'*'" }
                                };
                                response.Body = JsonConvert.SerializeObject(coupons, jsonResolver.GetSerializerSettings());
                            }
                            else
                            {
                                Context.Logger.LogLine("List of Coupons is null");
                            }
                        }
                        else
                        {
                            // Respond error
                            Error error = new Error((int)HttpStatusCode.NotAcceptable)
                            {
                                Description  = "Invalid Location input",
                                ReasonPharse = "Not Acceptable Location"
                            };
                            response.StatusCode = error.Code;
                            response.Body       = JsonConvert.SerializeObject(error);
                            Context.Logger.LogLine(error.Description);
                        }
                    }
                    else
                    {
                        // Respond error
                        Error error = new Error((int)HttpStatusCode.NotFound)
                        {
                            Description  = "User not found",
                            ReasonPharse = "User Not Found"
                        };
                        response.StatusCode = error.Code;
                        response.Body       = JsonConvert.SerializeObject(error);
                        Context.Logger.LogLine(error.Description);
                    }
                }
            }

            return(response);
        }