Exemplo n.º 1
0
        public static Row UpdateRow(Row currentRow)
        {
            string url  = string.Format(CultureInfo.CurrentCulture, "/row/save/");
            string json = RowShareCommunication.PostData(url, currentRow);

            return(JsonUtilities.Deserialize <Row>(json, Utility.DefaultOptions));
        }
Exemplo n.º 2
0
        internal static AnnotationResultSummary GetResultSummaryFromSuccessInvocation(MemoryStream payload)
        {
            var    annotationResult = JsonUtilities.Deserialize <AnnotationResult>(payload);
            string errorMessage     = annotationResult.errorCategory == null ? null : annotationResult.status;

            return(AnnotationResultSummary.Create(annotationResult, annotationResult.errorCategory, errorMessage));
        }
Exemplo n.º 3
0
        public GoogleNearby(double lat, double lng) : this()
        {
            using (var client = new WebClient())
            {
                client.Encoding = Encoding.UTF8;
                string json = client.DownloadString(string.Format(apiUrlFormat, lat, lng));

                var baseResponse = JsonUtilities.Deserialize <GoogleNearbyAPIBase>(json);

                if (baseResponse.results != null)
                {
                    List <SubwayStation> stations = JsonUtilities.Deserialize <List <SubwayStation> >(System.IO.File.ReadAllText(HostingEnvironment.MapPath("~/App_Data/ratp.json")));
                    foreach (GoogleNearbyAPIResult result in baseResponse.results)
                    {
                        var station = stations.First(s => s.station == result.name || s.alias == result.name);
                        if (Subways.Count(s => s.name == station.station) == 0)
                        {
                            var nearbyStation = new GoogleNearbyStation();
                            nearbyStation.name = station.station;
                            foreach (string line in station.lines)
                            {
                                nearbyStation.lines.Add(line);
                            }
                            Subways.Add(nearbyStation);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public static Row GetRowById(string id)
        {
            string url  = string.Format(CultureInfo.CurrentCulture, "/row/load/{0}", id);
            string json = RowShareCommunication.GetData(url);

            return(JsonUtilities.Deserialize <Row>(json, Utility.DefaultOptions));
        }
Exemplo n.º 5
0
        public static Collection <Row> GetRowsByListId(string id)
        {
            string url  = string.Format(CultureInfo.CurrentCulture, "row/loadForParent/{0}", id);
            string json = RowShareCommunication.GetData(url);

            return(JsonUtilities.Deserialize <Collection <Row> >(json, Utility.DefaultOptions));
        }
        static public void ValidateDatabase(string text)
        {
            var server = new Microsoft.AnalysisServices.Tabular.Server();

            server.ID   = "ID";
            server.Name = "Name";

            var database = JsonUtilities.Deserialize(text);

            server.Databases.Add(database);

            var errors = new ValidationErrorCollection();

            server.Validate(errors);
            Assert.AreEqual(0, errors.Count);

            database.Validate(errors);
            Assert.AreEqual(0, errors.Count);

            var result = database.Model.Validate();

            Assert.AreEqual(0, result.Errors.Count,
                            string.Join(Environment.NewLine,
                                        result.Errors.Select(
                                            error => error.Message
                                            )
                                        )
                            );
        }
Exemplo n.º 7
0
 public void Load(string jsonFilename)
 {
     foreach (var element in JsonUtilities.Deserialize <CanvasElement[]>(jsonFilename, true))
     {
         Add(element);
     }
 }
Exemplo n.º 8
0
        public static Collection <Column> GetColumnsByListId(string id)
        {
            string url  = string.Format(CultureInfo.CurrentCulture, "/column/loadForParent/{0}", id);
            string json = RowShareCommunication.GetData(url);

            return(JsonUtilities.Deserialize <Collection <Column> >(json));
        }
Exemplo n.º 9
0
        public static Column GetColumnById(string id)
        {
            string url  = string.Format(CultureInfo.CurrentCulture, "/column/load/", id);
            string json = RowShareCommunication.GetData(url);

            return(JsonUtilities.Deserialize <Column>(json));
        }
Exemplo n.º 10
0
        public void Load(string filename)
        {
            elements.Clear();
            elements.AddRange(JsonUtilities.Deserialize <HudElement[]>(filename, true));

            foreach (HudElement element in elements)
            {
                Alignments alignment = element.Alignment;

                int offsetX = element.OffsetX;
                int offsetY = element.OffsetY;
                int x       = (alignment & Alignments.Left) == Alignments.Left
                                        ? offsetX
                                        : (alignment & Alignments.Right) == Alignments.Right
                                                ? Resolution.Width - offsetX
                                                : Resolution.Width / 2 + offsetX;

                int y = (alignment & Alignments.Top) == Alignments.Top
                                        ? offsetY
                                        : (alignment & Alignments.Bottom) == Alignments.Bottom
                                                ? Resolution.Height - offsetY
                                                : Resolution.Height / 2 + offsetY;

                element.Position = new Vector2(x, y);
                element.Initialize();
            }
        }
Exemplo n.º 11
0
        public FoursquareVenue(string urlOrId)
        {
            string id = "";

            if (urlOrId.StartsWith("http")) // parameter is URL
            {
                // example : https://fr.foursquare.com/v/abracadabar/4c77fcf0a8683704d6b40b4d
                id = urlOrId.Split('/').Last();
            }
            else // paremeter id ID
            {
                id = urlOrId;
            }

            using (var client = new WebClient())
            {
                client.Encoding = Encoding.UTF8;
                string json = client.DownloadString(string.Format(apiUrlFormat, id));

                var baseResponse = JsonUtilities.Deserialize <FoursquareAPIBase>(json);
                var response     = baseResponse.response;
                //return response.venue;
                Id = response.venue.id;
                if (response.venue.contact.ContainsKey("phone"))
                {
                    Phone = response.venue.contact["phone"];
                }
                Website = response.venue.url;
                Menu    = response.venue.menu?.url;
                Price   = response.venue.price?.tier ?? 0;
            }
        }
Exemplo n.º 12
0
        public static RowShareUser LoadUser(string userName, string password)
        {
            var json   = RowShareCommunication.GetData("user", userName, password);
            var rsUser = JsonUtilities.Deserialize <RowShareUser>(json, Utility.DefaultOptions);

            return(rsUser);
        }
Exemplo n.º 13
0
        public override void Initialize()
        {
            var data   = JsonUtilities.Deserialize <CardData[]>("Cards.json");
            var random = new Random();

            scene        = new SimpleScene2D();
            scene.Camera = Camera;
            scene.Canvas = Canvas;

            hand  = new Hand(scene);
            board = new Board();

            for (int i = 0; i < 10; i++)
            {
                hand.Add(new Card(data[random.Next(data.Length)], false));
            }

            InputProcessor.Add(full =>
            {
                if (!full.TryGetData(out MouseData mouse))
                {
                    return;
                }

                if (mouse.Query(GLFW.GLFW_MOUSE_BUTTON_LEFT, InputStates.PressedThisFrame))
                {
                    board.PlayerLane.Add(hand.Play(0));
                }
            });
        }
Exemplo n.º 14
0
        public static List GetListById(string id)
        {
            string url  = string.Format(CultureInfo.CurrentCulture, "list/load/{0}", id);
            string json = RowShareCommunication.GetData(url);

            return(JsonUtilities.Deserialize <List>(json));
        }
Exemplo n.º 15
0
        private void TreeViewImportList_Click(object sender, RoutedEventArgs e)
        {
            var folder = TV.GetSelectedTag <Folder>();

            if (folder == null)
            {
                return;
            }

            var dlg = new OpenFileDialog();

            dlg.AddExtension     = true;
            dlg.CheckPathExists  = true;
            dlg.CheckPathExists  = true;
            dlg.DefaultExt       = ".json";
            dlg.RestoreDirectory = true;
            dlg.Title            = "Choose a list to import";
            dlg.Filter           = "JSON files (*.json)|*.json|All files (*.*)|*.*";
            dlg.FilterIndex      = 1;
            if (dlg.ShowDialog(this).GetValueOrDefault())
            {
                string s   = File.ReadAllText(dlg.FileName, Encoding.UTF8);
                var    lwr = JsonUtilities.Deserialize <ListWithRows>(s);
                if (lwr.List != null)
                {
                    string name        = lwr.List.DisplayName;
                    bool   showOptions = false;
                    if (folder.HasLazyChild)
                    {
                        folder.LazyLoadChildren();
                    }

                    var  list         = folder.Children.OfType <List>().FirstOrDefault(l => l.DisplayName.EqualsIgnoreCase(name));
                    List existingList = list;
                    int  i            = 1;
                    while (list != null)
                    {
                        showOptions = true;
                        name        = lwr.List.DisplayName + " - Copy(" + i + ")";
                        list        = folder.Children.OfType <List>().FirstOrDefault(l => l.DisplayName.EqualsIgnoreCase(name));
                        i++;
                    }

                    var def = new ImportOptionsDefinition(lwr.List, existingList, name);
                    if (showOptions)
                    {
                        var options = new ImportOptions(def);
                        options.Owner = this;
                        if (!options.ShowDialog().GetValueOrDefault())
                        {
                            return;
                        }
                    }

                    lwr.Import(folder, name, def);
                    this.ShowMessage("Ok");
                }
            }
        }
Exemplo n.º 16
0
        public object PostCall(ServerCallParameters parameters, object targetObject, object parent, object data)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            string sdata = SerializeData(data);

            using (var client = new CookieWebClient())
            {
                if (Cookie != null)
                {
                    client.Cookies.Add(new Cookie(CookieName, Cookie, "/", new Uri(Url).Host));
                }

                var uri = new EditableUri(Url + "/api/" + parameters.Api);

                if (parameters.Lcid != 0)
                {
                    uri.Parameters["l"] = parameters.Lcid;
                }
                client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
                client.Encoding = Encoding.UTF8;

                string s;
                try
                {
                    s = client.UploadString(uri.ToString(), sdata);
                }
                catch (WebException e)
                {
                    if (ShowMessageBoxOnError)
                    {
                        var eb = new ErrorBox(e, e.GetErrorText(null));
                        eb.ShowDialog();
                    }
                    throw;
                }

                var options = new JsonUtilitiesOptions();
                options.CreateInstanceCallback = (e) =>
                {
                    var type = (Type)e.Value;
                    if (typeof(TreeItem).IsAssignableFrom(type))
                    {
                        e.Value   = Activator.CreateInstance(type, new object[] { parent });
                        e.Handled = true;
                    }
                };

                if (targetObject != null)
                {
                    JsonUtilities.Deserialize(s, targetObject, options);
                    return(null);
                }
                return(JsonUtilities.Deserialize(s));
            }
        }
Exemplo n.º 17
0
        public Scene()
        {
            layers = JsonUtilities.Deserialize <SceneLayer[]>("Layers.json");

            // Lists are instantiated within the array as needed.
            addLists    = new List <Entity> [layers.Length];
            removeLists = new List <Entity> [layers.Length];
        }
Exemplo n.º 18
0
        public object Call(ServerCallParameters parameters, object targetObject, object parent)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            using (var client = new CookieWebClient())
            {
                if (Cookie != null)
                {
                    client.Cookies.Add(new Cookie(CookieName, Cookie, "/", new Uri(Url).Host));
                }

                var uri = new EditableUri(Url + "/api/" + parameters.Api);
                if (!string.IsNullOrWhiteSpace(parameters.Format))
                {
                    uri.Parameters["f"] = parameters.Format;
                }

                if (parameters.Lcid != 0)
                {
                    uri.Parameters["l"] = parameters.Lcid;
                }

                client.Encoding = Encoding.UTF8;

                string s;
                try
                {
                    s = client.DownloadString(uri.ToString());
                }
                catch (WebException e)
                {
                    var eb = new ErrorBox(e, e.GetErrorText(null));
                    eb.ShowDialog();
                    throw;
                }

                var options = new JsonUtilitiesOptions();
                options.CreateInstanceCallback = (e) =>
                {
                    Type type = (Type)e.Value;
                    if (typeof(TreeItem).IsAssignableFrom(type))
                    {
                        e.Value   = Activator.CreateInstance(type, new object[] { parent });
                        e.Handled = true;
                    }
                };

                if (targetObject != null)
                {
                    JsonUtilities.Deserialize(s, targetObject, options);
                    return(null);
                }
                return(JsonUtilities.Deserialize(s));
            }
        }
Exemplo n.º 19
0
 private static void LoadSettings()
 {
     try
     {
         RuntimeSettings = JsonUtilities.Deserialize <ProgramSettings>(File.ReadAllText(ProgramSettings.SaveSettingsDirectory + @"\settings.txt"));
         VisualsSettings.ApplyVisuals(RuntimeSettings.VisualSettings);
     }
     catch { Reset(); }
 }
Exemplo n.º 20
0
 public static UserSettings From(string path)
 {
     if (!File.Exists(path))
     {
         return(new UserSettings());
     }
     return(JsonUtilities.Deserialize <UserSettings>(path)
            ?? new UserSettings());
 }
Exemplo n.º 21
0
        public GoogleItineraryBase GetItinerary(GeoCoordinate positionA, GeoCoordinate positionB)
        {
            using (var client = new WebClient())
            {
                client.Encoding = Encoding.UTF8;
                string json = client.DownloadString(string.Format(apiUrlFormat, positionA.Latitude, positionA.Longitude, positionB.Latitude, positionB.Longitude));

                var baseResponse = JsonUtilities.Deserialize <GoogleItineraryBase>(json);
                return(baseResponse);
            }
        }
Exemplo n.º 22
0
        public static Animation Load(string filename)
        {
            Animation animation;

            if (!cache.TryGetValue(filename, out animation))
            {
                animation = JsonUtilities.Deserialize <Animation>("Animations/" + filename);
                cache.Add(filename, animation);
            }

            return(animation);
        }
Exemplo n.º 23
0
        public void Load(string filename, bool shouldClear = false)
        {
            if (shouldClear)
            {
                Clear();
            }

            foreach (var element in JsonUtilities.Deserialize <CanvasElement[]>(filename, true))
            {
                Add(element);
            }
        }
Exemplo n.º 24
0
 private static Product ProductFromDocument(Document document)
 {
     return(new Product(document["id"].AsGuid())
     {
         Sku = document["sku"].AsString(),
         Name = document["name"].AsString(),
         ShortDescription = document["shortDescription"].AsString(),
         LongDescription = document["longDescription"].AsString(),
         ImageUrl = document["imageUrl"].AsString(),
         Price = JsonUtilities.Deserialize <ProductPrice>(document["price"])
     });
 }
Exemplo n.º 25
0
        public static Folder GetFolderById(string id)
        {
            if (id == null)
            {
                return(null);
            }

            string url  = string.Format(CultureInfo.CurrentCulture, "folder/load/{0}", id.ToString().Replace("-", ""));
            string json = RowShareCommunication.GetData(url);

            return(JsonUtilities.Deserialize <Folder>(json, Utility.DefaultOptions));
        }
Exemplo n.º 26
0
        public static Dictionary <int, AttackData> Load(string filename)
        {
            var map    = JsonUtilities.Deserialize <Dictionary <string, AttackData> >("Combat/" + filename);
            var hashed = new Dictionary <int, AttackData>();

            // Attack names are internal, so they're stored using hash codes rather than the raw string.=
            foreach (var pair in map)
            {
                hashed.Add(pair.Key.GetHashCode(), pair.Value);
            }

            return(hashed);
        }
Exemplo n.º 27
0
        public AttackCollection(string filename, T parent)
        {
            Debug.Assert(parent != null, "Can't create an attack collection with a null parent.");

            var map = JsonUtilities.Deserialize <Dictionary <string, AttackData> >("Combat/" + filename);

            attacks = new Dictionary <int, Attack <T> >();

            // Attack names are internal, so they're stored using hash codes rather than the raw string.
            foreach (var pair in map)
            {
                attacks.Add(pair.Key.GetHashCode(), pair.Value.CreateAttack(parent));
            }
        }
Exemplo n.º 28
0
        public Collection <List> LoadFavoriteLists()
        {
            var json     = RowShareCommunication.GetData("userlistlink/loadall");
            var favList  = JsonUtilities.Deserialize <Collection <FavoriteList> >(json, Utility.DefaultOptions);
            var toReturn = new Collection <List>();

            foreach (var fav in favList)
            {
                if (fav.IsFavorite)
                {
                    toReturn.Add(fav.List);
                }
            }
            return(toReturn);
        }
Exemplo n.º 29
0
 private Cart CartFromDocument(Document document)
 {
     return(new Cart(document["id"].AsGuid())
     {
         CustomerId = document["customerId"].AsString(),
         Status = document["status"].AsString(),
         Items = JsonUtilities.Deserialize <List <dynamic> >(document["items"].AsString())
                 .Select(item => JObject.Parse(item.ToString()))
                 .Select(item => new CartItem(Guid.Parse(item.id.ToString()))
         {
             Price = long.Parse(item.price.ToString()),
             Scale = long.Parse(item.scale.ToString()),
             CurrencyCode = item.currencyCode.ToString()
         }).ToList()
     });
 }
Exemplo n.º 30
0
        public static MeasuresContainer ParseJson(string text)
        {
            try
            {
                var database = JsonUtilities.Deserialize(text);
                Debug.Assert(database != null);

                return(CreateFromDatabase(database));
            }
            catch (Exception exception)
            {
                throw new DaxException(
                          $@"Error while parsing Json:
Message: {exception.Message}
Input text: {text}", exception);
            }
        }